chat_document.api 4.4 KB

syntax = "v1"

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

@server(
    prefix: v1
    group: chat_document
    jwt: JwtAuth
)
service Core {
	@doc  "详情"
    @handler chat_documentGet
    get /chat_document/:id (ChatDocumentGetRequest) returns (ChatDocumentGetResponse)
    @doc  "保存"
	@handler chat_documentSave
    post /chat_document (ChatDocumentSaveRequest) returns (ChatDocumentSaveResponse)
    @doc  "删除"
	@handler chat_documentDelete
    delete /chat_document/:id (ChatDocumentDeleteRequest) returns (ChatDocumentDeleteResponse)
    @doc  "更新"
	@handler chat_documentUpdate
    put /chat_document/:id (ChatDocumentUpdateRequest) returns (ChatDocumentUpdateResponse)
    @doc  "搜索"
	@handler chat_documentSearch
    post /chat_document/search (ChatDocumentSearchRequest) returns (ChatDocumentSearchResponse)
}

type (
    ChatDocumentGetRequest {
		Id int64 `path:"id"`
	}
    ChatDocumentGetResponse {
		ChatDocument ChatDocumentItem `json:"chat_document"`
    }

	ChatDocumentSaveRequest {
		ChatDocument ChatDocumentItem `json:"chat_document"`
    }
    ChatDocumentSaveResponse {}

	ChatDocumentDeleteRequest {
        Id int64 `path:"id"`
    }
    ChatDocumentDeleteResponse {}

	ChatDocumentUpdateRequest {
		Id int64 `path:"id"`
        ChatDocument ChatDocumentItem `json:"chat_document"`
    }
    ChatDocumentUpdateResponse {}

 	ChatDocumentSearchRequest {
         Page int  `json:"page"`
         Size int  `json:"size"`
    }
    ChatDocumentSearchResponse{
        List []ChatDocumentItem  `json:"list"`
        Total int64 `json:"total"`
    }
	ChatDocumentItem {
	
	}
)

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

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

//func NewDomainChatDocument(item types.ChatDocumentItem) *domain.ChatDocument {
//	return &domain.ChatDocument{

//	}
//}
//
//func NewTypesChatDocument(item *domain.ChatDocument) types.ChatDocumentItem {
//	return types.ChatDocumentItem{
//		Id:     item.Id,
//	}
//}

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

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

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

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