feat:完善项目
This commit is contained in:
@ -1,7 +1,158 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/controller/manage"
|
||||
"ArmedPolice/app/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Manage struct{}
|
||||
|
||||
type (
|
||||
// manageEquipmentForm 装备参数信息
|
||||
manageEquipmentForm struct {
|
||||
Code string `json:"code" form:"code" binding:"required"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
ImageForm
|
||||
Config string `json:"config" form:"config"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
}
|
||||
// manageMaterialForm 装备参数信息
|
||||
manageMaterialForm struct {
|
||||
ManufacturerID uint64 `json:"manufacturer_id" form:"manufacturer_id"`
|
||||
Code string `json:"code" form:"code" binding:"required"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
ImageForm
|
||||
Position string `json:"position" form:"position"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
Unit int `json:"unit" form:"Unit" binding:"required"`
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* @apiDefine Manage 数据管理
|
||||
*/
|
||||
|
||||
func (*Manage) Equipment(c *gin.Context) {
|
||||
form := &struct {
|
||||
ParentID uint64 `json:"parent_id" form:"parent_id"`
|
||||
Title string `json:"title" form:"title"`
|
||||
PageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewEquipment()(getSession()(c).(*service.Session)).List(form.ParentID, form.Title, form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) EquipmentDetail(c *gin.Context) {
|
||||
form := new(IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewEquipment()(getSession()(c).(*service.Session)).Detail(form.Convert())
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) EquipmentAdd(c *gin.Context) {
|
||||
form := new(manageEquipmentForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewEquipment()(getSession()(c).(*service.Session)).Form(&manage.EquipmentParams{
|
||||
Code: form.Code, Title: form.Title, Image: form.FilterImageURL(), Config: form.Config,
|
||||
Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) EquipmentEdit(c *gin.Context) {
|
||||
form := &struct {
|
||||
IDStringForm
|
||||
manageEquipmentForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewEquipment()(getSession()(c).(*service.Session)).Form(&manage.EquipmentParams{
|
||||
ID: form.Convert(), Code: form.Code, Title: form.Title, Image: form.FilterImageURL(), Config: form.Config,
|
||||
Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) EquipmentDelete(c *gin.Context) {
|
||||
form := new(IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewEquipment()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) Material(c *gin.Context) {
|
||||
form := &struct {
|
||||
ManufacturerID uint64 `json:"manufacturer_id" form:"manufacturer_id"`
|
||||
SupplierID uint64 `json:"supplier_id" form:"supplier_id"`
|
||||
Code string `json:"code" form:"code"`
|
||||
Title string `json:"title" form:"title"`
|
||||
PageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewMaterial()(getSession()(c).(*service.Session)).
|
||||
List(form.ManufacturerID, form.SupplierID, form.Code, form.Title, form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) MaterialAdd(c *gin.Context) {
|
||||
form := new(manageMaterialForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewMaterial()(getSession()(c).(*service.Session)).Form(&manage.MaterialParams{
|
||||
ManufacturerID: form.ManufacturerID, Code: form.Code, Title: form.Title, Image: form.FilterImageURL(),
|
||||
Position: form.Position, Remark: form.Remark, Unit: form.Unit,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) MaterialEdit(c *gin.Context) {
|
||||
form := &struct {
|
||||
IDStringForm
|
||||
manageMaterialForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewMaterial()(getSession()(c).(*service.Session)).Form(&manage.MaterialParams{
|
||||
ID: form.Convert(), ManufacturerID: form.ManufacturerID, Code: form.Code, Title: form.Title,
|
||||
Image: form.FilterImageURL(), Position: form.Position, Remark: form.Remark, Unit: form.Unit,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) MaterialDelete(c *gin.Context) {
|
||||
form := new(IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewMaterial()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
Reference in New Issue
Block a user