mirror of https://gitee.com/answerdev/answer.git
update Adopt to Accept
This commit is contained in:
parent
c5ce51c2a9
commit
b8077d37b3
30
docs/docs.go
30
docs/docs.go
|
@ -1671,7 +1671,7 @@ const docTemplate = `{
|
|||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Adopted",
|
||||
"description": "Accepted",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
|
@ -1681,15 +1681,15 @@ const docTemplate = `{
|
|||
"tags": [
|
||||
"api-answer"
|
||||
],
|
||||
"summary": "Adopted",
|
||||
"summary": "Accepted",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "AnswerAdoptedReq",
|
||||
"description": "AnswerAcceptedReq",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.AnswerAdoptedReq"
|
||||
"$ref": "#/definitions/schema.AnswerAcceptedReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -5490,6 +5490,17 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"schema.AnswerAcceptedReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"answer_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"question_id": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.AnswerAddReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -5507,17 +5518,6 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"schema.AnswerAdoptedReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"answer_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"question_id": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.AnswerUpdateReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
@ -1659,7 +1659,7 @@
|
|||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Adopted",
|
||||
"description": "Accepted",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
|
@ -1669,15 +1669,15 @@
|
|||
"tags": [
|
||||
"api-answer"
|
||||
],
|
||||
"summary": "Adopted",
|
||||
"summary": "Accepted",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "AnswerAdoptedReq",
|
||||
"description": "AnswerAcceptedReq",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.AnswerAdoptedReq"
|
||||
"$ref": "#/definitions/schema.AnswerAcceptedReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -5478,6 +5478,17 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"schema.AnswerAcceptedReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"answer_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"question_id": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.AnswerAddReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -5495,17 +5506,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"schema.AnswerAdoptedReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"answer_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"question_id": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.AnswerUpdateReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
@ -207,6 +207,13 @@ definitions:
|
|||
status:
|
||||
type: string
|
||||
type: object
|
||||
schema.AnswerAcceptedReq:
|
||||
properties:
|
||||
answer_id:
|
||||
type: string
|
||||
question_id:
|
||||
type: string
|
||||
type: object
|
||||
schema.AnswerAddReq:
|
||||
properties:
|
||||
content:
|
||||
|
@ -219,13 +226,6 @@ definitions:
|
|||
description: question_id
|
||||
type: string
|
||||
type: object
|
||||
schema.AnswerAdoptedReq:
|
||||
properties:
|
||||
answer_id:
|
||||
type: string
|
||||
question_id:
|
||||
type: string
|
||||
type: object
|
||||
schema.AnswerUpdateReq:
|
||||
properties:
|
||||
content:
|
||||
|
@ -2881,14 +2881,14 @@ paths:
|
|||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Adopted
|
||||
description: Accepted
|
||||
parameters:
|
||||
- description: AnswerAdoptedReq
|
||||
- description: AnswerAcceptedReq
|
||||
in: body
|
||||
name: data
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/schema.AnswerAdoptedReq'
|
||||
$ref: '#/definitions/schema.AnswerAcceptedReq'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
|
@ -2898,7 +2898,7 @@ paths:
|
|||
type: string
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: Adopted
|
||||
summary: Accepted
|
||||
tags:
|
||||
- api-answer
|
||||
/answer/api/v1/answer/info:
|
||||
|
|
|
@ -205,7 +205,7 @@ backend:
|
|||
other: "answered question"
|
||||
update_answer:
|
||||
other: "updated answer"
|
||||
adopt_answer:
|
||||
accept_answer:
|
||||
other: "accepted answer"
|
||||
comment_question:
|
||||
other: "commented question"
|
||||
|
|
|
@ -210,7 +210,7 @@ backend:
|
|||
other: "answered question"
|
||||
update_answer:
|
||||
other: "updated answer"
|
||||
adopt_answer:
|
||||
accept_answer:
|
||||
other: "accepted answer"
|
||||
comment_question:
|
||||
other: "commented question"
|
||||
|
|
|
@ -205,7 +205,7 @@ backend:
|
|||
other: "answered question"
|
||||
update_answer:
|
||||
other: "updated answer"
|
||||
adopt_answer:
|
||||
accept_answer:
|
||||
other: "accepted answer"
|
||||
comment_question:
|
||||
other: "commented question"
|
||||
|
|
|
@ -205,7 +205,7 @@ backend:
|
|||
other: "answered question"
|
||||
update_answer:
|
||||
other: "updated answer"
|
||||
adopt_answer:
|
||||
accept_answer:
|
||||
other: "accepted answer"
|
||||
comment_question:
|
||||
other: "commented question"
|
||||
|
|
|
@ -205,8 +205,8 @@ backend:
|
|||
other: "domanda risposta"
|
||||
update_answer:
|
||||
other: "risposta aggiornata"
|
||||
adopt_answer:
|
||||
other: "risposta accettata"
|
||||
accept_answer:
|
||||
other: "risposta accepted"
|
||||
comment_question:
|
||||
other: "domanda commentata"
|
||||
comment_answer:
|
||||
|
|
|
@ -205,7 +205,7 @@ backend:
|
|||
other: "answered question"
|
||||
update_answer:
|
||||
other: "updated answer"
|
||||
adopt_answer:
|
||||
accept_answer:
|
||||
other: "accepted answer"
|
||||
comment_question:
|
||||
other: "commented question"
|
||||
|
|
|
@ -205,7 +205,7 @@ backend:
|
|||
other: "answered question"
|
||||
update_answer:
|
||||
other: "updated answer"
|
||||
adopt_answer:
|
||||
accept_answer:
|
||||
other: "accepted answer"
|
||||
comment_question:
|
||||
other: "commented question"
|
||||
|
|
|
@ -205,7 +205,7 @@ backend:
|
|||
other: "answered question"
|
||||
update_answer:
|
||||
other: "updated answer"
|
||||
adopt_answer:
|
||||
accept_answer:
|
||||
other: "accepted answer"
|
||||
comment_question:
|
||||
other: "commented question"
|
||||
|
|
|
@ -205,7 +205,7 @@ backend:
|
|||
other: "answered question"
|
||||
update_answer:
|
||||
other: "updated answer"
|
||||
adopt_answer:
|
||||
accept_answer:
|
||||
other: "accepted answer"
|
||||
comment_question:
|
||||
other: "commented question"
|
||||
|
|
|
@ -205,7 +205,7 @@ backend:
|
|||
other: "answered question"
|
||||
update_answer:
|
||||
other: "updated answer"
|
||||
adopt_answer:
|
||||
accept_answer:
|
||||
other: "accepted answer"
|
||||
comment_question:
|
||||
other: "commented question"
|
||||
|
|
|
@ -206,7 +206,7 @@ backend:
|
|||
other: "回答了问题"
|
||||
update_answer:
|
||||
other: "更新了答案"
|
||||
adopt_answer:
|
||||
accept_answer:
|
||||
other: "接受了答案"
|
||||
comment_question:
|
||||
other: "评论了问题"
|
||||
|
|
|
@ -205,7 +205,7 @@ backend:
|
|||
other: "answered question"
|
||||
update_answer:
|
||||
other: "updated answer"
|
||||
adopt_answer:
|
||||
accept_answer:
|
||||
other: "accepted answer"
|
||||
comment_question:
|
||||
other: "commented question"
|
||||
|
|
|
@ -7,8 +7,8 @@ const (
|
|||
AnswerTheQuestion = "notification.action.answer_the_question"
|
||||
// UpdateAnswer update answer
|
||||
UpdateAnswer = "notification.action.update_answer"
|
||||
// AdoptAnswer adopt answer
|
||||
AdoptAnswer = "notification.action.adopt_answer"
|
||||
// AcceptAnswer accept answer
|
||||
AcceptAnswer = "notification.action.accept_answer"
|
||||
// CommentQuestion comment question
|
||||
CommentQuestion = "notification.action.comment_question"
|
||||
// CommentAnswer comment answer
|
||||
|
|
|
@ -232,18 +232,18 @@ func (ac *AnswerController) AnswerList(ctx *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
// Adopted godoc
|
||||
// @Summary Adopted
|
||||
// @Description Adopted
|
||||
// Accepted godoc
|
||||
// @Summary Accepted
|
||||
// @Description Accepted
|
||||
// @Tags api-answer
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param data body schema.AnswerAdoptedReq true "AnswerAdoptedReq"
|
||||
// @Param data body schema.AnswerAcceptedReq true "AnswerAcceptedReq"
|
||||
// @Success 200 {string} string ""
|
||||
// @Router /answer/api/v1/answer/acceptance [post]
|
||||
func (ac *AnswerController) Adopted(ctx *gin.Context) {
|
||||
req := &schema.AnswerAdoptedReq{}
|
||||
func (ac *AnswerController) Accepted(ctx *gin.Context) {
|
||||
req := &schema.AnswerAcceptedReq{}
|
||||
if handler.BindAndCheck(ctx, req) {
|
||||
return
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ func (ac *AnswerController) Adopted(ctx *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
err = ac.answerService.UpdateAdopted(ctx, req)
|
||||
err = ac.answerService.UpdateAccepted(ctx, req)
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
}
|
||||
|
||||
|
|
|
@ -264,7 +264,7 @@ func (tc *TemplateController) QuestionInfo(ctx *gin.Context) {
|
|||
jsonLD.MainEntity.Author.Name = detail.UserInfo.DisplayName
|
||||
answerList := make([]*schema.SuggestedAnswerItem, 0)
|
||||
for _, answer := range answers {
|
||||
if answer.Adopted == schema.AnswerAdoptedEnable {
|
||||
if answer.Accepted == schema.AnswerAcceptedEnable {
|
||||
acceptedAnswerItem := &schema.AcceptedAnswerItem{}
|
||||
acceptedAnswerItem.Type = "Answer"
|
||||
acceptedAnswerItem.Text = answer.HTML
|
||||
|
|
|
@ -27,7 +27,7 @@ type Answer struct {
|
|||
OriginalText string `xorm:"not null MEDIUMTEXT original_text"`
|
||||
ParsedText string `xorm:"not null MEDIUMTEXT parsed_text"`
|
||||
Status int `xorm:"not null default 1 INT(11) status"`
|
||||
Adopted int `xorm:"not null default 1 INT(11) adopted"`
|
||||
Accepted int `xorm:"not null default 1 INT(11) adopted"`
|
||||
CommentCount int `xorm:"not null default 0 INT(11) comment_count"`
|
||||
VoteCount int `xorm:"not null default 0 INT(11) vote_count"`
|
||||
RevisionID string `xorm:"not null default 0 BIGINT(20) revision_id"`
|
||||
|
|
|
@ -214,7 +214,7 @@ func (ar *AnswerActivityRepo) AcceptAnswer(ctx context.Context,
|
|||
if act.UserID != questionUserID {
|
||||
msg.TriggerUserID = questionUserID
|
||||
msg.ObjectType = constant.AnswerObjectType
|
||||
msg.NotificationAction = constant.AdoptAnswer
|
||||
msg.NotificationAction = constant.AcceptAnswer
|
||||
notice_queue.AddNotification(msg)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,22 +133,22 @@ func (ar *answerRepo) GetAnswerPage(ctx context.Context, page, pageSize int, ans
|
|||
return
|
||||
}
|
||||
|
||||
// UpdateAdopted
|
||||
// UpdateAccepted
|
||||
// If no answer is selected, the answer id can be 0
|
||||
func (ar *answerRepo) UpdateAdopted(ctx context.Context, id string, questionID string) error {
|
||||
func (ar *answerRepo) UpdateAccepted(ctx context.Context, id string, questionID string) error {
|
||||
if questionID == "" {
|
||||
return nil
|
||||
}
|
||||
var data entity.Answer
|
||||
data.ID = id
|
||||
|
||||
data.Adopted = schema.AnswerAdoptedFailed
|
||||
data.Accepted = schema.AnswerAcceptedFailed
|
||||
_, err := ar.data.DB.Where("question_id =?", questionID).Cols("adopted").Update(&data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if id != "0" {
|
||||
data.Adopted = schema.AnswerAdoptedEnable
|
||||
data.Accepted = schema.AnswerAcceptedEnable
|
||||
_, err = ar.data.DB.Where("id = ?", id).Cols("adopted").Update(&data)
|
||||
if err != nil {
|
||||
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
|
|
|
@ -344,8 +344,8 @@ func (sr *searchRepo) SearchAnswers(ctx context.Context, words []string, tagIDs
|
|||
|
||||
// check limit accepted
|
||||
if accepted {
|
||||
b.Where(builder.Eq{"adopted": schema.AnswerAdoptedEnable})
|
||||
args = append(args, schema.AnswerAdoptedEnable)
|
||||
b.Where(builder.Eq{"adopted": schema.AnswerAcceptedEnable})
|
||||
args = append(args, schema.AnswerAcceptedEnable)
|
||||
}
|
||||
|
||||
// check question id
|
||||
|
|
|
@ -194,7 +194,7 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
|
|||
// answer
|
||||
r.POST("/answer", a.answerController.Add)
|
||||
r.PUT("/answer", a.answerController.Update)
|
||||
r.POST("/answer/acceptance", a.answerController.Adopted)
|
||||
r.POST("/answer/acceptance", a.answerController.Accepted)
|
||||
r.DELETE("/answer", a.answerController.RemoveAnswer)
|
||||
|
||||
// user
|
||||
|
|
|
@ -15,8 +15,8 @@ type RemoveAnswerReq struct {
|
|||
}
|
||||
|
||||
const (
|
||||
AnswerAdoptedFailed = 1
|
||||
AnswerAdoptedEnable = 2
|
||||
AnswerAcceptedFailed = 1
|
||||
AnswerAcceptedEnable = 2
|
||||
)
|
||||
|
||||
type AnswerAddReq struct {
|
||||
|
@ -74,7 +74,7 @@ type AnswerInfo struct {
|
|||
HTML string `json:"html" xorm:"html"` // html
|
||||
CreateTime int64 `json:"create_time" xorm:"created"` // create_time
|
||||
UpdateTime int64 `json:"update_time" xorm:"updated"` // update_time
|
||||
Adopted int `json:"adopted"` // 1 Failed 2 Adopted
|
||||
Accepted int `json:"accepted"` // 1 Failed 2 accepted
|
||||
UserID string `json:"-" `
|
||||
UpdateUserID string `json:"-" `
|
||||
UserInfo *UserBasicInfo `json:"user_info,omitempty"`
|
||||
|
@ -94,7 +94,7 @@ type AdminAnswerInfo struct {
|
|||
Description string `json:"description"`
|
||||
CreateTime int64 `json:"create_time"`
|
||||
UpdateTime int64 `json:"update_time"`
|
||||
Adopted int `json:"adopted"`
|
||||
Accepted int `json:"accepted"`
|
||||
UserID string `json:"-" `
|
||||
UpdateUserID string `json:"-" `
|
||||
UserInfo *UserBasicInfo `json:"user_info"`
|
||||
|
@ -104,7 +104,7 @@ type AdminAnswerInfo struct {
|
|||
} `json:"question_info"`
|
||||
}
|
||||
|
||||
type AnswerAdoptedReq struct {
|
||||
type AnswerAcceptedReq struct {
|
||||
QuestionID string `json:"question_id"`
|
||||
AnswerID string `json:"answer_id"`
|
||||
UserID string `json:"-" `
|
||||
|
|
|
@ -199,7 +199,7 @@ type GetCloseTypeResp struct {
|
|||
type UserAnswerInfo struct {
|
||||
AnswerID string `json:"answer_id"`
|
||||
QuestionID string `json:"question_id"`
|
||||
Adopted int `json:"adopted"`
|
||||
Accepted int `json:"accepted"`
|
||||
VoteCount int `json:"vote_count"`
|
||||
CreateTime int `json:"create_time"`
|
||||
UpdateTime int `json:"update_time"`
|
||||
|
|
|
@ -15,7 +15,7 @@ type AnswerRepo interface {
|
|||
GetAnswer(ctx context.Context, id string) (answer *entity.Answer, exist bool, err error)
|
||||
GetAnswerList(ctx context.Context, answer *entity.Answer) (answerList []*entity.Answer, err error)
|
||||
GetAnswerPage(ctx context.Context, page, pageSize int, answer *entity.Answer) (answerList []*entity.Answer, total int64, err error)
|
||||
UpdateAdopted(ctx context.Context, id string, questionID string) error
|
||||
UpdateAccepted(ctx context.Context, id string, questionID string) error
|
||||
GetByID(ctx context.Context, id string) (*entity.Answer, bool, error)
|
||||
GetByUserIDQuestionID(ctx context.Context, userID string, questionID string) (*entity.Answer, bool, error)
|
||||
SearchList(ctx context.Context, search *entity.AnswerSearch) ([]*entity.Answer, int64, error)
|
||||
|
@ -64,7 +64,7 @@ func (as *AnswerCommon) ShowFormat(ctx context.Context, data *entity.Answer) *sc
|
|||
info.QuestionID = data.QuestionID
|
||||
info.Content = data.OriginalText
|
||||
info.HTML = data.ParsedText
|
||||
info.Adopted = data.Adopted
|
||||
info.Accepted = data.Accepted
|
||||
info.VoteCount = data.VoteCount
|
||||
info.CreateTime = data.CreatedAt.Unix()
|
||||
info.UpdateTime = data.UpdatedAt.Unix()
|
||||
|
@ -80,7 +80,7 @@ func (as *AnswerCommon) AdminShowFormat(ctx context.Context, data *entity.Answer
|
|||
info := schema.AdminAnswerInfo{}
|
||||
info.ID = data.ID
|
||||
info.QuestionID = data.QuestionID
|
||||
info.Adopted = data.Adopted
|
||||
info.Accepted = data.Accepted
|
||||
info.VoteCount = data.VoteCount
|
||||
info.CreateTime = data.CreatedAt.Unix()
|
||||
info.UpdateTime = data.UpdatedAt.Unix()
|
||||
|
|
|
@ -80,7 +80,7 @@ func (as *AnswerService) RemoveAnswer(ctx context.Context, req *schema.RemoveAns
|
|||
if answerInfo.VoteCount > 0 {
|
||||
return errors.BadRequest(reason.AnswerCannotDeleted)
|
||||
}
|
||||
if answerInfo.Adopted == schema.AnswerAdoptedEnable {
|
||||
if answerInfo.Accepted == schema.AnswerAcceptedEnable {
|
||||
return errors.BadRequest(reason.AnswerCannotDeleted)
|
||||
}
|
||||
questionInfo, exist, err := as.questionRepo.GetQuestion(ctx, answerInfo.QuestionID)
|
||||
|
@ -138,7 +138,7 @@ func (as *AnswerService) Insert(ctx context.Context, req *schema.AnswerAddReq) (
|
|||
insertData.UserID = req.UserID
|
||||
insertData.OriginalText = req.Content
|
||||
insertData.ParsedText = req.HTML
|
||||
insertData.Adopted = schema.AnswerAdoptedFailed
|
||||
insertData.Accepted = schema.AnswerAcceptedFailed
|
||||
insertData.QuestionID = req.QuestionID
|
||||
insertData.RevisionID = "0"
|
||||
insertData.LastEditUserID = "0"
|
||||
|
@ -285,8 +285,8 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq
|
|||
return insertData.ID, nil
|
||||
}
|
||||
|
||||
// UpdateAdopted
|
||||
func (as *AnswerService) UpdateAdopted(ctx context.Context, req *schema.AnswerAdoptedReq) error {
|
||||
// UpdateAccepted
|
||||
func (as *AnswerService) UpdateAccepted(ctx context.Context, req *schema.AnswerAcceptedReq) error {
|
||||
if req.AnswerID == "" {
|
||||
req.AnswerID = "0"
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ func (as *AnswerService) UpdateAdopted(ctx context.Context, req *schema.AnswerAd
|
|||
}
|
||||
}
|
||||
|
||||
err = as.answerRepo.UpdateAdopted(ctx, req.AnswerID, req.QuestionID)
|
||||
err = as.answerRepo.UpdateAccepted(ctx, req.AnswerID, req.QuestionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ func (ns *NotificationCommon) SendNotificationToAllFollower(ctx context.Context,
|
|||
if msg.NotificationAction != constant.UpdateQuestion &&
|
||||
msg.NotificationAction != constant.AnswerTheQuestion &&
|
||||
msg.NotificationAction != constant.UpdateAnswer &&
|
||||
msg.NotificationAction != constant.AdoptAnswer {
|
||||
msg.NotificationAction != constant.AcceptAnswer {
|
||||
return
|
||||
}
|
||||
condObjectID := msg.ObjectID
|
||||
|
|
Loading…
Reference in New Issue