article_category.api 4.7 KB

syntax = "v1"

info(
    title: "xx实例"
    desc: "xx实例"
    author: "author"
    email: "email"
    version: "v1"
)

@server(
    prefix: article_category/v1
    group: article_category
    jwt: JwtAuth
)
service Core {
	@doc  "详情"
    @handler article_categoryGet
    get /article_category/:id (ArticleCategoryGetRequest) returns (ArticleCategoryGetResponse)
    @doc  "保存"
	@handler article_categorySave
    post /article_category (ArticleCategorySaveRequest) returns (ArticleCategorySaveResponse)
    @doc  "删除"
	@handler article_categoryDelete
    delete /article_category/:id (ArticleCategoryDeleteRequest) returns (ArticleCategoryDeleteResponse)
    @doc  "更新"
	@handler article_categoryUpdate
    put /article_category/:id (ArticleCategoryUpdateRequest) returns (ArticleCategoryUpdateResponse)
    @doc  "搜索"
	@handler article_categorySearch
    post /article_category/search (ArticleCategorySearchRequest) returns (ArticleCategorySearchResponse)
}

type (
    ArticleCategoryGetRequest {
		Id int64 `path:"id"`
	}
    ArticleCategoryGetResponse struct{
		ArticleCategory ArticleCategoryItem `json:"article_category"`
    }

	ArticleCategorySaveRequest struct{
		ArticleCategory ArticleCategoryItem `json:"article_category"`
    }
    ArticleCategorySaveResponse struct{}

	ArticleCategoryDeleteRequest struct{
        Id int64 `path:"id"`
    }
    ArticleCategoryDeleteResponse struct{}

	ArticleCategoryUpdateRequest struct{
		Id int64 `path:"id"`
        ArticleCategory ArticleCategoryItem `json:"article_category"`
    }
    ArticleCategoryUpdateResponse struct{}

 	ArticleCategorySearchRequest struct{
         Page int  `json:"page"`
         Size int  `json:"size"`
    }
    ArticleCategorySearchResponse{
        List []ArticleCategoryItem  `json:"list"`
        Total int64 `json:"total"`
    }
	ArticleCategoryItem struct{
	
	}
)

// logic CRUD
// Save
	//var (
	//	conn = l.svcCtx.DefaultDBConn()
	//	dm   *domain.ArticleCategory
	//)
	//// 唯一判断

	//dm = NewDomainArticleCategory(req.ArticleCategory)
	//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
	//	dm, err = l.svcCtx.ArticleCategoryRepository.Insert(l.ctx, conn, dm)
	//	return err
	//}, true); err != nil {
	//	return nil, xerr.NewErrMsg("保存失败")
	//}
	////resp = &types.ArticleCategorySaveResponse{}
	//return

//func NewDomainArticleCategory(item types.ArticleCategoryItem) *domain.ArticleCategory {
//	return &domain.ArticleCategory{

//	}
//}
//
//func NewTypesArticleCategory(item *domain.ArticleCategory) types.ArticleCategoryItem {
//	return types.ArticleCategoryItem{
//		Id:     item.Id,
//	}
//}

// Get
	//var (
	//	conn = l.svcCtx.DefaultDBConn()
	//	dm   *domain.ArticleCategory
	//)
	//// 货号唯一
	//if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil {
	//	return nil, xerr.NewErrMsgErr("不存在", err)
	//}
	//resp = &types.ArticleCategoryGetResponse{
	//	ArticleCategory: NewTypesArticleCategory(dm),
	//}
	//return

// Delete
	//var (
	//	conn = l.svcCtx.DefaultDBConn()
	//	dm   *domain.ArticleCategory
	//)
	//if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil {
	//	return nil, xerr.NewErrMsgErr("不存在", err)
	//}
	//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
	//	if dm, err = l.svcCtx.ArticleCategoryRepository.Delete(l.ctx, conn, dm); err != nil {
	//		return err
	//	}
	//	return nil
	//}, true); err != nil {
	//	return nil, xerr.NewErrMsgErr("移除失败", err)
	//}
	//return

// Search
	//var (
	//	conn  = l.svcCtx.DefaultDBConn()
	//	dms   []*domain.ArticleCategory
	//	total int64
	//)
	//
	//queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
	//	WithKV("", "")

	//total, dms, err = l.svcCtx.ArticleCategoryRepository.Find(l.ctx, conn, queryOptions)
	//list := make([]types.ArticleCategoryItem, 0)
	//for i := range dms {
	//	list = append(list, NewTypesArticleCategory(dms[i]))
	//}
	//resp = &types.ArticleCategorySearchResponse{
	//	List:  list,
	//	Total: total,
	//}
	//return

// Update
	//var (
	//	conn = l.svcCtx.DefaultDBConn()
	//	dm   *domain.ArticleCategory
	//)
	//if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil {
	//	return nil, xerr.NewErrMsgErr("不存在", err)
	//}
	//// 不可编辑判断
	
	//// 赋值

	//// 更新
	//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
	//	dm, err = l.svcCtx.ArticleCategoryRepository.UpdateWithVersion(l.ctx, conn, dm)
	//	return err
	//}, true); err != nil {
	//	return nil, xerr.NewErrMsg("更新失败")
	//}
	//resp = &types.ArticleCategoryUpdateResponse{}
	//return