article_template.api 4.7 KB

syntax = "v1"

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

@server(
    prefix: article_template/v1
    group: article_template
    jwt: JwtAuth
)
service Core {
	@doc  "详情"
    @handler article_templateGet
    get /article_template/:id (ArticleTemplateGetRequest) returns (ArticleTemplateGetResponse)
    @doc  "保存"
	@handler article_templateSave
    post /article_template (ArticleTemplateSaveRequest) returns (ArticleTemplateSaveResponse)
    @doc  "删除"
	@handler article_templateDelete
    delete /article_template/:id (ArticleTemplateDeleteRequest) returns (ArticleTemplateDeleteResponse)
    @doc  "更新"
	@handler article_templateUpdate
    put /article_template/:id (ArticleTemplateUpdateRequest) returns (ArticleTemplateUpdateResponse)
    @doc  "搜索"
	@handler article_templateSearch
    post /article_template/search (ArticleTemplateSearchRequest) returns (ArticleTemplateSearchResponse)
}

type (
    ArticleTemplateGetRequest {
		Id int64 `path:"id"`
	}
    ArticleTemplateGetResponse struct{
		ArticleTemplate ArticleTemplateItem `json:"article_template"`
    }

	ArticleTemplateSaveRequest struct{
		ArticleTemplate ArticleTemplateItem `json:"article_template"`
    }
    ArticleTemplateSaveResponse struct{}

	ArticleTemplateDeleteRequest struct{
        Id int64 `path:"id"`
    }
    ArticleTemplateDeleteResponse struct{}

	ArticleTemplateUpdateRequest struct{
		Id int64 `path:"id"`
        ArticleTemplate ArticleTemplateItem `json:"article_template"`
    }
    ArticleTemplateUpdateResponse struct{}

 	ArticleTemplateSearchRequest struct{
         Page int  `json:"page"`
         Size int  `json:"size"`
    }
    ArticleTemplateSearchResponse{
        List []ArticleTemplateItem  `json:"list"`
        Total int64 `json:"total"`
    }
	ArticleTemplateItem struct{
	
	}
)

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

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

//func NewDomainArticleTemplate(item types.ArticleTemplateItem) *domain.ArticleTemplate {
//	return &domain.ArticleTemplate{

//	}
//}
//
//func NewTypesArticleTemplate(item *domain.ArticleTemplate) types.ArticleTemplateItem {
//	return types.ArticleTemplateItem{
//		Id:     item.Id,
//	}
//}

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

// Delete
	//var (
	//	conn = l.svcCtx.DefaultDBConn()
	//	dm   *domain.ArticleTemplate
	//)
	//if dm, err = l.svcCtx.ArticleTemplateRepository.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.ArticleTemplateRepository.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.ArticleTemplate
	//	total int64
	//)
	//
	//queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
	//	WithKV("", "")

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

// Update
	//var (
	//	conn = l.svcCtx.DefaultDBConn()
	//	dm   *domain.ArticleTemplate
	//)
	//if dm, err = l.svcCtx.ArticleTemplateRepository.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.ArticleTemplateRepository.UpdateWithVersion(l.ctx, conn, dm)
	//	return err
	//}, true); err != nil {
	//	return nil, xerr.NewErrMsg("更新失败")
	//}
	//resp = &types.ArticleTemplateUpdateResponse{}
	//return