This commit is contained in:
parent
70e35c4dc6
commit
59a04bcb53
@ -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()
|
||||
}
|
||||
|
16
docs/docs.go
16
docs/docs.go
@ -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": {
|
||||
|
@ -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": {
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user