Skip to content

Commit

Permalink
feat: remove unused endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Caknoooo committed Jan 20, 2024
1 parent add5d86 commit 1aaf2bd
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 63 deletions.
22 changes: 0 additions & 22 deletions controller/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type UserController interface {
Me(ctx *gin.Context)
SendVerificationEmail(ctx *gin.Context)
VerifyEmail(ctx *gin.Context)
UpdateStatusIsVerified(ctx *gin.Context)
Login(ctx *gin.Context)
Update(ctx *gin.Context)
Delete(ctx *gin.Context)
Expand Down Expand Up @@ -78,27 +77,6 @@ func (c *userController) GetAllUser(ctx *gin.Context) {
ctx.JSON(http.StatusOK, resp)
}

func (c *userController) UpdateStatusIsVerified(ctx *gin.Context) {
adminId := ctx.MustGet("user_id").(string)

var req dto.UpdateStatusIsVerifiedRequest
if err := ctx.ShouldBind(&req); err != nil {
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_DATA_FROM_BODY, err.Error(), nil)
ctx.AbortWithStatusJSON(http.StatusBadRequest, res)
return
}

result, err := c.userService.UpdateStatusIsVerified(ctx.Request.Context(), req, adminId)
if err != nil {
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_UPDATE_USER, err.Error(), nil)
ctx.JSON(http.StatusBadRequest, res)
return
}

res := utils.BuildResponseSuccess(dto.MESSAGE_SUCCESS_UPDATE_USER, result)
ctx.JSON(http.StatusOK, res)
}

func (c *userController) Me(ctx *gin.Context) {
userId := ctx.MustGet("user_id").(string)

Expand Down
7 changes: 2 additions & 5 deletions routes/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ func User(route *gin.Engine, userController controller.UserController, jwtServic
routes.POST("", userController.Register)
routes.GET("", userController.GetAllUser)
routes.POST("/login", userController.Login)
routes.DELETE("/", middleware.Authenticate(jwtService), userController.Delete)
routes.PATCH("/", middleware.Authenticate(jwtService), userController.Update)
routes.DELETE("", middleware.Authenticate(jwtService), userController.Delete)
routes.PATCH("", middleware.Authenticate(jwtService), userController.Update)
routes.GET("/me", middleware.Authenticate(jwtService), userController.Me)
routes.POST("/verify-email", userController.VerifyEmail)
routes.POST("/verification-email", userController.SendVerificationEmail)

// Admin
routes.PATCH("/admin/verify", middleware.Authenticate(jwtService), userController.UpdateStatusIsVerified)
}
}
36 changes: 0 additions & 36 deletions service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type UserService interface {
GetAllUserWithPagination(ctx context.Context, req dto.PaginationRequest) (dto.UserPaginationResponse, error)
GetUserById(ctx context.Context, userId string) (dto.UserResponse, error)
GetUserByEmail(ctx context.Context, email string) (dto.UserResponse, error)
UpdateStatusIsVerified(ctx context.Context, req dto.UpdateStatusIsVerifiedRequest, adminId string) (dto.UserResponse, error)
SendVerificationEmail(ctx context.Context, req dto.SendVerificationEmailRequest) error
VerifyEmail(ctx context.Context, req dto.VerifyEmailRequest) (dto.VerifyEmailResponse, error)
CheckUser(ctx context.Context, email string) (bool, error)
Expand Down Expand Up @@ -238,41 +237,6 @@ func (s *userService) GetAllUserWithPagination(ctx context.Context, req dto.Pagi
}, nil
}

func (s *userService) UpdateStatusIsVerified(ctx context.Context, req dto.UpdateStatusIsVerifiedRequest, adminId string) (dto.UserResponse, error) {
admin, err := s.userRepo.GetUserById(ctx, adminId)
if err != nil {
return dto.UserResponse{}, dto.ErrUserNotFound
}

if admin.Role != constants.ENUM_ROLE_ADMIN {
return dto.UserResponse{}, dto.ErrUserNotAdmin
}

user, err := s.userRepo.GetUserById(ctx, req.UserId)
if err != nil {
return dto.UserResponse{}, dto.ErrUserNotFound
}

data := entity.User{
ID: user.ID,
IsVerified: req.IsVerified,
}

userUpdate, err := s.userRepo.UpdateUser(ctx, data)
if err != nil {
return dto.UserResponse{}, dto.ErrUpdateUser
}

return dto.UserResponse{
ID: user.ID.String(),
Name: user.Name,
TelpNumber: user.TelpNumber,
Role: user.Role,
Email: user.Email,
IsVerified: userUpdate.IsVerified,
}, nil
}

func (s *userService) GetUserById(ctx context.Context, userId string) (dto.UserResponse, error) {
user, err := s.userRepo.GetUserById(ctx, userId)
if err != nil {
Expand Down

0 comments on commit 1aaf2bd

Please sign in to comment.