Browse Source

fix:save 4

jimmyyem 5 months ago
parent
commit
badb67857d

+ 2 - 2
desc/wechat/category.api

@@ -46,9 +46,9 @@ type (
 )
 
 @server(
-	jwt: Auth
+//	jwt: Auth
 	group: category
-	middleware: Miniprogram
+//	middleware: Miniprogram
 )
 
 service Wechat {

+ 2 - 2
desc/wechat/chat_records.api

@@ -61,9 +61,9 @@ type (
 )
 
 @server(
-	jwt: Auth
+//	jwt: Auth
 	group: chatrecords
-	middleware: Miniprogram
+//	middleware: Miniprogram
 )
 
 service Wechat {

+ 2 - 2
desc/wechat/chat_session.api

@@ -51,9 +51,9 @@ type (
 )
 
 @server(
-	jwt: Auth
+//	jwt: Auth
 	group: chatsession
-	middleware: Miniprogram
+//	middleware: Miniprogram
 )
 
 service Wechat {

+ 2 - 2
desc/wechat/employee.api

@@ -114,9 +114,9 @@ type (
 )
 
 @server(
-	jwt: Auth
+//	jwt: Auth
 	group: employee
-	middleware: Miniprogram
+//	middleware: Miniprogram
 )
 
 service Wechat {

+ 3 - 2
desc/wechat/wx_card.api

@@ -50,6 +50,7 @@ type (
     }
 
 	WxCardSimpleInfo {
+		ID *uint64 `json:"id,optional"`
 		// 头像
 		Avatar  *string `json:"avatar,optional"`
 
@@ -97,9 +98,9 @@ type (
 )
 
 @server(
-	jwt: Auth
+//	jwt: Auth
 	group: wxcard
-	middleware: Miniprogram
+//	middleware: Miniprogram
 )
 
 service Wechat {

+ 2 - 4
desc/wechat/wx_card_user.api

@@ -67,14 +67,12 @@ type (
 )
 
 @server(
-	jwt: Auth
+//	jwt: Auth
 	group: wxcarduser
-	middleware: Miniprogram
+//	middleware: Miniprogram
 )
 
 service Wechat {
-
-
 	// Update wx card user information | 更新WxCardUser
 	@handler updateApiWxCardUser
 	post /api/user/update (WxCardUserInfo) returns (BaseMsgResp)

+ 2 - 2
desc/wechat/wx_card_visit.api

@@ -64,9 +64,9 @@ type (
 )
 
 @server(
-	jwt: Auth
+//	jwt: Auth
 	group: wxcardvisit
-	middleware: Miniprogram
+//	middleware: Miniprogram
 )
 
 service Wechat {

+ 79 - 107
internal/handler/routes.go

@@ -733,22 +733,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
-		rest.WithMiddlewares(
-			[]rest.Middleware{serverCtx.Miniprogram},
-			[]rest.Route{
-				{
-					Method:  http.MethodPost,
-					Path:    "/api/employee/list",
-					Handler: employee.GetApiEmployeeListHandler(serverCtx),
-				},
-				{
-					Method:  http.MethodPost,
-					Path:    "/api/employee/detail",
-					Handler: employee.GetApiEmployeeDetailHandler(serverCtx),
-				},
-			}...,
-		),
-		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+		[]rest.Route{
+			{
+				Method:  http.MethodPost,
+				Path:    "/api/employee/list",
+				Handler: employee.GetApiEmployeeListHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/api/employee/detail",
+				Handler: employee.GetApiEmployeeDetailHandler(serverCtx),
+			},
+		},
 	)
 
 	server.AddRoutes(
@@ -932,17 +928,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
-		rest.WithMiddlewares(
-			[]rest.Middleware{serverCtx.Miniprogram},
-			[]rest.Route{
-				{
-					Method:  http.MethodPost,
-					Path:    "/api/category/list",
-					Handler: category.GetApiCategoryListHandler(serverCtx),
-				},
-			}...,
-		),
-		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+		[]rest.Route{
+			{
+				Method:  http.MethodPost,
+				Path:    "/api/category/list",
+				Handler: category.GetApiCategoryListHandler(serverCtx),
+			},
+		},
 	)
 
 	server.AddRoutes(
@@ -1019,27 +1011,23 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
-		rest.WithMiddlewares(
-			[]rest.Middleware{serverCtx.Miniprogram},
-			[]rest.Route{
-				{
-					Method:  http.MethodPost,
-					Path:    "/api/chat/create",
-					Handler: chatrecords.SubmitApiChatHandler(serverCtx),
-				},
-				{
-					Method:  http.MethodPost,
-					Path:    "/api/chat/list",
-					Handler: chatrecords.GetApiChatListHandler(serverCtx),
-				},
-				{
-					Method:  http.MethodPost,
-					Path:    "/api/chat/save",
-					Handler: chatrecords.SaveApiChatHandler(serverCtx),
-				},
-			}...,
-		),
-		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+		[]rest.Route{
+			{
+				Method:  http.MethodPost,
+				Path:    "/api/chat/create",
+				Handler: chatrecords.SubmitApiChatHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/api/chat/list",
+				Handler: chatrecords.GetApiChatListHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/api/chat/save",
+				Handler: chatrecords.SaveApiChatHandler(serverCtx),
+			},
+		},
 	)
 
 	server.AddRoutes(
@@ -1077,27 +1065,23 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
-		rest.WithMiddlewares(
-			[]rest.Middleware{serverCtx.Miniprogram},
-			[]rest.Route{
-				{
-					Method:  http.MethodPost,
-					Path:    "/api/session/list",
-					Handler: chatsession.GetApiSessionListHandler(serverCtx),
-				},
-				{
-					Method:  http.MethodPost,
-					Path:    "/api/session/update",
-					Handler: chatsession.UpdateApiSessionHandler(serverCtx),
-				},
-				{
-					Method:  http.MethodPost,
-					Path:    "/api/session/delete",
-					Handler: chatsession.DeleteApiSessionHandler(serverCtx),
-				},
-			}...,
-		),
-		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+		[]rest.Route{
+			{
+				Method:  http.MethodPost,
+				Path:    "/api/session/list",
+				Handler: chatsession.GetApiSessionListHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/api/session/update",
+				Handler: chatsession.UpdateApiSessionHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/api/session/delete",
+				Handler: chatsession.DeleteApiSessionHandler(serverCtx),
+			},
+		},
 	)
 
 	server.AddRoutes(
@@ -1135,17 +1119,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
-		rest.WithMiddlewares(
-			[]rest.Middleware{serverCtx.Miniprogram},
-			[]rest.Route{
-				{
-					Method:  http.MethodPost,
-					Path:    "/api/card/detail",
-					Handler: wxcard.GetApiWxCardDetailHandler(serverCtx),
-				},
-			}...,
-		),
-		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+		[]rest.Route{
+			{
+				Method:  http.MethodPost,
+				Path:    "/api/card/detail",
+				Handler: wxcard.GetApiWxCardDetailHandler(serverCtx),
+			},
+		},
 	)
 
 	server.AddRoutes(
@@ -1183,17 +1163,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
-		rest.WithMiddlewares(
-			[]rest.Middleware{serverCtx.Miniprogram},
-			[]rest.Route{
-				{
-					Method:  http.MethodPost,
-					Path:    "/api/user/update",
-					Handler: wxcarduser.UpdateApiWxCardUserHandler(serverCtx),
-				},
-			}...,
-		),
-		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+		[]rest.Route{
+			{
+				Method:  http.MethodPost,
+				Path:    "/api/user/update",
+				Handler: wxcarduser.UpdateApiWxCardUserHandler(serverCtx),
+			},
+		},
 	)
 
 	server.AddRoutes(
@@ -1231,22 +1207,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
-		rest.WithMiddlewares(
-			[]rest.Middleware{serverCtx.Miniprogram},
-			[]rest.Route{
-				{
-					Method:  http.MethodPost,
-					Path:    "/api/card/visit",
-					Handler: wxcardvisit.SubmitApiWxCardVisitHandler(serverCtx),
-				},
-				{
-					Method:  http.MethodPost,
-					Path:    "/api/card/visit/history",
-					Handler: wxcardvisit.GetApiWxCardVisitListHandler(serverCtx),
-				},
-			}...,
-		),
-		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+		[]rest.Route{
+			{
+				Method:  http.MethodPost,
+				Path:    "/api/card/visit",
+				Handler: wxcardvisit.SubmitApiWxCardVisitHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/api/card/visit/history",
+				Handler: wxcardvisit.GetApiWxCardVisitListHandler(serverCtx),
+			},
+		},
 	)
 
 	server.AddRoutes(

+ 4 - 0
internal/logic/User/do_api_user_login_logic.go

@@ -62,6 +62,10 @@ func (l *DoApiUserLoginLogic) DoApiUserLogin(req *types.UserLoginReq) (*types.Us
 		return nil, errorx.NewApiInternalError("wechat login error")
 	}
 
+	if resp.ErrCode != 0 {
+		return nil, errorx.NewApiInternalError(resp.ErrMSG)
+	}
+
 	userInfo, err := l.svcCtx.DB.WxCardUser.Query().Where(wxcarduser.OpenID(resp.OpenID)).First(l.ctx)
 	if err != nil {
 		if ent.IsNotFound(err) {

+ 1 - 1
internal/logic/chatrecords/get_api_chat_list_logic.go

@@ -29,7 +29,7 @@ func NewGetApiChatListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
 }
 
 func (l *GetApiChatListLogic) GetApiChatList(req *types.ChatRecordsListReq) (*types.ChatRecordsListResp, error) {
-	userId := l.ctx.Value("userId").(uint64)
+	userId := uint64(1) //l.ctx.Value("userId").(uint64)
 
 	var predicates []predicate.ChatRecords
 	predicates = append(predicates, chatrecords.UserID(userId))

+ 1 - 1
internal/logic/chatrecords/save_api_chat_logic.go

@@ -25,7 +25,7 @@ func NewSaveApiChatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveA
 }
 
 func (l *SaveApiChatLogic) SaveApiChat(req *types.ChatRecordsInfo) (*types.BaseMsgResp, error) {
-	userId := l.ctx.Value("userId").(uint64)
+	userId := uint64(1) //l.ctx.Value("userId").(uint64)
 	sessionId := *req.SessionId
 
 	// 记录下问题

+ 1 - 1
internal/logic/chatrecords/submit_api_chat_logic.go

@@ -46,7 +46,7 @@ func NewSubmitApiChatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sub
 }
 
 func (l *SubmitApiChatLogic) SubmitApiChat(req *types.ChatRecordsInfo, w http.ResponseWriter) {
-	userId := l.ctx.Value("userId").(uint64)
+	userId := uint64(1) //l.ctx.Value("userId").(uint64)
 
 	// session_id 字段确保必须有
 	var sessionId uint64

+ 1 - 1
internal/logic/chatsession/delete_api_session_logic.go

@@ -27,7 +27,7 @@ func NewDeleteApiSessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 }
 
 func (l *DeleteApiSessionLogic) DeleteApiSession(req *types.IDsReq) (*types.BaseMsgResp, error) {
-	userId := l.ctx.Value("userId").(uint64)
+	userId := uint64(1) //l.ctx.Value("userId").(uint64)
 
 	msg := errormsg.Success
 	ids := req.Ids

+ 1 - 1
internal/logic/chatsession/get_api_session_list_logic.go

@@ -28,7 +28,7 @@ func NewGetApiSessionListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 }
 
 func (l *GetApiSessionListLogic) GetApiSessionList(req *types.ChatSessionListReq) (*types.ChatSessionListResp, error) {
-	userId := l.ctx.Value("userId").(uint64)
+	userId := uint64(1) //l.ctx.Value("userId").(uint64)
 
 	var predicates []predicate.ChatSession
 	predicates = append(predicates, chatsession.UserID(userId))

+ 1 - 1
internal/logic/chatsession/update_api_session_logic.go

@@ -27,7 +27,7 @@ func NewUpdateApiSessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 }
 
 func (l *UpdateApiSessionLogic) UpdateApiSession(req *types.ChatSessionInfo) (*types.BaseMsgResp, error) {
-	userId := l.ctx.Value("userId").(uint64)
+	userId := uint64(1) //l.ctx.Value("userId").(uint64)
 	var id uint64
 	var name string
 

+ 1 - 2
internal/logic/employee/get_api_employee_detail_logic.go

@@ -2,7 +2,6 @@ package employee
 
 import (
 	"context"
-	"fmt"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"wechat-api/ent/employee"
@@ -29,7 +28,7 @@ func NewGetApiEmployeeDetailLogic(ctx context.Context, svcCtx *svc.ServiceContex
 
 func (l *GetApiEmployeeDetailLogic) GetApiEmployeeDetail(req *types.IDReq) (*types.EmployeeInfoResp, error) {
 	data, err := l.svcCtx.DB.Employee.Query().Where(employee.ID(req.Id)).Only(l.ctx)
-	fmt.Printf("%v", data)
+	//fmt.Printf("%v", data)
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}

+ 1 - 1
internal/logic/wxcarduser/update_api_wx_card_user_logic.go

@@ -27,7 +27,7 @@ func NewUpdateApiWxCardUserLogic(ctx context.Context, svcCtx *svc.ServiceContext
 }
 
 func (l *UpdateApiWxCardUserLogic) UpdateApiWxCardUser(req *types.WxCardUserInfo) (*types.BaseMsgResp, error) {
-	userId := l.ctx.Value("userId").(uint64)
+	userId := uint64(1) //l.ctx.Value("userId").(uint64)
 
 	var nickname, avatar string
 	if req.Nickname != nil && *req.Nickname != "" {

+ 3 - 1
internal/logic/wxcardvisit/get_api_wx_card_visit_list_logic.go

@@ -32,7 +32,7 @@ func NewGetApiWxCardVisitListLogic(ctx context.Context, svcCtx *svc.ServiceConte
 }
 
 func (l *GetApiWxCardVisitListLogic) GetApiWxCardVisitList(req *types.WxCardVisitListReq) (*types.WxCardVisitListResp, error) {
-	userId := l.ctx.Value("userId").(uint64)
+	userId := uint64(1) //l.ctx.Value("userId").(uint64)
 
 	var predicates []predicate.WxCardVisit
 	predicates = append(predicates, wxcardvisit.UserID(userId))
@@ -80,11 +80,13 @@ func (l *GetApiWxCardVisitListLogic) GetApiWxCardVisitList(req *types.WxCardVisi
 			if card, ok := wxCardList[v.BotID]; ok {
 				cardInfo.Name = &card.Name
 				cardInfo.Avatar = &card.Avatar
+				cardInfo.ID = &card.ID
 			}
 		} else {
 			if agentItem, ok := wxAgentList[v.BotID]; ok {
 				cardInfo.Name = &agentItem.Name
 				cardInfo.Avatar = tea.String("")
+				cardInfo.ID = &agentItem.ID
 			}
 		}
 		resp.Data.Data = append(resp.Data.Data,

+ 1 - 1
internal/logic/wxcardvisit/submit_api_wx_card_visit_logic.go

@@ -29,7 +29,7 @@ func NewSubmitApiWxCardVisitLogic(ctx context.Context, svcCtx *svc.ServiceContex
 }
 
 func (l *SubmitApiWxCardVisitLogic) SubmitApiWxCardVisit(req *types.WxCardVisitInfo) (*types.BaseMsgResp, error) {
-	userId := l.ctx.Value("userId").(uint64)
+	userId := uint64(1) //l.ctx.Value("userId").(uint64)
 
 	var botId uint64
 	var botType uint8

+ 1 - 0
internal/types/types.go

@@ -2258,6 +2258,7 @@ type WxCardInfo struct {
 
 // swagger:model WxCardSimpleInfo
 type WxCardSimpleInfo struct {
+	ID *uint64 `json:"id,optional"`
 	// 头像
 	Avatar *string `json:"avatar,optional"`
 	// 名称