From 86ea5f66d1b31a882a0b72c4201adea17c29d236 Mon Sep 17 00:00:00 2001 From: hanif salafi Date: Mon, 22 Sep 2025 00:06:06 +0700 Subject: [PATCH] feat: update education and work history --- .../education_history.controller.go | 80 ++++--- .../request/education_history.request.go | 14 +- .../service/education_history.service.go | 80 ++----- .../controller/work_history.controller.go | 67 +++--- .../request/work_history.request.go | 15 +- .../service/work_history.service.go | 65 ++---- docs/swagger/docs.go | 206 ++++++---------- docs/swagger/swagger.json | 206 ++++++---------- docs/swagger/swagger.yaml | 221 ++++++++---------- 9 files changed, 404 insertions(+), 550 deletions(-) diff --git a/app/module/education_history/controller/education_history.controller.go b/app/module/education_history/controller/education_history.controller.go index 56550ad..5a71859 100644 --- a/app/module/education_history/controller/education_history.controller.go +++ b/app/module/education_history/controller/education_history.controller.go @@ -32,14 +32,12 @@ func NewEducationHistoryController(educationHistoryService service.EducationHist // All Education History // @Summary Get all Education History -// @Description API for getting all Education History for authenticated user +// @Description API for getting all Education History for specific user // @Tags Education History -// @Security Bearer // @Param req query request.EducationHistoryQueryRequest false "query parameters" // @Param req query paginator.Pagination false "pagination parameters" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError -// @Failure 401 {object} response.UnauthorizedError // @Failure 500 {object} response.InternalServerError // @Router /education-history [get] func (_i *educationHistoryController) All(c *fiber.Ctx) error { @@ -47,10 +45,8 @@ func (_i *educationHistoryController) All(c *fiber.Ctx) error { if err != nil { return err } - - authHeader := c.Get("Authorization") - reqContext := request.EducationHistoryQueryRequestContext{ + UserID: c.Query("userId"), SchoolName: c.Query("schoolName"), Major: c.Query("major"), EducationLevel: c.Query("educationLevel"), @@ -59,7 +55,7 @@ func (_i *educationHistoryController) All(c *fiber.Ctx) error { req := reqContext.ToParamRequest() req.Pagination = paginate - educationData, paging, err := _i.educationHistoryService.All(authHeader, req) + educationData, paging, err := _i.educationHistoryService.All(req) if err != nil { return err } @@ -76,11 +72,10 @@ func (_i *educationHistoryController) All(c *fiber.Ctx) error { // @Summary Get one Education History // @Description API for getting one Education History // @Tags Education History -// @Security Bearer // @Param id path int true "Education History ID" +// @Param userId query uint true "User ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError -// @Failure 401 {object} response.UnauthorizedError // @Failure 500 {object} response.InternalServerError // @Router /education-history/{id} [get] func (_i *educationHistoryController) Show(c *fiber.Ctx) error { @@ -89,9 +84,15 @@ func (_i *educationHistoryController) Show(c *fiber.Ctx) error { return err } - authHeader := c.Get("Authorization") + userId, err := strconv.ParseUint(c.Query("userId"), 10, 0) + if err != nil { + return utilRes.Resp(c, utilRes.Response{ + Success: false, + Messages: utilRes.Messages{"userId parameter is required and must be a valid number"}, + }) + } - educationData, err := _i.educationHistoryService.Show(authHeader, uint(id)) + educationData, err := _i.educationHistoryService.Show(uint(userId), uint(id)) if err != nil { return err } @@ -107,24 +108,28 @@ func (_i *educationHistoryController) Show(c *fiber.Ctx) error { // @Summary Create Education History // @Description API for create Education History // @Tags Education History -// @Security Bearer // @Param X-Csrf-Token header string true "Insert the X-Csrf-Token" -// @Param Authorization header string false "Insert your access token" default(Bearer ) +// @Param userId query uint true "User ID" // @Param payload body request.EducationHistoryCreateRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError -// @Failure 401 {object} response.UnauthorizedError // @Failure 500 {object} response.InternalServerError // @Router /education-history [post] func (_i *educationHistoryController) Save(c *fiber.Ctx) error { + userId, err := strconv.ParseUint(c.Query("userId"), 10, 0) + if err != nil { + return utilRes.Resp(c, utilRes.Response{ + Success: false, + Messages: utilRes.Messages{"userId parameter is required and must be a valid number"}, + }) + } + req := new(request.EducationHistoryCreateRequest) if err := utilVal.ParseAndValidate(c, req); err != nil { return err } - authHeader := c.Get("Authorization") - - dataResult, err := _i.educationHistoryService.Save(authHeader, *req) + dataResult, err := _i.educationHistoryService.Save(uint(userId), *req) if err != nil { return err } @@ -140,13 +145,12 @@ func (_i *educationHistoryController) Save(c *fiber.Ctx) error { // @Summary Update Education History // @Description API for update Education History // @Tags Education History -// @Security Bearer // @Param X-Csrf-Token header string true "Insert the X-Csrf-Token" // @Param id path int true "Education History ID" +// @Param userId query uint true "User ID" // @Param payload body request.EducationHistoryUpdateRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError -// @Failure 401 {object} response.UnauthorizedError // @Failure 500 {object} response.InternalServerError // @Router /education-history/{id} [put] func (_i *educationHistoryController) Update(c *fiber.Ctx) error { @@ -155,14 +159,20 @@ func (_i *educationHistoryController) Update(c *fiber.Ctx) error { return err } + userId, err := strconv.ParseUint(c.Query("userId"), 10, 0) + if err != nil { + return utilRes.Resp(c, utilRes.Response{ + Success: false, + Messages: utilRes.Messages{"userId parameter is required and must be a valid number"}, + }) + } + req := new(request.EducationHistoryUpdateRequest) if err := utilVal.ParseAndValidate(c, req); err != nil { return err } - authHeader := c.Get("Authorization") - - err = _i.educationHistoryService.Update(authHeader, uint(id), *req) + err = _i.educationHistoryService.Update(uint(userId), uint(id), *req) if err != nil { return err } @@ -177,12 +187,11 @@ func (_i *educationHistoryController) Update(c *fiber.Ctx) error { // @Summary Delete Education History // @Description API for delete Education History // @Tags Education History -// @Security Bearer // @Param X-Csrf-Token header string true "Insert the X-Csrf-Token" // @Param id path int true "Education History ID" +// @Param userId query uint true "User ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError -// @Failure 401 {object} response.UnauthorizedError // @Failure 500 {object} response.InternalServerError // @Router /education-history/{id} [delete] func (_i *educationHistoryController) Delete(c *fiber.Ctx) error { @@ -191,9 +200,15 @@ func (_i *educationHistoryController) Delete(c *fiber.Ctx) error { return err } - authHeader := c.Get("Authorization") + userId, err := strconv.ParseUint(c.Query("userId"), 10, 0) + if err != nil { + return utilRes.Resp(c, utilRes.Response{ + Success: false, + Messages: utilRes.Messages{"userId parameter is required and must be a valid number"}, + }) + } - err = _i.educationHistoryService.Delete(authHeader, uint(id)) + err = _i.educationHistoryService.Delete(uint(userId), uint(id)) if err != nil { return err } @@ -208,13 +223,12 @@ func (_i *educationHistoryController) Delete(c *fiber.Ctx) error { // @Summary Upload Certificate for Education History // @Description API for upload certificate image for Education History // @Tags Education History -// @Security Bearer // @Param X-Csrf-Token header string true "Insert the X-Csrf-Token" // @Param id path int true "Education History ID" +// @Param userId query uint true "User ID" // @Param certificate formData file true "Certificate image file" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError -// @Failure 401 {object} response.UnauthorizedError // @Failure 500 {object} response.InternalServerError // @Router /education-history/{id}/certificate [post] func (_i *educationHistoryController) UploadCertificate(c *fiber.Ctx) error { @@ -223,9 +237,15 @@ func (_i *educationHistoryController) UploadCertificate(c *fiber.Ctx) error { return err } - authHeader := c.Get("Authorization") + userId, err := strconv.ParseUint(c.Query("userId"), 10, 0) + if err != nil { + return utilRes.Resp(c, utilRes.Response{ + Success: false, + Messages: utilRes.Messages{"userId parameter is required and must be a valid number"}, + }) + } - err = _i.educationHistoryService.UploadCertificate(authHeader, uint(id), c) + err = _i.educationHistoryService.UploadCertificate(uint(userId), uint(id), c) if err != nil { return err } diff --git a/app/module/education_history/request/education_history.request.go b/app/module/education_history/request/education_history.request.go index c30efe4..58b8818 100644 --- a/app/module/education_history/request/education_history.request.go +++ b/app/module/education_history/request/education_history.request.go @@ -7,6 +7,7 @@ import ( ) type EducationHistoryQueryRequest struct { + UserID uint `json:"userId" validate:"required"` SchoolName *string `json:"schoolName"` Major *string `json:"major"` EducationLevel *string `json:"educationLevel"` @@ -22,13 +23,14 @@ type EducationHistoryCreateRequest struct { CertificateImage string `json:"certificateImage,omitempty"` } -func (req EducationHistoryCreateRequest) ToEntity() *entity.EducationHistory { +func (req EducationHistoryCreateRequest) ToEntity(userId uint) *entity.EducationHistory { certificateImage := &req.CertificateImage if req.CertificateImage == "" { certificateImage = nil } return &entity.EducationHistory{ + UserID: userId, SchoolName: req.SchoolName, Major: req.Major, EducationLevel: req.EducationLevel, @@ -45,13 +47,14 @@ type EducationHistoryUpdateRequest struct { CertificateImage string `json:"certificateImage,omitempty"` } -func (req EducationHistoryUpdateRequest) ToEntity() *entity.EducationHistory { +func (req EducationHistoryUpdateRequest) ToEntity(userId uint) *entity.EducationHistory { certificateImage := &req.CertificateImage if req.CertificateImage == "" { certificateImage = nil } return &entity.EducationHistory{ + UserID: userId, SchoolName: req.SchoolName, Major: req.Major, EducationLevel: req.EducationLevel, @@ -61,6 +64,7 @@ func (req EducationHistoryUpdateRequest) ToEntity() *entity.EducationHistory { } type EducationHistoryQueryRequestContext struct { + UserID string `json:"userId"` SchoolName string `json:"schoolName"` Major string `json:"major"` EducationLevel string `json:"educationLevel"` @@ -70,6 +74,12 @@ type EducationHistoryQueryRequestContext struct { func (req EducationHistoryQueryRequestContext) ToParamRequest() EducationHistoryQueryRequest { var request EducationHistoryQueryRequest + if userId := req.UserID; userId != "" { + userIdUint, err := strconv.ParseUint(userId, 10, 0) + if err == nil { + request.UserID = uint(userIdUint) + } + } if schoolName := req.SchoolName; schoolName != "" { request.SchoolName = &schoolName } diff --git a/app/module/education_history/service/education_history.service.go b/app/module/education_history/service/education_history.service.go index d0d3b8c..ff570b8 100644 --- a/app/module/education_history/service/education_history.service.go +++ b/app/module/education_history/service/education_history.service.go @@ -18,7 +18,6 @@ import ( "narasi-ahli-be/config/config" minioStorage "narasi-ahli-be/config/config" "narasi-ahli-be/utils/paginator" - utilSvc "narasi-ahli-be/utils/service" "github.com/gofiber/fiber/v2" "github.com/minio/minio-go/v7" @@ -34,12 +33,12 @@ type educationHistoryService struct { } type EducationHistoryService interface { - All(authToken string, req request.EducationHistoryQueryRequest) (educationHistories []*response.EducationHistoryResponse, paging paginator.Pagination, err error) - Show(authToken string, id uint) (educationHistory *response.EducationHistoryResponse, err error) - Save(authToken string, req request.EducationHistoryCreateRequest) (educationHistory *response.EducationHistoryResponse, err error) - Update(authToken string, id uint, req request.EducationHistoryUpdateRequest) (err error) - Delete(authToken string, id uint) error - UploadCertificate(authToken string, id uint, c *fiber.Ctx) error + All(req request.EducationHistoryQueryRequest) (educationHistories []*response.EducationHistoryResponse, paging paginator.Pagination, err error) + Show(userId uint, id uint) (educationHistory *response.EducationHistoryResponse, err error) + Save(userId uint, req request.EducationHistoryCreateRequest) (educationHistory *response.EducationHistoryResponse, err error) + Update(userId uint, id uint, req request.EducationHistoryUpdateRequest) (err error) + Delete(userId uint, id uint) error + UploadCertificate(userId uint, id uint, c *fiber.Ctx) error } func NewEducationHistoryService(repo repository.EducationHistoryRepository, usersRepo usersRepository.UsersRepository, log zerolog.Logger, cfg *config.Config, minioStorage *minioStorage.MinioStorage) EducationHistoryService { @@ -52,13 +51,8 @@ func NewEducationHistoryService(repo repository.EducationHistoryRepository, user } } -func (_i *educationHistoryService) All(authToken string, req request.EducationHistoryQueryRequest) (educationHistories []*response.EducationHistoryResponse, paging paginator.Pagination, err error) { - userInfo := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) - if userInfo == nil { - return nil, paginator.Pagination{}, errors.New("unauthorized") - } - - results, paging, err := _i.Repo.GetAll(userInfo.ID, req) +func (_i *educationHistoryService) All(req request.EducationHistoryQueryRequest) (educationHistories []*response.EducationHistoryResponse, paging paginator.Pagination, err error) { + results, paging, err := _i.Repo.GetAll(req.UserID, req) if err != nil { return } @@ -70,13 +64,8 @@ func (_i *educationHistoryService) All(authToken string, req request.EducationHi return } -func (_i *educationHistoryService) Show(authToken string, id uint) (educationHistory *response.EducationHistoryResponse, err error) { - userInfo := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) - if userInfo == nil { - return nil, errors.New("unauthorized") - } - - result, err := _i.Repo.FindOneByUserAndId(userInfo.ID, id) +func (_i *educationHistoryService) Show(userId uint, id uint) (educationHistory *response.EducationHistoryResponse, err error) { + result, err := _i.Repo.FindOneByUserAndId(userId, id) if err != nil { return nil, err } @@ -84,16 +73,10 @@ func (_i *educationHistoryService) Show(authToken string, id uint) (educationHis return mapper.EducationHistoryResponseMapper(result), nil } -func (_i *educationHistoryService) Save(authToken string, req request.EducationHistoryCreateRequest) (educationHistory *response.EducationHistoryResponse, err error) { +func (_i *educationHistoryService) Save(userId uint, req request.EducationHistoryCreateRequest) (educationHistory *response.EducationHistoryResponse, err error) { _i.Log.Info().Interface("data", req).Msg("Creating education history") - userInfo := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) - if userInfo == nil { - return nil, errors.New("unauthorized") - } - - entity := req.ToEntity() - entity.UserID = userInfo.ID + entity := req.ToEntity(userId) result, err := _i.Repo.Create(entity) if err != nil { @@ -103,16 +86,11 @@ func (_i *educationHistoryService) Save(authToken string, req request.EducationH return mapper.EducationHistoryResponseMapper(result), nil } -func (_i *educationHistoryService) Update(authToken string, id uint, req request.EducationHistoryUpdateRequest) (err error) { +func (_i *educationHistoryService) Update(userId uint, id uint, req request.EducationHistoryUpdateRequest) (err error) { _i.Log.Info().Interface("data", req).Msg("Updating education history") - userInfo := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) - if userInfo == nil { - return errors.New("unauthorized") - } - // Check if record exists and belongs to user - existing, err := _i.Repo.FindOneByUserAndId(userInfo.ID, id) + existing, err := _i.Repo.FindOneByUserAndId(userId, id) if err != nil { return err } @@ -120,20 +98,15 @@ func (_i *educationHistoryService) Update(authToken string, id uint, req request return errors.New("education history not found") } - entity := req.ToEntity() - return _i.Repo.Update(userInfo.ID, id, entity) + entity := req.ToEntity(userId) + return _i.Repo.Update(userId, id, entity) } -func (_i *educationHistoryService) Delete(authToken string, id uint) error { - _i.Log.Info().Str("authToken", authToken).Uint("id", id).Msg("Deleting education history") - - userInfo := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) - if userInfo == nil { - return errors.New("unauthorized") - } +func (_i *educationHistoryService) Delete(userId uint, id uint) error { + _i.Log.Info().Uint("userId", userId).Uint("id", id).Msg("Deleting education history") // Check if record exists and belongs to user - existing, err := _i.Repo.FindOneByUserAndId(userInfo.ID, id) + existing, err := _i.Repo.FindOneByUserAndId(userId, id) if err != nil { return err } @@ -141,19 +114,14 @@ func (_i *educationHistoryService) Delete(authToken string, id uint) error { return errors.New("education history not found") } - return _i.Repo.Delete(userInfo.ID, id) + return _i.Repo.Delete(userId, id) } -func (_i *educationHistoryService) UploadCertificate(authToken string, id uint, c *fiber.Ctx) error { - _i.Log.Info().Str("authToken", authToken).Uint("id", id).Msg("Uploading certificate") - - userInfo := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) - if userInfo == nil { - return errors.New("unauthorized") - } +func (_i *educationHistoryService) UploadCertificate(userId uint, id uint, c *fiber.Ctx) error { + _i.Log.Info().Uint("userId", userId).Uint("id", id).Msg("Uploading certificate") // Check if record exists and belongs to user - existing, err := _i.Repo.FindOneByUserAndId(userInfo.ID, id) + existing, err := _i.Repo.FindOneByUserAndId(userId, id) if err != nil { return err } @@ -214,5 +182,5 @@ func (_i *educationHistoryService) UploadCertificate(authToken string, id uint, // Update certificate image path with MinIO object name existing.CertificateImage = &objectName - return _i.Repo.Update(userInfo.ID, id, existing) + return _i.Repo.Update(userId, id, existing) } diff --git a/app/module/work_history/controller/work_history.controller.go b/app/module/work_history/controller/work_history.controller.go index 99c96f4..32db37c 100644 --- a/app/module/work_history/controller/work_history.controller.go +++ b/app/module/work_history/controller/work_history.controller.go @@ -31,14 +31,12 @@ func NewWorkHistoryController(workHistoryService service.WorkHistoryService) Wor // All Work History // @Summary Get all Work History -// @Description API for getting all Work History for authenticated user +// @Description API for getting all Work History for specific user // @Tags Work History -// @Security Bearer // @Param req query request.WorkHistoryQueryRequest false "query parameters" // @Param req query paginator.Pagination false "pagination parameters" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError -// @Failure 401 {object} response.UnauthorizedError // @Failure 500 {object} response.InternalServerError // @Router /work-history [get] func (_i *workHistoryController) All(c *fiber.Ctx) error { @@ -46,18 +44,16 @@ func (_i *workHistoryController) All(c *fiber.Ctx) error { if err != nil { return err } - - authHeader := c.Get("Authorization") - reqContext := request.WorkHistoryQueryRequestContext{ JobTitle: c.Query("jobTitle"), CompanyName: c.Query("companyName"), IsCurrent: c.Query("isCurrent"), + UserID: c.Query("userId"), } req := reqContext.ToParamRequest() req.Pagination = paginate - workData, paging, err := _i.workHistoryService.All(authHeader, req) + workData, paging, err := _i.workHistoryService.All(req) if err != nil { return err } @@ -74,11 +70,10 @@ func (_i *workHistoryController) All(c *fiber.Ctx) error { // @Summary Get one Work History // @Description API for getting one Work History // @Tags Work History -// @Security Bearer // @Param id path int true "Work History ID" +// @Param userId query uint true "User ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError -// @Failure 401 {object} response.UnauthorizedError // @Failure 500 {object} response.InternalServerError // @Router /work-history/{id} [get] func (_i *workHistoryController) Show(c *fiber.Ctx) error { @@ -87,9 +82,15 @@ func (_i *workHistoryController) Show(c *fiber.Ctx) error { return err } - authHeader := c.Get("Authorization") + userId, err := strconv.ParseUint(c.Query("userId"), 10, 0) + if err != nil { + return utilRes.Resp(c, utilRes.Response{ + Success: false, + Messages: utilRes.Messages{"userId parameter is required and must be a valid number"}, + }) + } - workData, err := _i.workHistoryService.Show(authHeader, uint(id)) + workData, err := _i.workHistoryService.Show(uint(userId), uint(id)) if err != nil { return err } @@ -105,24 +106,28 @@ func (_i *workHistoryController) Show(c *fiber.Ctx) error { // @Summary Create Work History // @Description API for create Work History // @Tags Work History -// @Security Bearer // @Param X-Csrf-Token header string true "Insert the X-Csrf-Token" -// @Param Authorization header string false "Insert your access token" default(Bearer ) +// @Param userId query uint true "User ID" // @Param payload body request.WorkHistoryCreateRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError -// @Failure 401 {object} response.UnauthorizedError // @Failure 500 {object} response.InternalServerError // @Router /work-history [post] func (_i *workHistoryController) Save(c *fiber.Ctx) error { + userId, err := strconv.ParseUint(c.Query("userId"), 10, 0) + if err != nil { + return utilRes.Resp(c, utilRes.Response{ + Success: false, + Messages: utilRes.Messages{"userId parameter is required and must be a valid number"}, + }) + } + req := new(request.WorkHistoryCreateRequest) if err := utilVal.ParseAndValidate(c, req); err != nil { return err } - authHeader := c.Get("Authorization") - - dataResult, err := _i.workHistoryService.Save(authHeader, *req) + dataResult, err := _i.workHistoryService.Save(uint(userId), *req) if err != nil { return err } @@ -138,13 +143,12 @@ func (_i *workHistoryController) Save(c *fiber.Ctx) error { // @Summary Update Work History // @Description API for update Work History // @Tags Work History -// @Security Bearer // @Param X-Csrf-Token header string true "Insert the X-Csrf-Token" // @Param id path int true "Work History ID" +// @Param userId query uint true "User ID" // @Param payload body request.WorkHistoryUpdateRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError -// @Failure 401 {object} response.UnauthorizedError // @Failure 500 {object} response.InternalServerError // @Router /work-history/{id} [put] func (_i *workHistoryController) Update(c *fiber.Ctx) error { @@ -153,14 +157,20 @@ func (_i *workHistoryController) Update(c *fiber.Ctx) error { return err } + userId, err := strconv.ParseUint(c.Query("userId"), 10, 0) + if err != nil { + return utilRes.Resp(c, utilRes.Response{ + Success: false, + Messages: utilRes.Messages{"userId parameter is required and must be a valid number"}, + }) + } + req := new(request.WorkHistoryUpdateRequest) if err := utilVal.ParseAndValidate(c, req); err != nil { return err } - authHeader := c.Get("Authorization") - - err = _i.workHistoryService.Update(authHeader, uint(id), *req) + err = _i.workHistoryService.Update(uint(userId), uint(id), *req) if err != nil { return err } @@ -175,12 +185,11 @@ func (_i *workHistoryController) Update(c *fiber.Ctx) error { // @Summary Delete Work History // @Description API for delete Work History // @Tags Work History -// @Security Bearer // @Param X-Csrf-Token header string true "Insert the X-Csrf-Token" // @Param id path int true "Work History ID" +// @Param userId query uint true "User ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError -// @Failure 401 {object} response.UnauthorizedError // @Failure 500 {object} response.InternalServerError // @Router /work-history/{id} [delete] func (_i *workHistoryController) Delete(c *fiber.Ctx) error { @@ -189,9 +198,15 @@ func (_i *workHistoryController) Delete(c *fiber.Ctx) error { return err } - authHeader := c.Get("Authorization") + userId, err := strconv.ParseUint(c.Query("userId"), 10, 0) + if err != nil { + return utilRes.Resp(c, utilRes.Response{ + Success: false, + Messages: utilRes.Messages{"userId parameter is required and must be a valid number"}, + }) + } - err = _i.workHistoryService.Delete(authHeader, uint(id)) + err = _i.workHistoryService.Delete(uint(userId), uint(id)) if err != nil { return err } diff --git a/app/module/work_history/request/work_history.request.go b/app/module/work_history/request/work_history.request.go index a3d36bf..ce5b3c8 100644 --- a/app/module/work_history/request/work_history.request.go +++ b/app/module/work_history/request/work_history.request.go @@ -3,10 +3,12 @@ package request import ( "narasi-ahli-be/app/database/entity" "narasi-ahli-be/utils/paginator" + "strconv" "time" ) type WorkHistoryQueryRequest struct { + UserID uint `json:"userId" validate:"required"` JobTitle *string `json:"jobTitle"` CompanyName *string `json:"companyName"` IsCurrent *bool `json:"isCurrent"` // filter for current job (EndDate is null) @@ -20,8 +22,9 @@ type WorkHistoryCreateRequest struct { EndDate *time.Time `json:"endDate"` } -func (req WorkHistoryCreateRequest) ToEntity() *entity.WorkHistory { +func (req WorkHistoryCreateRequest) ToEntity(userId uint) *entity.WorkHistory { return &entity.WorkHistory{ + UserID: userId, JobTitle: req.JobTitle, CompanyName: req.CompanyName, StartDate: req.StartDate, @@ -36,8 +39,9 @@ type WorkHistoryUpdateRequest struct { EndDate *time.Time `json:"endDate"` } -func (req WorkHistoryUpdateRequest) ToEntity() *entity.WorkHistory { +func (req WorkHistoryUpdateRequest) ToEntity(userId uint) *entity.WorkHistory { return &entity.WorkHistory{ + UserID: userId, JobTitle: req.JobTitle, CompanyName: req.CompanyName, StartDate: req.StartDate, @@ -46,6 +50,7 @@ func (req WorkHistoryUpdateRequest) ToEntity() *entity.WorkHistory { } type WorkHistoryQueryRequestContext struct { + UserID string `json:"userId"` JobTitle string `json:"jobTitle"` CompanyName string `json:"companyName"` IsCurrent string `json:"isCurrent"` @@ -54,6 +59,12 @@ type WorkHistoryQueryRequestContext struct { func (req WorkHistoryQueryRequestContext) ToParamRequest() WorkHistoryQueryRequest { var request WorkHistoryQueryRequest + if userId := req.UserID; userId != "" { + userIdUint, err := strconv.ParseUint(userId, 10, 0) + if err == nil { + request.UserID = uint(userIdUint) + } + } if jobTitle := req.JobTitle; jobTitle != "" { request.JobTitle = &jobTitle } diff --git a/app/module/work_history/service/work_history.service.go b/app/module/work_history/service/work_history.service.go index 1ec38c4..97fff74 100644 --- a/app/module/work_history/service/work_history.service.go +++ b/app/module/work_history/service/work_history.service.go @@ -8,7 +8,6 @@ import ( "narasi-ahli-be/app/module/work_history/request" "narasi-ahli-be/app/module/work_history/response" "narasi-ahli-be/utils/paginator" - utilSvc "narasi-ahli-be/utils/service" "github.com/rs/zerolog" ) @@ -20,11 +19,11 @@ type workHistoryService struct { } type WorkHistoryService interface { - All(authToken string, req request.WorkHistoryQueryRequest) (workHistories []*response.WorkHistoryResponse, paging paginator.Pagination, err error) - Show(authToken string, id uint) (workHistory *response.WorkHistoryResponse, err error) - Save(authToken string, req request.WorkHistoryCreateRequest) (workHistory *response.WorkHistoryResponse, err error) - Update(authToken string, id uint, req request.WorkHistoryUpdateRequest) (err error) - Delete(authToken string, id uint) error + All(req request.WorkHistoryQueryRequest) (workHistories []*response.WorkHistoryResponse, paging paginator.Pagination, err error) + Show(userId uint, id uint) (workHistory *response.WorkHistoryResponse, err error) + Save(userId uint, req request.WorkHistoryCreateRequest) (workHistory *response.WorkHistoryResponse, err error) + Update(userId uint, id uint, req request.WorkHistoryUpdateRequest) (err error) + Delete(userId uint, id uint) error } func NewWorkHistoryService(repo repository.WorkHistoryRepository, usersRepo usersRepository.UsersRepository, log zerolog.Logger) WorkHistoryService { @@ -35,13 +34,8 @@ func NewWorkHistoryService(repo repository.WorkHistoryRepository, usersRepo user } } -func (_i *workHistoryService) All(authToken string, req request.WorkHistoryQueryRequest) (workHistories []*response.WorkHistoryResponse, paging paginator.Pagination, err error) { - userInfo := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) - if userInfo == nil { - return nil, paginator.Pagination{}, errors.New("unauthorized") - } - - results, paging, err := _i.Repo.GetAll(userInfo.ID, req) +func (_i *workHistoryService) All(req request.WorkHistoryQueryRequest) (workHistories []*response.WorkHistoryResponse, paging paginator.Pagination, err error) { + results, paging, err := _i.Repo.GetAll(req.UserID, req) if err != nil { return } @@ -53,13 +47,8 @@ func (_i *workHistoryService) All(authToken string, req request.WorkHistoryQuery return } -func (_i *workHistoryService) Show(authToken string, id uint) (workHistory *response.WorkHistoryResponse, err error) { - userInfo := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) - if userInfo == nil { - return nil, errors.New("unauthorized") - } - - result, err := _i.Repo.FindOneByUserAndId(userInfo.ID, id) +func (_i *workHistoryService) Show(userId uint, id uint) (workHistory *response.WorkHistoryResponse, err error) { + result, err := _i.Repo.FindOneByUserAndId(userId, id) if err != nil { return nil, err } @@ -67,21 +56,15 @@ func (_i *workHistoryService) Show(authToken string, id uint) (workHistory *resp return mapper.WorkHistoryResponseMapper(result), nil } -func (_i *workHistoryService) Save(authToken string, req request.WorkHistoryCreateRequest) (workHistory *response.WorkHistoryResponse, err error) { +func (_i *workHistoryService) Save(userId uint, req request.WorkHistoryCreateRequest) (workHistory *response.WorkHistoryResponse, err error) { _i.Log.Info().Interface("data", req).Msg("Creating work history") - userInfo := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) - if userInfo == nil { - return nil, errors.New("unauthorized") - } - // Validate business rules if req.EndDate != nil && req.EndDate.Before(req.StartDate) { return nil, errors.New("end date cannot be before start date") } - entity := req.ToEntity() - entity.UserID = userInfo.ID + entity := req.ToEntity(userId) result, err := _i.Repo.Create(entity) if err != nil { @@ -91,16 +74,11 @@ func (_i *workHistoryService) Save(authToken string, req request.WorkHistoryCrea return mapper.WorkHistoryResponseMapper(result), nil } -func (_i *workHistoryService) Update(authToken string, id uint, req request.WorkHistoryUpdateRequest) (err error) { +func (_i *workHistoryService) Update(userId uint, id uint, req request.WorkHistoryUpdateRequest) (err error) { _i.Log.Info().Interface("data", req).Msg("Updating work history") - userInfo := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) - if userInfo == nil { - return errors.New("unauthorized") - } - // Check if record exists and belongs to user - existing, err := _i.Repo.FindOneByUserAndId(userInfo.ID, id) + existing, err := _i.Repo.FindOneByUserAndId(userId, id) if err != nil { return err } @@ -113,20 +91,15 @@ func (_i *workHistoryService) Update(authToken string, id uint, req request.Work return errors.New("end date cannot be before start date") } - entity := req.ToEntity() - return _i.Repo.Update(userInfo.ID, id, entity) + entity := req.ToEntity(userId) + return _i.Repo.Update(userId, id, entity) } -func (_i *workHistoryService) Delete(authToken string, id uint) error { - _i.Log.Info().Str("authToken", authToken).Uint("id", id).Msg("Deleting work history") - - userInfo := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) - if userInfo == nil { - return errors.New("unauthorized") - } +func (_i *workHistoryService) Delete(userId uint, id uint) error { + _i.Log.Info().Uint("userId", userId).Uint("id", id).Msg("Deleting work history") // Check if record exists and belongs to user - existing, err := _i.Repo.FindOneByUserAndId(userInfo.ID, id) + existing, err := _i.Repo.FindOneByUserAndId(userId, id) if err != nil { return err } @@ -134,5 +107,5 @@ func (_i *workHistoryService) Delete(authToken string, id uint) error { return errors.New("work history not found") } - return _i.Repo.Delete(userInfo.ID, id) + return _i.Repo.Delete(userId, id) } diff --git a/docs/swagger/docs.go b/docs/swagger/docs.go index 3acd167..1dfb0f1 100644 --- a/docs/swagger/docs.go +++ b/docs/swagger/docs.go @@ -7264,12 +7264,7 @@ const docTemplate = `{ }, "/education-history": { "get": { - "security": [ - { - "Bearer": [] - } - ], - "description": "API for getting all Education History for authenticated user", + "description": "API for getting all Education History for specific user", "tags": [ "Education History" ], @@ -7295,6 +7290,12 @@ const docTemplate = `{ "name": "schoolName", "in": "query" }, + { + "type": "integer", + "name": "userId", + "in": "query", + "required": true + }, { "type": "integer", "name": "count", @@ -7349,12 +7350,6 @@ const docTemplate = `{ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -7364,11 +7359,6 @@ const docTemplate = `{ } }, "post": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for create Education History", "tags": [ "Education History" @@ -7383,11 +7373,11 @@ const docTemplate = `{ "required": true }, { - "type": "string", - "default": "Bearer \u003cAdd access token here\u003e", - "description": "Insert your access token", - "name": "Authorization", - "in": "header" + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true }, { "description": "Required payload", @@ -7412,12 +7402,6 @@ const docTemplate = `{ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -7429,11 +7413,6 @@ const docTemplate = `{ }, "/education-history/{id}": { "get": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for getting one Education History", "tags": [ "Education History" @@ -7446,6 +7425,13 @@ const docTemplate = `{ "name": "id", "in": "path", "required": true + }, + { + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true } ], "responses": { @@ -7461,12 +7447,6 @@ const docTemplate = `{ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -7476,11 +7456,6 @@ const docTemplate = `{ } }, "put": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for update Education History", "tags": [ "Education History" @@ -7501,6 +7476,13 @@ const docTemplate = `{ "in": "path", "required": true }, + { + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true + }, { "description": "Required payload", "name": "payload", @@ -7524,12 +7506,6 @@ const docTemplate = `{ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -7539,11 +7515,6 @@ const docTemplate = `{ } }, "delete": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for delete Education History", "tags": [ "Education History" @@ -7563,6 +7534,13 @@ const docTemplate = `{ "name": "id", "in": "path", "required": true + }, + { + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true } ], "responses": { @@ -7578,12 +7556,6 @@ const docTemplate = `{ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -7595,11 +7567,6 @@ const docTemplate = `{ }, "/education-history/{id}/certificate": { "post": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for upload certificate image for Education History", "tags": [ "Education History" @@ -7620,6 +7587,13 @@ const docTemplate = `{ "in": "path", "required": true }, + { + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true + }, { "type": "file", "description": "Certificate image file", @@ -7641,12 +7615,6 @@ const docTemplate = `{ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -12943,12 +12911,7 @@ const docTemplate = `{ }, "/work-history": { "get": { - "security": [ - { - "Bearer": [] - } - ], - "description": "API for getting all Work History for authenticated user", + "description": "API for getting all Work History for specific user", "tags": [ "Work History" ], @@ -12970,6 +12933,12 @@ const docTemplate = `{ "name": "jobTitle", "in": "query" }, + { + "type": "integer", + "name": "userId", + "in": "query", + "required": true + }, { "type": "integer", "name": "count", @@ -13024,12 +12993,6 @@ const docTemplate = `{ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -13039,11 +13002,6 @@ const docTemplate = `{ } }, "post": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for create Work History", "tags": [ "Work History" @@ -13058,11 +13016,11 @@ const docTemplate = `{ "required": true }, { - "type": "string", - "default": "Bearer \u003cAdd access token here\u003e", - "description": "Insert your access token", - "name": "Authorization", - "in": "header" + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true }, { "description": "Required payload", @@ -13087,12 +13045,6 @@ const docTemplate = `{ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -13104,11 +13056,6 @@ const docTemplate = `{ }, "/work-history/{id}": { "get": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for getting one Work History", "tags": [ "Work History" @@ -13121,6 +13068,13 @@ const docTemplate = `{ "name": "id", "in": "path", "required": true + }, + { + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true } ], "responses": { @@ -13136,12 +13090,6 @@ const docTemplate = `{ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -13151,11 +13099,6 @@ const docTemplate = `{ } }, "put": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for update Work History", "tags": [ "Work History" @@ -13176,6 +13119,13 @@ const docTemplate = `{ "in": "path", "required": true }, + { + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true + }, { "description": "Required payload", "name": "payload", @@ -13199,12 +13149,6 @@ const docTemplate = `{ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -13214,11 +13158,6 @@ const docTemplate = `{ } }, "delete": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for delete Work History", "tags": [ "Work History" @@ -13238,6 +13177,13 @@ const docTemplate = `{ "name": "id", "in": "path", "required": true + }, + { + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true } ], "responses": { @@ -13253,12 +13199,6 @@ const docTemplate = `{ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { diff --git a/docs/swagger/swagger.json b/docs/swagger/swagger.json index 8578321..9d23622 100644 --- a/docs/swagger/swagger.json +++ b/docs/swagger/swagger.json @@ -7253,12 +7253,7 @@ }, "/education-history": { "get": { - "security": [ - { - "Bearer": [] - } - ], - "description": "API for getting all Education History for authenticated user", + "description": "API for getting all Education History for specific user", "tags": [ "Education History" ], @@ -7284,6 +7279,12 @@ "name": "schoolName", "in": "query" }, + { + "type": "integer", + "name": "userId", + "in": "query", + "required": true + }, { "type": "integer", "name": "count", @@ -7338,12 +7339,6 @@ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -7353,11 +7348,6 @@ } }, "post": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for create Education History", "tags": [ "Education History" @@ -7372,11 +7362,11 @@ "required": true }, { - "type": "string", - "default": "Bearer \u003cAdd access token here\u003e", - "description": "Insert your access token", - "name": "Authorization", - "in": "header" + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true }, { "description": "Required payload", @@ -7401,12 +7391,6 @@ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -7418,11 +7402,6 @@ }, "/education-history/{id}": { "get": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for getting one Education History", "tags": [ "Education History" @@ -7435,6 +7414,13 @@ "name": "id", "in": "path", "required": true + }, + { + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true } ], "responses": { @@ -7450,12 +7436,6 @@ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -7465,11 +7445,6 @@ } }, "put": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for update Education History", "tags": [ "Education History" @@ -7490,6 +7465,13 @@ "in": "path", "required": true }, + { + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true + }, { "description": "Required payload", "name": "payload", @@ -7513,12 +7495,6 @@ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -7528,11 +7504,6 @@ } }, "delete": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for delete Education History", "tags": [ "Education History" @@ -7552,6 +7523,13 @@ "name": "id", "in": "path", "required": true + }, + { + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true } ], "responses": { @@ -7567,12 +7545,6 @@ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -7584,11 +7556,6 @@ }, "/education-history/{id}/certificate": { "post": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for upload certificate image for Education History", "tags": [ "Education History" @@ -7609,6 +7576,13 @@ "in": "path", "required": true }, + { + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true + }, { "type": "file", "description": "Certificate image file", @@ -7630,12 +7604,6 @@ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -12932,12 +12900,7 @@ }, "/work-history": { "get": { - "security": [ - { - "Bearer": [] - } - ], - "description": "API for getting all Work History for authenticated user", + "description": "API for getting all Work History for specific user", "tags": [ "Work History" ], @@ -12959,6 +12922,12 @@ "name": "jobTitle", "in": "query" }, + { + "type": "integer", + "name": "userId", + "in": "query", + "required": true + }, { "type": "integer", "name": "count", @@ -13013,12 +12982,6 @@ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -13028,11 +12991,6 @@ } }, "post": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for create Work History", "tags": [ "Work History" @@ -13047,11 +13005,11 @@ "required": true }, { - "type": "string", - "default": "Bearer \u003cAdd access token here\u003e", - "description": "Insert your access token", - "name": "Authorization", - "in": "header" + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true }, { "description": "Required payload", @@ -13076,12 +13034,6 @@ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -13093,11 +13045,6 @@ }, "/work-history/{id}": { "get": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for getting one Work History", "tags": [ "Work History" @@ -13110,6 +13057,13 @@ "name": "id", "in": "path", "required": true + }, + { + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true } ], "responses": { @@ -13125,12 +13079,6 @@ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -13140,11 +13088,6 @@ } }, "put": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for update Work History", "tags": [ "Work History" @@ -13165,6 +13108,13 @@ "in": "path", "required": true }, + { + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true + }, { "description": "Required payload", "name": "payload", @@ -13188,12 +13138,6 @@ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { @@ -13203,11 +13147,6 @@ } }, "delete": { - "security": [ - { - "Bearer": [] - } - ], "description": "API for delete Work History", "tags": [ "Work History" @@ -13227,6 +13166,13 @@ "name": "id", "in": "path", "required": true + }, + { + "type": "integer", + "description": "User ID", + "name": "userId", + "in": "query", + "required": true } ], "responses": { @@ -13242,12 +13188,6 @@ "$ref": "#/definitions/response.BadRequestError" } }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/response.UnauthorizedError" - } - }, "500": { "description": "Internal Server Error", "schema": { diff --git a/docs/swagger/swagger.yaml b/docs/swagger/swagger.yaml index e8a0447..353c413 100644 --- a/docs/swagger/swagger.yaml +++ b/docs/swagger/swagger.yaml @@ -5812,7 +5812,7 @@ paths: - Ebook Wishlist /education-history: get: - description: API for getting all Education History for authenticated user + description: API for getting all Education History for specific user parameters: - in: query name: educationLevel @@ -5826,6 +5826,10 @@ paths: - in: query name: schoolName type: string + - in: query + name: userId + required: true + type: integer - in: query name: count type: integer @@ -5859,16 +5863,10 @@ paths: description: Bad Request schema: $ref: '#/definitions/response.BadRequestError' - "401": - description: Unauthorized - schema: - $ref: '#/definitions/response.UnauthorizedError' "500": description: Internal Server Error schema: $ref: '#/definitions/response.InternalServerError' - security: - - Bearer: [] summary: Get all Education History tags: - Education History @@ -5880,11 +5878,11 @@ paths: name: X-Csrf-Token required: true type: string - - default: Bearer - description: Insert your access token - in: header - name: Authorization - type: string + - description: User ID + in: query + name: userId + required: true + type: integer - description: Required payload in: body name: payload @@ -5900,16 +5898,10 @@ paths: description: Bad Request schema: $ref: '#/definitions/response.BadRequestError' - "401": - description: Unauthorized - schema: - $ref: '#/definitions/response.UnauthorizedError' "500": description: Internal Server Error schema: $ref: '#/definitions/response.InternalServerError' - security: - - Bearer: [] summary: Create Education History tags: - Education History @@ -5927,34 +5919,38 @@ paths: name: id required: true type: integer - responses: - "200": - description: OK - schema: - $ref: '#/definitions/response.Response' - "400": - description: Bad Request - schema: - $ref: '#/definitions/response.BadRequestError' - "401": - description: Unauthorized - schema: - $ref: '#/definitions/response.UnauthorizedError' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/response.InternalServerError' - security: - - Bearer: [] - summary: Delete Education History - tags: - - Education History - get: - description: API for getting one Education History - parameters: - - description: Education History ID - in: path - name: id + - description: User ID + in: query + name: userId + required: true + type: integer + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.BadRequestError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.InternalServerError' + summary: Delete Education History + tags: + - Education History + get: + description: API for getting one Education History + parameters: + - description: Education History ID + in: path + name: id + required: true + type: integer + - description: User ID + in: query + name: userId required: true type: integer responses: @@ -5966,16 +5962,10 @@ paths: description: Bad Request schema: $ref: '#/definitions/response.BadRequestError' - "401": - description: Unauthorized - schema: - $ref: '#/definitions/response.UnauthorizedError' "500": description: Internal Server Error schema: $ref: '#/definitions/response.InternalServerError' - security: - - Bearer: [] summary: Get one Education History tags: - Education History @@ -5992,6 +5982,11 @@ paths: name: id required: true type: integer + - description: User ID + in: query + name: userId + required: true + type: integer - description: Required payload in: body name: payload @@ -6007,16 +6002,10 @@ paths: description: Bad Request schema: $ref: '#/definitions/response.BadRequestError' - "401": - description: Unauthorized - schema: - $ref: '#/definitions/response.UnauthorizedError' "500": description: Internal Server Error schema: $ref: '#/definitions/response.InternalServerError' - security: - - Bearer: [] summary: Update Education History tags: - Education History @@ -6034,6 +6023,11 @@ paths: name: id required: true type: integer + - description: User ID + in: query + name: userId + required: true + type: integer - description: Certificate image file in: formData name: certificate @@ -6048,16 +6042,10 @@ paths: description: Bad Request schema: $ref: '#/definitions/response.BadRequestError' - "401": - description: Unauthorized - schema: - $ref: '#/definitions/response.UnauthorizedError' "500": description: Internal Server Error schema: $ref: '#/definitions/response.InternalServerError' - security: - - Bearer: [] summary: Upload Certificate for Education History tags: - Education History @@ -9423,7 +9411,7 @@ paths: - Users /work-history: get: - description: API for getting all Work History for authenticated user + description: API for getting all Work History for specific user parameters: - in: query name: companyName @@ -9435,6 +9423,10 @@ paths: - in: query name: jobTitle type: string + - in: query + name: userId + required: true + type: integer - in: query name: count type: integer @@ -9468,16 +9460,10 @@ paths: description: Bad Request schema: $ref: '#/definitions/response.BadRequestError' - "401": - description: Unauthorized - schema: - $ref: '#/definitions/response.UnauthorizedError' "500": description: Internal Server Error schema: $ref: '#/definitions/response.InternalServerError' - security: - - Bearer: [] summary: Get all Work History tags: - Work History @@ -9489,11 +9475,11 @@ paths: name: X-Csrf-Token required: true type: string - - default: Bearer - description: Insert your access token - in: header - name: Authorization - type: string + - description: User ID + in: query + name: userId + required: true + type: integer - description: Required payload in: body name: payload @@ -9509,16 +9495,10 @@ paths: description: Bad Request schema: $ref: '#/definitions/response.BadRequestError' - "401": - description: Unauthorized - schema: - $ref: '#/definitions/response.UnauthorizedError' "500": description: Internal Server Error schema: $ref: '#/definitions/response.InternalServerError' - security: - - Bearer: [] summary: Create Work History tags: - Work History @@ -9536,34 +9516,38 @@ paths: name: id required: true type: integer - responses: - "200": - description: OK - schema: - $ref: '#/definitions/response.Response' - "400": - description: Bad Request - schema: - $ref: '#/definitions/response.BadRequestError' - "401": - description: Unauthorized - schema: - $ref: '#/definitions/response.UnauthorizedError' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/response.InternalServerError' - security: - - Bearer: [] - summary: Delete Work History - tags: - - Work History - get: - description: API for getting one Work History - parameters: - - description: Work History ID - in: path - name: id + - description: User ID + in: query + name: userId + required: true + type: integer + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "400": + description: Bad Request + schema: + $ref: '#/definitions/response.BadRequestError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.InternalServerError' + summary: Delete Work History + tags: + - Work History + get: + description: API for getting one Work History + parameters: + - description: Work History ID + in: path + name: id + required: true + type: integer + - description: User ID + in: query + name: userId required: true type: integer responses: @@ -9575,16 +9559,10 @@ paths: description: Bad Request schema: $ref: '#/definitions/response.BadRequestError' - "401": - description: Unauthorized - schema: - $ref: '#/definitions/response.UnauthorizedError' "500": description: Internal Server Error schema: $ref: '#/definitions/response.InternalServerError' - security: - - Bearer: [] summary: Get one Work History tags: - Work History @@ -9601,6 +9579,11 @@ paths: name: id required: true type: integer + - description: User ID + in: query + name: userId + required: true + type: integer - description: Required payload in: body name: payload @@ -9616,16 +9599,10 @@ paths: description: Bad Request schema: $ref: '#/definitions/response.BadRequestError' - "401": - description: Unauthorized - schema: - $ref: '#/definitions/response.UnauthorizedError' "500": description: Internal Server Error schema: $ref: '#/definitions/response.InternalServerError' - security: - - Bearer: [] summary: Update Work History tags: - Work History