chat_session.api 4.4 KB

syntax = "v1"

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

@server(
    prefix: v1
    group: chat_session
    jwt: JwtAuth
)
service Core {
	@doc  "详情"
    @handler chat_sessionGet
    get /chat_session/:id (ChatSessionGetRequest) returns (ChatSessionGetResponse)
    @doc  "保存"
	@handler chat_sessionSave
    post /chat_session (ChatSessionSaveRequest) returns (ChatSessionSaveResponse)
    @doc  "删除"
	@handler chat_sessionDelete
    delete /chat_session/:id (ChatSessionDeleteRequest) returns (ChatSessionDeleteResponse)
    @doc  "更新"
	@handler chat_sessionUpdate
    put /chat_session/:id (ChatSessionUpdateRequest) returns (ChatSessionUpdateResponse)
    @doc  "搜索"
	@handler chat_sessionSearch
    post /chat_session/search (ChatSessionSearchRequest) returns (ChatSessionSearchResponse)
}

type (
    ChatSessionGetRequest {
		Id int64 `path:"id"`
	}
    ChatSessionGetResponse {
		ChatSession ChatSessionItem `json:"chat_session"`
    }

	ChatSessionSaveRequest {
		ChatSession ChatSessionItem `json:"chat_session"`
    }
    ChatSessionSaveResponse {}

	ChatSessionDeleteRequest {
        Id int64 `path:"id"`
    }
    ChatSessionDeleteResponse {}

	ChatSessionUpdateRequest {
		Id int64 `path:"id"`
        ChatSession ChatSessionItem `json:"chat_session"`
    }
    ChatSessionUpdateResponse {}

 	ChatSessionSearchRequest {
         Page int  `json:"page"`
         Size int  `json:"size"`
    }
    ChatSessionSearchResponse{
        List []ChatSessionItem  `json:"list"`
        Total int64 `json:"total"`
    }
	ChatSessionItem {
	
	}
)

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

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

//func NewDomainChatSession(item types.ChatSessionItem) *domain.ChatSession {
//	return &domain.ChatSession{

//	}
//}
//
//func NewTypesChatSession(item *domain.ChatSession) types.ChatSessionItem {
//	return types.ChatSessionItem{
//		Id:     item.Id,
//	}
//}

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

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

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

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