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

This commit is contained in:
LinkinStars 2023-03-03 14:40:30 +08:00
parent ee3fb56d54
commit a90495c9f1
6 changed files with 172 additions and 12 deletions

View File

@ -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"
}
}
},

View File

@ -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"
}
}
},

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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