供应商

This commit is contained in:
范俊成 2023-10-18 11:37:45 +08:00
parent 3015514478
commit 24c555de63
6 changed files with 311 additions and 3 deletions

View File

@ -112,3 +112,31 @@ func UpdateCategory(c *gin.Context) {
app.OK(c, nil, "ok")
}
type DeleteCategoryRequest struct {
Id uint32 `json:"id" validate:"required"`
}
func DeleteCategory(c *gin.Context) {
req := new(DeleteCategoryRequest)
_ = c.ShouldBindJSON(req)
if err := tools.Validate(req); err != nil {
app.Error(c, 400, err, "参数错误")
return
}
category, err := models.GetCategoryById(req.Id)
if err != nil {
app.Error(c, 500, err, "分类不存在")
return
}
err = orm.Eloquent.Model(category).Delete(category.ID).Error
if err != nil {
app.Error(c, 500, err, "删除失败")
return
}
app.OK(c, nil, "ok")
return
}

View File

@ -60,7 +60,7 @@ func GetSupplier(req GetSupplierRequest) ([]*Supplier, error) {
var list []*Supplier
m := orm.Eloquent.Model(Supplier{})
if req.Name != "" {
m = m.Where("name = ?", req.Number)
m = m.Where("name = ?", req.Name)
}
if req.Number != "" {

View File

@ -11,7 +11,7 @@ func registerSupplierRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddl
r := v1.Group("/supplier").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
r.POST("create", basic.SupplierCreate)
r.POST("update", basic.SupplierUpdate)
r.DELETE("delete/{id}", basic.SupplierDel)
r.GET("detail/{id}", basic.SupplierDetail)
r.DELETE("delete/:id", basic.SupplierDel)
r.GET("detail/:id", basic.SupplierDetail)
r.POST("list", basic.SupplierList)
}

View File

@ -19,6 +19,72 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/api/v1/category/create": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"商品分类"
],
"summary": "创建分类",
"parameters": [
{
"description": "商品分类创建模型",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/basic.CreateCategoryRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/app.Response"
}
}
}
}
},
"/api/v1/category/update": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"商品分类"
],
"summary": "编辑分类",
"parameters": [
{
"description": "商品分类编辑模型",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/basic.UpdateCategoryRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/app.Response"
}
}
}
}
},
"/api/v1/config": {
"put": {
"security": [
@ -2673,6 +2739,22 @@ const docTemplate = `{
}
}
},
"basic.CreateCategoryRequest": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"description": "名称",
"type": "string"
},
"pid": {
"description": "父分类id",
"type": "integer"
}
}
},
"basic.SupplierCreateRequest": {
"type": "object",
"required": [
@ -2754,9 +2836,11 @@ const docTemplate = `{
"type": "object",
"properties": {
"name": {
"description": "供应商名称",
"type": "string"
},
"number": {
"description": "供应商编号",
"type": "string"
}
}
@ -2842,6 +2926,27 @@ const docTemplate = `{
}
}
},
"basic.UpdateCategoryRequest": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": {
"description": "分类id",
"type": "integer"
},
"name": {
"description": "名称",
"type": "string"
},
"pid": {
"description": "父分类id",
"type": "integer"
}
}
},
"models.DictType": {
"type": "object",
"properties": {

View File

@ -11,6 +11,72 @@
"version": "1.0.1"
},
"paths": {
"/api/v1/category/create": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"商品分类"
],
"summary": "创建分类",
"parameters": [
{
"description": "商品分类创建模型",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/basic.CreateCategoryRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/app.Response"
}
}
}
}
},
"/api/v1/category/update": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"商品分类"
],
"summary": "编辑分类",
"parameters": [
{
"description": "商品分类编辑模型",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/basic.UpdateCategoryRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/app.Response"
}
}
}
}
},
"/api/v1/config": {
"put": {
"security": [
@ -2665,6 +2731,22 @@
}
}
},
"basic.CreateCategoryRequest": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"description": "名称",
"type": "string"
},
"pid": {
"description": "父分类id",
"type": "integer"
}
}
},
"basic.SupplierCreateRequest": {
"type": "object",
"required": [
@ -2746,9 +2828,11 @@
"type": "object",
"properties": {
"name": {
"description": "供应商名称",
"type": "string"
},
"number": {
"description": "供应商编号",
"type": "string"
}
}
@ -2834,6 +2918,27 @@
}
}
},
"basic.UpdateCategoryRequest": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": {
"description": "分类id",
"type": "integer"
},
"name": {
"description": "名称",
"type": "string"
},
"pid": {
"description": "父分类id",
"type": "integer"
}
}
},
"models.DictType": {
"type": "object",
"properties": {

View File

@ -23,6 +23,17 @@ definitions:
requestId:
type: string
type: object
basic.CreateCategoryRequest:
properties:
name:
description: 名称
type: string
pid:
description: 父分类id
type: integer
required:
- name
type: object
basic.SupplierCreateRequest:
properties:
account_holder:
@ -85,8 +96,10 @@ definitions:
basic.SupplierListRequest:
properties:
name:
description: 供应商名称
type: string
number:
description: 供应商编号
type: string
type: object
basic.SupplierUpdateRequest:
@ -151,6 +164,21 @@ definitions:
- province
- tel
type: object
basic.UpdateCategoryRequest:
properties:
id:
description: 分类id
type: integer
name:
description: 名称
type: string
pid:
description: 父分类id
type: integer
required:
- id
- name
type: object
models.DictType:
properties:
createBy:
@ -984,6 +1012,48 @@ info:
title: go-admin API
version: 1.0.1
paths:
/api/v1/category/create:
post:
consumes:
- application/json
parameters:
- description: 商品分类创建模型
in: body
name: request
required: true
schema:
$ref: '#/definitions/basic.CreateCategoryRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/app.Response'
summary: 创建分类
tags:
- 商品分类
/api/v1/category/update:
post:
consumes:
- application/json
parameters:
- description: 商品分类编辑模型
in: body
name: request
required: true
schema:
$ref: '#/definitions/basic.UpdateCategoryRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/app.Response'
summary: 编辑分类
tags:
- 商品分类
/api/v1/config:
put:
consumes: