Merge branch 'ai/0.4.0/tag' into 'test'

Ai/0.4.0/tag

See merge request opensource/answer!255
This commit is contained in:
aichy 2022-11-17 11:28:36 +00:00
commit 7336bae653
5 changed files with 95 additions and 30 deletions

View File

@ -6393,6 +6393,10 @@ const docTemplate = `{
}, },
"schema.UserEmailLogin": { "schema.UserEmailLogin": {
"type": "object", "type": "object",
"required": [
"e_mail",
"pass"
],
"properties": { "properties": {
"captcha_code": { "captcha_code": {
"description": "captcha_code", "description": "captcha_code",
@ -6404,11 +6408,14 @@ const docTemplate = `{
}, },
"e_mail": { "e_mail": {
"description": "e_mail", "description": "e_mail",
"type": "string" "type": "string",
"maxLength": 500
}, },
"pass": { "pass": {
"description": "password", "description": "password",
"type": "string" "type": "string",
"maxLength": 32,
"minLength": 8
} }
} }
}, },

View File

@ -6381,6 +6381,10 @@
}, },
"schema.UserEmailLogin": { "schema.UserEmailLogin": {
"type": "object", "type": "object",
"required": [
"e_mail",
"pass"
],
"properties": { "properties": {
"captcha_code": { "captcha_code": {
"description": "captcha_code", "description": "captcha_code",
@ -6392,11 +6396,14 @@
}, },
"e_mail": { "e_mail": {
"description": "e_mail", "description": "e_mail",
"type": "string" "type": "string",
"maxLength": 500
}, },
"pass": { "pass": {
"description": "password", "description": "password",
"type": "string" "type": "string",
"maxLength": 32,
"minLength": 8
} }
} }
}, },

View File

@ -1484,10 +1484,16 @@ definitions:
type: string type: string
e_mail: e_mail:
description: e_mail description: e_mail
maxLength: 500
type: string type: string
pass: pass:
description: password description: password
maxLength: 32
minLength: 8
type: string type: string
required:
- e_mail
- pass
type: object type: object
schema.UserModifyPassWordRequest: schema.UserModifyPassWordRequest:
properties: properties:

View File

@ -3,6 +3,7 @@ package service
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings"
"time" "time"
"github.com/answerdev/answer/internal/base/constant" "github.com/answerdev/answer/internal/base/constant"
@ -225,6 +226,28 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
if dbinfo.UserID != req.UserID { if dbinfo.UserID != req.UserID {
return return
} }
//CheckChangeTag
oldTags, err := qs.tagCommon.GetObjectEntityTag(ctx, question.ID)
if err != nil {
return
}
tagNameList := make([]string, 0)
for _, tag := range req.Tags {
tagNameList = append(tagNameList, tag.SlugName)
}
Tags, err := qs.tagCommon.GetTagListByNames(ctx, tagNameList)
if err != nil {
return
}
CheckTag, CheckTaglist := qs.CheckChangeTag(ctx, oldTags, Tags)
if !CheckTag {
err = errors.BadRequest(reason.UnauthorizedError).WithMsg(fmt.Sprintf("tag [%s] cannot be modified",
strings.Join(CheckTaglist, ",")))
return
}
//update question to db
err = qs.questionRepo.UpdateQuestion(ctx, question, []string{"title", "original_text", "parsed_text", "updated_at"}) err = qs.questionRepo.UpdateQuestion(ctx, question, []string{"title", "original_text", "parsed_text", "updated_at"})
if err != nil { if err != nil {
return return
@ -276,6 +299,10 @@ func (qs *QuestionService) ChangeTag(ctx context.Context, objectTagData *schema.
return qs.tagCommon.ObjectChangeTag(ctx, objectTagData) return qs.tagCommon.ObjectChangeTag(ctx, objectTagData)
} }
func (qs *QuestionService) CheckChangeTag(ctx context.Context, oldobjectTagData, objectTagData []*entity.Tag) (bool, []string) {
return qs.tagCommon.ObjectCheckChangeTag(ctx, oldobjectTagData, objectTagData)
}
func (qs *QuestionService) SearchUserList(ctx context.Context, userName, order string, page, pageSize int, loginUserID string) ([]*schema.UserQuestionInfo, int64, error) { func (qs *QuestionService) SearchUserList(ctx context.Context, userName, order string, page, pageSize int, loginUserID string) ([]*schema.UserQuestionInfo, int64, error) {
userlist := make([]*schema.UserQuestionInfo, 0) userlist := make([]*schema.UserQuestionInfo, 0)

View File

@ -205,7 +205,11 @@ func (ts *TagCommonService) ExistRecommend(ctx context.Context, tags []*schema.T
// GetObjectTag get object tag // GetObjectTag get object tag
func (ts *TagCommonService) GetObjectTag(ctx context.Context, objectId string) (objTags []*schema.TagResp, err error) { func (ts *TagCommonService) GetObjectTag(ctx context.Context, objectId string) (objTags []*schema.TagResp, err error) {
objTags = make([]*schema.TagResp, 0) tagsInfoList, err := ts.GetObjectEntityTag(ctx, objectId)
return ts.TagFormat(ctx, tagsInfoList)
}
func (ts *TagCommonService) GetObjectEntityTag(ctx context.Context, objectId string) (objTags []*entity.Tag, err error) {
tagIDList := make([]string, 0) tagIDList := make([]string, 0)
tagList, err := ts.tagRelRepo.GetObjectTagRelList(ctx, objectId) tagList, err := ts.tagRelRepo.GetObjectTagRelList(ctx, objectId)
if err != nil { if err != nil {
@ -214,11 +218,17 @@ func (ts *TagCommonService) GetObjectTag(ctx context.Context, objectId string) (
for _, tag := range tagList { for _, tag := range tagList {
tagIDList = append(tagIDList, tag.TagID) tagIDList = append(tagIDList, tag.TagID)
} }
tagsInfoList, err := ts.tagRepo.GetTagListByIDs(ctx, tagIDList) objTags, err = ts.tagRepo.GetTagListByIDs(ctx, tagIDList)
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, tagInfo := range tagsInfoList {
return objTags, nil
}
func (ts *TagCommonService) TagFormat(ctx context.Context, tags []*entity.Tag) (objTags []*schema.TagResp, err error) {
objTags = make([]*schema.TagResp, 0)
for _, tagInfo := range tags {
objTags = append(objTags, &schema.TagResp{ objTags = append(objTags, &schema.TagResp{
SlugName: tagInfo.SlugName, SlugName: tagInfo.SlugName,
DisplayName: tagInfo.DisplayName, DisplayName: tagInfo.DisplayName,
@ -281,7 +291,6 @@ func (ts *TagCommonService) CheckTag(ctx context.Context, tags []string, userID
} }
thisTagNameList := make([]string, 0) thisTagNameList := make([]string, 0)
thisTagIDList := make([]string, 0)
for _, t := range tags { for _, t := range tags {
t = strings.ToLower(t) t = strings.ToLower(t)
thisTagNameList = append(thisTagNameList, t) thisTagNameList = append(thisTagNameList, t)
@ -294,13 +303,17 @@ func (ts *TagCommonService) CheckTag(ctx context.Context, tags []string, userID
} }
tagInDbMapping := make(map[string]*entity.Tag) tagInDbMapping := make(map[string]*entity.Tag)
checktags := make([]string, 0)
for _, tag := range tagListInDb { for _, tag := range tagListInDb {
if tag.MainTagID != 0 { if tag.MainTagID != 0 {
err = errors.BadRequest(reason.TagNotContainSynonym).WithMsg(fmt.Sprintf("tag name:%s", tag.SlugName)) checktags = append(checktags, fmt.Sprintf("\"%s\"", tag.SlugName))
return err
} }
tagInDbMapping[tag.SlugName] = tag tagInDbMapping[tag.SlugName] = tag
thisTagIDList = append(thisTagIDList, tag.ID) }
if len(checktags) > 0 {
err = errors.BadRequest(reason.TagNotContainSynonym).WithMsg(fmt.Sprintf("Should not contain synonym tags %s", strings.Join(checktags, ",")))
return err
} }
addTagList := make([]*entity.Tag, 0) addTagList := make([]*entity.Tag, 0)
@ -324,30 +337,35 @@ func (ts *TagCommonService) CheckTag(ctx context.Context, tags []string, userID
err = errors.BadRequest(reason.TagNotFound).WithMsg(fmt.Sprintf("tag [%s] does not exist", err = errors.BadRequest(reason.TagNotFound).WithMsg(fmt.Sprintf("tag [%s] does not exist",
strings.Join(addTagMsgList, ","))) strings.Join(addTagMsgList, ",")))
return err return err
// todo if need add
// err = ts.tagRepo.AddTagList(ctx, addTagList)
// if err != nil {
// return err
// }
// for _, tag := range addTagList {
// thisTagIDList = append(thisTagIDList, tag.ID)
// revisionDTO := &schema.AddRevisionDTO{
// UserID: userID,
// ObjectID: tag.ID,
// Title: tag.SlugName,
// }
// tagInfoJson, _ := json.Marshal(tag)
// revisionDTO.Content = string(tagInfoJson)
// err = ts.revisionService.AddRevision(ctx, revisionDTO, true)
// if err != nil {
// return err
// }
// }
} }
return nil return nil
} }
func (ts *TagCommonService) ObjectCheckChangeTag(ctx context.Context, oldobjectTagData, objectTagData []*entity.Tag) (bool, []string) {
reservedTagsMap := make(map[string]bool)
needTagsMap := make([]string, 0)
for _, tag := range objectTagData {
if tag.Reserved {
reservedTagsMap[tag.SlugName] = true
}
}
for _, tag := range oldobjectTagData {
if tag.Reserved {
_, ok := reservedTagsMap[tag.SlugName]
if !ok {
needTagsMap = append(needTagsMap, tag.SlugName)
}
}
}
if len(needTagsMap) > 0 {
return false, needTagsMap
}
return true, []string{}
}
// ObjectChangeTag change object tag list // ObjectChangeTag change object tag list
func (ts *TagCommonService) ObjectChangeTag(ctx context.Context, objectTagData *schema.TagChange) (err error) { func (ts *TagCommonService) ObjectChangeTag(ctx context.Context, objectTagData *schema.TagChange) (err error) {
if len(objectTagData.Tags) == 0 { if len(objectTagData.Tags) == 0 {