Browse Source

list 接口输出 object id 转字符串

boweniac 1 month ago
parent
commit
4bf43500b1

+ 25 - 0
desc/wechat/fastgpt.api

@@ -34,6 +34,22 @@ type (
 
         Intro string `json:"intro"`
     }
+
+    CreateAppsReq {
+        Type string `json:"type"`
+        Name string `json:"name"`
+        Intro string `json:"intro,optional"`
+    }
+
+    UpdateAppsReq {
+        Id string `json:"id"`
+        Name string `json:"name"`
+        Intro string `json:"intro,optional"`
+    }
+
+    DeleteAppsReq {
+        Id string `json:"id"`
+    }
 )
 
 @server(
@@ -58,4 +74,13 @@ service Wechat {
 service Wechat {
     @handler GetAppsList
     post /api/fastgpt/apps_list (AppsListReq) returns (AppsListResp)
+
+    @handler CreateApp
+    post /api/fastgpt/create_app (CreateAppsReq) returns (BaseMsgResp)
+
+    @handler UpdateApp
+    post /api/fastgpt/update_app (UpdateAppsReq) returns (BaseMsgResp)
+
+    @handler DeleteApp
+    post /api/fastgpt/delete_app (DeleteAppsReq) returns (BaseMsgResp)
 }

+ 44 - 0
internal/handler/fastgpt/create_app_handler.go

@@ -0,0 +1,44 @@
+package fastgpt
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/fastgpt"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /api/fastgpt/create_app fastgpt CreateApp
+//
+
+//
+
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: CreateAppsReq
+//
+// Responses:
+//  200: BaseMsgResp
+
+func CreateAppHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.CreateAppsReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := fastgpt.NewCreateAppLogic(r.Context(), svcCtx)
+		resp, err := l.CreateApp(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/fastgpt/delete_app_handler.go

@@ -0,0 +1,44 @@
+package fastgpt
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/fastgpt"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /api/fastgpt/delete_app fastgpt DeleteApp
+//
+
+//
+
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: DeleteAppsReq
+//
+// Responses:
+//  200: BaseMsgResp
+
+func DeleteAppHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.DeleteAppsReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := fastgpt.NewDeleteAppLogic(r.Context(), svcCtx)
+		resp, err := l.DeleteApp(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/fastgpt/update_app_handler.go

@@ -0,0 +1,44 @@
+package fastgpt
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/fastgpt"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /api/fastgpt/update_app fastgpt UpdateApp
+//
+
+//
+
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: UpdateAppsReq
+//
+// Responses:
+//  200: BaseMsgResp
+
+func UpdateAppHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.UpdateAppsReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := fastgpt.NewUpdateAppLogic(r.Context(), svcCtx)
+		resp, err := l.UpdateApp(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 15 - 0
internal/handler/routes.go

@@ -2156,6 +2156,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 					Path:    "/api/fastgpt/apps_list",
 					Handler: fastgpt.GetAppsListHandler(serverCtx),
 				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/api/fastgpt/create_app",
+					Handler: fastgpt.CreateAppHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/api/fastgpt/update_app",
+					Handler: fastgpt.UpdateAppHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/api/fastgpt/delete_app",
+					Handler: fastgpt.DeleteAppHandler(serverCtx),
+				},
 			}...,
 		),
 		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),

+ 29 - 0
internal/logic/fastgpt/create_app_logic.go

@@ -0,0 +1,29 @@
+package fastgpt
+
+import (
+	"context"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type CreateAppLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewCreateAppLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAppLogic {
+	return &CreateAppLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *CreateAppLogic) CreateApp(req *types.CreateAppsReq) (resp *types.BaseMsgResp, err error) {
+	// todo: add your logic here and delete this line
+
+	return
+}

+ 29 - 0
internal/logic/fastgpt/delete_app_logic.go

@@ -0,0 +1,29 @@
+package fastgpt
+
+import (
+	"context"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type DeleteAppLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewDeleteAppLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteAppLogic {
+	return &DeleteAppLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *DeleteAppLogic) DeleteApp(req *types.DeleteAppsReq) (resp *types.BaseMsgResp, err error) {
+	// todo: add your logic here and delete this line
+
+	return
+}

+ 3 - 3
internal/logic/fastgpt/get_apps_list_logic.go

@@ -49,9 +49,9 @@ func (l *GetAppsListLogic) GetAppsList(req *types.AppsListReq) (resp *types.Apps
 	if data != nil {
 		for _, app := range data {
 			appList = append(appList, &types.AppsListRespInfo{
-				Id:     app.ID.String(),
-				TeamId: app.TeamID.String(),
-				TmbId:  app.TmbID.String(),
+				Id:     app.ID.Hex(),
+				TeamId: app.TeamID.Hex(),
+				TmbId:  app.TmbID.Hex(),
 				Avatar: app.Avatar,
 				Name:   app.Name,
 				Intro:  app.Intro,

+ 29 - 0
internal/logic/fastgpt/update_app_logic.go

@@ -0,0 +1,29 @@
+package fastgpt
+
+import (
+	"context"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type UpdateAppLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewUpdateAppLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateAppLogic {
+	return &UpdateAppLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *UpdateAppLogic) UpdateApp(req *types.UpdateAppsReq) (resp *types.BaseMsgResp, err error) {
+	// todo: add your logic here and delete this line
+
+	return
+}

+ 19 - 0
internal/types/types.go

@@ -4325,3 +4325,22 @@ type AppsListRespInfo struct {
 	Name   string `json:"name"`
 	Intro  string `json:"intro"`
 }
+
+// swagger:model CreateAppsReq
+type CreateAppsReq struct {
+	Type  string `json:"type"`
+	Name  string `json:"name"`
+	Intro string `json:"intro,optional"`
+}
+
+// swagger:model UpdateAppsReq
+type UpdateAppsReq struct {
+	Id    string `json:"id"`
+	Name  string `json:"name"`
+	Intro string `json:"intro,optional"`
+}
+
+// swagger:model DeleteAppsReq
+type DeleteAppsReq struct {
+	Id string `json:"id"`
+}