新增分页选项
All checks were successful
Deploy on Tag / build-and-deploy (push) Successful in 24s

This commit is contained in:
wzj 2024-11-11 22:38:17 +08:00
parent 70e35c4dc6
commit 59a04bcb53
6 changed files with 57 additions and 3 deletions

View File

@ -54,11 +54,14 @@ func (c *ItemController) Detail(id uint) mvc.Result {
// @Accept json
// @Produce json
// @Param type path string true "商品类型"
// @Param getListByTypeParam query validate.GetListByTypeParam true "分页信息"
// @Success 200 {object} []model.ItemModel "{["id":1],["id":2]}"
// @Failure 400 {object} map[string]interface{} "{"msg": "错误信息","code":0}"
// @Router /api/item/list/type/{type} [get]
func (c *ItemController) GetListByType(ttype int) mvc.Result {
items, e := c.Service.Item.GetItems(ttype)
getListByTypeParam := new(validate.GetListByTypeParam)
e := validate.ReadJSON(c.Ctx, getListByTypeParam)
items, e := c.Service.Item.GetItems(ttype, getListByTypeParam.Page, getListByTypeParam.PageSize)
if e.Error() {
return e.Response()
}

View File

@ -324,6 +324,22 @@ const docTemplate = `{
"name": "type",
"in": "path",
"required": true
},
{
"type": "integer",
"example": 1,
"description": "@description 页码",
"name": "page",
"in": "query",
"required": true
},
{
"type": "integer",
"example": 10,
"description": "@description 每页数量",
"name": "pageSize",
"in": "query",
"required": true
}
],
"responses": {

View File

@ -318,6 +318,22 @@
"name": "type",
"in": "path",
"required": true
},
{
"type": "integer",
"example": 1,
"description": "@description 页码",
"name": "page",
"in": "query",
"required": true
},
{
"type": "integer",
"example": 10,
"description": "@description 每页数量",
"name": "pageSize",
"in": "query",
"required": true
}
],
"responses": {

View File

@ -363,6 +363,18 @@ paths:
name: type
required: true
type: string
- description: '@description 页码'
example: 1
in: query
name: page
required: true
type: integer
- description: '@description 每页数量'
example: 10
in: query
name: pageSize
required: true
type: integer
produces:
- application/json
responses:

View File

@ -45,9 +45,9 @@ func (s *ItemService) GetItem(id uint) (item *model.ItemModel, e *ecode.Ecode) {
return
}
func (s *ItemService) GetItems(ttype int) (items []model.ItemModel, e *ecode.Ecode) {
func (s *ItemService) GetItems(ttype int, page int, page_size int) (items []model.ItemModel, e *ecode.Ecode) {
e = ecode.OK()
model.DB.Where("type_string like ?", "%["+strconv.Itoa(ttype)+"]%").Where("state!=?", model.ItemStateDelete).Find(&items)
model.DB.Where("state!=?", model.ItemStateDelete).Where("types like ?", "%"+strconv.Itoa(ttype)+"%").Offset((page - 1) * page_size).Limit(page_size).Find(&items)
return
}

View File

@ -14,3 +14,10 @@ type CreateItemParam struct {
type DeleteItemParam struct {
Id uint `json:"id" validate:"required" example:"1"`
}
type GetListByTypeParam struct {
// @description 页码
Page int `json:"page" validate:"required" example:"1"`
// @description 每页数量
PageSize int `json:"pageSize" validate:"required" example:"10"`
}