-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d49efea
commit 7119973
Showing
13 changed files
with
273 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package profile | ||
|
||
import model "github.com/donaderoyan/talentgrowth-be/models" | ||
|
||
func (s *service) GetProfileService(userID string) (*model.User, error) { | ||
result, err := s.repository.GetProfile(userID) | ||
return result, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package profile | ||
|
||
import model "github.com/donaderoyan/talentgrowth-be/models" | ||
|
||
type Service interface { | ||
UpdateProfileService(userID string, input *UpdateProfileInput) (*model.User, error) | ||
PutProfileService(userID string, input *UpdateProfileInput) (*model.User, error) | ||
GetProfileService(userID string) (*model.User, error) | ||
} | ||
|
||
type service struct { | ||
repository Repository | ||
} | ||
|
||
func NewProfileService(repository Repository) *service { | ||
return &service{repository: repository} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package profilehandler | ||
|
||
import ( | ||
"net/http" | ||
|
||
profile "github.com/donaderoyan/talentgrowth-be/controllers/user/profile" | ||
util "github.com/donaderoyan/talentgrowth-be/utils" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// Swagger documentation for GetProfileHandler | ||
// @Summary Get user profile | ||
// @Description Get the profile of a user by their ID | ||
// @Tags User | ||
// @Accept json | ||
// @Produce json | ||
// @Param id path string true "User ID" | ||
// @Success 200 {object} profile.UpdateProfileInput | ||
// @Failure 400 {object} map[string]interface{} "Bad request" | ||
// @Failure 500 {object} map[string]interface{} "Internal server error" | ||
// @Router /api/v1/user/profile/{id} [get] | ||
func (h *handler) GetProfileHandler(ctx *gin.Context) { | ||
userID := ctx.Param("id") | ||
if userID == "" { | ||
util.ErrorResponse(ctx, "Update profile failed", http.StatusBadRequest, http.MethodPut, "ID is required") | ||
return | ||
} | ||
|
||
dataUser, errData := h.service.GetProfileService(userID) | ||
if errData != nil { | ||
switch errData.(type) { | ||
case *profile.GetUserProfileError: | ||
util.ErrorResponse(ctx, "Get user profile failed", http.StatusBadRequest, http.MethodPatch, errData.Error()) | ||
return | ||
default: | ||
// Handle other unexpected errors | ||
util.ErrorResponse(ctx, "Internal server error", http.StatusInternalServerError, http.MethodPatch, nil) | ||
return | ||
} | ||
} | ||
|
||
// masking data | ||
responseData := gin.H{ | ||
"firstName": dataUser.FirstName, | ||
"lastName": dataUser.LastName, | ||
"phone": dataUser.Phone, | ||
"address": dataUser.Address, | ||
"birthday": dataUser.Birthday, | ||
"gender": dataUser.Gender, | ||
"nationality": dataUser.Nationality, | ||
"bio": dataUser.Bio, | ||
} | ||
|
||
util.APIResponse(ctx, "Get user profile successfully", http.StatusOK, http.MethodPatch, responseData) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package profilehandler | ||
|
||
import profile "github.com/donaderoyan/talentgrowth-be/controllers/user/profile" | ||
|
||
type handler struct { | ||
service profile.Service | ||
} | ||
|
||
func NewHandlerProfile(service profile.Service) *handler { | ||
return &handler{service: service} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.