|
@@ -17,13 +17,16 @@ import (
|
|
|
func Material(r *GinRouter) {
|
|
|
|
|
|
// 新增材料
|
|
|
- r.POST("/material", CreateMaterial)
|
|
|
+ r.POST("/material/create", CreateMaterial)
|
|
|
|
|
|
// 获取材料信息
|
|
|
- r.GET("/material/:id", GetMaterial)
|
|
|
+ r.GET("/material/detail/:id", GetMaterial)
|
|
|
|
|
|
// 获取材料列表
|
|
|
- r.GET("/materials", GetMaterials)
|
|
|
+ r.GET("/material/list", GetMaterials)
|
|
|
+
|
|
|
+ // 材料列表
|
|
|
+ r.POST("/material/update", UpdateMaterial)
|
|
|
|
|
|
r.POST("/material/delete/:id", DelMaterial)
|
|
|
}
|
|
@@ -38,10 +41,10 @@ func CreateMaterial(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
}
|
|
|
ctx := apictx.CreateRepoCtx()
|
|
|
|
|
|
- if material.Name == "" {
|
|
|
+ if len(material.Name) < 1 {
|
|
|
return nil, errors.New("材料名为空")
|
|
|
}
|
|
|
- if material.Type == "" {
|
|
|
+ if len(material.Category) < 1 {
|
|
|
return nil, errors.New("材料类型为空")
|
|
|
}
|
|
|
|
|
@@ -89,6 +92,19 @@ func GetMaterials(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
return repo.RepoPageSearch(apictx.CreateRepoCtx(), option)
|
|
|
}
|
|
|
|
|
|
+func UpdateMaterial(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
+ var mat model.Material
|
|
|
+ err := c.ShouldBindJSON(&mat)
|
|
|
+ if err != nil {
|
|
|
+ return nil, errors.New("参数错误")
|
|
|
+ }
|
|
|
+ if mat.Id == primitive.NilObjectID {
|
|
|
+ return nil, errors.New("id的为空")
|
|
|
+ }
|
|
|
+ mat.UpdateTime = time.Now()
|
|
|
+ return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionMaterial, mat.Id.Hex(), &mat)
|
|
|
+}
|
|
|
+
|
|
|
// 删除材料
|
|
|
func DelMaterial(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
materialId := c.Param("id")
|