GetUnreviewedRevisionList

This commit is contained in:
aichy126 2022-11-23 16:27:35 +08:00
parent a680944168
commit 6202877bdc
10 changed files with 182 additions and 0 deletions

View File

@ -3069,6 +3069,50 @@ const docTemplate = `{
}
}
},
"/answer/api/v1/revisions/unreviewed": {
"get": {
"description": "get unreviewed revision list",
"produces": [
"application/json"
],
"tags": [
"Revision"
],
"summary": "get unreviewed revision list",
"parameters": [
{
"type": "string",
"description": "page id",
"name": "page",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/handler.RespBody"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/schema.GetRevisionResp"
}
}
}
}
]
}
}
}
}
},
"/answer/api/v1/search": {
"get": {
"security": [

View File

@ -3057,6 +3057,50 @@
}
}
},
"/answer/api/v1/revisions/unreviewed": {
"get": {
"description": "get unreviewed revision list",
"produces": [
"application/json"
],
"tags": [
"Revision"
],
"summary": "get unreviewed revision list",
"parameters": [
{
"type": "string",
"description": "page id",
"name": "page",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/handler.RespBody"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/schema.GetRevisionResp"
}
}
}
}
]
}
}
}
}
},
"/answer/api/v1/search": {
"get": {
"security": [

View File

@ -3494,6 +3494,32 @@ paths:
summary: get revision list
tags:
- Revision
/answer/api/v1/revisions/unreviewed:
get:
description: get unreviewed revision list
parameters:
- description: page id
in: query
name: page
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/handler.RespBody'
- properties:
data:
items:
$ref: '#/definitions/schema.GetRevisionResp'
type: array
type: object
summary: get unreviewed revision list
tags:
- Revision
/answer/api/v1/search:
get:
description: search object

View File

@ -5,6 +5,7 @@ import (
"github.com/answerdev/answer/internal/base/reason"
"github.com/answerdev/answer/internal/schema"
"github.com/answerdev/answer/internal/service"
"github.com/answerdev/answer/pkg/converter"
"github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/errors"
)
@ -41,3 +42,24 @@ func (rc *RevisionController) GetRevisionList(ctx *gin.Context) {
resp, err := rc.revisionListService.GetRevisionList(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// GetUnreviewedRevisionList godoc
// @Summary get unreviewed revision list
// @Description get unreviewed revision list
// @Tags Revision
// @Produce json
// @Param page query string true "page id"
// @Success 200 {object} handler.RespBody{data=[]schema.GetRevisionResp}
// @Router /answer/api/v1/revisions/unreviewed [get]
func (rc *RevisionController) GetUnreviewedRevisionList(ctx *gin.Context) {
pageStr := ctx.Query("page")
page := converter.StringToInt(pageStr)
req := &schema.RevisionSearch{
Page: page,
}
resp, count, err := rc.revisionListService.GetUnreviewedRevisionList(ctx, req)
handler.HandleResponse(ctx, err, gin.H{
"list": resp,
"count": count,
})
}

View File

@ -26,6 +26,10 @@ type Revision struct {
ReviewUserID int64 `xorm:"not null default 0 BIGINT(20) review_user_id"`
}
type RevisionSearch struct {
Page int `json:"page" form:"page"` // Query number of pages
}
// TableName revision table name
func (Revision) TableName() string {
return "revision"

View File

@ -149,3 +149,25 @@ func (rr *revisionRepo) allowRecord(objectType int) (ok bool) {
return false
}
}
func (rr *revisionRepo) SearchUnreviewedList(ctx context.Context, search *entity.RevisionSearch) ([]*entity.Revision, int64, error) {
var count int64
var err error
rows := make([]*entity.Revision, 0)
if search.Page > 0 {
search.Page = search.Page - 1
} else {
search.Page = 0
}
PageSize := 1
offset := search.Page * PageSize
session := rr.data.DB.Where("")
session = session.And("status = ?", entity.RevisionUnreviewedStatus)
session = session.OrderBy("created_at desc")
session = session.Limit(PageSize, offset)
count, err = session.FindAndCount(&rows)
if err != nil {
return rows, count, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
return rows, count, nil
}

View File

@ -123,6 +123,7 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
//revision
r.GET("/revisions", a.revisionController.GetRevisionList)
r.GET("/revisions/unreviewed", a.revisionController.GetUnreviewedRevisionList)
// tag
r.GET("/tags/page", a.tagController.GetTagWithPage)

View File

@ -26,6 +26,10 @@ type GetRevisionListReq struct {
ObjectID string `validate:"required" comment:"object_id" form:"object_id"`
}
type RevisionSearch struct {
Page int `json:"page" form:"page"` // Query number of pages
}
// GetRevisionResp get revision response
type GetRevisionResp struct {
// id

View File

@ -15,4 +15,5 @@ type RevisionRepo interface {
GetRevisionList(ctx context.Context, revision *entity.Revision) (revisionList []entity.Revision, err error)
UpdateObjectRevisionId(ctx context.Context, revision *entity.Revision, session *xorm.Session) (err error)
ExistUnreviewedByObjectID(ctx context.Context, objectID string) (revision *entity.Revision, exist bool, err error)
SearchUnreviewedList(ctx context.Context, search *entity.RevisionSearch) ([]*entity.Revision, int64, error)
}

View File

@ -10,6 +10,7 @@ import (
questioncommon "github.com/answerdev/answer/internal/service/question_common"
"github.com/answerdev/answer/internal/service/revision"
usercommon "github.com/answerdev/answer/internal/service/user_common"
"github.com/davecgh/go-spew/spew"
"github.com/jinzhu/copier"
)
@ -34,6 +35,19 @@ func NewRevisionService(
}
}
// SearchUnreviewedList get unreviewed list
func (rs *RevisionService) GetUnreviewedRevisionList(ctx context.Context, req *schema.RevisionSearch) (resp []schema.GetRevisionResp, count int64, err error) {
resp = []schema.GetRevisionResp{}
search := &entity.RevisionSearch{}
_ = copier.Copy(search, req)
list, count, err := rs.revisionRepo.SearchUnreviewedList(ctx, search)
for _, item := range list {
spew.Dump(item)
}
return
}
// GetRevisionList get revision list all
func (rs *RevisionService) GetRevisionList(ctx context.Context, req *schema.GetRevisionListReq) (resp []schema.GetRevisionResp, err error) {
var (