feat:完善项目
This commit is contained in:
132
app/api/supplier.go
Normal file
132
app/api/supplier.go
Normal file
@ -0,0 +1,132 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/common/model"
|
||||
"ArmedPolice/app/controller/supplier"
|
||||
"ArmedPolice/app/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Supplier struct{}
|
||||
|
||||
type (
|
||||
// supplierForm 参数信息
|
||||
supplierForm struct {
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||||
Address string `json:"address" form:"address"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
}
|
||||
)
|
||||
|
||||
func (*Supplier) Material(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
PageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := supplier.NewInstance()(getSession()(c).(*service.Session)).
|
||||
List(form.Name, form.Mobile, model.ManageSupplierKindForMaterial, form.Page, form.PageSize)
|
||||
APIResponse(err, data)
|
||||
}
|
||||
|
||||
func (*Supplier) MaterialAdd(c *gin.Context) {
|
||||
form := new(supplierForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := supplier.NewInstance()(getSession()(c).(*service.Session)).Form(&supplier.InstanceParams{
|
||||
Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
||||
Kind: model.ManageSupplierKindForMaterial,
|
||||
})
|
||||
APIResponse(err)
|
||||
}
|
||||
|
||||
func (*Supplier) MaterialEdit(c *gin.Context) {
|
||||
form := &struct {
|
||||
IDStringForm
|
||||
supplierForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := supplier.NewInstance()(getSession()(c).(*service.Session)).Form(&supplier.InstanceParams{
|
||||
ID: form.Convert(), Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
||||
Kind: model.ManageSupplierKindForMaterial,
|
||||
})
|
||||
APIResponse(err)
|
||||
}
|
||||
|
||||
func (*Supplier) MaterialDelete(c *gin.Context) {
|
||||
form := new(IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := supplier.NewInstance()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
||||
APIResponse(err)
|
||||
}
|
||||
|
||||
func (*Supplier) Repair(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
PageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := supplier.NewInstance()(getSession()(c).(*service.Session)).
|
||||
List(form.Name, form.Mobile, model.ManageSupplierKindForRepair, form.Page, form.PageSize)
|
||||
APIResponse(err, data)
|
||||
}
|
||||
|
||||
func (*Supplier) RepairAdd(c *gin.Context) {
|
||||
form := new(supplierForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := supplier.NewInstance()(getSession()(c).(*service.Session)).Form(&supplier.InstanceParams{
|
||||
Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
||||
Kind: model.ManageSupplierKindForRepair,
|
||||
})
|
||||
APIResponse(err)
|
||||
}
|
||||
|
||||
func (*Supplier) RepairEdit(c *gin.Context) {
|
||||
form := &struct {
|
||||
IDStringForm
|
||||
supplierForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := supplier.NewInstance()(getSession()(c).(*service.Session)).Form(&supplier.InstanceParams{
|
||||
ID: form.Convert(), Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
||||
Kind: model.ManageSupplierKindForRepair,
|
||||
})
|
||||
APIResponse(err)
|
||||
}
|
||||
|
||||
func (*Supplier) RepairDelete(c *gin.Context) {
|
||||
form := new(IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := supplier.NewInstance()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
||||
APIResponse(err)
|
||||
}
|
Reference in New Issue
Block a user