Merge branch 'feat/1.0.6/object-not-found' into test

This commit is contained in:
aichy126 2023-03-01 17:50:22 +08:00
commit f3d48f61e0
9 changed files with 57 additions and 23 deletions

View File

@ -1,5 +1,4 @@
// Package docs GENERATED BY SWAG; DO NOT EDIT
// This file was generated by swaggo/swag
// Code generated by swaggo/swag. DO NOT EDIT
package docs
import "github.com/swaggo/swag"
@ -5984,9 +5983,6 @@ const docTemplate = `{
"schema.GetOtherUserInfoResp": {
"type": "object",
"properties": {
"has": {
"type": "boolean"
},
"info": {
"$ref": "#/definitions/schema.GetOtherUserInfoByUsernameResp"
}
@ -6986,7 +6982,11 @@ const docTemplate = `{
},
"user_info": {
"description": "user info",
"$ref": "#/definitions/schema.UserBasicInfo"
"allOf": [
{
"$ref": "#/definitions/schema.UserBasicInfo"
}
]
},
"vote_count": {
"type": "integer"
@ -6998,7 +6998,11 @@ const docTemplate = `{
"properties": {
"object": {
"description": "this object",
"$ref": "#/definitions/schema.SearchObject"
"allOf": [
{
"$ref": "#/definitions/schema.SearchObject"
}
]
},
"object_type": {
"description": "object_type",
@ -7511,7 +7515,11 @@ const docTemplate = `{
"properties": {
"avatar": {
"description": "avatar",
"$ref": "#/definitions/schema.AvatarInfo"
"allOf": [
{
"$ref": "#/definitions/schema.AvatarInfo"
}
]
},
"bio": {
"description": "bio",

View File

@ -5972,9 +5972,6 @@
"schema.GetOtherUserInfoResp": {
"type": "object",
"properties": {
"has": {
"type": "boolean"
},
"info": {
"$ref": "#/definitions/schema.GetOtherUserInfoByUsernameResp"
}
@ -6974,7 +6971,11 @@
},
"user_info": {
"description": "user info",
"$ref": "#/definitions/schema.UserBasicInfo"
"allOf": [
{
"$ref": "#/definitions/schema.UserBasicInfo"
}
]
},
"vote_count": {
"type": "integer"
@ -6986,7 +6987,11 @@
"properties": {
"object": {
"description": "this object",
"$ref": "#/definitions/schema.SearchObject"
"allOf": [
{
"$ref": "#/definitions/schema.SearchObject"
}
]
},
"object_type": {
"description": "object_type",
@ -7499,7 +7504,11 @@
"properties": {
"avatar": {
"description": "avatar",
"$ref": "#/definitions/schema.AvatarInfo"
"allOf": [
{
"$ref": "#/definitions/schema.AvatarInfo"
}
]
},
"bio": {
"description": "bio",

View File

@ -488,8 +488,6 @@ definitions:
type: object
schema.GetOtherUserInfoResp:
properties:
has:
type: boolean
info:
$ref: '#/definitions/schema.GetOtherUserInfoByUsernameResp'
type: object
@ -1201,7 +1199,8 @@ definitions:
title:
type: string
user_info:
$ref: '#/definitions/schema.UserBasicInfo'
allOf:
- $ref: '#/definitions/schema.UserBasicInfo'
description: user info
vote_count:
type: integer
@ -1209,7 +1208,8 @@ definitions:
schema.SearchResp:
properties:
object:
$ref: '#/definitions/schema.SearchObject'
allOf:
- $ref: '#/definitions/schema.SearchObject'
description: this object
object_type:
description: object_type
@ -1563,7 +1563,8 @@ definitions:
schema.UpdateInfoRequest:
properties:
avatar:
$ref: '#/definitions/schema.AvatarInfo'
allOf:
- $ref: '#/definitions/schema.AvatarInfo'
description: avatar
bio:
description: bio

View File

@ -35,9 +35,11 @@ type Answer struct {
type AnswerSearch struct {
Answer
Order string `json:"order_by" ` // default or updated
Page int `json:"page" form:"page"` // Query number of pages
PageSize int `json:"page_size" form:"page_size"` // Search page size
IncludeDeleted bool `json:"include_deleted"`
LoginUserID string `json:"login_user_id"`
Order string `json:"order_by"` // default or updated
Page int `json:"page" form:"page"` // Query number of pages
PageSize int `json:"page_size" form:"page_size"` // Search page size
}
type AdminAnswerSearch struct {

View File

@ -206,7 +206,9 @@ func (ar *answerRepo) SearchList(ctx context.Context, search *entity.AnswerSearc
default:
session = session.OrderBy("adopted desc,vote_count desc,created_at asc")
}
session = session.And("status = ?", entity.AnswerStatusAvailable)
if !search.IncludeDeleted {
session = session.And("status = ? OR user_id = ?", entity.AnswerStatusAvailable, search.UserID)
}
session = session.Limit(search.PageSize, offset)
count, err = session.FindAndCount(&rows)

View File

@ -83,6 +83,7 @@ type AnswerInfo struct {
VoteStatus string `json:"vote_status"`
VoteCount int `json:"vote_count"`
QuestionInfo *QuestionInfo `json:"question_info,omitempty"`
Status int `json:"status"`
// MemberActions
MemberActions []*PermissionMemberAction `json:"member_actions"`

View File

@ -73,6 +73,7 @@ func (as *AnswerCommon) ShowFormat(ctx context.Context, data *entity.Answer) *sc
}
info.UserID = data.UserID
info.UpdateUserID = data.LastEditUserID
info.Status = data.Status
return &info
}

View File

@ -232,6 +232,11 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq
return "", nil
}
if answerInfo.Status == entity.AnswerStatusDeleted {
err = errors.BadRequest(reason.AnswerCannotUpdate)
return "", err
}
//If the content is the same, ignore it
if answerInfo.OriginalText == req.Content {
return "", nil
@ -473,6 +478,7 @@ func (as *AnswerService) SearchList(ctx context.Context, req *schema.AnswerListR
dbSearch.Page = req.Page
dbSearch.PageSize = req.PageSize
dbSearch.Order = req.Order
dbSearch.IncludeDeleted = req.CanDelete
answerOriginalList, count, err := as.answerRepo.SearchList(ctx, &dbSearch)
if err != nil {
return list, count, err

View File

@ -470,6 +470,10 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
if !has {
return
}
if dbinfo.Status == entity.QuestionStatusDeleted {
err = errors.BadRequest(reason.QuestionCannotUpdate)
return
}
now := time.Now()
question := &entity.Question{}