Spaces:
Runtime error
Runtime error
RyZ commited on
Commit ·
ca90ab4
1
Parent(s): 404f2d9
fix: fixing hf bug
Browse files- controllers/auth_controller.go +115 -0
- models/dto/auth_dto.go +23 -0
- repositories/user_repository.go +5 -0
- router/auth_router.go +10 -0
- router/router.go +0 -2
- services/auth_service.go +121 -0
controllers/auth_controller.go
CHANGED
|
@@ -22,6 +22,10 @@ type AuthController interface {
|
|
| 22 |
GetAllUsers(ctx *gin.Context)
|
| 23 |
GetAllWorkers(ctx *gin.Context)
|
| 24 |
AssignWorkerRole(ctx *gin.Context)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
|
| 27 |
type authController struct {
|
|
@@ -267,3 +271,114 @@ func (c *authController) AssignWorkerRole(ctx *gin.Context) {
|
|
| 267 |
|
| 268 |
utils.SendSuccessResponse(ctx, "Worker role assigned successfully", nil)
|
| 269 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
GetAllUsers(ctx *gin.Context)
|
| 23 |
GetAllWorkers(ctx *gin.Context)
|
| 24 |
AssignWorkerRole(ctx *gin.Context)
|
| 25 |
+
CreateWorker(ctx *gin.Context)
|
| 26 |
+
GetWorkerByID(ctx *gin.Context)
|
| 27 |
+
UpdateWorker(ctx *gin.Context)
|
| 28 |
+
DeleteWorker(ctx *gin.Context)
|
| 29 |
}
|
| 30 |
|
| 31 |
type authController struct {
|
|
|
|
| 271 |
|
| 272 |
utils.SendSuccessResponse(ctx, "Worker role assigned successfully", nil)
|
| 273 |
}
|
| 274 |
+
|
| 275 |
+
// @Summary Create Worker
|
| 276 |
+
// @Description Create a new worker account (Admin only)
|
| 277 |
+
// @Tags Admin
|
| 278 |
+
// @Accept json
|
| 279 |
+
// @Produce json
|
| 280 |
+
// @Security BearerAuth
|
| 281 |
+
// @Param request body dto.CreateWorkerRequest true "Create Worker Request"
|
| 282 |
+
// @Success 200 {object} dto.WorkerResponse
|
| 283 |
+
// @Failure 400 {object} map[string]string
|
| 284 |
+
// @Router /api/admin/worker [post]
|
| 285 |
+
func (c *authController) CreateWorker(ctx *gin.Context) {
|
| 286 |
+
var req dto.CreateWorkerRequest
|
| 287 |
+
if err := ctx.ShouldBindJSON(&req); err != nil {
|
| 288 |
+
utils.SendErrorResponse(ctx, http.StatusBadRequest, err.Error())
|
| 289 |
+
return
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
worker, err := c.authService.CreateWorker(req)
|
| 293 |
+
if err != nil {
|
| 294 |
+
utils.SendErrorResponse(ctx, http.StatusBadRequest, err.Error())
|
| 295 |
+
return
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
utils.SendSuccessResponse(ctx, "Worker created successfully", worker)
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
// @Summary Get Worker By ID
|
| 302 |
+
// @Description Get worker details by ID (Admin only)
|
| 303 |
+
// @Tags Admin
|
| 304 |
+
// @Produce json
|
| 305 |
+
// @Security BearerAuth
|
| 306 |
+
// @Param id path string true "Worker ID"
|
| 307 |
+
// @Success 200 {object} dto.WorkerResponse
|
| 308 |
+
// @Failure 400 {object} map[string]string
|
| 309 |
+
// @Router /api/admin/worker/{id} [get]
|
| 310 |
+
func (c *authController) GetWorkerByID(ctx *gin.Context) {
|
| 311 |
+
workerIDStr := ctx.Param("id")
|
| 312 |
+
workerID, err := uuid.Parse(workerIDStr)
|
| 313 |
+
if err != nil {
|
| 314 |
+
utils.SendErrorResponse(ctx, http.StatusBadRequest, "Invalid worker ID")
|
| 315 |
+
return
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
worker, err := c.authService.GetWorkerByID(workerID)
|
| 319 |
+
if err != nil {
|
| 320 |
+
utils.SendErrorResponse(ctx, http.StatusBadRequest, err.Error())
|
| 321 |
+
return
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
utils.SendSuccessResponse(ctx, "Worker retrieved successfully", worker)
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
// @Summary Update Worker
|
| 328 |
+
// @Description Update worker details (Admin only)
|
| 329 |
+
// @Tags Admin
|
| 330 |
+
// @Accept json
|
| 331 |
+
// @Produce json
|
| 332 |
+
// @Security BearerAuth
|
| 333 |
+
// @Param id path string true "Worker ID"
|
| 334 |
+
// @Param request body dto.UpdateWorkerRequest true "Update Worker Request"
|
| 335 |
+
// @Success 200 {object} dto.WorkerResponse
|
| 336 |
+
// @Failure 400 {object} map[string]string
|
| 337 |
+
// @Router /api/admin/worker/{id} [put]
|
| 338 |
+
func (c *authController) UpdateWorker(ctx *gin.Context) {
|
| 339 |
+
workerIDStr := ctx.Param("id")
|
| 340 |
+
workerID, err := uuid.Parse(workerIDStr)
|
| 341 |
+
if err != nil {
|
| 342 |
+
utils.SendErrorResponse(ctx, http.StatusBadRequest, "Invalid worker ID")
|
| 343 |
+
return
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
var req dto.UpdateWorkerRequest
|
| 347 |
+
if err := ctx.ShouldBindJSON(&req); err != nil {
|
| 348 |
+
utils.SendErrorResponse(ctx, http.StatusBadRequest, err.Error())
|
| 349 |
+
return
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
worker, err := c.authService.UpdateWorker(workerID, req)
|
| 353 |
+
if err != nil {
|
| 354 |
+
utils.SendErrorResponse(ctx, http.StatusBadRequest, err.Error())
|
| 355 |
+
return
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
utils.SendSuccessResponse(ctx, "Worker updated successfully", worker)
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
// @Summary Delete Worker
|
| 362 |
+
// @Description Delete a worker (Admin only)
|
| 363 |
+
// @Tags Admin
|
| 364 |
+
// @Produce json
|
| 365 |
+
// @Security BearerAuth
|
| 366 |
+
// @Param id path string true "Worker ID"
|
| 367 |
+
// @Success 200 {object} map[string]string
|
| 368 |
+
// @Failure 400 {object} map[string]string
|
| 369 |
+
// @Router /api/admin/worker/{id} [delete]
|
| 370 |
+
func (c *authController) DeleteWorker(ctx *gin.Context) {
|
| 371 |
+
workerIDStr := ctx.Param("id")
|
| 372 |
+
workerID, err := uuid.Parse(workerIDStr)
|
| 373 |
+
if err != nil {
|
| 374 |
+
utils.SendErrorResponse(ctx, http.StatusBadRequest, "Invalid worker ID")
|
| 375 |
+
return
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
if err := c.authService.DeleteWorker(workerID); err != nil {
|
| 379 |
+
utils.SendErrorResponse(ctx, http.StatusBadRequest, err.Error())
|
| 380 |
+
return
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
utils.SendSuccessResponse(ctx, "Worker deleted successfully", nil)
|
| 384 |
+
}
|
models/dto/auth_dto.go
CHANGED
|
@@ -35,3 +35,26 @@ type UserResponse struct {
|
|
| 35 |
type AssignWorkerRoleRequest struct {
|
| 36 |
WorkerID uuid.UUID `json:"worker_id" binding:"required"`
|
| 37 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
type AssignWorkerRoleRequest struct {
|
| 36 |
WorkerID uuid.UUID `json:"worker_id" binding:"required"`
|
| 37 |
}
|
| 38 |
+
|
| 39 |
+
type CreateWorkerRequest struct {
|
| 40 |
+
Fullname string `json:"fullname" binding:"required"`
|
| 41 |
+
Username string `json:"username" binding:"required"`
|
| 42 |
+
Email string `json:"email" binding:"required,email"`
|
| 43 |
+
Password string `json:"password" binding:"required,min=6"`
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
type UpdateWorkerRequest struct {
|
| 47 |
+
Fullname string `json:"fullname"`
|
| 48 |
+
Username string `json:"username"`
|
| 49 |
+
Email string `json:"email"`
|
| 50 |
+
Password string `json:"password"`
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
type WorkerResponse struct {
|
| 54 |
+
ID uuid.UUID `json:"id"`
|
| 55 |
+
Username string `json:"username"`
|
| 56 |
+
Fullname string `json:"fullname"`
|
| 57 |
+
Email string `json:"email"`
|
| 58 |
+
Verified bool `json:"verified"`
|
| 59 |
+
CreatedAt string `json:"created_at"`
|
| 60 |
+
}
|
repositories/user_repository.go
CHANGED
|
@@ -18,6 +18,7 @@ type UserRepository interface {
|
|
| 18 |
GetTopUsersByXP(limit int) ([]entity.User, error)
|
| 19 |
GetAllUsers() ([]entity.User, error)
|
| 20 |
GetUsersByRole(role string) ([]entity.User, error)
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
type userRepository struct {
|
|
@@ -81,3 +82,7 @@ func (r *userRepository) GetTopUsersByXP(limit int) ([]entity.User, error) {
|
|
| 81 |
err := r.db.Order("total_xp DESC").Limit(limit).Find(&users).Error
|
| 82 |
return users, err
|
| 83 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
GetTopUsersByXP(limit int) ([]entity.User, error)
|
| 19 |
GetAllUsers() ([]entity.User, error)
|
| 20 |
GetUsersByRole(role string) ([]entity.User, error)
|
| 21 |
+
DeleteUser(id uuid.UUID) error
|
| 22 |
}
|
| 23 |
|
| 24 |
type userRepository struct {
|
|
|
|
| 82 |
err := r.db.Order("total_xp DESC").Limit(limit).Find(&users).Error
|
| 83 |
return users, err
|
| 84 |
}
|
| 85 |
+
|
| 86 |
+
func (r *userRepository) DeleteUser(id uuid.UUID) error {
|
| 87 |
+
return r.db.Delete(&entity.User{}, "id = ?", id).Error
|
| 88 |
+
}
|
router/auth_router.go
CHANGED
|
@@ -55,4 +55,14 @@ func (r *authRouter) Setup(router *gin.RouterGroup) {
|
|
| 55 |
userProtected.Use(middleware.AuthMiddleware())
|
| 56 |
userProtected.Use(middleware.RoleMiddleware("user", "admin"))
|
| 57 |
userProtected.GET("/me", r.authController.GetProfile)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
}
|
|
|
|
| 55 |
userProtected.Use(middleware.AuthMiddleware())
|
| 56 |
userProtected.Use(middleware.RoleMiddleware("user", "admin"))
|
| 57 |
userProtected.GET("/me", r.authController.GetProfile)
|
| 58 |
+
|
| 59 |
+
// Worker CRUD routes (Admin only)
|
| 60 |
+
workerCRUD := router.Group("/admin/worker")
|
| 61 |
+
workerCRUD.Use(middleware.AuthMiddleware())
|
| 62 |
+
workerCRUD.Use(middleware.RoleMiddleware("admin"))
|
| 63 |
+
workerCRUD.POST("", r.authController.CreateWorker)
|
| 64 |
+
workerCRUD.GET("", r.authController.GetAllWorkers)
|
| 65 |
+
workerCRUD.GET("/:id", r.authController.GetWorkerByID)
|
| 66 |
+
workerCRUD.PUT("/:id", r.authController.UpdateWorker)
|
| 67 |
+
workerCRUD.DELETE("/:id", r.authController.DeleteWorker)
|
| 68 |
}
|
router/router.go
CHANGED
|
@@ -6,7 +6,6 @@ import (
|
|
| 6 |
|
| 7 |
brotli "github.com/anargu/gin-brotli"
|
| 8 |
"github.com/gin-contrib/cors"
|
| 9 |
-
"github.com/gin-contrib/gzip"
|
| 10 |
swaggerFiles "github.com/swaggo/files"
|
| 11 |
ginSwagger "github.com/swaggo/gin-swagger"
|
| 12 |
)
|
|
@@ -23,7 +22,6 @@ func RunRouter(appProvider provider.AppProvider) {
|
|
| 23 |
AllowCredentials: true,
|
| 24 |
}))
|
| 25 |
router.Use(brotli.Brotli(brotli.DefaultCompression))
|
| 26 |
-
router.Use(gzip.Gzip(gzip.DefaultCompression))
|
| 27 |
|
| 28 |
authRouter := NewAuthRouter(controller.ProvideAuthController())
|
| 29 |
authRouter.Setup(router.Group("/api"))
|
|
|
|
| 6 |
|
| 7 |
brotli "github.com/anargu/gin-brotli"
|
| 8 |
"github.com/gin-contrib/cors"
|
|
|
|
| 9 |
swaggerFiles "github.com/swaggo/files"
|
| 10 |
ginSwagger "github.com/swaggo/gin-swagger"
|
| 11 |
)
|
|
|
|
| 22 |
AllowCredentials: true,
|
| 23 |
}))
|
| 24 |
router.Use(brotli.Brotli(brotli.DefaultCompression))
|
|
|
|
| 25 |
|
| 26 |
authRouter := NewAuthRouter(controller.ProvideAuthController())
|
| 27 |
authRouter.Setup(router.Group("/api"))
|
services/auth_service.go
CHANGED
|
@@ -23,6 +23,10 @@ type AuthService interface {
|
|
| 23 |
GetAllUsers() ([]dto.UserResponse, error)
|
| 24 |
GetAllWorkers() ([]dto.UserResponse, error)
|
| 25 |
AssignWorkerRole(userID uuid.UUID) error
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
}
|
| 27 |
|
| 28 |
type authService struct {
|
|
@@ -276,3 +280,120 @@ func (s *authService) AssignWorkerRole(userID uuid.UUID) error {
|
|
| 276 |
user.Role = entity.ROLE_WORKER
|
| 277 |
return s.userRepo.UpdateUser(user)
|
| 278 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
GetAllUsers() ([]dto.UserResponse, error)
|
| 24 |
GetAllWorkers() ([]dto.UserResponse, error)
|
| 25 |
AssignWorkerRole(userID uuid.UUID) error
|
| 26 |
+
CreateWorker(req dto.CreateWorkerRequest) (*dto.WorkerResponse, error)
|
| 27 |
+
GetWorkerByID(workerID uuid.UUID) (*dto.WorkerResponse, error)
|
| 28 |
+
UpdateWorker(workerID uuid.UUID, req dto.UpdateWorkerRequest) (*dto.WorkerResponse, error)
|
| 29 |
+
DeleteWorker(workerID uuid.UUID) error
|
| 30 |
}
|
| 31 |
|
| 32 |
type authService struct {
|
|
|
|
| 280 |
user.Role = entity.ROLE_WORKER
|
| 281 |
return s.userRepo.UpdateUser(user)
|
| 282 |
}
|
| 283 |
+
|
| 284 |
+
func (s *authService) CreateWorker(req dto.CreateWorkerRequest) (*dto.WorkerResponse, error) {
|
| 285 |
+
existingUser, err := s.userRepo.FindUserByEmail(req.Email)
|
| 286 |
+
if err != nil {
|
| 287 |
+
return nil, err
|
| 288 |
+
}
|
| 289 |
+
if existingUser != nil {
|
| 290 |
+
return nil, errors.New("email already registered")
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
hashedPassword, err := utils.HashPassword(req.Password)
|
| 294 |
+
if err != nil {
|
| 295 |
+
return nil, err
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
worker := &entity.User{
|
| 299 |
+
Username: req.Username,
|
| 300 |
+
Fullname: req.Fullname,
|
| 301 |
+
Email: req.Email,
|
| 302 |
+
Role: entity.ROLE_WORKER,
|
| 303 |
+
Password: hashedPassword,
|
| 304 |
+
Verified: true,
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
if err := s.userRepo.CreateUser(worker); err != nil {
|
| 308 |
+
return nil, err
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
return &dto.WorkerResponse{
|
| 312 |
+
ID: worker.ID,
|
| 313 |
+
Username: worker.Username,
|
| 314 |
+
Fullname: worker.Fullname,
|
| 315 |
+
Email: worker.Email,
|
| 316 |
+
Verified: worker.Verified,
|
| 317 |
+
CreatedAt: worker.CreatedAt.Format("2006-01-02 15:04:05"),
|
| 318 |
+
}, nil
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
func (s *authService) GetWorkerByID(workerID uuid.UUID) (*dto.WorkerResponse, error) {
|
| 322 |
+
worker, err := s.userRepo.FindUserByID(workerID)
|
| 323 |
+
if err != nil {
|
| 324 |
+
return nil, err
|
| 325 |
+
}
|
| 326 |
+
if worker == nil {
|
| 327 |
+
return nil, errors.New("worker not found")
|
| 328 |
+
}
|
| 329 |
+
if worker.Role != entity.ROLE_WORKER {
|
| 330 |
+
return nil, errors.New("user is not a worker")
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
return &dto.WorkerResponse{
|
| 334 |
+
ID: worker.ID,
|
| 335 |
+
Username: worker.Username,
|
| 336 |
+
Fullname: worker.Fullname,
|
| 337 |
+
Email: worker.Email,
|
| 338 |
+
Verified: worker.Verified,
|
| 339 |
+
CreatedAt: worker.CreatedAt.Format("2006-01-02 15:04:05"),
|
| 340 |
+
}, nil
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
func (s *authService) UpdateWorker(workerID uuid.UUID, req dto.UpdateWorkerRequest) (*dto.WorkerResponse, error) {
|
| 344 |
+
worker, err := s.userRepo.FindUserByID(workerID)
|
| 345 |
+
if err != nil {
|
| 346 |
+
return nil, err
|
| 347 |
+
}
|
| 348 |
+
if worker == nil {
|
| 349 |
+
return nil, errors.New("worker not found")
|
| 350 |
+
}
|
| 351 |
+
if worker.Role != entity.ROLE_WORKER {
|
| 352 |
+
return nil, errors.New("user is not a worker")
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
if req.Fullname != "" {
|
| 356 |
+
worker.Fullname = req.Fullname
|
| 357 |
+
}
|
| 358 |
+
if req.Username != "" {
|
| 359 |
+
worker.Username = req.Username
|
| 360 |
+
}
|
| 361 |
+
if req.Email != "" {
|
| 362 |
+
worker.Email = req.Email
|
| 363 |
+
}
|
| 364 |
+
if req.Password != "" {
|
| 365 |
+
hashedPassword, err := utils.HashPassword(req.Password)
|
| 366 |
+
if err != nil {
|
| 367 |
+
return nil, err
|
| 368 |
+
}
|
| 369 |
+
worker.Password = hashedPassword
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
if err := s.userRepo.UpdateUser(worker); err != nil {
|
| 373 |
+
return nil, err
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
return &dto.WorkerResponse{
|
| 377 |
+
ID: worker.ID,
|
| 378 |
+
Username: worker.Username,
|
| 379 |
+
Fullname: worker.Fullname,
|
| 380 |
+
Email: worker.Email,
|
| 381 |
+
Verified: worker.Verified,
|
| 382 |
+
CreatedAt: worker.CreatedAt.Format("2006-01-02 15:04:05"),
|
| 383 |
+
}, nil
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
func (s *authService) DeleteWorker(workerID uuid.UUID) error {
|
| 387 |
+
worker, err := s.userRepo.FindUserByID(workerID)
|
| 388 |
+
if err != nil {
|
| 389 |
+
return err
|
| 390 |
+
}
|
| 391 |
+
if worker == nil {
|
| 392 |
+
return errors.New("worker not found")
|
| 393 |
+
}
|
| 394 |
+
if worker.Role != entity.ROLE_WORKER {
|
| 395 |
+
return errors.New("user is not a worker")
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
return s.userRepo.DeleteUser(workerID)
|
| 399 |
+
}
|