chat_model.api 4.2 KB

syntax = "v1"

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

@server(
    prefix: v1
    group: chat_model
    jwt: JwtAuth
)
service Core {
	@doc  "详情"
    @handler chat_modelGet
    get /chat_model/:id (ChatModelGetRequest) returns (ChatModelGetResponse)
    @doc  "保存"
	@handler chat_modelSave
    post /chat_model (ChatModelSaveRequest) returns (ChatModelSaveResponse)
    @doc  "删除"
	@handler chat_modelDelete
    delete /chat_model/:id (ChatModelDeleteRequest) returns (ChatModelDeleteResponse)
    @doc  "更新"
	@handler chat_modelUpdate
    put /chat_model/:id (ChatModelUpdateRequest) returns (ChatModelUpdateResponse)
    @doc  "搜索"
	@handler chat_modelSearch
    post /chat_model/search (ChatModelSearchRequest) returns (ChatModelSearchResponse)
}

type (
    ChatModelGetRequest {
		Id int64 `path:"id"`
	}
    ChatModelGetResponse {
		ChatModel ChatModelItem `json:"chat_model"`
    }

	ChatModelSaveRequest {
		ChatModel ChatModelItem `json:"chat_model"`
    }
    ChatModelSaveResponse {}

	ChatModelDeleteRequest {
        Id int64 `path:"id"`
    }
    ChatModelDeleteResponse {}

	ChatModelUpdateRequest {
		Id int64 `path:"id"`
        ChatModel ChatModelItem `json:"chat_model"`
    }
    ChatModelUpdateResponse {}

 	ChatModelSearchRequest {
         Page int  `json:"page"`
         Size int  `json:"size"`
    }
    ChatModelSearchResponse{
        List []ChatModelItem  `json:"list"`
        Total int64 `json:"total"`
    }
	ChatModelItem {
	
	}
)

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

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

//func NewDomainChatModel(item types.ChatModelItem) *domain.ChatModel {
//	return &domain.ChatModel{

//	}
//}
//
//func NewTypesChatModel(item *domain.ChatModel) types.ChatModelItem {
//	return types.ChatModelItem{
//		Id:     item.Id,
//	}
//}

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

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

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

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