Browse Source

fix:save 5

jimmyyem 5 months ago
parent
commit
7a20c81c5c

+ 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_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 {

+ 2 - 2
desc/wechat/wx_card.api

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

+ 2 - 2
desc/wechat/wx_card_user.api

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

+ 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 {

+ 86 - 62
internal/handler/routes.go

@@ -733,18 +733,22 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
-		[]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.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),
 	)
 
 	server.AddRoutes(
@@ -928,13 +932,17 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
-		[]rest.Route{
-			{
-				Method:  http.MethodPost,
-				Path:    "/api/category/list",
-				Handler: category.GetApiCategoryListHandler(serverCtx),
-			},
-		},
+		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),
 	)
 
 	server.AddRoutes(
@@ -1069,23 +1077,27 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
-		[]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.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),
 	)
 
 	server.AddRoutes(
@@ -1123,13 +1135,17 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
-		[]rest.Route{
-			{
-				Method:  http.MethodPost,
-				Path:    "/api/card/detail",
-				Handler: wxcard.GetApiWxCardDetailHandler(serverCtx),
-			},
-		},
+		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),
 	)
 
 	server.AddRoutes(
@@ -1167,13 +1183,17 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
-		[]rest.Route{
-			{
-				Method:  http.MethodPost,
-				Path:    "/api/user/update",
-				Handler: wxcarduser.UpdateApiWxCardUserHandler(serverCtx),
-			},
-		},
+		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),
 	)
 
 	server.AddRoutes(
@@ -1211,18 +1231,22 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
-		[]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.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),
 	)
 
 	server.AddRoutes(

+ 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 := uint64(1) //l.ctx.Value("userId").(uint64)
+	userId := 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 := uint64(1) //l.ctx.Value("userId").(uint64)
+	userId := 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 := uint64(1) //l.ctx.Value("userId").(uint64)
+	userId := 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 := uint64(1) //l.ctx.Value("userId").(uint64)
+	userId := 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 := uint64(1) //l.ctx.Value("userId").(uint64)
+	userId := l.ctx.Value("userId").(uint64)
 	var id uint64
 	var name string
 

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

@@ -28,7 +28,6 @@ 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)
 	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 := uint64(1) //l.ctx.Value("userId").(uint64)
+	userId := l.ctx.Value("userId").(uint64)
 
 	var nickname, avatar string
 	if req.Nickname != nil && *req.Nickname != "" {

+ 1 - 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 := uint64(1) //l.ctx.Value("userId").(uint64)
+	userId := l.ctx.Value("userId").(uint64)
 
 	var predicates []predicate.WxCardVisit
 	predicates = append(predicates, wxcardvisit.UserID(userId))

+ 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 := uint64(1) //l.ctx.Value("userId").(uint64)
+	userId := l.ctx.Value("userId").(uint64)
 
 	var botId uint64
 	var botType uint8