-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jjnavanon/sucu 46 user get user by #15
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,30 @@ func (u *userUsecase) GetAllUsers(req *dtos.UserDTO) (*[]dtos.UserDTO, *apperror | |
} | ||
|
||
func (u *userUsecase) GetUserByID(req *dtos.UserDTO, userID string) (*dtos.UserDTO, *apperror.AppError) { | ||
return nil, nil | ||
role, err := utils.GetRole(req.Role) | ||
if err != nil { | ||
u.logger.Named("GetUserByID").Error(constant.ErrInvalidRole, zap.String("role", req.Role), zap.Error(err)) | ||
return nil, apperror.BadRequestError(constant.ErrInvalidRole) | ||
} | ||
res, err := u.userRepository.FindUserByID(userID) | ||
if err != nil { | ||
u.logger.Named("GetUserByID").Error(constant.ErrFindUserByID, zap.String("userID", req.ID), zap.Error(err)) | ||
return nil, apperror.NotFoundError(constant.ErrFindUserByID) | ||
} | ||
if res.RoleID != role { | ||
u.logger.Named("GetUserByID").Error(constant.ErrInvalidRole, zap.String("role", req.Role), zap.Error(err)) | ||
return nil, apperror.ForbiddenError(constant.ErrInvalidRole) | ||
} | ||
res_return := dtos.UserDTO{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. แก้ชื่อตัวแปรให้เป็น camel ด้วยคับบ like resReturn |
||
ID: res.ID, | ||
FirstName: res.FirstName, | ||
LastName: res.LastName, | ||
Role: res.RoleID, | ||
CreatedAt: res.CreatedAt, | ||
UpdatedAt: res.UpdatedAt, | ||
} | ||
return &res_return, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. นี่ด้วย |
||
|
||
} | ||
|
||
func (u *userUsecase) CreateUser(req *dtos.UserDTO, createUserDTO *dtos.CreateUserDTO) *apperror.AppError { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,13 @@ func (h *UserHandler) GetAllUsers(c *fiber.Ctx) error { | |
// @Failure 500 {object} response.Response | ||
// @Router /users/{user_id} [get] | ||
func (h *UserHandler) GetUserByID(c *fiber.Ctx) error { | ||
return nil | ||
userID := c.Params("user_id") // how to get this? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove comment plss |
||
req := c.Locals("user").(*dtos.UserDTO) | ||
res, err := h.userUsecase.GetUserByID(req, userID) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(res) | ||
Comment on lines
+49
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ใช้ package responses เวลา return นะะ |
||
} | ||
|
||
// CreateUser godoc | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ฝากแก้ให้เหมือนเดิมด้วย bro ใน macos มันไม่มี .exe @JJnvn