From 0176af3f107775553d36debf73d1a85103bac386 Mon Sep 17 00:00:00 2001 From: LinkinStar Date: Fri, 16 Dec 2022 17:14:25 +0800 Subject: [PATCH 1/2] feat(init): Add init version table --- internal/migrations/init.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/migrations/init.go b/internal/migrations/init.go index b90a8196..fed56b97 100644 --- a/internal/migrations/init.go +++ b/internal/migrations/init.go @@ -73,6 +73,10 @@ func InitDB(dataConf *data.Database) (err error) { if err != nil { return fmt.Errorf("sync table failed: %s", err) } + _, err = engine.InsertOne(&entity.Version{ID: 1, VersionNumber: ExpectedVersion()}) + if err != nil { + return fmt.Errorf("init version table failed: %s", err) + } err = initAdminUser(engine) if err != nil { From c3adc710e9e5391fbf1b3c0b44647d97e367bf22 Mon Sep 17 00:00:00 2001 From: LinkinStar Date: Fri, 16 Dec 2022 17:19:04 +0800 Subject: [PATCH 2/2] fix(user): Change logout router position --- internal/controller/user_controller.go | 4 ++++ internal/router/answer_api_router.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/controller/user_controller.go b/internal/controller/user_controller.go index 3be345d2..d64eb837 100644 --- a/internal/controller/user_controller.go +++ b/internal/controller/user_controller.go @@ -198,6 +198,10 @@ func (uc *UserController) UseRePassWord(ctx *gin.Context) { // @Router /answer/api/v1/user/logout [get] func (uc *UserController) UserLogout(ctx *gin.Context) { accessToken := middleware.ExtractToken(ctx) + if len(accessToken) == 0 { + handler.HandleResponse(ctx, nil, nil) + return + } _ = uc.authService.RemoveUserCacheInfo(ctx, accessToken) handler.HandleResponse(ctx, nil, nil) } diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.go index 3fb10bcc..3768b07a 100644 --- a/internal/router/answer_api_router.go +++ b/internal/router/answer_api_router.go @@ -109,6 +109,7 @@ func (a *AnswerAPIRouter) RegisterMustUnAuthAnswerAPIRouter(r *gin.RouterGroup) func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) { // user + r.GET("/user/logout", a.userController.UserLogout) r.POST("/user/email/change/code", a.userController.UserChangeEmailSendCode) r.POST("/user/email/verification/send", a.userController.UserVerifyEmailSend) r.GET("/personal/user/info", a.userController.GetOtherUserInfoByUsername) @@ -196,7 +197,6 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) { r.DELETE("/answer", a.answerController.RemoveAnswer) // user - r.GET("/user/logout", a.userController.UserLogout) r.PUT("/user/password", a.userController.UserModifyPassWord) r.PUT("/user/info", a.userController.UserUpdateInfo) r.PUT("/user/interface", a.userController.UserUpdateInterface)