新增获取类型接口
This commit is contained in:
parent
663866381e
commit
f94c3e1668
@ -16,6 +16,8 @@ func (c *ItemController) BeforeActivation(b mvc.BeforeActivation) {
|
|||||||
b.Handle("GET", "/detail/{id:uint}", "Detail")
|
b.Handle("GET", "/detail/{id:uint}", "Detail")
|
||||||
b.Handle("GET", "/list/{ttype:int}", "GetList")
|
b.Handle("GET", "/list/{ttype:int}", "GetList")
|
||||||
|
|
||||||
|
b.Handle("GET", "types", "GetTypes")
|
||||||
|
|
||||||
// 管理员接口
|
// 管理员接口
|
||||||
{
|
{
|
||||||
b.Handle("POST", "/oper/create", "Create", middleware.JwtMiddleware.Serve)
|
b.Handle("POST", "/oper/create", "Create", middleware.JwtMiddleware.Serve)
|
||||||
@ -64,6 +66,24 @@ func (c *ItemController) GetList(ttype int) mvc.Result {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Summary get item types api
|
||||||
|
// @Description 获取商品类型列表
|
||||||
|
// @Tags item api
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} []model.TypeModel "[{id:1,name:类型1},{id:2,name:类型2}]"
|
||||||
|
// @Failure 400 {object} map[string]interface{} "{"msg": "错误信息","code":0}"
|
||||||
|
// @Router /api/item/types [get]
|
||||||
|
func (c *ItemController) GetTypes() mvc.Result {
|
||||||
|
types, e := c.Service.Item.GetTypes()
|
||||||
|
if e.Error() {
|
||||||
|
return e.Response()
|
||||||
|
}
|
||||||
|
return mvc.Response{
|
||||||
|
Object: types,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// @Summary 创建商品
|
// @Summary 创建商品
|
||||||
// @Description 创建商品接口
|
// @Description 创建商品接口
|
||||||
// @Tags item api
|
// @Tags item api
|
||||||
|
50
docs/docs.go
50
docs/docs.go
@ -387,6 +387,39 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/api/item/types": {
|
||||||
|
"get": {
|
||||||
|
"description": "获取商品类型列表",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"item api"
|
||||||
|
],
|
||||||
|
"summary": "get item types api",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "[{id:1,name:类型1},{id:2,name:类型2}]",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/model.TypeModel"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "{\"msg\": \"错误信息\",\"code\":0}",
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/api/item/{id}": {
|
"/api/item/{id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"description": "获取相关ID的商品信息",
|
"description": "获取相关ID的商品信息",
|
||||||
@ -553,6 +586,23 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"model.TypeModel": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"createdAt": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"updatedAt": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"validate.CreateItemParam": {
|
"validate.CreateItemParam": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
|
@ -381,6 +381,39 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/api/item/types": {
|
||||||
|
"get": {
|
||||||
|
"description": "获取商品类型列表",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"item api"
|
||||||
|
],
|
||||||
|
"summary": "get item types api",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "[{id:1,name:类型1},{id:2,name:类型2}]",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/model.TypeModel"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "{\"msg\": \"错误信息\",\"code\":0}",
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/api/item/{id}": {
|
"/api/item/{id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"description": "获取相关ID的商品信息",
|
"description": "获取相关ID的商品信息",
|
||||||
@ -547,6 +580,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"model.TypeModel": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"createdAt": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"updatedAt": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"validate.CreateItemParam": {
|
"validate.CreateItemParam": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
|
@ -27,6 +27,17 @@ definitions:
|
|||||||
updatedAt:
|
updatedAt:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
|
model.TypeModel:
|
||||||
|
properties:
|
||||||
|
createdAt:
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
updatedAt:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
validate.CreateItemParam:
|
validate.CreateItemParam:
|
||||||
properties:
|
properties:
|
||||||
desc:
|
desc:
|
||||||
@ -396,6 +407,28 @@ paths:
|
|||||||
summary: 删除商品
|
summary: 删除商品
|
||||||
tags:
|
tags:
|
||||||
- item api
|
- item api
|
||||||
|
/api/item/types:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: 获取商品类型列表
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: '[{id:1,name:类型1},{id:2,name:类型2}]'
|
||||||
|
schema:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/model.TypeModel'
|
||||||
|
type: array
|
||||||
|
"400":
|
||||||
|
description: '{"msg": "错误信息","code":0}'
|
||||||
|
schema:
|
||||||
|
additionalProperties: true
|
||||||
|
type: object
|
||||||
|
summary: get item types api
|
||||||
|
tags:
|
||||||
|
- item api
|
||||||
/api/user/auth/login:
|
/api/user/auth/login:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
|
@ -21,7 +21,7 @@ func ConnectToDb(dsn string) *gorm.DB {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = DB.AutoMigrate(&CaptchaModel{}, &UserModel{}, &ItemModel{}, &LoginLogModel{}, &FileModel{})
|
err = DB.AutoMigrate(&CaptchaModel{}, &UserModel{}, &ItemModel{}, &LoginLogModel{}, &FileModel{}, &TypeModel{})
|
||||||
return DB
|
return DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
model/type_model.go
Normal file
10
model/type_model.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
type TypeModel struct {
|
||||||
|
BaseModel
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TypeModel) TableName() string {
|
||||||
|
return "types"
|
||||||
|
}
|
@ -50,3 +50,9 @@ func (s *ItemService) GetItems(ttype int) (items []model.ItemModel, e *ecode.Eco
|
|||||||
model.DB.Where("type_string like ?", "%["+strconv.Itoa(ttype)+"]%").Where("state!=?", model.ItemStateDelete).Find(&items)
|
model.DB.Where("type_string like ?", "%["+strconv.Itoa(ttype)+"]%").Where("state!=?", model.ItemStateDelete).Find(&items)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ItemService) GetTypes() (types []model.TypeModel, e *ecode.Ecode) {
|
||||||
|
e = ecode.OK()
|
||||||
|
model.DB.Find(&types)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user