Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat(tag): Add tag response the tag slug name

LinkinStarsa90495c9f1a2
diff --git a/docs/docs.go b/docs/docs.go
index 1dedea4d..9f73acfa 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -3932,6 +3932,38 @@ const docTemplate = `{
}
}
},
+ "post": {
+ "description": "add tag",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Tag"
+ ],
+ "summary": "add tag",
+ "parameters": [
+ {
+ "description": "tag",
+ "name": "data",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/schema.AddTagReq"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ },
"delete": {
"description": "delete tag",
"consumes": [
@@ -5545,6 +5577,30 @@ const docTemplate = `{
}
}
},
+ "schema.AddTagReq": {
+ "type": "object",
+ "required": [
+ "display_name",
+ "original_text",
+ "slug_name"
+ ],
+ "properties": {
+ "display_name": {
+ "description": "display_name",
+ "type": "string",
+ "maxLength": 35
+ },
+ "original_text": {
+ "description": "original text",
+ "type": "string"
+ },
+ "slug_name": {
+ "description": "slug_name",
+ "type": "string",
+ "maxLength": 35
+ }
+ }
+ },
"schema.AddUserReq": {
"type": "object",
"required": [
@@ -7173,6 +7229,9 @@ const docTemplate = `{
},
"theme": {
"$ref": "#/definitions/schema.SiteThemeResp"
+ },
+ "version": {
+ "type": "string"
}
}
},
diff --git a/docs/swagger.json b/docs/swagger.json
index ca8d737d..3ebb716e 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -3920,6 +3920,38 @@
}
}
},
+ "post": {
+ "description": "add tag",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Tag"
+ ],
+ "summary": "add tag",
+ "parameters": [
+ {
+ "description": "tag",
+ "name": "data",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/schema.AddTagReq"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ },
"delete": {
"description": "delete tag",
"consumes": [
@@ -5533,6 +5565,30 @@
}
}
},
+ "schema.AddTagReq": {
+ "type": "object",
+ "required": [
+ "display_name",
+ "original_text",
+ "slug_name"
+ ],
+ "properties": {
+ "display_name": {
+ "description": "display_name",
+ "type": "string",
+ "maxLength": 35
+ },
+ "original_text": {
+ "description": "original text",
+ "type": "string"
+ },
+ "slug_name": {
+ "description": "slug_name",
+ "type": "string",
+ "maxLength": 35
+ }
+ }
+ },
"schema.AddUserReq": {
"type": "object",
"required": [
@@ -7161,6 +7217,9 @@
},
"theme": {
"$ref": "#/definitions/schema.SiteThemeResp"
+ },
+ "version": {
+ "type": "string"
}
}
},
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index da69a617..e0561059 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -174,6 +174,24 @@ definitions:
- object_id
- report_type
type: object
+ schema.AddTagReq:
+ properties:
+ display_name:
+ description: display_name
+ maxLength: 35
+ type: string
+ original_text:
+ description: original text
+ type: string
+ slug_name:
+ description: slug_name
+ maxLength: 35
+ type: string
+ required:
+ - display_name
+ - original_text
+ - slug_name
+ type: object
schema.AddUserReq:
properties:
display_name:
@@ -1335,6 +1353,8 @@ definitions:
$ref: '#/definitions/schema.SiteSeoReq'
theme:
$ref: '#/definitions/schema.SiteThemeResp'
+ version:
+ type: string
type: object
schema.SiteInterfaceReq:
properties:
@@ -4284,6 +4304,27 @@ paths:
summary: get tag one
tags:
- Tag
+ post:
+ consumes:
+ - application/json
+ description: add tag
+ parameters:
+ - description: tag
+ in: body
+ name: data
+ required: true
+ schema:
+ $ref: '#/definitions/schema.AddTagReq'
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/handler.RespBody'
+ summary: add tag
+ tags:
+ - Tag
put:
consumes:
- application/json
diff --git a/internal/controller/tag_controller.go b/internal/controller/tag_controller.go
index 70e63d20..55edc8ec 100644
--- a/internal/controller/tag_controller.go
+++ b/internal/controller/tag_controller.go
@@ -126,12 +126,8 @@ func (tc *TagController) AddTag(ctx *gin.Context) {
return
}
- err = tc.tagCommonService.AddTag(ctx, req)
- if err != nil {
- handler.HandleResponse(ctx, err, nil)
- } else {
- handler.HandleResponse(ctx, err, nil)
- }
+ resp, err := tc.tagCommonService.AddTag(ctx, req)
+ handler.HandleResponse(ctx, err, resp)
}
// UpdateTag update tag
diff --git a/internal/schema/tag_schema.go b/internal/schema/tag_schema.go
index c5d1c7c1..f4c61a74 100644
--- a/internal/schema/tag_schema.go
+++ b/internal/schema/tag_schema.go
@@ -168,7 +168,7 @@ type AddTagReq struct {
// display_name
DisplayName string `validate:"required,gt=0,lte=35" json:"display_name"`
// original text
- OriginalText string `validate:"required" json:"original_text"`
+ OriginalText string `validate:"required,gt=0,lte=65536" json:"original_text"`
// parsed text
ParsedText string `json:"-"`
// user id
@@ -177,12 +177,13 @@ type AddTagReq struct {
func (req *AddTagReq) Check() (errFields []*validator.FormErrorField, err error) {
req.ParsedText = converter.Markdown2HTML(req.OriginalText)
+ req.SlugName = strings.ToLower(req.SlugName)
return nil, nil
}
// AddTagResp add tag response
type AddTagResp struct {
- TagID string `json:"tag_id"`
+ SlugName string `json:"slug_name"`
}
// UpdateTagReq update tag request
diff --git a/internal/service/tag_common/tag_common.go b/internal/service/tag_common/tag_common.go
index 82148b53..094ce594 100644
--- a/internal/service/tag_common/tag_common.go
+++ b/internal/service/tag_common/tag_common.go
@@ -223,13 +223,13 @@ func (ts *TagCommonService) GetObjectTag(ctx context.Context, objectId string) (
}
// AddTag get object tag
-func (ts *TagCommonService) AddTag(ctx context.Context, req *schema.AddTagReq) (err error) {
+func (ts *TagCommonService) AddTag(ctx context.Context, req *schema.AddTagReq) (resp *schema.AddTagResp, err error) {
_, exist, err := ts.GetTagBySlugName(ctx, req.SlugName)
if err != nil {
- return err
+ return nil, err
}
if exist {
- return errors.BadRequest(reason.TagAlreadyExist)
+ return nil, errors.BadRequest(reason.TagAlreadyExist)
}
tagInfo := &entity.Tag{
SlugName: req.SlugName,
@@ -240,7 +240,11 @@ func (ts *TagCommonService) AddTag(ctx context.Context, req *schema.AddTagReq) (
UserID: req.UserID,
}
tagList := []*entity.Tag{tagInfo}
- return ts.tagCommonRepo.AddTagList(ctx, tagList)
+ err = ts.tagCommonRepo.AddTagList(ctx, tagList)
+ if err != nil {
+ return nil, err
+ }
+ return &schema.AddTagResp{SlugName: tagInfo.SlugName}, nil
}
// AddTagList get object tag