|
@@ -22,6 +22,29 @@ func MyCaseRoute(r *GinRouter) {
|
|
|
r.POSTJWT("/mycase/update", UpdateMyCase)
|
|
|
}
|
|
|
|
|
|
+func MyMatLib(r *GinRouter) {
|
|
|
+ r.POST("/mymat/create", CreateMyMat)
|
|
|
+ r.POST("/mymat/delete/:id", DeleteMyMat)
|
|
|
+ r.GET("/mymat/list", MatMyList)
|
|
|
+ r.GET("/mymat/detail/:id", MatMyDetail)
|
|
|
+ r.POST("/mymat/update", UpdateMyMat)
|
|
|
+}
|
|
|
+
|
|
|
+func CreateMyMat(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
+ var data model.MyMatLib
|
|
|
+ err := c.ShouldBindJSON(&data)
|
|
|
+ if err != nil {
|
|
|
+ log.Error(err)
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ data.CreateTime = time.Now()
|
|
|
+ data.UpdateTime = time.Now()
|
|
|
+ data.UserId = apictx.User.Id
|
|
|
+ data.UserName = apictx.User.DisplayName
|
|
|
+ return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionMyMat, &data)
|
|
|
+}
|
|
|
+
|
|
|
func CreateMyCase(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
var obj model.MyCase
|
|
|
err := c.ShouldBindJSON(&obj)
|
|
@@ -38,6 +61,15 @@ func CreateMyCase(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionMyCase, &obj)
|
|
|
}
|
|
|
|
|
|
+func DeleteMyMat(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
+ _id := c.Param("id")
|
|
|
+ id, _ := primitive.ObjectIDFromHex(_id)
|
|
|
+ if id.IsZero() {
|
|
|
+ return nil, errors.New("id错误")
|
|
|
+ }
|
|
|
+ return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionMyMat, _id)
|
|
|
+}
|
|
|
+
|
|
|
func DeleteMyCase(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
_id := c.Param("id")
|
|
|
id, _ := primitive.ObjectIDFromHex(_id)
|
|
@@ -47,6 +79,21 @@ func DeleteMyCase(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionMyCase, _id)
|
|
|
}
|
|
|
|
|
|
+func MatMyList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
+
|
|
|
+ page, size, query := UtilQueryPageSize(c)
|
|
|
+ query["userId"] = apictx.User.Id
|
|
|
+
|
|
|
+ return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
|
|
|
+ CollectName: repo.CollectionMyMat,
|
|
|
+ Page: page,
|
|
|
+ Size: size,
|
|
|
+ Query: query,
|
|
|
+ Project: []string{"_id", "name", "cover", "createTime", "updateTime", "userName"},
|
|
|
+ Sort: bson.M{"createTime": -1},
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
func MyCaseList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
|
|
page, size, query := UtilQueryPageSize(c)
|
|
@@ -70,6 +117,28 @@ func MyCaseList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+func MatMyDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
+ _id := c.Param("id")
|
|
|
+ id, _ := primitive.ObjectIDFromHex(_id)
|
|
|
+ if id.IsZero() {
|
|
|
+ return nil, errors.New("id错误")
|
|
|
+ }
|
|
|
+ box := &model.MyMatLib{}
|
|
|
+ found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
+ CollectName: repo.CollectionMyMat,
|
|
|
+ Query: repo.Map{"_id": id},
|
|
|
+ }, box)
|
|
|
+ if err != nil {
|
|
|
+ log.Error(err)
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ if !found {
|
|
|
+ return nil, errors.New("未找到该数据")
|
|
|
+ }
|
|
|
+ return box, nil
|
|
|
+}
|
|
|
+
|
|
|
func MyCaseDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
_id := c.Param("id")
|
|
|
id, _ := primitive.ObjectIDFromHex(_id)
|
|
@@ -92,6 +161,20 @@ func MyCaseDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
return box, nil
|
|
|
}
|
|
|
|
|
|
+func UpdateMyMat(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
+ var box model.MyMatLib
|
|
|
+ err := c.ShouldBindJSON(&box)
|
|
|
+ if err != nil {
|
|
|
+ log.Error(err)
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ if box.Id.IsZero() {
|
|
|
+ return nil, errors.New("id错误")
|
|
|
+ }
|
|
|
+ box.UpdateTime = time.Now()
|
|
|
+ return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionMyMat, box.Id.Hex(), &box)
|
|
|
+}
|
|
|
+
|
|
|
func UpdateMyCase(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
var box model.MyCase
|
|
|
err := c.ShouldBindJSON(&box)
|
|
@@ -102,5 +185,6 @@ func UpdateMyCase(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
if box.Id.IsZero() {
|
|
|
return nil, errors.New("id错误")
|
|
|
}
|
|
|
+ box.UpdateTime = time.Now()
|
|
|
return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionMyCase, box.Id.Hex(), &box)
|
|
|
}
|