mirror of https://gitee.com/answerdev/answer.git
GetUnreviewedRevisionList
This commit is contained in:
parent
a680944168
commit
6202877bdc
44
docs/docs.go
44
docs/docs.go
|
@ -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": [
|
||||
|
|
|
@ -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": [
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 (
|
||||
|
|
Loading…
Reference in New Issue