update question tags

This commit is contained in:
aichy126 2022-11-23 12:07:06 +08:00
parent 5b005e652f
commit 1bf0d6365e
5 changed files with 155 additions and 33 deletions

View File

@ -1068,6 +1068,47 @@ const docTemplate = `{
}
}
},
"/answer/api/v1/activity/timeline/detail": {
"get": {
"description": "get object timeline detail",
"produces": [
"application/json"
],
"tags": [
"Comment"
],
"summary": "get object timeline detail",
"parameters": [
{
"type": "string",
"description": "revision id",
"name": "revision_id",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/handler.RespBody"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/schema.GetObjectTimelineResp"
}
}
}
]
}
}
}
}
},
"/answer/api/v1/answer": {
"put": {
"security": [

View File

@ -1056,6 +1056,47 @@
}
}
},
"/answer/api/v1/activity/timeline/detail": {
"get": {
"description": "get object timeline detail",
"produces": [
"application/json"
],
"tags": [
"Comment"
],
"summary": "get object timeline detail",
"parameters": [
{
"type": "string",
"description": "revision id",
"name": "revision_id",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/handler.RespBody"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/schema.GetObjectTimelineResp"
}
}
}
]
}
}
}
}
},
"/answer/api/v1/answer": {
"put": {
"security": [

View File

@ -2273,6 +2273,30 @@ paths:
summary: get object timeline
tags:
- Comment
/answer/api/v1/activity/timeline/detail:
get:
description: get object timeline detail
parameters:
- description: revision id
in: query
name: revision_id
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/handler.RespBody'
- properties:
data:
$ref: '#/definitions/schema.GetObjectTimelineResp'
type: object
summary: get object timeline detail
tags:
- Comment
/answer/api/v1/answer:
delete:
consumes:

View File

@ -16,6 +16,8 @@ type AddRevisionDTO struct {
Content string
// log
Log string
// status
Status int
}
// GetRevisionListReq get revision list all request

View File

@ -162,7 +162,17 @@ func (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.Question
ObjectID: question.ID,
Title: question.Title,
}
questionWithTagsRevision, err := qs.changeQuestionToRevision(ctx, question)
tagNameList := make([]string, 0)
for _, tag := range req.Tags {
tagNameList = append(tagNameList, tag.SlugName)
}
Tags, tagerr := qs.tagCommon.GetTagListByNames(ctx, tagNameList)
if tagerr != nil {
return questionInfo, tagerr
}
questionWithTagsRevision, err := qs.changeQuestionToRevision(ctx, question, Tags)
if err != nil {
return nil, err
}
@ -270,23 +280,21 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
if !has {
return
}
// If it's not admin
if !req.IsAdmin {
if dbinfo.UserID != req.UserID {
return questionInfo, errors.BadRequest(reason.QuestionCannotUpdate)
}
//CheckChangeTag
oldTags, tagerr := qs.tagCommon.GetObjectEntityTag(ctx, question.ID)
if err != nil {
return questionInfo, tagerr
}
tagNameList := make([]string, 0)
for _, tag := range req.Tags {
tagNameList = append(tagNameList, tag.SlugName)
}
Tags, tagerr := qs.tagCommon.GetTagListByNames(ctx, tagNameList)
if err != nil {
if tagerr != nil {
return questionInfo, tagerr
}
// If it's not admin
if !req.IsAdmin {
//CheckChangeTag
oldTags, tagerr := qs.tagCommon.GetObjectEntityTag(ctx, question.ID)
if tagerr != nil {
return questionInfo, tagerr
}
@ -318,19 +326,7 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
return errorlist, err
}
//update question to db
err = qs.questionRepo.UpdateQuestion(ctx, question, []string{"title", "original_text", "parsed_text", "updated_at"})
if err != nil {
return
}
objectTagData := schema.TagChange{}
objectTagData.ObjectID = question.ID
objectTagData.Tags = req.Tags
objectTagData.UserID = req.UserID
err = qs.ChangeTag(ctx, &objectTagData)
if err != nil {
return
}
//Administrators and themselves do not need to be audited
revisionDTO := &schema.AddRevisionDTO{
UserID: question.UserID,
@ -338,7 +334,29 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
Title: question.Title,
Log: req.EditSummary,
}
questionWithTagsRevision, err := qs.changeQuestionToRevision(ctx, question)
// It's not you or the administrator that needs to be reviewed
if dbinfo.UserID != req.UserID && !req.IsAdmin {
revisionDTO.Status = entity.RevisionUnreviewedStatus
} else {
//Direct modification
revisionDTO.Status = entity.RevisionReviewPassStatus
//update question to db
saveerr := qs.questionRepo.UpdateQuestion(ctx, question, []string{"title", "original_text", "parsed_text", "updated_at"})
if saveerr != nil {
return questionInfo, saveerr
}
objectTagData := schema.TagChange{}
objectTagData.ObjectID = question.ID
objectTagData.Tags = req.Tags
objectTagData.UserID = req.UserID
tagerr := qs.ChangeTag(ctx, &objectTagData)
if err != nil {
return questionInfo, tagerr
}
}
questionWithTagsRevision, err := qs.changeQuestionToRevision(ctx, question, Tags)
if err != nil {
return nil, err
}
@ -786,15 +804,11 @@ func (qs *QuestionService) CmsSearchAnswerList(ctx context.Context, search *enti
return answerlist, count, nil
}
func (qs *QuestionService) changeQuestionToRevision(ctx context.Context, questionInfo *entity.Question) (
func (qs *QuestionService) changeQuestionToRevision(ctx context.Context, questionInfo *entity.Question, tags []*entity.Tag) (
questionRevision *entity.QuestionWithTagsRevision, err error) {
questionRevision = &entity.QuestionWithTagsRevision{}
questionRevision.Question = *questionInfo
tags, err := qs.tagCommon.GetObjectEntityTag(ctx, questionInfo.ID)
if err != nil {
return nil, err
}
for _, tag := range tags {
item := &entity.TagSimpleInfoForRevision{}
_ = copier.Copy(item, tag)