Skip to content

Commit

Permalink
Refactor UserController to remove token manager dependency and update…
Browse files Browse the repository at this point in the history
… utils dependency to v0.3.0
  • Loading branch information
L4B0MB4 committed Dec 1, 2024
1 parent 0831b5a commit 2216d91
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
9 changes: 2 additions & 7 deletions cmd/queryer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@ func main() {
log.Error().Err(err).Msg("Unsuccessful initialization of client")
return
}
tokenManager, err := auth.NewTokenManager()
if err != nil {
log.Error().Err(err).Msg("Unsuccessful initialization of token manager")
return
}
eventRepo := utilsRepo.NewEventRepository(conn)
userRepo := repository.NewUserRepository(conn)
uc := controller.NewUserController(userRepo, tokenManager)
aut := auth.NewAuthMiddleware(tokenManager)
uc := controller.NewUserController(userRepo)
aut := auth.NewAuthMiddleware()
h := httphandler.NewHttpHandler(uc, aut)

userEventHandler := eventhandling.NewUserEventHandler(userRepo)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require github.com/mattn/go-sqlite3 v1.14.24

require (
github.com/L4B0MB4/EVTSRC v0.5.3 // indirect
github.com/PRYVT/utils v0.2.1 // indirect
github.com/PRYVT/utils v0.3.0 // indirect
github.com/bytedance/sonic v1.12.2 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ github.com/PRYVT/utils v0.2.0 h1:hWdHchXlGOYlJ1nfMmGffq/EjFn3ncvzTgsGCLUpiEE=
github.com/PRYVT/utils v0.2.0/go.mod h1:j61GmoyWWXgnCq/laZTIJm4yhD0PreLDMZnYQqjSv7w=
github.com/PRYVT/utils v0.2.1 h1:GiTbziM3lqRLc4EWGV28+T/aKaY+B80KTqnkBklf9q0=
github.com/PRYVT/utils v0.2.1/go.mod h1:j61GmoyWWXgnCq/laZTIJm4yhD0PreLDMZnYQqjSv7w=
github.com/PRYVT/utils v0.3.0 h1:E0q08Gba+TdIsflKBA2XJLEE/RqbB8u3oXxy1wM7l+s=
github.com/PRYVT/utils v0.3.0/go.mod h1:j61GmoyWWXgnCq/laZTIJm4yhD0PreLDMZnYQqjSv7w=
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic v1.12.2 h1:oaMFuRTpMHYLpCntGca65YWt5ny+wAceDERTkT2L9lg=
Expand Down
13 changes: 6 additions & 7 deletions pkg/query/httphandler/controller/user_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import (
)

type UserController struct {
userRepo *repository.UserRepository
tokenManager *auth.TokenManager
userRepo *repository.UserRepository
}

func NewUserController(userRepo *repository.UserRepository, tokenManager *auth.TokenManager) *UserController {
return &UserController{userRepo: userRepo, tokenManager: tokenManager}
func NewUserController(userRepo *repository.UserRepository) *UserController {
return &UserController{userRepo: userRepo}
}

func (ctrl *UserController) GetToken(c *gin.Context) {
Expand All @@ -42,7 +41,7 @@ func (ctrl *UserController) GetToken(c *gin.Context) {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
return
}
token, err := ctrl.tokenManager.CreateToken(userUuid)
token, err := auth.CreateToken(userUuid)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
Expand All @@ -52,12 +51,12 @@ func (ctrl *UserController) GetToken(c *gin.Context) {
func (ctrl *UserController) RefreshToken(c *gin.Context) {

tokenStr := auth.GetTokenFromHeader(c)
userUuid, err := ctrl.tokenManager.GetUserUuidFromToken(tokenStr)
userUuid, err := auth.GetUserUuidFromToken(tokenStr)
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
return
}
token, err := ctrl.tokenManager.CreateToken(userUuid)
token, err := auth.CreateToken(userUuid)

if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
Expand Down

0 comments on commit 2216d91

Please sign in to comment.