Spaces:
Configuration error
Configuration error
| package cv_controller | |
| import ( | |
| "net/http" | |
| "strconv" | |
| "api.qobiltu.id/middleware" | |
| "api.qobiltu.id/models" | |
| "api.qobiltu.id/response" | |
| "api.qobiltu.id/services" | |
| "github.com/gin-gonic/gin" | |
| ) | |
| type CVController interface { | |
| SaveAccountDetails(ctx *gin.Context) | |
| GetAccountDetails(ctx *gin.Context) | |
| SavePersonalityAndPreference(ctx *gin.Context) | |
| GetPersonalityAndPreference(ctx *gin.Context) | |
| CreateFamilyMember(ctx *gin.Context) | |
| UpdateFamilyMember(ctx *gin.Context) | |
| ListFamilyMember(ctx *gin.Context) | |
| GetFamilyMember(ctx *gin.Context) | |
| DeleteFamilyMember(ctx *gin.Context) | |
| SavePhysicalAndHealth(ctx *gin.Context) | |
| GetPhysicalAndHealth(ctx *gin.Context) | |
| SaveWorshipAndReligiousUnderstanding(ctx *gin.Context) | |
| GetWorshipAndReligiousUnderstanding(ctx *gin.Context) | |
| CreateEducation(ctx *gin.Context) | |
| UpdateEducation(ctx *gin.Context) | |
| ListEducation(ctx *gin.Context) | |
| GetEducation(ctx *gin.Context) | |
| DeleteEducation(ctx *gin.Context) | |
| CreateJob(ctx *gin.Context) | |
| UpdateJob(ctx *gin.Context) | |
| ListJob(ctx *gin.Context) | |
| GetJob(ctx *gin.Context) | |
| DeleteJob(ctx *gin.Context) | |
| CreateAchievement(ctx *gin.Context) | |
| UpdateAchievement(ctx *gin.Context) | |
| ListAchievement(ctx *gin.Context) | |
| GetAchievement(ctx *gin.Context) | |
| DeleteAchievement(ctx *gin.Context) | |
| UploadProfileImage(ctx *gin.Context) | |
| GetProgressCV(ctx *gin.Context) | |
| } | |
| type cvController struct { | |
| cvService services.CVService | |
| } | |
| func NewCVController(cvService services.CVService) CVController { | |
| return &cvController{ | |
| cvService: cvService, | |
| } | |
| } | |
| // --- Account Details --- | |
| func (c *cvController) SaveAccountDetails(ctx *gin.Context) { | |
| var req models.SaveAccountDetailsRequest | |
| if err := ctx.ShouldBindJSON(&req); err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| accountData := middleware.GetAccountData(ctx) | |
| req.AccountID = int64(accountData.UserID) | |
| res, err := c.cvService.SaveAccountDetails(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Account details saved", res, nil) | |
| } | |
| func (c *cvController) GetAccountDetails(ctx *gin.Context) { | |
| accountData := middleware.GetAccountData(ctx) | |
| accountID := int64(accountData.UserID) | |
| req := models.GetAccountDetailsRequest{ | |
| AccountID: accountID, | |
| } | |
| res, err := c.cvService.GetAccountDetails(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Get account details success", res, nil) | |
| } | |
| // --- Personality & Preference --- | |
| func (c *cvController) SavePersonalityAndPreference(ctx *gin.Context) { | |
| var req models.SavePersonalityAndPreferenceRequest | |
| if err := ctx.ShouldBindJSON(&req); err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| accountData := middleware.GetAccountData(ctx) | |
| req.AccountID = int64(accountData.UserID) | |
| res, err := c.cvService.SavePersonalityAndPreference(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Personality and Preference saved", res, nil) | |
| } | |
| func (c *cvController) GetPersonalityAndPreference(ctx *gin.Context) { | |
| accountData := middleware.GetAccountData(ctx) | |
| accountID := int64(accountData.UserID) | |
| req := models.GetPersonalityAndPreferenceRequest{ | |
| AccountID: accountID, | |
| } | |
| res, err := c.cvService.GetPersonalityAndPreference(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Get Personality and Preference success", res, nil) | |
| } | |
| // --- Family Member --- | |
| func (c *cvController) CreateFamilyMember(ctx *gin.Context) { | |
| var req models.CreateFamilyMemberRequest | |
| if err := ctx.ShouldBindJSON(&req); err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| accountData := middleware.GetAccountData(ctx) | |
| req.AccountID = int64(accountData.UserID) | |
| res, err := c.cvService.CreateFamilyMember(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Family member saved", res, nil) | |
| } | |
| func (c *cvController) UpdateFamilyMember(ctx *gin.Context) { | |
| idStr := ctx.Param("id") | |
| id, err := strconv.ParseInt(idStr, 10, 64) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| var req models.UpdateFamilyMemberRequest | |
| if err := ctx.ShouldBindJSON(&req); err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| req.ID = id | |
| res, err := c.cvService.UpdateFamilyMember(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Family member updated", res, nil) | |
| } | |
| func (c *cvController) ListFamilyMember(ctx *gin.Context) { | |
| accountData := middleware.GetAccountData(ctx) | |
| accountID := int64(accountData.UserID) | |
| req := models.ListFamilyMemberRequest{ | |
| AccountID: accountID, | |
| } | |
| list, err := c.cvService.ListFamilyMember(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "List family members", list, nil) | |
| } | |
| func (c *cvController) GetFamilyMember(ctx *gin.Context) { | |
| idStr := ctx.Param("id") | |
| id, err := strconv.ParseInt(idStr, 10, 64) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| req := models.GetFamilyMemberRequest{ | |
| ID: id, | |
| } | |
| res, err := c.cvService.GetFamilyMember(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Get family member success", res, nil) | |
| } | |
| func (c *cvController) DeleteFamilyMember(ctx *gin.Context) { | |
| idStr := ctx.Param("id") | |
| id, err := strconv.ParseInt(idStr, 10, 64) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| req := models.DeleteFamilyMemberRequest{ | |
| ID: id, | |
| } | |
| err = c.cvService.DeleteFamilyMember(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Family member deleted", nil, nil) | |
| } | |
| // --- Physical and Health --- | |
| func (c *cvController) SavePhysicalAndHealth(ctx *gin.Context) { | |
| var req models.SavePhysicalAndHealthRequest | |
| if err := ctx.ShouldBindJSON(&req); err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| accountData := middleware.GetAccountData(ctx) | |
| req.AccountID = int64(accountData.UserID) | |
| res, err := c.cvService.SavePhysicalAndHealth(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Physical and health saved", res, nil) | |
| } | |
| func (c *cvController) GetPhysicalAndHealth(ctx *gin.Context) { | |
| accountData := middleware.GetAccountData(ctx) | |
| accountID := int64(accountData.UserID) | |
| req := models.GetPhysicalAndHealthRequest{ | |
| AccountID: accountID, | |
| } | |
| res, err := c.cvService.GetPhysicalAndHealth(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Get physical and health success", res, nil) | |
| } | |
| // --- Worship and Religious Understanding --- | |
| func (c *cvController) SaveWorshipAndReligiousUnderstanding(ctx *gin.Context) { | |
| var req models.SaveWorshipAndReligiousUnderstandingRequest | |
| if err := ctx.ShouldBindJSON(&req); err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| accountData := middleware.GetAccountData(ctx) | |
| req.AccountID = int64(accountData.UserID) | |
| res, err := c.cvService.SaveWorshipAndReligiousUnderstanding(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Worship and religious understanding saved", res, nil) | |
| } | |
| func (c *cvController) GetWorshipAndReligiousUnderstanding(ctx *gin.Context) { | |
| accountData := middleware.GetAccountData(ctx) | |
| accountID := int64(accountData.UserID) | |
| req := models.GetWorshipAndReligiousUnderstandingRequest{ | |
| AccountID: accountID, | |
| } | |
| res, err := c.cvService.GetWorshipAndReligiousUnderstanding(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Get worship and religious understanding success", res, nil) | |
| } | |
| // --- Education --- | |
| func (c *cvController) CreateEducation(ctx *gin.Context) { | |
| var req models.CreateEducationRequest | |
| if err := ctx.ShouldBindJSON(&req); err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| accountData := middleware.GetAccountData(ctx) | |
| req.AccountID = int64(accountData.UserID) | |
| res, err := c.cvService.CreateEducation(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Education created successfully", res, nil) | |
| } | |
| func (c *cvController) UpdateEducation(ctx *gin.Context) { | |
| idStr := ctx.Param("id") | |
| id, err := strconv.ParseInt(idStr, 10, 64) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| var req models.UpdateEducationRequest | |
| if err := ctx.ShouldBindJSON(&req); err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| req.ID = id | |
| res, err := c.cvService.UpdateEducation(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Education updated successfully", res, nil) | |
| } | |
| func (c *cvController) ListEducation(ctx *gin.Context) { | |
| accountData := middleware.GetAccountData(ctx) | |
| accountID := int64(accountData.UserID) | |
| req := models.ListEducationRequest{ | |
| AccountID: accountID, | |
| } | |
| res, err := c.cvService.ListEducation(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "List of education retrieved successfully", res, nil) | |
| } | |
| func (c *cvController) GetEducation(ctx *gin.Context) { | |
| idStr := ctx.Param("id") | |
| id, err := strconv.ParseInt(idStr, 10, 64) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| req := models.GetEducationRequest{ | |
| ID: id, | |
| } | |
| res, err := c.cvService.GetEducation(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Get education success", res, nil) | |
| } | |
| func (c *cvController) DeleteEducation(ctx *gin.Context) { | |
| idStr := ctx.Param("id") | |
| id, err := strconv.ParseInt(idStr, 10, 64) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| req := models.DeleteEducationRequest{ | |
| ID: id, | |
| } | |
| err = c.cvService.DeleteEducation(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Education deleted successfully", nil, nil) | |
| } | |
| // --- Job --- | |
| func (c *cvController) CreateJob(ctx *gin.Context) { | |
| var req models.CreateJobRequest | |
| if err := ctx.ShouldBindJSON(&req); err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| accountData := middleware.GetAccountData(ctx) | |
| req.AccountID = int64(accountData.UserID) | |
| res, err := c.cvService.CreateJob(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Job created successfully", res, nil) | |
| } | |
| func (c *cvController) UpdateJob(ctx *gin.Context) { | |
| idStr := ctx.Param("id") | |
| id, err := strconv.ParseInt(idStr, 10, 64) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| var req models.UpdateJobRequest | |
| if err := ctx.ShouldBindJSON(&req); err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| req.ID = id | |
| res, err := c.cvService.UpdateJob(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Job updated successfully", res, nil) | |
| } | |
| func (c *cvController) ListJob(ctx *gin.Context) { | |
| accountData := middleware.GetAccountData(ctx) | |
| accountID := int64(accountData.UserID) | |
| req := models.ListJobRequest{ | |
| AccountID: accountID, | |
| } | |
| res, err := c.cvService.ListJob(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "List of jobs retrieved successfully", res, nil) | |
| } | |
| func (c *cvController) GetJob(ctx *gin.Context) { | |
| idStr := ctx.Param("id") | |
| id, err := strconv.ParseInt(idStr, 10, 64) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| req := models.GetJobRequest{ | |
| ID: id, | |
| } | |
| res, err := c.cvService.GetJob(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Get job success", res, nil) | |
| } | |
| func (c *cvController) DeleteJob(ctx *gin.Context) { | |
| idStr := ctx.Param("id") | |
| id, err := strconv.ParseInt(idStr, 10, 64) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| req := models.DeleteJobRequest{ | |
| ID: id, | |
| } | |
| err = c.cvService.DeleteJob(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Job deleted successfully", nil, nil) | |
| } | |
| // --- Achievement --- | |
| func (c *cvController) CreateAchievement(ctx *gin.Context) { | |
| var req models.CreateAchievementRequest | |
| if err := ctx.ShouldBindJSON(&req); err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| accountData := middleware.GetAccountData(ctx) | |
| req.AccountID = int64(accountData.UserID) | |
| res, err := c.cvService.CreateAchievement(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Achievement created successfully", res, nil) | |
| } | |
| func (c *cvController) UpdateAchievement(ctx *gin.Context) { | |
| idStr := ctx.Param("id") | |
| id, err := strconv.ParseInt(idStr, 10, 64) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| var req models.UpdateAchievementRequest | |
| if err := ctx.ShouldBindJSON(&req); err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| req.ID = id | |
| res, err := c.cvService.UpdateAchievement(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Achievement updated successfully", res, nil) | |
| } | |
| func (c *cvController) ListAchievement(ctx *gin.Context) { | |
| accountData := middleware.GetAccountData(ctx) | |
| accountID := int64(accountData.UserID) | |
| req := models.ListAchievementRequest{ | |
| AccountID: accountID, | |
| } | |
| res, err := c.cvService.ListAchievement(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "List of achievements retrieved successfully", res, nil) | |
| } | |
| func (c *cvController) GetAchievement(ctx *gin.Context) { | |
| idStr := ctx.Param("id") | |
| id, err := strconv.ParseInt(idStr, 10, 64) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| req := models.GetAchievementRequest{ | |
| ID: id, | |
| } | |
| res, err := c.cvService.GetAchievement(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Get achievement success", res, nil) | |
| } | |
| func (c *cvController) DeleteAchievement(ctx *gin.Context) { | |
| idStr := ctx.Param("id") | |
| id, err := strconv.ParseInt(idStr, 10, 64) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| req := models.DeleteAchievementRequest{ | |
| ID: id, | |
| } | |
| err = c.cvService.DeleteAchievement(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Achievement deleted successfully", nil, nil) | |
| } | |
| func (c *cvController) UploadProfileImage(ctx *gin.Context) { | |
| accountData := middleware.GetAccountData(ctx) | |
| avatarFile, _ := ctx.FormFile("avatar") | |
| req := models.UploadProfileImageRequest{ | |
| AccountID: int64(accountData.UserID), | |
| File: avatarFile, | |
| } | |
| res, err := c.cvService.UploadProfileImage(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Profile image uploaded successfully", res, nil) | |
| } | |
| func (c *cvController) GetProgressCV(ctx *gin.Context) { | |
| accountData := middleware.GetAccountData(ctx) | |
| accountID := int64(accountData.UserID) | |
| req := models.GetProgressCVRequest{ | |
| AccountID: accountID, | |
| } | |
| res, err := c.cvService.GetProgressCV(ctx, &req) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Progress retrieved successfully", res, nil) | |
| } | |