package api import ( "assetcenter/db/model" "assetcenter/db/repo" "time" "github.com/gin-gonic/gin" "go.mongodb.org/mongo-driver/bson/primitive" ) func ServiceProjectCreate(c *gin.Context, apictx *ApiSession) (interface{}, error) { body := &struct { Name string }{} err := c.ShouldBindJSON(body) if err != nil { return nil, NewError("参数解析错误") } if len(body.Name) < 1 { return nil, NewError("名称不能为空") } project := &model.Project{ Name: body.Name, CreateTime: time.Now(), Products: []*model.Product{}, Scenes: []*model.Scene{}, } project.UserId, _ = primitive.ObjectIDFromHex(apictx.User.ID) return repo.AddProject(apictx.CreateRepoCtx(), project) } func ServiceProjectList(c *gin.Context, apictx *ApiSession) (interface{}, error) { page, size, query := UtilQueryPageSize(c) if query == nil { query = map[string]interface{}{} } query["userId"], _ = primitive.ObjectIDFromHex(apictx.User.ID) return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{ CollectName: repo.CollectionProject, Page: page, Size: size, Query: query, Project: []string{"name", "thumbnail", "createTime"}, }) } func ServiceProjectDelete(c *gin.Context, apictx *ApiSession) (interface{}, error) { id := c.Param("id") if len(id) < 1 { return nil, NewError("参数不能为空") } return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionProject, id) }