| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- package controllers
- import (
- "github.com/gogf/gf/v2/net/ghttp"
- "yx-dataset-server/app/bll"
- "yx-dataset-server/app/errors"
- "yx-dataset-server/app/schema"
- "yx-dataset-server/library/gplus"
- )
- type ChatSession struct {
- ChatSessionBll bll.IChatSession
- }
- func NewChatSession(bChatSession bll.IChatSession) *ChatSession {
- return &ChatSession{
- ChatSessionBll: bChatSession,
- }
- }
- // Query 查询数据
- func (a *ChatSession) Query(r *ghttp.Request) {
- switch r.Get("q").String() {
- case "page":
- a.QueryPage(r)
- case "list":
- a.QueryList(r)
- default:
- gplus.ResError(r, errors.ErrUnknownQuery)
- }
- }
- // QueryPage 查询分页数据
- // @Tags
- // @Summary 查询分页数据
- // @Param Authorization header string false "Bearer 用户令牌"
- // @Param current query int true "分页索引" 1
- // @Param pageSize query int true "分页大小" 10
- // @Success 200 []schema.ChatSession "查询结果:{list:列表数据,pagination:{current:页索引,pageSize:页大小,total:总数量}}"
- // @Failure 400 schema.HTTPError "{error:{code:0,message:未知的查询类型}}"
- // @Failure 401 schema.HTTPError "{error:{code:0,message:未授权}}"
- // @Failure 500 schema.HTTPError "{error:{code:0,message:服务器错误}}"
- // @Router GET /api/v1/chat_session?q=page
- func (a *ChatSession) QueryPage(r *ghttp.Request) {
- ctx := gplus.NewContext(r)
- var params schema.ChatSessionQueryParam
- result, err := a.ChatSessionBll.Query(ctx, params, schema.ChatSessionQueryOptions{
- PageParam: &schema.PaginationParam{
- PageIndex: gplus.GetPageIndex(r),
- PageSize: gplus.GetPageSize(r),
- },
- })
- if err != nil {
- gplus.ResError(r, err)
- }
- gplus.ResPage(r, result.Data, result.PageResult)
- }
- // QueryList 查询列表数据
- // @Tags
- // @Summary 查询列表数据
- // @Param Authorization header string false "Bearer 用户令牌"
- // @Success 200 []schema.ChatSession "查询结果:{list:列表数据}"
- // @Failure 400 schema.HTTPError "{error:{code:0,message:未知的查询类型}}"
- // @Failure 401 schema.HTTPError "{error:{code:0,message:未授权}}"
- // @Failure 500 schema.HTTPError "{error:{code:0,message:服务器错误}}"
- // @Router GET /api/v1/chat_session?q=list
- func (a *ChatSession) QueryList(r *ghttp.Request) {
- ctx := gplus.NewContext(r)
- var params schema.ChatSessionQueryParam
- result, err := a.ChatSessionBll.Query(ctx, params)
- if err != nil {
- gplus.ResError(r, err)
- }
- gplus.ResList(r, result.Data)
- }
- // Get 获取数据
- // @Summary 获取数据
- // @Param id path string true "记录ID"
- // @Success 200 schema.ChatSession
- // @Failure 400 schema.HTTPError "{error:{code:0,message:无效的请求参数}}"
- // @Failure 401 schema.HTTPError "{error:{code:0,message:未授权}}"
- // @Failure 500 schema.HTTPError "{error:{code:0,message:服务器错误}}"
- // @Router /api/v1/chat_session/{id}
- func (a *ChatSession) Get(r *ghttp.Request) {
- ctx := gplus.NewContext(r)
- result, err := a.ChatSessionBll.Get(ctx, r.Get("id").String())
- if err != nil {
- gplus.ResError(r, err)
- }
- gplus.ResSuccess(r, result)
- }
- // Create 创建数据
- // @Tags API-ChatSession
- // @Summary 创建数据
- // @Param body schema.ChatSession true "提交的数据"
- // @Success 200 schema.ChatSession
- // @Failure 400 schema.HTTPError "{error:{code:0,message:无效的请求参数}}"
- // @Failure 401 schema.HTTPError "{error:{code:0,message:未授权}}"
- // @Failure 500 schema.HTTPError "{error:{code:0,message:服务器错误}}"
- // @Router /api/v1/chat_session/ [post]
- func (a *ChatSession) Create(r *ghttp.Request) {
- var data schema.ChatSession
- if err := gplus.ParseJson(r, &data); err != nil {
- gplus.ResError(r, err)
- }
- ctx := gplus.NewContext(r)
- _, err := a.ChatSessionBll.Create(ctx, data)
- if err != nil {
- gplus.ResError(r, err)
- }
- ResSuccess(r, nil)
- }
- // Update 更新数据
- // @Summary 更新数据
- // @Param body schema.ChatSession true "更新数据"
- // @Success 200 schema.ChatSession
- // @Failure 400 schema.HTTPError "{error:{code:0,message:无效的请求参数}}"
- // @Failure 401 schema.HTTPError "{error:{code:0,message:未授权}}"
- // @Failure 500 schema.HTTPError "{error:{code:0,message:服务器错误}}"
- // @Router /api/v1/chat_session/{id}
- func (a *ChatSession) Update(r *ghttp.Request) {
- var data schema.ChatSession
- if err := gplus.ParseJson(r, &data); err != nil {
- gplus.ResError(r, err)
- }
- ctx := gplus.NewContext(r)
- _, err := a.ChatSessionBll.Update(ctx, r.Get("id").String(), data)
- if err != nil {
- gplus.ResError(r, err)
- }
- ResSuccess(r, nil)
- }
- // Delete 删除数据
- // @Summary 删除数据
- // @Param id path string true "记录ID"
- // @Success 200 schema.HTTPStatus "{status:OK}"
- // @Failure 400 schema.HTTPError "{error:{code:0,message:无效的请求参数}}"
- // @Failure 401 schema.HTTPError "{error:{code:0,message:未授权}}"
- // @Failure 500 schema.HTTPError "{error:{code:0,message:服务器错误}}"
- // @Router /api/v1/chat_session/{id}
- func (a *ChatSession) Delete(r *ghttp.Request) {
- ctx := gplus.NewContext(r)
- err := a.ChatSessionBll.Delete(ctx, r.Get("id").String())
- if err != nil {
- gplus.ResError(r, err)
- }
- gplus.ResOK(r)
- }
|