From a18d5991b71e83f1383fa1f535e9bb6afd871916 Mon Sep 17 00:00:00 2001 From: hanif salafi Date: Wed, 1 Oct 2025 10:10:18 +0700 Subject: [PATCH] major update --- add_clientid_extraction.ps1 | 66 + add_clientid_to_remaining.ps1 | 59 + .../service/activity_logs.service.go | 2 +- .../approval_workflow_steps.controller.go | 75 +- .../approval_workflow_steps.service.go | 203 ++- .../approval_workflows.controller.go | 104 +- .../service/approval_workflows.service.go | 260 +++- .../article_approval_flows.controller.go | 116 +- .../service/article_approval_flows.service.go | 379 ++++- .../article_approval_flows.service.go.backup | 817 ++++++++++ .../service/article_approvals.service.go | 2 +- .../article_categories.controller.go | 59 +- .../service/article_categories.service.go | 112 +- .../controller/article_files.controller.go | 63 +- .../article_files/controller/controller.go | 9 +- .../service/article_files.service.go | 104 +- .../controller/articles.controller.go | 158 +- .../articles/service/articles.service.go | 318 +++- .../controller/bookmarks.controller.go | 65 +- .../bookmarks/service/bookmarks.service.go | 98 +- .../client_approval_settings.controller.go | 95 +- .../client_approval_settings.service.go | 278 +++- .../clients/controller/clients.controller.go | 20 +- app/module/clients/request/clients.request.go | 12 +- app/module/clients/service/clients.service.go | 28 +- .../controller/user_levels.controller.go | 57 +- .../service/user_levels.service.go | 112 +- .../users/controller/users.controller.go | 99 +- app/module/users/service/users.service.go | 154 +- docs/MODULE_UPDATE_TEMPLATE.md | 135 ++ docs/swagger/docs.go | 1373 +++++++++-------- docs/swagger/swagger.json | 1373 +++++++++-------- docs/swagger/swagger.yaml | 1046 +++++++------ fix_all_article_approval_flows.ps1 | 59 + fix_all_article_approval_flows_final.ps1 | 59 + fix_all_article_approval_flows_final10.ps1 | 59 + fix_all_article_approval_flows_final11.ps1 | 59 + fix_all_article_approval_flows_final12.ps1 | 59 + fix_all_article_approval_flows_final13.ps1 | 59 + fix_all_article_approval_flows_final14.ps1 | 59 + fix_all_article_approval_flows_final15.ps1 | 59 + fix_all_article_approval_flows_final16.ps1 | 59 + fix_all_article_approval_flows_final2.ps1 | 59 + fix_all_article_approval_flows_final3.ps1 | 59 + fix_all_article_approval_flows_final4.ps1 | 59 + fix_all_article_approval_flows_final5.ps1 | 59 + fix_all_article_approval_flows_final6.ps1 | 59 + fix_all_article_approval_flows_final7.ps1 | 59 + fix_all_article_approval_flows_final8.ps1 | 59 + fix_all_article_approval_flows_final9.ps1 | 59 + fix_all_clientid.ps1 | 59 + fix_article_approval_flows_clientid.ps1 | 59 + fix_remaining_article_approval_flows.ps1 | 59 + fix_remaining_clientid.ps1 | 61 + replace_clientid_calls.ps1 | 43 + scripts/update_modules_remove_x_client_key.sh | 65 + update_service_methods.ps1 | 44 + update_service_methods.sh | 30 + 58 files changed, 6804 insertions(+), 2470 deletions(-) create mode 100644 add_clientid_extraction.ps1 create mode 100644 add_clientid_to_remaining.ps1 create mode 100644 app/module/article_approval_flows/service/article_approval_flows.service.go.backup create mode 100644 docs/MODULE_UPDATE_TEMPLATE.md create mode 100644 fix_all_article_approval_flows.ps1 create mode 100644 fix_all_article_approval_flows_final.ps1 create mode 100644 fix_all_article_approval_flows_final10.ps1 create mode 100644 fix_all_article_approval_flows_final11.ps1 create mode 100644 fix_all_article_approval_flows_final12.ps1 create mode 100644 fix_all_article_approval_flows_final13.ps1 create mode 100644 fix_all_article_approval_flows_final14.ps1 create mode 100644 fix_all_article_approval_flows_final15.ps1 create mode 100644 fix_all_article_approval_flows_final16.ps1 create mode 100644 fix_all_article_approval_flows_final2.ps1 create mode 100644 fix_all_article_approval_flows_final3.ps1 create mode 100644 fix_all_article_approval_flows_final4.ps1 create mode 100644 fix_all_article_approval_flows_final5.ps1 create mode 100644 fix_all_article_approval_flows_final6.ps1 create mode 100644 fix_all_article_approval_flows_final7.ps1 create mode 100644 fix_all_article_approval_flows_final8.ps1 create mode 100644 fix_all_article_approval_flows_final9.ps1 create mode 100644 fix_all_clientid.ps1 create mode 100644 fix_article_approval_flows_clientid.ps1 create mode 100644 fix_remaining_article_approval_flows.ps1 create mode 100644 fix_remaining_clientid.ps1 create mode 100644 replace_clientid_calls.ps1 create mode 100644 scripts/update_modules_remove_x_client_key.sh create mode 100644 update_service_methods.ps1 create mode 100644 update_service_methods.sh diff --git a/add_clientid_extraction.ps1 b/add_clientid_extraction.ps1 new file mode 100644 index 0000000..60bf285 --- /dev/null +++ b/add_clientid_extraction.ps1 @@ -0,0 +1,66 @@ +# PowerShell script to add clientId extraction logic to service methods +# Usage: .\add_clientid_extraction.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Adding clientId extraction logic to: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Pattern to find method definitions that need clientId extraction +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\)' + +# Find all method matches +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Processing method: $MethodName" + + # Skip methods that already have clientId extraction logic + if ($Content -match "func \(_i \*${ServiceName}Service\) ${MethodName}\(authToken string, ${Parameters}\) \{[^}]*Extract clientId from authToken") { + Write-Host " Skipping $MethodName - already has clientId extraction" + continue + } + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "ClientId extraction logic added to service methods." diff --git a/add_clientid_to_remaining.ps1 b/add_clientid_to_remaining.ps1 new file mode 100644 index 0000000..786a194 --- /dev/null +++ b/add_clientid_to_remaining.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to add clientId extraction to remaining methods +# Usage: .\add_clientid_to_remaining.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Adding clientId extraction to remaining methods in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Adding clientId extraction to method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "ClientId extraction added to remaining methods." diff --git a/app/module/activity_logs/service/activity_logs.service.go b/app/module/activity_logs/service/activity_logs.service.go index 5c25a7a..79f221b 100644 --- a/app/module/activity_logs/service/activity_logs.service.go +++ b/app/module/activity_logs/service/activity_logs.service.go @@ -86,7 +86,7 @@ func (_i *activityLogsService) Save(clientId *uuid.UUID, req request.ActivityLog } // update article - err = _i.ArticleService.UpdateActivityCount(clientId, *req.ArticleId, req.ActivityTypeId) + err = _i.ArticleService.UpdateActivityCount(*authToken, *req.ArticleId, req.ActivityTypeId) if err != nil { return nil, err } diff --git a/app/module/approval_workflow_steps/controller/approval_workflow_steps.controller.go b/app/module/approval_workflow_steps/controller/approval_workflow_steps.controller.go index 9a605b1..b1520e6 100644 --- a/app/module/approval_workflow_steps/controller/approval_workflow_steps.controller.go +++ b/app/module/approval_workflow_steps/controller/approval_workflow_steps.controller.go @@ -2,7 +2,6 @@ package controller import ( "netidhub-saas-be/app/database/entity" - "netidhub-saas-be/app/middleware" "netidhub-saas-be/app/module/approval_workflow_steps/request" "netidhub-saas-be/app/module/approval_workflow_steps/service" "netidhub-saas-be/utils/paginator" @@ -82,7 +81,7 @@ func NewApprovalWorkflowStepsController(approvalWorkflowStepsService service.App // @Description API for getting all ApprovalWorkflowSteps // @Tags ApprovalWorkflowSteps // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param workflowId query int false "Workflow ID filter" // @Param stepOrder query int false "Step order filter" // @Param stepName query string false "Step name filter" @@ -111,12 +110,12 @@ func (_i *approvalWorkflowStepsController) All(c *fiber.Ctx) error { Limit: 10, } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - _i.Log.Info().Interface("clientId", clientId).Msg("") + _i.Log.Info().Interface("authToken", authToken).Msg("") - approvalWorkflowStepsData, paging, err := _i.approvalWorkflowStepsService.GetAll(clientId, req) + approvalWorkflowStepsData, paging, err := _i.approvalWorkflowStepsService.GetAll(authToken, req) if err != nil { return err } @@ -134,7 +133,7 @@ func (_i *approvalWorkflowStepsController) All(c *fiber.Ctx) error { // @Description API for getting one ApprovalWorkflowSteps // @Tags ApprovalWorkflowSteps // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param id path int true "ApprovalWorkflowSteps ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -147,10 +146,10 @@ func (_i *approvalWorkflowStepsController) Show(c *fiber.Ctx) error { return utilRes.ErrorBadRequest(c, "Invalid ID format") } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - approvalWorkflowStepsData, err := _i.approvalWorkflowStepsService.FindOne(clientId, uint(id)) + approvalWorkflowStepsData, err := _i.approvalWorkflowStepsService.FindOne(authToken, uint(id)) if err != nil { return err } @@ -167,7 +166,7 @@ func (_i *approvalWorkflowStepsController) Show(c *fiber.Ctx) error { // @Description API for saving ApprovalWorkflowSteps // @Tags ApprovalWorkflowSteps // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param payload body request.CreateApprovalWorkflowStepsRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -180,8 +179,8 @@ func (_i *approvalWorkflowStepsController) Save(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") // Convert request to entity step := &entity.ApprovalWorkflowSteps{ @@ -192,7 +191,7 @@ func (_i *approvalWorkflowStepsController) Save(c *fiber.Ctx) error { CanSkip: &req.IsOptional, } - approvalWorkflowStepsData, err := _i.approvalWorkflowStepsService.Create(clientId, step) + approvalWorkflowStepsData, err := _i.approvalWorkflowStepsService.Create(authToken, step) if err != nil { return err } @@ -209,7 +208,7 @@ func (_i *approvalWorkflowStepsController) Save(c *fiber.Ctx) error { // @Description API for updating ApprovalWorkflowSteps // @Tags ApprovalWorkflowSteps // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param id path int true "ApprovalWorkflowSteps ID" // @Param payload body request.UpdateApprovalWorkflowStepsRequest true "Required payload" // @Success 200 {object} response.Response @@ -228,8 +227,8 @@ func (_i *approvalWorkflowStepsController) Update(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") // Convert request to entity step := &entity.ApprovalWorkflowSteps{} @@ -246,7 +245,7 @@ func (_i *approvalWorkflowStepsController) Update(c *fiber.Ctx) error { step.CanSkip = req.IsOptional } - err = _i.approvalWorkflowStepsService.Update(clientId, uint(id), step) + err = _i.approvalWorkflowStepsService.Update(authToken, uint(id), step) if err != nil { return err } @@ -262,7 +261,7 @@ func (_i *approvalWorkflowStepsController) Update(c *fiber.Ctx) error { // @Description API for deleting ApprovalWorkflowSteps // @Tags ApprovalWorkflowSteps // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param id path int true "ApprovalWorkflowSteps ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -275,10 +274,10 @@ func (_i *approvalWorkflowStepsController) Delete(c *fiber.Ctx) error { return utilRes.ErrorBadRequest(c, "Invalid ID format") } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - err = _i.approvalWorkflowStepsService.Delete(clientId, uint(id)) + err = _i.approvalWorkflowStepsService.Delete(authToken, uint(id)) if err != nil { return err } @@ -294,7 +293,7 @@ func (_i *approvalWorkflowStepsController) Delete(c *fiber.Ctx) error { // @Description API for getting ApprovalWorkflowSteps by Workflow ID // @Tags ApprovalWorkflowSteps // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param workflowId path int true "Workflow ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -307,10 +306,10 @@ func (_i *approvalWorkflowStepsController) GetByWorkflow(c *fiber.Ctx) error { return utilRes.ErrorBadRequest(c, "Invalid workflow ID format") } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - approvalWorkflowStepsData, err := _i.approvalWorkflowStepsService.GetByWorkflowID(clientId, uint(workflowId)) + approvalWorkflowStepsData, err := _i.approvalWorkflowStepsService.GetByWorkflowID(authToken, uint(workflowId)) if err != nil { return err } @@ -327,7 +326,7 @@ func (_i *approvalWorkflowStepsController) GetByWorkflow(c *fiber.Ctx) error { // @Description API for getting ApprovalWorkflowSteps by Role ID // @Tags ApprovalWorkflowSteps // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param roleId path int true "Role ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -340,10 +339,10 @@ func (_i *approvalWorkflowStepsController) GetByRole(c *fiber.Ctx) error { return utilRes.ErrorBadRequest(c, "Invalid role ID format") } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - approvalWorkflowStepsData, err := _i.approvalWorkflowStepsService.GetByWorkflowID(clientId, uint(roleId)) + approvalWorkflowStepsData, err := _i.approvalWorkflowStepsService.GetByWorkflowID(authToken, uint(roleId)) if err != nil { return err } @@ -360,7 +359,7 @@ func (_i *approvalWorkflowStepsController) GetByRole(c *fiber.Ctx) error { // @Description API for bulk creating ApprovalWorkflowSteps // @Tags ApprovalWorkflowSteps // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param payload body request.BulkCreateApprovalWorkflowStepsRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -373,8 +372,8 @@ func (_i *approvalWorkflowStepsController) BulkSave(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") // Convert request to entities var steps []*entity.ApprovalWorkflowSteps @@ -389,7 +388,7 @@ func (_i *approvalWorkflowStepsController) BulkSave(c *fiber.Ctx) error { steps = append(steps, step) } - approvalWorkflowStepsData, err := _i.approvalWorkflowStepsService.BulkCreate(clientId, req.WorkflowID, steps) + approvalWorkflowStepsData, err := _i.approvalWorkflowStepsService.BulkCreate(authToken, req.WorkflowID, steps) if err != nil { return err } @@ -406,7 +405,7 @@ func (_i *approvalWorkflowStepsController) BulkSave(c *fiber.Ctx) error { // @Description API for reordering ApprovalWorkflowSteps // @Tags ApprovalWorkflowSteps // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param workflowId path int true "Workflow ID" // @Param payload body request.ReorderApprovalWorkflowStepsRequest true "Required payload" // @Success 200 {object} response.Response @@ -425,13 +424,13 @@ func (_i *approvalWorkflowStepsController) Reorder(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") // Convert request to expected format stepOrders := req.ToStepOrders() - err = _i.approvalWorkflowStepsService.ReorderSteps(clientId, uint(workflowId), stepOrders) + err = _i.approvalWorkflowStepsService.ReorderSteps(authToken, uint(workflowId), stepOrders) if err != nil { return err } diff --git a/app/module/approval_workflow_steps/service/approval_workflow_steps.service.go b/app/module/approval_workflow_steps/service/approval_workflow_steps.service.go index e467d9f..1443097 100644 --- a/app/module/approval_workflow_steps/service/approval_workflow_steps.service.go +++ b/app/module/approval_workflow_steps/service/approval_workflow_steps.service.go @@ -7,7 +7,9 @@ import ( "netidhub-saas-be/app/module/approval_workflow_steps/repository" "netidhub-saas-be/app/module/approval_workflow_steps/request" workflowRepo "netidhub-saas-be/app/module/approval_workflows/repository" + usersRepo "netidhub-saas-be/app/module/users/repository" "netidhub-saas-be/utils/paginator" + utilSvc "netidhub-saas-be/utils/service" "github.com/google/uuid" "github.com/rs/zerolog" @@ -16,54 +18,99 @@ import ( type approvalWorkflowStepsService struct { ApprovalWorkflowStepsRepository repository.ApprovalWorkflowStepsRepository ApprovalWorkflowsRepository workflowRepo.ApprovalWorkflowsRepository + UsersRepository usersRepo.UsersRepository Log zerolog.Logger } // ApprovalWorkflowStepsService define interface of IApprovalWorkflowStepsService type ApprovalWorkflowStepsService interface { // Basic CRUD - GetAll(clientId *uuid.UUID, req request.GetApprovalWorkflowStepsRequest) (steps []*entity.ApprovalWorkflowSteps, paging paginator.Pagination, err error) - FindOne(clientId *uuid.UUID, id uint) (step *entity.ApprovalWorkflowSteps, err error) - Create(clientId *uuid.UUID, step *entity.ApprovalWorkflowSteps) (stepReturn *entity.ApprovalWorkflowSteps, err error) - Update(clientId *uuid.UUID, id uint, step *entity.ApprovalWorkflowSteps) (err error) - Delete(clientId *uuid.UUID, id uint) (err error) + GetAll(authToken string, req request.GetApprovalWorkflowStepsRequest) (steps []*entity.ApprovalWorkflowSteps, paging paginator.Pagination, err error) + FindOne(authToken string, id uint) (step *entity.ApprovalWorkflowSteps, err error) + Create(authToken string, step *entity.ApprovalWorkflowSteps) (stepReturn *entity.ApprovalWorkflowSteps, err error) + Update(authToken string, id uint, step *entity.ApprovalWorkflowSteps) (err error) + Delete(authToken string, id uint) (err error) // Workflow steps management - GetByWorkflowID(clientId *uuid.UUID, workflowID uint) (steps []*entity.ApprovalWorkflowSteps, err error) - // GetByRoleID(clientId *uuid.UUID, roleID uint) (steps []*entity.ApprovalWorkflowSteps, err error) // Not implemented yet - BulkCreate(clientId *uuid.UUID, workflowID uint, steps []*entity.ApprovalWorkflowSteps) (stepsReturn []*entity.ApprovalWorkflowSteps, err error) - ReorderSteps(clientId *uuid.UUID, workflowID uint, stepOrders []struct { + GetByWorkflowID(authToken string, workflowID uint) (steps []*entity.ApprovalWorkflowSteps, err error) + // GetByRoleID(authToken string, roleID uint) (steps []*entity.ApprovalWorkflowSteps, err error) // Not implemented yet + BulkCreate(authToken string, workflowID uint, steps []*entity.ApprovalWorkflowSteps) (stepsReturn []*entity.ApprovalWorkflowSteps, err error) + ReorderSteps(authToken string, workflowID uint, stepOrders []struct { ID uint StepOrder int }) (err error) // Validation - ValidateStep(clientId *uuid.UUID, step *entity.ApprovalWorkflowSteps) (isValid bool, errors []string, err error) - CanDeleteStep(clientId *uuid.UUID, id uint) (canDelete bool, reason string, err error) - ValidateStepOrder(clientId *uuid.UUID, workflowID uint, stepOrder int, excludeID *uint) (isValid bool, err error) + ValidateStep(authToken string, step *entity.ApprovalWorkflowSteps) (isValid bool, errors []string, err error) + CanDeleteStep(authToken string, id uint) (canDelete bool, reason string, err error) + ValidateStepOrder(authToken string, workflowID uint, stepOrder int, excludeID *uint) (isValid bool, err error) } func NewApprovalWorkflowStepsService( approvalWorkflowStepsRepository repository.ApprovalWorkflowStepsRepository, approvalWorkflowsRepository workflowRepo.ApprovalWorkflowsRepository, + usersRepository usersRepo.UsersRepository, log zerolog.Logger, ) ApprovalWorkflowStepsService { return &approvalWorkflowStepsService{ ApprovalWorkflowStepsRepository: approvalWorkflowStepsRepository, ApprovalWorkflowsRepository: approvalWorkflowsRepository, + UsersRepository: usersRepository, Log: log, } } -func (_i *approvalWorkflowStepsService) GetAll(clientId *uuid.UUID, req request.GetApprovalWorkflowStepsRequest) (steps []*entity.ApprovalWorkflowSteps, paging paginator.Pagination, err error) { +func (_i *approvalWorkflowStepsService) GetAll(authToken string, req request.GetApprovalWorkflowStepsRequest) (steps []*entity.ApprovalWorkflowSteps, paging paginator.Pagination, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, paginator.Pagination{}, errors.New("clientId not found in auth token") + } + return _i.ApprovalWorkflowStepsRepository.GetAll(clientId, req) } -func (_i *approvalWorkflowStepsService) FindOne(clientId *uuid.UUID, id uint) (step *entity.ApprovalWorkflowSteps, err error) { +func (_i *approvalWorkflowStepsService) FindOne(authToken string, id uint) (step *entity.ApprovalWorkflowSteps, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + return _i.ApprovalWorkflowStepsRepository.FindOne(clientId, id) } -func (_i *approvalWorkflowStepsService) Create(clientId *uuid.UUID, step *entity.ApprovalWorkflowSteps) (stepReturn *entity.ApprovalWorkflowSteps, err error) { +func (_i *approvalWorkflowStepsService) Create(authToken string, step *entity.ApprovalWorkflowSteps) (stepReturn *entity.ApprovalWorkflowSteps, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + // Validate workflow exists workflow, err := _i.ApprovalWorkflowsRepository.FindOne(clientId, step.WorkflowId) if err != nil { @@ -74,7 +121,7 @@ func (_i *approvalWorkflowStepsService) Create(clientId *uuid.UUID, step *entity } // Validate step order is unique within workflow - isValid, err := _i.ValidateStepOrder(clientId, step.WorkflowId, step.StepOrder, nil) + isValid, err := _i.ValidateStepOrder(authToken, step.WorkflowId, step.StepOrder, nil) if err != nil { return nil, err } @@ -83,7 +130,7 @@ func (_i *approvalWorkflowStepsService) Create(clientId *uuid.UUID, step *entity } // Validate step data - isValid, validationErrors, err := _i.ValidateStep(clientId, step) + isValid, validationErrors, err := _i.ValidateStep(authToken, step) if err != nil { return nil, err } @@ -94,7 +141,21 @@ func (_i *approvalWorkflowStepsService) Create(clientId *uuid.UUID, step *entity return _i.ApprovalWorkflowStepsRepository.Create(clientId, step) } -func (_i *approvalWorkflowStepsService) Update(clientId *uuid.UUID, id uint, step *entity.ApprovalWorkflowSteps) (err error) { +func (_i *approvalWorkflowStepsService) Update(authToken string, id uint, step *entity.ApprovalWorkflowSteps) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return errors.New("clientId not found in auth token") + } + // Check if step exists existingStep, err := _i.ApprovalWorkflowStepsRepository.FindOne(clientId, id) if err != nil { @@ -106,7 +167,7 @@ func (_i *approvalWorkflowStepsService) Update(clientId *uuid.UUID, id uint, ste // If step order is being changed, validate it's unique if step.StepOrder != 0 && step.StepOrder != existingStep.StepOrder { - isValid, err := _i.ValidateStepOrder(clientId, existingStep.WorkflowId, step.StepOrder, &id) + isValid, err := _i.ValidateStepOrder(authToken, existingStep.WorkflowId, step.StepOrder, &id) if err != nil { return err } @@ -118,9 +179,23 @@ func (_i *approvalWorkflowStepsService) Update(clientId *uuid.UUID, id uint, ste return _i.ApprovalWorkflowStepsRepository.Update(id, step) } -func (_i *approvalWorkflowStepsService) Delete(clientId *uuid.UUID, id uint) (err error) { +func (_i *approvalWorkflowStepsService) Delete(authToken string, id uint) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return errors.New("clientId not found in auth token") + } + // Check if step can be deleted - canDelete, reason, err := _i.CanDeleteStep(clientId, id) + canDelete, reason, err := _i.CanDeleteStep(authToken, id) if err != nil { return err } @@ -131,16 +206,44 @@ func (_i *approvalWorkflowStepsService) Delete(clientId *uuid.UUID, id uint) (er return _i.ApprovalWorkflowStepsRepository.Delete(clientId, id) } -func (_i *approvalWorkflowStepsService) GetByWorkflowID(clientId *uuid.UUID, workflowID uint) (steps []*entity.ApprovalWorkflowSteps, err error) { +func (_i *approvalWorkflowStepsService) GetByWorkflowID(authToken string, workflowID uint) (steps []*entity.ApprovalWorkflowSteps, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + return _i.ApprovalWorkflowStepsRepository.GetByWorkflowId(clientId, workflowID) } // GetByRoleID method is not implemented in repository yet -// func (_i *approvalWorkflowStepsService) GetByRoleID(clientId *uuid.UUID, roleID uint) (steps []*entity.ApprovalWorkflowSteps, err error) { +// func (_i *approvalWorkflowStepsService) GetByRoleID(authToken string, roleID uint) (steps []*entity.ApprovalWorkflowSteps, err error) { // return _i.ApprovalWorkflowStepsRepository.GetByRoleID(clientId, roleID) // } -func (_i *approvalWorkflowStepsService) BulkCreate(clientId *uuid.UUID, workflowID uint, steps []*entity.ApprovalWorkflowSteps) (stepsReturn []*entity.ApprovalWorkflowSteps, err error) { +func (_i *approvalWorkflowStepsService) BulkCreate(authToken string, workflowID uint, steps []*entity.ApprovalWorkflowSteps) (stepsReturn []*entity.ApprovalWorkflowSteps, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + // Validate workflow exists workflow, err := _i.ApprovalWorkflowsRepository.FindOne(clientId, workflowID) if err != nil { @@ -162,7 +265,7 @@ func (_i *approvalWorkflowStepsService) BulkCreate(clientId *uuid.UUID, workflow stepOrders[step.StepOrder] = true // Validate step order is unique in database - isValid, err := _i.ValidateStepOrder(clientId, workflowID, step.StepOrder, nil) + isValid, err := _i.ValidateStepOrder(authToken, workflowID, step.StepOrder, nil) if err != nil { return nil, err } @@ -198,10 +301,24 @@ func (_i *approvalWorkflowStepsService) BulkCreate(clientId *uuid.UUID, workflow return nil, fmt.Errorf("BulkCreate method not implemented yet") } -func (_i *approvalWorkflowStepsService) ReorderSteps(clientId *uuid.UUID, workflowID uint, stepOrders []struct { +func (_i *approvalWorkflowStepsService) ReorderSteps(authToken string, workflowID uint, stepOrders []struct { ID uint StepOrder int }) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return errors.New("clientId not found in auth token") + } + // Validate workflow exists workflow, err := _i.ApprovalWorkflowsRepository.FindOne(clientId, workflowID) if err != nil { @@ -245,7 +362,7 @@ func (_i *approvalWorkflowStepsService) ReorderSteps(clientId *uuid.UUID, workfl return _i.ApprovalWorkflowStepsRepository.ReorderSteps(clientId, workflowID, stepOrderMaps) } -func (_i *approvalWorkflowStepsService) ValidateStep(clientId *uuid.UUID, step *entity.ApprovalWorkflowSteps) (isValid bool, errors []string, err error) { +func (_i *approvalWorkflowStepsService) ValidateStep(authToken string, step *entity.ApprovalWorkflowSteps) (isValid bool, errors []string, err error) { var validationErrors []string // Validate step name @@ -280,7 +397,21 @@ func (_i *approvalWorkflowStepsService) ValidateStep(clientId *uuid.UUID, step * return len(validationErrors) == 0, validationErrors, nil } -func (_i *approvalWorkflowStepsService) CanDeleteStep(clientId *uuid.UUID, id uint) (canDelete bool, reason string, err error) { +func (_i *approvalWorkflowStepsService) CanDeleteStep(authToken string, id uint) (canDelete bool, reason string, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return false, "clientId not found in auth token", errors.New("clientId not found in auth token") + } + // Check if step exists step, err := _i.ApprovalWorkflowStepsRepository.FindOne(clientId, id) if err != nil { @@ -298,7 +429,21 @@ func (_i *approvalWorkflowStepsService) CanDeleteStep(clientId *uuid.UUID, id ui return true, "", nil } -func (_i *approvalWorkflowStepsService) ValidateStepOrder(clientId *uuid.UUID, workflowID uint, stepOrder int, excludeID *uint) (isValid bool, err error) { +func (_i *approvalWorkflowStepsService) ValidateStepOrder(authToken string, workflowID uint, stepOrder int, excludeID *uint) (isValid bool, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return false, errors.New("clientId not found in auth token") + } + existingStep, err := _i.ApprovalWorkflowStepsRepository.FindByWorkflowAndStep(clientId, workflowID, stepOrder) if err != nil { return false, err diff --git a/app/module/approval_workflows/controller/approval_workflows.controller.go b/app/module/approval_workflows/controller/approval_workflows.controller.go index e8fca51..9ce40d6 100644 --- a/app/module/approval_workflows/controller/approval_workflows.controller.go +++ b/app/module/approval_workflows/controller/approval_workflows.controller.go @@ -1,15 +1,15 @@ package controller import ( - "github.com/gofiber/fiber/v2" - "github.com/rs/zerolog" "netidhub-saas-be/app/database/entity" - "netidhub-saas-be/app/middleware" "netidhub-saas-be/app/module/approval_workflows/request" "netidhub-saas-be/app/module/approval_workflows/service" "netidhub-saas-be/utils/paginator" "strconv" + "github.com/gofiber/fiber/v2" + "github.com/rs/zerolog" + utilRes "netidhub-saas-be/utils/response" utilVal "netidhub-saas-be/utils/validator" ) @@ -46,7 +46,7 @@ func NewApprovalWorkflowsController(approvalWorkflowsService service.ApprovalWor // @Description API for getting all ApprovalWorkflows // @Tags ApprovalWorkflows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param req query request.ApprovalWorkflowsQueryRequest false "query parameters" // @Param req query paginator.Pagination false "pagination parameters" // @Success 200 {object} response.Response @@ -69,12 +69,12 @@ func (_i *approvalWorkflowsController) All(c *fiber.Ctx) error { req := reqContext.ToParamRequest() req.Pagination = paginate - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get authToken from context + authToken := c.Get("Authorization") - _i.Log.Info().Interface("clientId", clientId).Msg("") + _i.Log.Info().Interface("authToken", authToken).Msg("") - approvalWorkflowsData, paging, err := _i.approvalWorkflowsService.GetAll(clientId, req) + approvalWorkflowsData, paging, err := _i.approvalWorkflowsService.GetAll(authToken, req) if err != nil { return err } @@ -92,7 +92,7 @@ func (_i *approvalWorkflowsController) All(c *fiber.Ctx) error { // @Description API for getting one ApprovalWorkflows // @Tags ApprovalWorkflows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param id path int true "ApprovalWorkflows ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -105,10 +105,10 @@ func (_i *approvalWorkflowsController) Show(c *fiber.Ctx) error { return utilRes.ErrorBadRequest(c, "Invalid ID format") } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get authToken from context + authToken := c.Get("Authorization") - approvalWorkflowsData, err := _i.approvalWorkflowsService.FindOne(clientId, uint(id)) + approvalWorkflowsData, err := _i.approvalWorkflowsService.FindOne(authToken, uint(id)) if err != nil { return err } @@ -125,7 +125,7 @@ func (_i *approvalWorkflowsController) Show(c *fiber.Ctx) error { // @Description API for saving ApprovalWorkflows // @Tags ApprovalWorkflows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param payload body request.ApprovalWorkflowsCreateRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -138,14 +138,14 @@ func (_i *approvalWorkflowsController) Save(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get authToken from context + authToken := c.Get("Authorization") // Convert request to entity workflow := req.ToEntity() steps := req.ToStepsEntity() - approvalWorkflowsData, err := _i.approvalWorkflowsService.Create(clientId, workflow, steps) + approvalWorkflowsData, err := _i.approvalWorkflowsService.Create(authToken, workflow, steps) if err != nil { return err } @@ -162,7 +162,7 @@ func (_i *approvalWorkflowsController) Save(c *fiber.Ctx) error { // @Description API for updating ApprovalWorkflows // @Tags ApprovalWorkflows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param id path int true "ApprovalWorkflows ID" // @Param payload body request.ApprovalWorkflowsUpdateRequest true "Required payload" // @Success 200 {object} response.Response @@ -181,13 +181,13 @@ func (_i *approvalWorkflowsController) Update(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get authToken from context + authToken := c.Get("Authorization") // Convert request to entity workflow := req.ToEntity() - err = _i.approvalWorkflowsService.Update(clientId, uint(id), workflow) + err = _i.approvalWorkflowsService.Update(authToken, uint(id), workflow) if err != nil { return err } @@ -203,7 +203,7 @@ func (_i *approvalWorkflowsController) Update(c *fiber.Ctx) error { // @Description API for deleting ApprovalWorkflows // @Tags ApprovalWorkflows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param id path int true "ApprovalWorkflows ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -216,10 +216,10 @@ func (_i *approvalWorkflowsController) Delete(c *fiber.Ctx) error { return utilRes.ErrorBadRequest(c, "Invalid ID format") } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get authToken from context + authToken := c.Get("Authorization") - err = _i.approvalWorkflowsService.Delete(clientId, uint(id)) + err = _i.approvalWorkflowsService.Delete(authToken, uint(id)) if err != nil { return err } @@ -235,17 +235,17 @@ func (_i *approvalWorkflowsController) Delete(c *fiber.Ctx) error { // @Description API for getting default ApprovalWorkflows // @Tags ApprovalWorkflows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError // @Failure 401 {object} response.UnauthorizedError // @Failure 500 {object} response.InternalServerError // @Router /approval-workflows/default [get] func (_i *approvalWorkflowsController) GetDefault(c *fiber.Ctx) error { - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get authToken from context + authToken := c.Get("Authorization") - approvalWorkflowsData, err := _i.approvalWorkflowsService.GetDefault(clientId) + approvalWorkflowsData, err := _i.approvalWorkflowsService.GetDefault(authToken) if err != nil { return err } @@ -262,7 +262,7 @@ func (_i *approvalWorkflowsController) GetDefault(c *fiber.Ctx) error { // @Description API for setting default ApprovalWorkflows // @Tags ApprovalWorkflows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param id path int true "ApprovalWorkflows ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -275,10 +275,10 @@ func (_i *approvalWorkflowsController) SetDefault(c *fiber.Ctx) error { return utilRes.ErrorBadRequest(c, "Invalid ID format") } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get authToken from context + authToken := c.Get("Authorization") - err = _i.approvalWorkflowsService.SetDefault(clientId, uint(id)) + err = _i.approvalWorkflowsService.SetDefault(authToken, uint(id)) if err != nil { return err } @@ -294,7 +294,7 @@ func (_i *approvalWorkflowsController) SetDefault(c *fiber.Ctx) error { // @Description API for activating ApprovalWorkflows // @Tags ApprovalWorkflows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param id path int true "ApprovalWorkflows ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -307,10 +307,10 @@ func (_i *approvalWorkflowsController) Activate(c *fiber.Ctx) error { return utilRes.ErrorBadRequest(c, "Invalid ID format") } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get authToken from context + authToken := c.Get("Authorization") - err = _i.approvalWorkflowsService.ActivateWorkflow(clientId, uint(id)) + err = _i.approvalWorkflowsService.ActivateWorkflow(authToken, uint(id)) if err != nil { return err } @@ -326,7 +326,7 @@ func (_i *approvalWorkflowsController) Activate(c *fiber.Ctx) error { // @Description API for deactivating ApprovalWorkflows // @Tags ApprovalWorkflows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param id path int true "ApprovalWorkflows ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -339,10 +339,10 @@ func (_i *approvalWorkflowsController) Deactivate(c *fiber.Ctx) error { return utilRes.ErrorBadRequest(c, "Invalid ID format") } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get authToken from context + authToken := c.Get("Authorization") - err = _i.approvalWorkflowsService.DeactivateWorkflow(clientId, uint(id)) + err = _i.approvalWorkflowsService.DeactivateWorkflow(authToken, uint(id)) if err != nil { return err } @@ -358,7 +358,7 @@ func (_i *approvalWorkflowsController) Deactivate(c *fiber.Ctx) error { // @Description API for getting ApprovalWorkflows with steps // @Tags ApprovalWorkflows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param id path int true "ApprovalWorkflows ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -371,10 +371,10 @@ func (_i *approvalWorkflowsController) GetWithSteps(c *fiber.Ctx) error { return utilRes.ErrorBadRequest(c, "Invalid ID format") } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get authToken from context + authToken := c.Get("Authorization") - workflowData, stepsData, err := _i.approvalWorkflowsService.GetWorkflowWithSteps(clientId, uint(id)) + workflowData, stepsData, err := _i.approvalWorkflowsService.GetWorkflowWithSteps(authToken, uint(id)) if err != nil { return err } @@ -397,7 +397,7 @@ func (_i *approvalWorkflowsController) GetWithSteps(c *fiber.Ctx) error { // @Description API for creating ApprovalWorkflows with steps // @Tags ApprovalWorkflows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param req body request.ApprovalWorkflowsWithStepsCreateRequest true "ApprovalWorkflows with steps data" // @Success 201 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -410,14 +410,14 @@ func (_i *approvalWorkflowsController) SaveWithSteps(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get authToken from context + authToken := c.Get("Authorization") // Convert request to entities workflow := req.ToEntity() steps := req.ToStepsEntity() - approvalWorkflowsData, err := _i.approvalWorkflowsService.CreateWorkflowWithSteps(clientId, workflow, steps) + approvalWorkflowsData, err := _i.approvalWorkflowsService.CreateWorkflowWithSteps(authToken, workflow, steps) if err != nil { return err } @@ -434,7 +434,7 @@ func (_i *approvalWorkflowsController) SaveWithSteps(c *fiber.Ctx) error { // @Description API for updating ApprovalWorkflows with steps // @Tags ApprovalWorkflows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param id path int true "ApprovalWorkflows ID" // @Param req body request.ApprovalWorkflowsWithStepsUpdateRequest true "ApprovalWorkflows with steps data" // @Success 200 {object} response.Response @@ -453,8 +453,8 @@ func (_i *approvalWorkflowsController) UpdateWithSteps(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get authToken from context + authToken := c.Get("Authorization") // Convert request to entities workflow := &entity.ApprovalWorkflows{ @@ -469,7 +469,7 @@ func (_i *approvalWorkflowsController) UpdateWithSteps(c *fiber.Ctx) error { steps[i] = stepReq.ToEntity(uint(id)) } - err = _i.approvalWorkflowsService.UpdateWorkflowWithSteps(clientId, uint(id), workflow, steps) + err = _i.approvalWorkflowsService.UpdateWorkflowWithSteps(authToken, uint(id), workflow, steps) if err != nil { return err } diff --git a/app/module/approval_workflows/service/approval_workflows.service.go b/app/module/approval_workflows/service/approval_workflows.service.go index 5cd0e7d..1697418 100644 --- a/app/module/approval_workflows/service/approval_workflows.service.go +++ b/app/module/approval_workflows/service/approval_workflows.service.go @@ -3,70 +3,118 @@ package service import ( "errors" "fmt" - "github.com/google/uuid" - "github.com/rs/zerolog" "netidhub-saas-be/app/database/entity" stepRepo "netidhub-saas-be/app/module/approval_workflow_steps/repository" "netidhub-saas-be/app/module/approval_workflows/repository" "netidhub-saas-be/app/module/approval_workflows/request" + usersRepo "netidhub-saas-be/app/module/users/repository" "netidhub-saas-be/utils/paginator" + utilSvc "netidhub-saas-be/utils/service" + + "github.com/google/uuid" + "github.com/rs/zerolog" ) type approvalWorkflowsService struct { ApprovalWorkflowsRepository repository.ApprovalWorkflowsRepository ApprovalWorkflowStepsRepository stepRepo.ApprovalWorkflowStepsRepository + UsersRepository usersRepo.UsersRepository Log zerolog.Logger } // ApprovalWorkflowsService define interface of IApprovalWorkflowsService type ApprovalWorkflowsService interface { // Basic CRUD - GetAll(clientId *uuid.UUID, req request.ApprovalWorkflowsQueryRequest) (workflows []*entity.ApprovalWorkflows, paging paginator.Pagination, err error) - FindOne(clientId *uuid.UUID, id uint) (workflow *entity.ApprovalWorkflows, err error) - Create(clientId *uuid.UUID, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (workflowReturn *entity.ApprovalWorkflows, err error) - Update(clientId *uuid.UUID, id uint, workflow *entity.ApprovalWorkflows) (err error) - Delete(clientId *uuid.UUID, id uint) (err error) + GetAll(authToken string, req request.ApprovalWorkflowsQueryRequest) (workflows []*entity.ApprovalWorkflows, paging paginator.Pagination, err error) + FindOne(authToken string, id uint) (workflow *entity.ApprovalWorkflows, err error) + Create(authToken string, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (workflowReturn *entity.ApprovalWorkflows, err error) + Update(authToken string, id uint, workflow *entity.ApprovalWorkflows) (err error) + Delete(authToken string, id uint) (err error) // Workflow management - GetDefault(clientId *uuid.UUID) (workflow *entity.ApprovalWorkflows, err error) - SetDefault(clientId *uuid.UUID, id uint) (err error) - ActivateWorkflow(clientId *uuid.UUID, id uint) (err error) - DeactivateWorkflow(clientId *uuid.UUID, id uint) (err error) + GetDefault(authToken string) (workflow *entity.ApprovalWorkflows, err error) + SetDefault(authToken string, id uint) (err error) + ActivateWorkflow(authToken string, id uint) (err error) + DeactivateWorkflow(authToken string, id uint) (err error) // Workflow with steps - GetWorkflowWithSteps(clientId *uuid.UUID, id uint) (workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps, err error) - CreateWorkflowWithSteps(clientId *uuid.UUID, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (workflowReturn *entity.ApprovalWorkflows, err error) - UpdateWorkflowWithSteps(clientId *uuid.UUID, id uint, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (err error) + GetWorkflowWithSteps(authToken string, id uint) (workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps, err error) + CreateWorkflowWithSteps(authToken string, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (workflowReturn *entity.ApprovalWorkflows, err error) + UpdateWorkflowWithSteps(authToken string, id uint, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (err error) // Validation - ValidateWorkflow(clientId *uuid.UUID, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (isValid bool, errors []string, err error) - CanDeleteWorkflow(clientId *uuid.UUID, id uint) (canDelete bool, reason string, err error) + ValidateWorkflow(authToken string, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (isValid bool, errors []string, err error) + CanDeleteWorkflow(authToken string, id uint) (canDelete bool, reason string, err error) } func NewApprovalWorkflowsService( approvalWorkflowsRepository repository.ApprovalWorkflowsRepository, approvalWorkflowStepsRepository stepRepo.ApprovalWorkflowStepsRepository, + usersRepository usersRepo.UsersRepository, log zerolog.Logger, ) ApprovalWorkflowsService { return &approvalWorkflowsService{ ApprovalWorkflowsRepository: approvalWorkflowsRepository, ApprovalWorkflowStepsRepository: approvalWorkflowStepsRepository, + UsersRepository: usersRepository, Log: log, } } // Basic CRUD implementations -func (_i *approvalWorkflowsService) GetAll(clientId *uuid.UUID, req request.ApprovalWorkflowsQueryRequest) (workflows []*entity.ApprovalWorkflows, paging paginator.Pagination, err error) { +func (_i *approvalWorkflowsService) GetAll(authToken string, req request.ApprovalWorkflowsQueryRequest) (workflows []*entity.ApprovalWorkflows, paging paginator.Pagination, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, paginator.Pagination{}, errors.New("clientId not found in auth token") + } + return _i.ApprovalWorkflowsRepository.GetAll(clientId, req) } -func (_i *approvalWorkflowsService) FindOne(clientId *uuid.UUID, id uint) (workflow *entity.ApprovalWorkflows, err error) { +func (_i *approvalWorkflowsService) FindOne(authToken string, id uint) (workflow *entity.ApprovalWorkflows, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + return _i.ApprovalWorkflowsRepository.FindOne(clientId, id) } -func (_i *approvalWorkflowsService) Create(clientId *uuid.UUID, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (workflowReturn *entity.ApprovalWorkflows, err error) { +func (_i *approvalWorkflowsService) Create(authToken string, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (workflowReturn *entity.ApprovalWorkflows, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + // Validate workflow and steps - isValid, validationErrors, err := _i.ValidateWorkflow(clientId, workflow, steps) + isValid, validationErrors, err := _i.ValidateWorkflow(authToken, workflow, steps) if err != nil { return nil, err } @@ -96,7 +144,21 @@ func (_i *approvalWorkflowsService) Create(clientId *uuid.UUID, workflow *entity return workflowReturn, nil } -func (_i *approvalWorkflowsService) Update(clientId *uuid.UUID, id uint, workflow *entity.ApprovalWorkflows) (err error) { +func (_i *approvalWorkflowsService) Update(authToken string, id uint, workflow *entity.ApprovalWorkflows) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return errors.New("clientId not found in auth token") + } + // Check if workflow exists existingWorkflow, err := _i.ApprovalWorkflowsRepository.FindOne(clientId, id) if err != nil { @@ -110,9 +172,23 @@ func (_i *approvalWorkflowsService) Update(clientId *uuid.UUID, id uint, workflo return _i.ApprovalWorkflowsRepository.Update(clientId, id, workflow) } -func (_i *approvalWorkflowsService) Delete(clientId *uuid.UUID, id uint) (err error) { +func (_i *approvalWorkflowsService) Delete(authToken string, id uint) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return errors.New("clientId not found in auth token") + } + // Check if workflow can be deleted - canDelete, reason, err := _i.CanDeleteWorkflow(clientId, id) + canDelete, reason, err := _i.CanDeleteWorkflow(authToken, id) if err != nil { return err } @@ -125,11 +201,39 @@ func (_i *approvalWorkflowsService) Delete(clientId *uuid.UUID, id uint) (err er } // Workflow management -func (_i *approvalWorkflowsService) GetDefault(clientId *uuid.UUID) (workflow *entity.ApprovalWorkflows, err error) { +func (_i *approvalWorkflowsService) GetDefault(authToken string) (workflow *entity.ApprovalWorkflows, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + return _i.ApprovalWorkflowsRepository.FindDefault(clientId) } -func (_i *approvalWorkflowsService) SetDefault(clientId *uuid.UUID, id uint) (err error) { +func (_i *approvalWorkflowsService) SetDefault(authToken string, id uint) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return errors.New("clientId not found in auth token") + } + // Check if workflow exists and is active workflow, err := _i.ApprovalWorkflowsRepository.FindOne(clientId, id) if err != nil { @@ -147,7 +251,21 @@ func (_i *approvalWorkflowsService) SetDefault(clientId *uuid.UUID, id uint) (er return _i.ApprovalWorkflowsRepository.SetDefault(clientId, id) } -func (_i *approvalWorkflowsService) ActivateWorkflow(clientId *uuid.UUID, id uint) (err error) { +func (_i *approvalWorkflowsService) ActivateWorkflow(authToken string, id uint) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return errors.New("clientId not found in auth token") + } + // Validate workflow before activation workflow, err := _i.ApprovalWorkflowsRepository.FindOne(clientId, id) if err != nil { @@ -164,7 +282,7 @@ func (_i *approvalWorkflowsService) ActivateWorkflow(clientId *uuid.UUID, id uin return err } - isValid, validationErrors, err := _i.ValidateWorkflow(clientId, workflow, steps) + isValid, validationErrors, err := _i.ValidateWorkflow(authToken, workflow, steps) if err != nil { return err } @@ -179,7 +297,21 @@ func (_i *approvalWorkflowsService) ActivateWorkflow(clientId *uuid.UUID, id uin return _i.ApprovalWorkflowsRepository.Update(clientId, id, updateData) } -func (_i *approvalWorkflowsService) DeactivateWorkflow(clientId *uuid.UUID, id uint) (err error) { +func (_i *approvalWorkflowsService) DeactivateWorkflow(authToken string, id uint) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return errors.New("clientId not found in auth token") + } + // Check if this is the default workflow defaultWorkflow, err := _i.ApprovalWorkflowsRepository.FindDefault(clientId) if err != nil { @@ -191,7 +323,7 @@ func (_i *approvalWorkflowsService) DeactivateWorkflow(clientId *uuid.UUID, id u } // Check if workflow is being used in active approval flows - canDelete, reason, err := _i.CanDeleteWorkflow(clientId, id) + canDelete, reason, err := _i.CanDeleteWorkflow(authToken, id) if err != nil { return err } @@ -207,7 +339,21 @@ func (_i *approvalWorkflowsService) DeactivateWorkflow(clientId *uuid.UUID, id u } // Workflow with steps -func (_i *approvalWorkflowsService) GetWorkflowWithSteps(clientId *uuid.UUID, id uint) (workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps, err error) { +func (_i *approvalWorkflowsService) GetWorkflowWithSteps(authToken string, id uint) (workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, nil, errors.New("clientId not found in auth token") + } + workflow, err = _i.ApprovalWorkflowsRepository.FindOne(clientId, id) if err != nil { return nil, nil, err @@ -221,13 +367,41 @@ func (_i *approvalWorkflowsService) GetWorkflowWithSteps(clientId *uuid.UUID, id return workflow, steps, nil } -func (_i *approvalWorkflowsService) CreateWorkflowWithSteps(clientId *uuid.UUID, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (workflowReturn *entity.ApprovalWorkflows, err error) { - return _i.Create(clientId, workflow, steps) +func (_i *approvalWorkflowsService) CreateWorkflowWithSteps(authToken string, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (workflowReturn *entity.ApprovalWorkflows, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + + return _i.Create(authToken, workflow, steps) } -func (_i *approvalWorkflowsService) UpdateWorkflowWithSteps(clientId *uuid.UUID, id uint, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (err error) { +func (_i *approvalWorkflowsService) UpdateWorkflowWithSteps(authToken string, id uint, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return errors.New("clientId not found in auth token") + } + // Update workflow - err = _i.Update(clientId, id, workflow) + err = _i.Update(authToken, id, workflow) if err != nil { return err } @@ -260,7 +434,7 @@ func (_i *approvalWorkflowsService) UpdateWorkflowWithSteps(clientId *uuid.UUID, } // Validation -func (_i *approvalWorkflowsService) ValidateWorkflow(clientId *uuid.UUID, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (isValid bool, errors []string, err error) { +func (_i *approvalWorkflowsService) ValidateWorkflow(authToken string, workflow *entity.ApprovalWorkflows, steps []*entity.ApprovalWorkflowSteps) (isValid bool, errors []string, err error) { errors = make([]string, 0) // Validate workflow @@ -299,7 +473,21 @@ func (_i *approvalWorkflowsService) ValidateWorkflow(clientId *uuid.UUID, workfl return isValid, errors, nil } -func (_i *approvalWorkflowsService) CanDeleteWorkflow(clientId *uuid.UUID, id uint) (canDelete bool, reason string, err error) { +func (_i *approvalWorkflowsService) CanDeleteWorkflow(authToken string, id uint) (canDelete bool, reason string, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return false, "clientId not found in auth token", errors.New("clientId not found in auth token") + } + // Check if workflow is default defaultWorkflow, err := _i.ApprovalWorkflowsRepository.FindDefault(clientId) if err != nil { diff --git a/app/module/article_approval_flows/controller/article_approval_flows.controller.go b/app/module/article_approval_flows/controller/article_approval_flows.controller.go index ab5911c..ab25afd 100644 --- a/app/module/article_approval_flows/controller/article_approval_flows.controller.go +++ b/app/module/article_approval_flows/controller/article_approval_flows.controller.go @@ -1,7 +1,6 @@ package controller import ( - "netidhub-saas-be/app/middleware" "netidhub-saas-be/app/module/article_approval_flows/request" "netidhub-saas-be/app/module/article_approval_flows/service" usersRepository "netidhub-saas-be/app/module/users/repository" @@ -51,7 +50,7 @@ func NewArticleApprovalFlowsController(articleApprovalFlowsService service.Artic // @Description API for getting all ArticleApprovalFlows // @Tags ArticleApprovalFlows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param req query request.ArticleApprovalFlowsQueryRequest false "query parameters" // @Param req query paginator.Pagination false "pagination parameters" // @Success 200 {object} response.Response @@ -77,12 +76,12 @@ func (_i *articleApprovalFlowsController) All(c *fiber.Ctx) error { req := reqContext.ToParamRequest() req.Pagination = paginate - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - _i.Log.Info().Interface("clientId", clientId).Msg("") + _i.Log.Info().Interface("authToken", authToken).Msg("") - articleApprovalFlowsData, paging, err := _i.articleApprovalFlowsService.GetAll(clientId, req) + articleApprovalFlowsData, paging, err := _i.articleApprovalFlowsService.GetAll(authToken, req) if err != nil { return err } @@ -100,7 +99,7 @@ func (_i *articleApprovalFlowsController) All(c *fiber.Ctx) error { // @Description API for getting one ArticleApprovalFlows // @Tags ArticleApprovalFlows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param id path int true "ArticleApprovalFlows ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -113,10 +112,10 @@ func (_i *articleApprovalFlowsController) Show(c *fiber.Ctx) error { return utilRes.ErrorBadRequest(c, "Invalid ID format") } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - articleApprovalFlowsData, err := _i.articleApprovalFlowsService.FindOne(clientId, uint(id)) + articleApprovalFlowsData, err := _i.articleApprovalFlowsService.FindOne(authToken, uint(id)) if err != nil { return err } @@ -133,7 +132,7 @@ func (_i *articleApprovalFlowsController) Show(c *fiber.Ctx) error { // @Description API for submitting article for approval // @Tags ArticleApprovalFlows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param req body request.SubmitForApprovalRequest true "Submit for approval data" // @Success 201 {object} response.Response @@ -151,9 +150,6 @@ func (_i *articleApprovalFlowsController) SubmitForApproval(c *fiber.Ctx) error return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) - // Get Authorization token from header and extract user ID authToken := c.Get("Authorization") if authToken == "" { @@ -170,7 +166,7 @@ func (_i *articleApprovalFlowsController) SubmitForApproval(c *fiber.Ctx) error workflowIdVal := uint(*req.WorkflowId) workflowId = &workflowIdVal } - articleApprovalFlowsData, err := _i.articleApprovalFlowsService.SubmitArticleForApproval(clientId, uint(req.ArticleId), user.ID, workflowId) + articleApprovalFlowsData, err := _i.articleApprovalFlowsService.SubmitArticleForApproval(authToken, uint(req.ArticleId), user.ID, workflowId) if err != nil { return err } @@ -187,7 +183,7 @@ func (_i *articleApprovalFlowsController) SubmitForApproval(c *fiber.Ctx) error // @Description API for approving article // @Tags ArticleApprovalFlows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "ArticleApprovalFlows ID" // @Param req body request.ApprovalActionRequest true "Approval action data" @@ -211,10 +207,7 @@ func (_i *articleApprovalFlowsController) Approve(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) - - // Get Authorization token from header and extract user ID + // Get Authorization token from header authToken := c.Get("Authorization") if authToken == "" { return utilRes.ErrorBadRequest(c, "Authorization token required") @@ -225,7 +218,7 @@ func (_i *articleApprovalFlowsController) Approve(c *fiber.Ctx) error { return utilRes.ErrorBadRequest(c, "Invalid authorization token") } - err = _i.articleApprovalFlowsService.ApproveStep(clientId, uint(id), user.ID, req.Message) + err = _i.articleApprovalFlowsService.ApproveStep(authToken, uint(id), user.ID, req.Message) if err != nil { return err } @@ -242,7 +235,7 @@ func (_i *articleApprovalFlowsController) Approve(c *fiber.Ctx) error { // @Description API for rejecting article // @Tags ArticleApprovalFlows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "ArticleApprovalFlows ID" // @Param req body request.RejectionRequest true "Rejection data" @@ -266,10 +259,7 @@ func (_i *articleApprovalFlowsController) Reject(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) - - // Get Authorization token from header and extract user ID + // Get Authorization token from header authToken := c.Get("Authorization") if authToken == "" { return utilRes.ErrorBadRequest(c, "Authorization token required") @@ -280,7 +270,7 @@ func (_i *articleApprovalFlowsController) Reject(c *fiber.Ctx) error { return utilRes.ErrorBadRequest(c, "Invalid authorization token") } - err = _i.articleApprovalFlowsService.RejectArticle(clientId, uint(id), user.ID, req.Reason) + err = _i.articleApprovalFlowsService.RejectArticle(authToken, uint(id), user.ID, req.Reason) if err != nil { return err } @@ -297,7 +287,7 @@ func (_i *articleApprovalFlowsController) Reject(c *fiber.Ctx) error { // @Description API for requesting revision for article // @Tags ArticleApprovalFlows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "ArticleApprovalFlows ID" // @Param req body request.RevisionRequest true "Revision request data" @@ -321,10 +311,7 @@ func (_i *articleApprovalFlowsController) RequestRevision(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) - - // Get Authorization token from header and extract user ID + // Get Authorization token from header authToken := c.Get("Authorization") if authToken == "" { return utilRes.ErrorBadRequest(c, "Authorization token required") @@ -335,7 +322,7 @@ func (_i *articleApprovalFlowsController) RequestRevision(c *fiber.Ctx) error { return utilRes.ErrorBadRequest(c, "Invalid authorization token") } - err = _i.articleApprovalFlowsService.RequestRevision(clientId, uint(id), user.ID, req.Message) + err = _i.articleApprovalFlowsService.RequestRevision(authToken, uint(id), user.ID, req.Message) if err != nil { return err } @@ -352,7 +339,7 @@ func (_i *articleApprovalFlowsController) RequestRevision(c *fiber.Ctx) error { // @Description API for resubmitting article after revision // @Tags ArticleApprovalFlows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "ArticleApprovalFlows ID" // @Param req body request.ResubmitRequest true "Resubmit data" @@ -376,10 +363,7 @@ func (_i *articleApprovalFlowsController) Resubmit(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) - - // Get Authorization token from header and extract user ID + // Get Authorization token from header authToken := c.Get("Authorization") if authToken == "" { return utilRes.ErrorBadRequest(c, "Authorization token required") @@ -390,7 +374,7 @@ func (_i *articleApprovalFlowsController) Resubmit(c *fiber.Ctx) error { return utilRes.ErrorBadRequest(c, "Invalid authorization token") } - err = _i.articleApprovalFlowsService.ResubmitAfterRevision(clientId, uint(id), user.ID) + err = _i.articleApprovalFlowsService.ResubmitAfterRevision(authToken, uint(id), user.ID) if err != nil { return err } @@ -407,7 +391,7 @@ func (_i *articleApprovalFlowsController) Resubmit(c *fiber.Ctx) error { // @Description API for getting my approval queue // @Tags ArticleApprovalFlows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param includePreview query bool false "Include article preview" // @Param urgentOnly query bool false "Show only urgent articles" @@ -423,10 +407,7 @@ func (_i *articleApprovalFlowsController) GetMyApprovalQueue(c *fiber.Ctx) error return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) - - // Get Authorization token from header and extract user level ID + // Get Authorization token from header authToken := c.Get("Authorization") if authToken == "" { return utilRes.ErrorBadRequest(c, "Authorization token required") @@ -441,7 +422,7 @@ func (_i *articleApprovalFlowsController) GetMyApprovalQueue(c *fiber.Ctx) error includePreview := c.QueryBool("includePreview", false) urgentOnly := c.QueryBool("urgentOnly", false) - approvalQueueData, paging, err := _i.articleApprovalFlowsService.GetMyApprovalQueue(clientId, user.UserLevelId, paginate.Page, paginate.Limit, includePreview, urgentOnly) + approvalQueueData, paging, err := _i.articleApprovalFlowsService.GetMyApprovalQueue(authToken, user.UserLevelId, paginate.Page, paginate.Limit, includePreview, urgentOnly) if err != nil { return err } @@ -459,7 +440,7 @@ func (_i *articleApprovalFlowsController) GetMyApprovalQueue(c *fiber.Ctx) error // @Description API for getting pending approvals // @Tags ArticleApprovalFlows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param req query paginator.Pagination false "pagination parameters" // @Success 200 {object} response.Response @@ -473,10 +454,7 @@ func (_i *articleApprovalFlowsController) GetPendingApprovals(c *fiber.Ctx) erro return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) - - // Get Authorization token from header and extract user level ID + // Get Authorization token from header authToken := c.Get("Authorization") if authToken == "" { return utilRes.ErrorBadRequest(c, "Authorization token required") @@ -488,7 +466,7 @@ func (_i *articleApprovalFlowsController) GetPendingApprovals(c *fiber.Ctx) erro } filters := make(map[string]interface{}) - pendingApprovalsData, paging, err := _i.articleApprovalFlowsService.GetPendingApprovals(clientId, user.UserLevelId, paginate.Page, paginate.Limit, filters) + pendingApprovalsData, paging, err := _i.articleApprovalFlowsService.GetPendingApprovals(authToken, user.UserLevelId, paginate.Page, paginate.Limit, filters) if err != nil { return err } @@ -506,7 +484,7 @@ func (_i *articleApprovalFlowsController) GetPendingApprovals(c *fiber.Ctx) erro // @Description API for getting approval history // @Tags ArticleApprovalFlows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param articleId query int false "Article ID filter" // @Param userId query int false "User ID filter" // @Param req query paginator.Pagination false "pagination parameters" @@ -538,10 +516,10 @@ func (_i *articleApprovalFlowsController) GetApprovalHistory(c *fiber.Ctx) error // } // } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - approvalHistoryData, paging, err := _i.articleApprovalFlowsService.GetApprovalHistory(clientId, uint(articleId), paginate.Page, paginate.Limit) + approvalHistoryData, paging, err := _i.articleApprovalFlowsService.GetApprovalHistory(authToken, uint(articleId), paginate.Page, paginate.Limit) if err != nil { return err } @@ -559,7 +537,7 @@ func (_i *articleApprovalFlowsController) GetApprovalHistory(c *fiber.Ctx) error // @Description API for getting dashboard statistics // @Tags ArticleApprovalFlows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -567,10 +545,7 @@ func (_i *articleApprovalFlowsController) GetApprovalHistory(c *fiber.Ctx) error // @Failure 500 {object} response.InternalServerError // @Router /article-approval-flows/dashboard-stats [get] func (_i *articleApprovalFlowsController) GetDashboardStats(c *fiber.Ctx) error { - // Get ClientId from context - clientId := middleware.GetClientID(c) - - // Get Authorization token from header and extract user level ID + // Get Authorization token from header authToken := c.Get("Authorization") if authToken == "" { return utilRes.ErrorBadRequest(c, "Authorization token required") @@ -582,9 +557,8 @@ func (_i *articleApprovalFlowsController) GetDashboardStats(c *fiber.Ctx) error } // TODO: Implement GetDashboardStats method in service - _ = clientId // suppress unused variable warning _ = user.UserLevelId // suppress unused variable warning - // dashboardStatsData, err := _i.articleApprovalFlowsService.GetDashboardStats(clientId, user.UserLevelId) + // dashboardStatsData, err := _i.articleApprovalFlowsService.GetDashboardStats(authToken, user.UserLevelId) // if err != nil { // return err // } @@ -601,7 +575,7 @@ func (_i *articleApprovalFlowsController) GetDashboardStats(c *fiber.Ctx) error // @Description API for getting workload statistics // @Tags ArticleApprovalFlows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -609,12 +583,11 @@ func (_i *articleApprovalFlowsController) GetDashboardStats(c *fiber.Ctx) error // @Failure 500 {object} response.InternalServerError // @Router /article-approval-flows/workload-stats [get] func (_i *articleApprovalFlowsController) GetWorkloadStats(c *fiber.Ctx) error { - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + // authToken := c.Get("Authorization") // TODO: Implement GetWorkloadStats method in service - _ = clientId // suppress unused variable warning - // workloadStatsData, err := _i.articleApprovalFlowsService.GetWorkloadStats(clientId) + // workloadStatsData, err := _i.articleApprovalFlowsService.GetWorkloadStats(authToken) // if err != nil { // return err // } @@ -631,7 +604,7 @@ func (_i *articleApprovalFlowsController) GetWorkloadStats(c *fiber.Ctx) error { // @Description API for getting approval analytics // @Tags ArticleApprovalFlows // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param period query string false "Period filter (daily, weekly, monthly)" // @Param startDate query string false "Start date filter (YYYY-MM-DD)" @@ -646,12 +619,11 @@ func (_i *articleApprovalFlowsController) GetApprovalAnalytics(c *fiber.Ctx) err // startDate := c.Query("startDate") // endDate := c.Query("endDate") - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + // authToken := c.Get("Authorization") // TODO: Implement GetApprovalAnalytics method in service - _ = clientId // suppress unused variable warning - // analyticsData, err := _i.articleApprovalFlowsService.GetApprovalAnalytics(clientId, period, startDate, endDate) + // analyticsData, err := _i.articleApprovalFlowsService.GetApprovalAnalytics(authToken, period, startDate, endDate) // if err != nil { // return err // } diff --git a/app/module/article_approval_flows/service/article_approval_flows.service.go b/app/module/article_approval_flows/service/article_approval_flows.service.go index d060526..e26362a 100644 --- a/app/module/article_approval_flows/service/article_approval_flows.service.go +++ b/app/module/article_approval_flows/service/article_approval_flows.service.go @@ -11,6 +11,7 @@ import ( articlesRepo "netidhub-saas-be/app/module/articles/repository" usersRepo "netidhub-saas-be/app/module/users/repository" "netidhub-saas-be/utils/paginator" + utilSvc "netidhub-saas-be/utils/service" "time" "github.com/google/uuid" @@ -30,34 +31,34 @@ type articleApprovalFlowsService struct { // ArticleApprovalFlowsService define interface of IArticleApprovalFlowsService type ArticleApprovalFlowsService interface { // Basic CRUD - GetAll(clientId *uuid.UUID, req request.ArticleApprovalFlowsQueryRequest) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) - FindOne(clientId *uuid.UUID, id uint) (flow *entity.ArticleApprovalFlows, err error) - Create(clientId *uuid.UUID, flow *entity.ArticleApprovalFlows) (flowReturn *entity.ArticleApprovalFlows, err error) + GetAll(authToken string, req request.ArticleApprovalFlowsQueryRequest) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) + FindOne(authToken string, id uint) (flow *entity.ArticleApprovalFlows, err error) + Create(authToken string, flow *entity.ArticleApprovalFlows) (flowReturn *entity.ArticleApprovalFlows, err error) Update(id uint, flow *entity.ArticleApprovalFlows) (err error) - Delete(clientId *uuid.UUID, id uint) (err error) + Delete(authToken string, id uint) (err error) // Article submission and approval workflow - SubmitArticleForApproval(clientId *uuid.UUID, articleId uint, submittedById uint, workflowId *uint) (flow *entity.ArticleApprovalFlows, err error) - ApproveStep(clientId *uuid.UUID, flowId uint, approvedById uint, message string) (err error) - RejectArticle(clientId *uuid.UUID, flowId uint, rejectedById uint, reason string) (err error) - RequestRevision(clientId *uuid.UUID, flowId uint, requestedById uint, revisionMessage string) (err error) - ResubmitAfterRevision(clientId *uuid.UUID, flowId uint, resubmittedById uint) (err error) + SubmitArticleForApproval(authToken string, articleId uint, submittedById uint, workflowId *uint) (flow *entity.ArticleApprovalFlows, err error) + ApproveStep(authToken string, flowId uint, approvedById uint, message string) (err error) + RejectArticle(authToken string, flowId uint, rejectedById uint, reason string) (err error) + RequestRevision(authToken string, flowId uint, requestedById uint, revisionMessage string) (err error) + ResubmitAfterRevision(authToken string, flowId uint, resubmittedById uint) (err error) // Dashboard and queue methods - GetPendingApprovals(clientId *uuid.UUID, userLevelId uint, page, limit int, filters map[string]interface{}) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) - GetMyApprovalQueue(clientId *uuid.UUID, userLevelId uint, page, limit int, includePreview bool, urgentOnly bool) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) - GetApprovalHistory(clientId *uuid.UUID, articleId uint, page, limit int) (logs []*entity.ArticleApprovalStepLogs, paging paginator.Pagination, err error) + GetPendingApprovals(authToken string, userLevelId uint, page, limit int, filters map[string]interface{}) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) + GetMyApprovalQueue(authToken string, userLevelId uint, page, limit int, includePreview bool, urgentOnly bool) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) + GetApprovalHistory(authToken string, articleId uint, page, limit int) (logs []*entity.ArticleApprovalStepLogs, paging paginator.Pagination, err error) // Statistics and analytics - GetPendingCountByLevel(clientId *uuid.UUID, userLevelId uint) (count int64, err error) - GetOverdueCountByLevel(clientId *uuid.UUID, userLevelId uint) (count int64, err error) - GetApprovalStatistics(clientId *uuid.UUID, userLevelId uint, startDate, endDate time.Time) (stats map[string]interface{}, err error) - GetWorkloadAnalytics(clientId *uuid.UUID, userLevelId uint) (analytics map[string]interface{}, err error) + GetPendingCountByLevel(authToken string, userLevelId uint) (count int64, err error) + GetOverdueCountByLevel(authToken string, userLevelId uint) (count int64, err error) + GetApprovalStatistics(authToken string, userLevelId uint, startDate, endDate time.Time) (stats map[string]interface{}, err error) + GetWorkloadAnalytics(authToken string, userLevelId uint) (analytics map[string]interface{}, err error) // Workflow management - CanUserApproveStep(clientId *uuid.UUID, flowId uint, userId uint, userLevelId uint) (canApprove bool, reason string, err error) - GetCurrentStepInfo(clientId *uuid.UUID, flowId uint) (stepInfo map[string]interface{}, err error) - GetNextStepPreview(clientId *uuid.UUID, flowId uint) (nextStep *entity.ApprovalWorkflowSteps, err error) + CanUserApproveStep(authToken string, flowId uint, userId uint, userLevelId uint) (canApprove bool, reason string, err error) + GetCurrentStepInfo(authToken string, flowId uint) (stepInfo map[string]interface{}, err error) + GetNextStepPreview(authToken string, flowId uint) (nextStep *entity.ApprovalWorkflowSteps, err error) } func NewArticleApprovalFlowsService( @@ -81,14 +82,56 @@ func NewArticleApprovalFlowsService( } // Basic CRUD implementations -func (_i *articleApprovalFlowsService) GetAll(clientId *uuid.UUID, req request.ArticleApprovalFlowsQueryRequest) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) { +func (_i *articleApprovalFlowsService) GetAll(authToken string, req request.ArticleApprovalFlowsQueryRequest) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, paginator.Pagination{}, errors.New("clientId not found in auth token") + } + return _i.ArticleApprovalFlowsRepository.GetAll(clientId, req) } -func (_i *articleApprovalFlowsService) FindOne(clientId *uuid.UUID, id uint) (flow *entity.ArticleApprovalFlows, err error) { +func (_i *articleApprovalFlowsService) FindOne(authToken string, id uint) (flow *entity.ArticleApprovalFlows, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + return _i.ArticleApprovalFlowsRepository.FindOne(clientId, id) } -func (_i *articleApprovalFlowsService) Create(clientId *uuid.UUID, flow *entity.ArticleApprovalFlows) (flowReturn *entity.ArticleApprovalFlows, err error) { +func (_i *articleApprovalFlowsService) Create(authToken string, flow *entity.ArticleApprovalFlows) (flowReturn *entity.ArticleApprovalFlows, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + return _i.ArticleApprovalFlowsRepository.Create(clientId, flow) } @@ -96,12 +139,40 @@ func (_i *articleApprovalFlowsService) Update(id uint, flow *entity.ArticleAppro return _i.ArticleApprovalFlowsRepository.Update(id, flow) } -func (_i *articleApprovalFlowsService) Delete(clientId *uuid.UUID, id uint) (err error) { +func (_i *articleApprovalFlowsService) Delete(authToken string, id uint) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return errors.New("clientId not found in auth token") + } + return _i.ArticleApprovalFlowsRepository.Delete(clientId, id) } // Article submission and approval workflow -func (_i *articleApprovalFlowsService) SubmitArticleForApproval(clientId *uuid.UUID, articleId uint, submittedById uint, workflowId *uint) (flow *entity.ArticleApprovalFlows, err error) { +func (_i *articleApprovalFlowsService) SubmitArticleForApproval(authToken string, articleId uint, submittedById uint, workflowId *uint) (flow *entity.ArticleApprovalFlows, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + // Check if article already has an active approval flow existingFlow, err := _i.ArticleApprovalFlowsRepository.FindActiveByArticleId(articleId) if err == nil && existingFlow != nil { @@ -170,7 +241,7 @@ func (_i *articleApprovalFlowsService) SubmitArticleForApproval(clientId *uuid.U } // Process auto-skip logic based on user level - err = _i.processAutoSkipSteps(clientId, flow, submittedById) + err = _i.processAutoSkipSteps(authToken, flow, submittedById) if err != nil { return nil, err } @@ -179,9 +250,23 @@ func (_i *articleApprovalFlowsService) SubmitArticleForApproval(clientId *uuid.U } // processAutoSkipSteps handles automatic step skipping based on user level -func (_i *articleApprovalFlowsService) processAutoSkipSteps(clientId *uuid.UUID, flow *entity.ArticleApprovalFlows, submittedById uint) error { +func (_i *articleApprovalFlowsService) processAutoSkipSteps(authToken string, flow *entity.ArticleApprovalFlows, submittedById uint) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return errors.New("clientId not found in auth token") + } + // Get user level of the submitter - userLevelId, err := _i.getUserLevelId(clientId, submittedById) + userLevelId, err := _i.getUserLevelId(authToken, submittedById) if err != nil { return err } @@ -286,7 +371,21 @@ func (_i *articleApprovalFlowsService) processAutoSkipSteps(clientId *uuid.UUID, } // getUserLevelId gets the user level ID for a given user -func (_i *articleApprovalFlowsService) getUserLevelId(clientId *uuid.UUID, userId uint) (uint, error) { +func (_i *articleApprovalFlowsService) getUserLevelId(authToken string, userId uint) (uint, error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return 0, errors.New("clientId not found in auth token") + } + // Get user from database to retrieve user level user, err := _i.UsersRepository.FindOne(clientId, userId) if err != nil { @@ -333,7 +432,21 @@ func sortStepsByOrder(steps []*entity.ApprovalWorkflowSteps) { } } -func (_i *articleApprovalFlowsService) ApproveStep(clientId *uuid.UUID, flowId uint, approvedById uint, message string) (err error) { +func (_i *articleApprovalFlowsService) ApproveStep(authToken string, flowId uint, approvedById uint, message string) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return errors.New("clientId not found in auth token") + } + // Get approval flow flow, err := _i.ArticleApprovalFlowsRepository.FindOne(clientId, flowId) if err != nil { @@ -445,7 +558,21 @@ func (_i *articleApprovalFlowsService) ApproveStep(clientId *uuid.UUID, flowId u return nil } -func (_i *articleApprovalFlowsService) RejectArticle(clientId *uuid.UUID, flowId uint, rejectedById uint, reason string) (err error) { +func (_i *articleApprovalFlowsService) RejectArticle(authToken string, flowId uint, rejectedById uint, reason string) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return errors.New("clientId not found in auth token") + } + // Get approval flow flow, err := _i.ArticleApprovalFlowsRepository.FindOne(clientId, flowId) if err != nil { @@ -513,7 +640,21 @@ func (_i *articleApprovalFlowsService) RejectArticle(clientId *uuid.UUID, flowId return nil } -func (_i *articleApprovalFlowsService) RequestRevision(clientId *uuid.UUID, flowId uint, requestedById uint, revisionMessage string) (err error) { +func (_i *articleApprovalFlowsService) RequestRevision(authToken string, flowId uint, requestedById uint, revisionMessage string) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return errors.New("clientId not found in auth token") + } + // Get approval flow flow, err := _i.ArticleApprovalFlowsRepository.FindOne(clientId, flowId) if err != nil { @@ -580,7 +721,21 @@ func (_i *articleApprovalFlowsService) RequestRevision(clientId *uuid.UUID, flow return nil } -func (_i *articleApprovalFlowsService) ResubmitAfterRevision(clientId *uuid.UUID, flowId uint, resubmittedById uint) (err error) { +func (_i *articleApprovalFlowsService) ResubmitAfterRevision(authToken string, flowId uint, resubmittedById uint) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return errors.New("clientId not found in auth token") + } + // Get approval flow flow, err := _i.ArticleApprovalFlowsRepository.FindOne(clientId, flowId) if err != nil { @@ -643,28 +798,112 @@ func (_i *articleApprovalFlowsService) ResubmitAfterRevision(clientId *uuid.UUID } // Dashboard and queue methods -func (_i *articleApprovalFlowsService) GetPendingApprovals(clientId *uuid.UUID, userLevelId uint, page, limit int, filters map[string]interface{}) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) { +func (_i *articleApprovalFlowsService) GetPendingApprovals(authToken string, userLevelId uint, page, limit int, filters map[string]interface{}) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, paginator.Pagination{}, errors.New("clientId not found in auth token") + } + return _i.ArticleApprovalFlowsRepository.GetPendingApprovals(clientId, userLevelId, page, limit, filters) } -func (_i *articleApprovalFlowsService) GetMyApprovalQueue(clientId *uuid.UUID, userLevelId uint, page, limit int, includePreview bool, urgentOnly bool) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) { +func (_i *articleApprovalFlowsService) GetMyApprovalQueue(authToken string, userLevelId uint, page, limit int, includePreview bool, urgentOnly bool) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, paginator.Pagination{}, errors.New("clientId not found in auth token") + } + return _i.ArticleApprovalFlowsRepository.GetMyApprovalQueue(clientId, userLevelId, page, limit, includePreview, urgentOnly) } -func (_i *articleApprovalFlowsService) GetApprovalHistory(clientId *uuid.UUID, articleId uint, page, limit int) (logs []*entity.ArticleApprovalStepLogs, paging paginator.Pagination, err error) { +func (_i *articleApprovalFlowsService) GetApprovalHistory(authToken string, articleId uint, page, limit int) (logs []*entity.ArticleApprovalStepLogs, paging paginator.Pagination, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, paginator.Pagination{}, errors.New("clientId not found in auth token") + } + return _i.ArticleApprovalStepLogsRepository.GetApprovalHistory(clientId, articleId, page, limit) } // Statistics and analytics -func (_i *articleApprovalFlowsService) GetPendingCountByLevel(clientId *uuid.UUID, userLevelId uint) (count int64, err error) { +func (_i *articleApprovalFlowsService) GetPendingCountByLevel(authToken string, userLevelId uint) (count int64, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return 0, errors.New("clientId not found in auth token") + } + return _i.ArticleApprovalFlowsRepository.GetPendingCountByLevel(clientId, userLevelId) } -func (_i *articleApprovalFlowsService) GetOverdueCountByLevel(clientId *uuid.UUID, userLevelId uint) (count int64, err error) { +func (_i *articleApprovalFlowsService) GetOverdueCountByLevel(authToken string, userLevelId uint) (count int64, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return 0, errors.New("clientId not found in auth token") + } + return _i.ArticleApprovalFlowsRepository.GetOverdueCountByLevel(clientId, userLevelId) } -func (_i *articleApprovalFlowsService) GetApprovalStatistics(clientId *uuid.UUID, userLevelId uint, startDate, endDate time.Time) (stats map[string]interface{}, err error) { +func (_i *articleApprovalFlowsService) GetApprovalStatistics(authToken string, userLevelId uint, startDate, endDate time.Time) (stats map[string]interface{}, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + stats = make(map[string]interface{}) // Get approved count @@ -695,12 +934,40 @@ func (_i *articleApprovalFlowsService) GetApprovalStatistics(clientId *uuid.UUID return stats, nil } -func (_i *articleApprovalFlowsService) GetWorkloadAnalytics(clientId *uuid.UUID, userLevelId uint) (analytics map[string]interface{}, err error) { +func (_i *articleApprovalFlowsService) GetWorkloadAnalytics(authToken string, userLevelId uint) (analytics map[string]interface{}, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + return _i.ArticleApprovalFlowsRepository.GetLevelWorkload(clientId, userLevelId) } // Workflow management -func (_i *articleApprovalFlowsService) CanUserApproveStep(clientId *uuid.UUID, flowId uint, userId uint, userLevelId uint) (canApprove bool, reason string, err error) { +func (_i *articleApprovalFlowsService) CanUserApproveStep(authToken string, flowId uint, userId uint, userLevelId uint) (canApprove bool, reason string, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return false, "clientId not found in auth token", errors.New("clientId not found in auth token") + } + // Get approval flow flow, err := _i.ArticleApprovalFlowsRepository.FindOne(clientId, flowId) if err != nil { @@ -738,7 +1005,21 @@ func (_i *articleApprovalFlowsService) CanUserApproveStep(clientId *uuid.UUID, f return true, "", nil } -func (_i *articleApprovalFlowsService) GetCurrentStepInfo(clientId *uuid.UUID, flowId uint) (stepInfo map[string]interface{}, err error) { +func (_i *articleApprovalFlowsService) GetCurrentStepInfo(authToken string, flowId uint) (stepInfo map[string]interface{}, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + stepInfo = make(map[string]interface{}) // Get approval flow @@ -767,7 +1048,21 @@ func (_i *articleApprovalFlowsService) GetCurrentStepInfo(clientId *uuid.UUID, f return stepInfo, nil } -func (_i *articleApprovalFlowsService) GetNextStepPreview(clientId *uuid.UUID, flowId uint) (nextStep *entity.ApprovalWorkflowSteps, err error) { +func (_i *articleApprovalFlowsService) GetNextStepPreview(authToken string, flowId uint) (nextStep *entity.ApprovalWorkflowSteps, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + // Get approval flow flow, err := _i.ArticleApprovalFlowsRepository.FindOne(clientId, flowId) if err != nil { diff --git a/app/module/article_approval_flows/service/article_approval_flows.service.go.backup b/app/module/article_approval_flows/service/article_approval_flows.service.go.backup new file mode 100644 index 0000000..188ffe9 --- /dev/null +++ b/app/module/article_approval_flows/service/article_approval_flows.service.go.backup @@ -0,0 +1,817 @@ +package service + +import ( + "errors" + "netidhub-saas-be/app/database/entity" + approvalWorkflowStepsRepo "netidhub-saas-be/app/module/approval_workflow_steps/repository" + approvalWorkflowsRepo "netidhub-saas-be/app/module/approval_workflows/repository" + "netidhub-saas-be/app/module/article_approval_flows/repository" + "netidhub-saas-be/app/module/article_approval_flows/request" + approvalStepLogsRepo "netidhub-saas-be/app/module/article_approval_step_logs/repository" + articlesRepo "netidhub-saas-be/app/module/articles/repository" + usersRepo "netidhub-saas-be/app/module/users/repository" + "netidhub-saas-be/utils/paginator" + utilSvc "netidhub-saas-be/utils/service" + "time" + + "github.com/google/uuid" + "github.com/rs/zerolog" +) + +type articleApprovalFlowsService struct { + ArticleApprovalFlowsRepository repository.ArticleApprovalFlowsRepository + ApprovalWorkflowsRepository approvalWorkflowsRepo.ApprovalWorkflowsRepository + ApprovalWorkflowStepsRepository approvalWorkflowStepsRepo.ApprovalWorkflowStepsRepository + ArticleApprovalStepLogsRepository approvalStepLogsRepo.ArticleApprovalStepLogsRepository + ArticlesRepository articlesRepo.ArticlesRepository + UsersRepository usersRepo.UsersRepository + Log zerolog.Logger +} + +// ArticleApprovalFlowsService define interface of IArticleApprovalFlowsService +type ArticleApprovalFlowsService interface { + // Basic CRUD + GetAll(authToken string, req request.ArticleApprovalFlowsQueryRequest) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) + FindOne(authToken string, id uint) (flow *entity.ArticleApprovalFlows, err error) + Create(authToken string, flow *entity.ArticleApprovalFlows) (flowReturn *entity.ArticleApprovalFlows, err error) + Update(id uint, flow *entity.ArticleApprovalFlows) (err error) + Delete(authToken string, id uint) (err error) + + // Article submission and approval workflow + SubmitArticleForApproval(authToken string, articleId uint, submittedById uint, workflowId *uint) (flow *entity.ArticleApprovalFlows, err error) + ApproveStep(authToken string, flowId uint, approvedById uint, message string) (err error) + RejectArticle(authToken string, flowId uint, rejectedById uint, reason string) (err error) + RequestRevision(authToken string, flowId uint, requestedById uint, revisionMessage string) (err error) + ResubmitAfterRevision(authToken string, flowId uint, resubmittedById uint) (err error) + + // Dashboard and queue methods + GetPendingApprovals(authToken string, userLevelId uint, page, limit int, filters map[string]interface{}) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) + GetMyApprovalQueue(authToken string, userLevelId uint, page, limit int, includePreview bool, urgentOnly bool) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) + GetApprovalHistory(authToken string, articleId uint, page, limit int) (logs []*entity.ArticleApprovalStepLogs, paging paginator.Pagination, err error) + + // Statistics and analytics + GetPendingCountByLevel(authToken string, userLevelId uint) (count int64, err error) + GetOverdueCountByLevel(authToken string, userLevelId uint) (count int64, err error) + GetApprovalStatistics(authToken string, userLevelId uint, startDate, endDate time.Time) (stats map[string]interface{}, err error) + GetWorkloadAnalytics(authToken string, userLevelId uint) (analytics map[string]interface{}, err error) + + // Workflow management + CanUserApproveStep(authToken string, flowId uint, userId uint, userLevelId uint) (canApprove bool, reason string, err error) + GetCurrentStepInfo(authToken string, flowId uint) (stepInfo map[string]interface{}, err error) + GetNextStepPreview(authToken string, flowId uint) (nextStep *entity.ApprovalWorkflowSteps, err error) +} + +func NewArticleApprovalFlowsService( + articleApprovalFlowsRepository repository.ArticleApprovalFlowsRepository, + approvalWorkflowsRepository approvalWorkflowsRepo.ApprovalWorkflowsRepository, + approvalWorkflowStepsRepository approvalWorkflowStepsRepo.ApprovalWorkflowStepsRepository, + articleApprovalStepLogsRepository approvalStepLogsRepo.ArticleApprovalStepLogsRepository, + articlesRepository articlesRepo.ArticlesRepository, + usersRepository usersRepo.UsersRepository, + log zerolog.Logger, +) ArticleApprovalFlowsService { + return &articleApprovalFlowsService{ + ArticleApprovalFlowsRepository: articleApprovalFlowsRepository, + ApprovalWorkflowsRepository: approvalWorkflowsRepository, + ApprovalWorkflowStepsRepository: approvalWorkflowStepsRepository, + ArticleApprovalStepLogsRepository: articleApprovalStepLogsRepository, + ArticlesRepository: articlesRepository, + UsersRepository: usersRepository, + Log: log, + } +} + +// Basic CRUD implementations +func (_i *articleApprovalFlowsService) GetAll(authToken string, req request.ArticleApprovalFlowsQueryRequest) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, paginator.Pagination{}, errors.New("clientId not found in auth token") + } + + return _i.ArticleApprovalFlowsRepository.GetAll(clientId, req) +} +func (_i *articleApprovalFlowsService) FindOne(authToken string, id uint) (flow *entity.ArticleApprovalFlows, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + + return _i.ArticleApprovalFlowsRepository.FindOne(clientId, id) +} + +func (_i *articleApprovalFlowsService) Create(clientId *uuid.UUID, flow *entity.ArticleApprovalFlows) (flowReturn *entity.ArticleApprovalFlows, err error) { + return _i.ArticleApprovalFlowsRepository.Create(clientId, flow) +} + +func (_i *articleApprovalFlowsService) Update(id uint, flow *entity.ArticleApprovalFlows) (err error) { + return _i.ArticleApprovalFlowsRepository.Update(id, flow) +} + +func (_i *articleApprovalFlowsService) Delete(clientId *uuid.UUID, id uint) (err error) { + return _i.ArticleApprovalFlowsRepository.Delete(clientId, id) +} + +// Article submission and approval workflow +func (_i *articleApprovalFlowsService) SubmitArticleForApproval(clientId *uuid.UUID, articleId uint, submittedById uint, workflowId *uint) (flow *entity.ArticleApprovalFlows, err error) { + // Check if article already has an active approval flow + existingFlow, err := _i.ArticleApprovalFlowsRepository.FindActiveByArticleId(articleId) + if err == nil && existingFlow != nil { + return nil, errors.New("article already has an active approval flow") + } + + // Get workflow (use default if not specified) + var workflow *entity.ApprovalWorkflows + if workflowId != nil { + workflow, err = _i.ApprovalWorkflowsRepository.FindOne(clientId, *workflowId) + } else { + workflow, err = _i.ApprovalWorkflowsRepository.FindDefault(clientId) + } + + if err != nil { + return nil, err + } + + if workflow == nil { + return nil, errors.New("no workflow found") + } + + if workflow.IsActive != nil && !*workflow.IsActive { + return nil, errors.New("workflow is not active") + } + + // Get first step of workflow + firstStep, err := _i.ApprovalWorkflowStepsRepository.FindByWorkflowAndStep(clientId, workflow.ID, 1) + if err != nil { + return nil, err + } + + if firstStep == nil { + return nil, errors.New("workflow has no steps") + } + + // Create approval flow + flow = &entity.ArticleApprovalFlows{ + ArticleId: articleId, + WorkflowId: workflow.ID, + CurrentStep: 1, + StatusId: 1, // pending + SubmittedById: submittedById, + SubmittedAt: time.Now(), + } + + flow, err = _i.ArticleApprovalFlowsRepository.Create(clientId, flow) + if err != nil { + return nil, err + } + + // Get current article data first + currentArticle, err := _i.ArticlesRepository.FindOne(clientId, articleId) + if err != nil { + return nil, err + } + + // Update only the necessary fields + currentArticle.WorkflowId = &workflow.ID + currentArticle.CurrentApprovalStep = &flow.CurrentStep + currentArticle.StatusId = &[]int{1}[0] // pending approval + + err = _i.ArticlesRepository.UpdateSkipNull(clientId, articleId, currentArticle) + if err != nil { + return nil, err + } + + // Process auto-skip logic based on user level + err = _i.processAutoSkipSteps(clientId, flow, submittedById) + if err != nil { + return nil, err + } + + return flow, nil +} + +// processAutoSkipSteps handles automatic step skipping based on user level +func (_i *articleApprovalFlowsService) processAutoSkipSteps(clientId *uuid.UUID, flow *entity.ArticleApprovalFlows, submittedById uint) error { + // Get user level of the submitter + userLevelId, err := _i.getUserLevelId(clientId, submittedById) + if err != nil { + return err + } + + // Get all workflow steps + steps, err := _i.ApprovalWorkflowStepsRepository.GetByWorkflowId(clientId, flow.WorkflowId) + if err != nil { + return err + } + + // Sort steps by step order + sortStepsByOrder(steps) + + // Process each step to determine if it should be auto-skipped + for _, step := range steps { + shouldSkip := _i.shouldSkipStep(userLevelId, step.RequiredUserLevelId) + + if shouldSkip { + // Create skip log + stepLog := &entity.ArticleApprovalStepLogs{ + ApprovalFlowId: flow.ID, + StepOrder: step.StepOrder, + StepName: step.StepName, + ApprovedById: &submittedById, + Action: "auto_skip", + Message: &[]string{"Step auto-skipped due to user level"}[0], + ProcessedAt: time.Now(), + UserLevelId: step.RequiredUserLevelId, + } + + _, err = _i.ArticleApprovalStepLogsRepository.Create(clientId, stepLog) + if err != nil { + return err + } + + // Update flow to next step (handle step order starting from 0) + nextStepOrder := step.StepOrder + 1 + flow.CurrentStep = nextStepOrder + } else { + // Stop at first step that cannot be skipped + break + } + } + + // Update flow with final current step + err = _i.ArticleApprovalFlowsRepository.Update(flow.ID, flow) + if err != nil { + return err + } + + // Get current article data first + currentArticle, err := _i.ArticlesRepository.FindOne(clientId, flow.ArticleId) + if err != nil { + return err + } + + // Update only the necessary fields + currentArticle.CurrentApprovalStep = &flow.CurrentStep + + err = _i.ArticlesRepository.UpdateSkipNull(clientId, flow.ArticleId, currentArticle) + if err != nil { + return err + } + + // Check if all steps were skipped (workflow complete) + // Find the highest step order + maxStepOrder := 0 + for _, step := range steps { + if step.StepOrder > maxStepOrder { + maxStepOrder = step.StepOrder + } + } + + if flow.CurrentStep > maxStepOrder { + // All steps completed, mark as approved + flow.StatusId = 2 // approved + flow.CurrentStep = 0 // Set to 0 to indicate completion + flow.CompletedAt = &[]time.Time{time.Now()}[0] + + err = _i.ArticleApprovalFlowsRepository.Update(flow.ID, flow) + if err != nil { + return err + } + + // Get current article data first + currentArticle, err := _i.ArticlesRepository.FindOne(clientId, flow.ArticleId) + if err != nil { + return err + } + + // Update only the necessary fields + currentArticle.StatusId = &[]int{2}[0] // approved + currentArticle.CurrentApprovalStep = &[]int{0}[0] // Set to 0 to indicate completion + + err = _i.ArticlesRepository.UpdateSkipNull(clientId, flow.ArticleId, currentArticle) + if err != nil { + return err + } + } + + return nil +} + +// getUserLevelId gets the user level ID for a given user +func (_i *articleApprovalFlowsService) getUserLevelId(clientId *uuid.UUID, userId uint) (uint, error) { + // Get user from database to retrieve user level + user, err := _i.UsersRepository.FindOne(clientId, userId) + if err != nil { + _i.Log.Error().Err(err).Uint("userId", userId).Msg("Failed to find user") + return 0, err + } + + if user.UserLevel == nil { + _i.Log.Error().Uint("userId", userId).Msg("User has no user level") + return 0, errors.New("user has no user level") + } + + _i.Log.Info(). + Uint("userId", userId). + Uint("userLevelId", user.UserLevel.ID). + Str("userLevelName", user.UserLevel.Name). + Msg("Retrieved user level from database") + + return user.UserLevel.ID, nil +} + +// shouldSkipStep determines if a step should be auto-skipped based on user level +func (_i *articleApprovalFlowsService) shouldSkipStep(userLevelId, requiredLevelId uint) bool { + // Get user level details to compare level numbers + // User level with lower level_number (higher authority) can skip steps requiring higher level_number + // For now, we'll use a simple comparison based on IDs + // In production, this should compare level_number fields + + // Simple logic: if user level ID is less than required level ID, they can skip + // This assumes level 1 (ID=1) has higher authority than level 2 (ID=2), etc. + return userLevelId < requiredLevelId +} + +// sortStepsByOrder sorts workflow steps by their step order +func sortStepsByOrder(steps []*entity.ApprovalWorkflowSteps) { + // Simple bubble sort for step order + n := len(steps) + for i := 0; i < n-1; i++ { + for j := 0; j < n-i-1; j++ { + if steps[j].StepOrder > steps[j+1].StepOrder { + steps[j], steps[j+1] = steps[j+1], steps[j] + } + } + } +} + +func (_i *articleApprovalFlowsService) ApproveStep(clientId *uuid.UUID, flowId uint, approvedById uint, message string) (err error) { + // Get approval flow + flow, err := _i.ArticleApprovalFlowsRepository.FindOne(clientId, flowId) + if err != nil { + return err + } + + if flow == nil { + return errors.New("approval flow not found") + } + + if flow.StatusId != 1 && flow.StatusId != 4 { // not pending or revision_requested + return errors.New("approval flow is not in pending state") + } + + // Get current step + currentStep, err := _i.ApprovalWorkflowStepsRepository.FindByWorkflowAndStep(clientId, flow.WorkflowId, flow.CurrentStep) + if err != nil { + return err + } + + if currentStep == nil { + return errors.New("current step not found") + } + + // Create step log + stepLog := &entity.ArticleApprovalStepLogs{ + ApprovalFlowId: flow.ID, + StepOrder: flow.CurrentStep, + StepName: currentStep.StepName, + ApprovedById: &approvedById, + Action: "approve", + Message: &message, + ProcessedAt: time.Now(), + UserLevelId: currentStep.RequiredUserLevelId, + } + + _, err = _i.ArticleApprovalStepLogsRepository.Create(clientId, stepLog) + if err != nil { + return err + } + + // Check if there's a next step + nextStep, err := _i.ApprovalWorkflowStepsRepository.GetNextStep(clientId, flow.WorkflowId, flow.CurrentStep) + if err != nil && err.Error() != "record not found" { + return err + } + + if nextStep == nil || nextStep.ID == 0 { + // No next step - approval complete + flowUpdate := &entity.ArticleApprovalFlows{ + StatusId: 2, // approved + CurrentStep: 0, // Set to 0 to indicate completion + CompletedAt: &[]time.Time{time.Now()}[0], + } + + // Debug logging + _i.Log.Info(). + Interface("flowUpdate :: ", flowUpdate). + Msg("Retrieved next step from database") + + err = _i.ArticleApprovalFlowsRepository.Update(flowId, flowUpdate) + if err != nil { + return err + } + + // Get current article data first + currentArticle, err := _i.ArticlesRepository.FindOne(clientId, flow.ArticleId) + if err != nil { + return err + } + + // Update only the necessary fields + currentArticle.StatusId = &[]int{2}[0] // approved + currentArticle.CurrentApprovalStep = &[]int{0}[0] // Set to 0 to indicate completion + currentArticle.IsPublish = &[]bool{true}[0] // Set to true to indicate publication + currentArticle.IsDraft = &[]bool{false}[0] // Set to false to indicate publication + + err = _i.ArticlesRepository.UpdateSkipNull(clientId, flow.ArticleId, currentArticle) + if err != nil { + return err + } + } else { + // Move to next step + flowUpdate := &entity.ArticleApprovalFlows{ + CurrentStep: nextStep.StepOrder, + StatusId: 1, // pending + } + + err = _i.ArticleApprovalFlowsRepository.Update(flowId, flowUpdate) + if err != nil { + return err + } + + // Get current article data first + currentArticle, err := _i.ArticlesRepository.FindOne(clientId, flow.ArticleId) + if err != nil { + return err + } + + // Update only the necessary fields + currentArticle.CurrentApprovalStep = &nextStep.StepOrder + + err = _i.ArticlesRepository.UpdateSkipNull(clientId, flow.ArticleId, currentArticle) + if err != nil { + return err + } + } + + return nil +} + +func (_i *articleApprovalFlowsService) RejectArticle(clientId *uuid.UUID, flowId uint, rejectedById uint, reason string) (err error) { + // Get approval flow + flow, err := _i.ArticleApprovalFlowsRepository.FindOne(clientId, flowId) + if err != nil { + return err + } + + if flow == nil { + return errors.New("approval flow not found") + } + + if flow.StatusId != 1 && flow.StatusId != 4 { // not pending or revision_requested + return errors.New("approval flow is not in pending state") + } + + // Get current step + currentStep, err := _i.ApprovalWorkflowStepsRepository.FindByWorkflowAndStep(clientId, flow.WorkflowId, flow.CurrentStep) + if err != nil { + return err + } + + // Create step log + stepLog := &entity.ArticleApprovalStepLogs{ + ApprovalFlowId: flow.ID, + StepOrder: flow.CurrentStep, + StepName: currentStep.StepName, + ApprovedById: &rejectedById, + Action: "reject", + Message: &reason, + ProcessedAt: time.Now(), + UserLevelId: currentStep.RequiredUserLevelId, + } + + _, err = _i.ArticleApprovalStepLogsRepository.Create(clientId, stepLog) + if err != nil { + return err + } + + // Update approval flow status + flowUpdate := &entity.ArticleApprovalFlows{ + StatusId: 3, // rejected + RejectionReason: &reason, + CompletedAt: &[]time.Time{time.Now()}[0], + } + + err = _i.ArticleApprovalFlowsRepository.Update(flowId, flowUpdate) + if err != nil { + return err + } + + // Get current article data first + currentArticle, err := _i.ArticlesRepository.FindOne(clientId, flow.ArticleId) + if err != nil { + return err + } + + // Update only the necessary fields + currentArticle.StatusId = &[]int{3}[0] // rejected + currentArticle.CurrentApprovalStep = nil + + err = _i.ArticlesRepository.UpdateSkipNull(clientId, flow.ArticleId, currentArticle) + if err != nil { + return err + } + + return nil +} + +func (_i *articleApprovalFlowsService) RequestRevision(clientId *uuid.UUID, flowId uint, requestedById uint, revisionMessage string) (err error) { + // Get approval flow + flow, err := _i.ArticleApprovalFlowsRepository.FindOne(clientId, flowId) + if err != nil { + return err + } + + if flow == nil { + return errors.New("approval flow not found") + } + + if flow.StatusId != 1 { // not pending + return errors.New("approval flow is not in pending state") + } + + // Get current step + currentStep, err := _i.ApprovalWorkflowStepsRepository.FindByWorkflowAndStep(clientId, flow.WorkflowId, flow.CurrentStep) + if err != nil { + return err + } + + // Create step log + stepLog := &entity.ArticleApprovalStepLogs{ + ApprovalFlowId: flow.ID, + StepOrder: flow.CurrentStep, + StepName: currentStep.StepName, + ApprovedById: &requestedById, + Action: "request_revision", + Message: &revisionMessage, + ProcessedAt: time.Now(), + UserLevelId: currentStep.RequiredUserLevelId, + } + + _, err = _i.ArticleApprovalStepLogsRepository.Create(clientId, stepLog) + if err != nil { + return err + } + + // Update approval flow status + flowUpdate := &entity.ArticleApprovalFlows{ + StatusId: 4, // revision_requested + RevisionRequested: &[]bool{true}[0], + RevisionMessage: &revisionMessage, + } + + err = _i.ArticleApprovalFlowsRepository.Update(flowId, flowUpdate) + if err != nil { + return err + } + + // Get current article data first + currentArticle, err := _i.ArticlesRepository.FindOne(clientId, flow.ArticleId) + if err != nil { + return err + } + + // Update only the necessary fields + currentArticle.StatusId = &[]int{4}[0] // revision_requested + + err = _i.ArticlesRepository.UpdateSkipNull(clientId, flow.ArticleId, currentArticle) + if err != nil { + return err + } + + return nil +} + +func (_i *articleApprovalFlowsService) ResubmitAfterRevision(clientId *uuid.UUID, flowId uint, resubmittedById uint) (err error) { + // Get approval flow + flow, err := _i.ArticleApprovalFlowsRepository.FindOne(clientId, flowId) + if err != nil { + return err + } + + if flow == nil { + return errors.New("approval flow not found") + } + + if flow.StatusId != 4 { // not revision_requested + return errors.New("approval flow is not in revision requested state") + } + + // Reset approval flow to pending + flowUpdate := &entity.ArticleApprovalFlows{ + StatusId: 1, // pending + RevisionRequested: &[]bool{false}[0], + RevisionMessage: nil, + CurrentStep: 1, // restart from first step + } + + err = _i.ArticleApprovalFlowsRepository.Update(flowId, flowUpdate) + if err != nil { + return err + } + + // Get current article data first + currentArticle, err := _i.ArticlesRepository.FindOne(clientId, flow.ArticleId) + if err != nil { + return err + } + + // Update only the necessary fields + currentArticle.StatusId = &[]int{1}[0] // pending approval + currentArticle.CurrentApprovalStep = &[]int{1}[0] + + err = _i.ArticlesRepository.UpdateSkipNull(clientId, flow.ArticleId, currentArticle) + if err != nil { + return err + } + + // Create resubmission log + stepLog := &entity.ArticleApprovalStepLogs{ + ApprovalFlowId: flow.ID, + StepOrder: 1, + StepName: "Resubmission", + ApprovedById: &resubmittedById, + Action: "resubmit", + Message: &[]string{"Article resubmitted after revision"}[0], + ProcessedAt: time.Now(), + } + + _, err = _i.ArticleApprovalStepLogsRepository.Create(clientId, stepLog) + if err != nil { + return err + } + + return nil +} + +// Dashboard and queue methods +func (_i *articleApprovalFlowsService) GetPendingApprovals(clientId *uuid.UUID, userLevelId uint, page, limit int, filters map[string]interface{}) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) { + return _i.ArticleApprovalFlowsRepository.GetPendingApprovals(clientId, userLevelId, page, limit, filters) +} + +func (_i *articleApprovalFlowsService) GetMyApprovalQueue(clientId *uuid.UUID, userLevelId uint, page, limit int, includePreview bool, urgentOnly bool) (flows []*entity.ArticleApprovalFlows, paging paginator.Pagination, err error) { + return _i.ArticleApprovalFlowsRepository.GetMyApprovalQueue(clientId, userLevelId, page, limit, includePreview, urgentOnly) +} + +func (_i *articleApprovalFlowsService) GetApprovalHistory(clientId *uuid.UUID, articleId uint, page, limit int) (logs []*entity.ArticleApprovalStepLogs, paging paginator.Pagination, err error) { + return _i.ArticleApprovalStepLogsRepository.GetApprovalHistory(clientId, articleId, page, limit) +} + +// Statistics and analytics +func (_i *articleApprovalFlowsService) GetPendingCountByLevel(clientId *uuid.UUID, userLevelId uint) (count int64, err error) { + return _i.ArticleApprovalFlowsRepository.GetPendingCountByLevel(clientId, userLevelId) +} + +func (_i *articleApprovalFlowsService) GetOverdueCountByLevel(clientId *uuid.UUID, userLevelId uint) (count int64, err error) { + return _i.ArticleApprovalFlowsRepository.GetOverdueCountByLevel(clientId, userLevelId) +} + +func (_i *articleApprovalFlowsService) GetApprovalStatistics(clientId *uuid.UUID, userLevelId uint, startDate, endDate time.Time) (stats map[string]interface{}, err error) { + stats = make(map[string]interface{}) + + // Get approved count + approvedCount, err := _i.ArticleApprovalFlowsRepository.GetApprovedCountByPeriod(clientId, userLevelId, startDate, endDate) + if err != nil { + return nil, err + } + + // Get rejected count + rejectedCount, err := _i.ArticleApprovalFlowsRepository.GetRejectedCountByPeriod(clientId, userLevelId, startDate, endDate) + if err != nil { + return nil, err + } + + // Get revision request count + revisionCount, err := _i.ArticleApprovalFlowsRepository.GetRevisionRequestCountByPeriod(clientId, userLevelId, startDate, endDate) + if err != nil { + return nil, err + } + + stats["approved_count"] = approvedCount + stats["rejected_count"] = rejectedCount + stats["revision_requested_count"] = revisionCount + stats["total_processed"] = approvedCount + rejectedCount + revisionCount + stats["period_start"] = startDate + stats["period_end"] = endDate + + return stats, nil +} + +func (_i *articleApprovalFlowsService) GetWorkloadAnalytics(clientId *uuid.UUID, userLevelId uint) (analytics map[string]interface{}, err error) { + return _i.ArticleApprovalFlowsRepository.GetLevelWorkload(clientId, userLevelId) +} + +// Workflow management +func (_i *articleApprovalFlowsService) CanUserApproveStep(clientId *uuid.UUID, flowId uint, userId uint, userLevelId uint) (canApprove bool, reason string, err error) { + // Get approval flow + flow, err := _i.ArticleApprovalFlowsRepository.FindOne(clientId, flowId) + if err != nil { + return false, "", err + } + + if flow == nil { + return false, "approval flow not found", nil + } + + if flow.StatusId != 1 && flow.StatusId != 4 { // not pending or revision_requested + return false, "approval flow is not in pending state", nil + } + + // Get current step + currentStep, err := _i.ApprovalWorkflowStepsRepository.FindByWorkflowAndStep(clientId, flow.WorkflowId, flow.CurrentStep) + if err != nil { + return false, "", err + } + + if currentStep == nil { + return false, "current step not found", nil + } + + // Check if user level matches required level + if currentStep.RequiredUserLevelId != userLevelId { + return false, "user level does not match required level for this step", nil + } + + // Check if user submitted the article (cannot approve own submission) + if flow.SubmittedById == userId { + return false, "cannot approve own submission", nil + } + + return true, "", nil +} + +func (_i *articleApprovalFlowsService) GetCurrentStepInfo(clientId *uuid.UUID, flowId uint) (stepInfo map[string]interface{}, err error) { + stepInfo = make(map[string]interface{}) + + // Get approval flow + flow, err := _i.ArticleApprovalFlowsRepository.FindOne(clientId, flowId) + if err != nil { + return nil, err + } + + if flow == nil { + return nil, errors.New("approval flow not found") + } + + // Get current step + currentStep, err := _i.ApprovalWorkflowStepsRepository.FindByWorkflowAndStep(clientId, flow.WorkflowId, flow.CurrentStep) + if err != nil { + return nil, err + } + + stepInfo["current_step"] = flow.CurrentStep + stepInfo["step_name"] = currentStep.StepName + stepInfo["required_user_level_id"] = currentStep.RequiredUserLevelId + stepInfo["can_skip"] = currentStep.CanSkip + stepInfo["auto_approve_after_hours"] = currentStep.AutoApproveAfterHours + stepInfo["status"] = flow.StatusId + + return stepInfo, nil +} + +func (_i *articleApprovalFlowsService) GetNextStepPreview(clientId *uuid.UUID, flowId uint) (nextStep *entity.ApprovalWorkflowSteps, err error) { + // Get approval flow + flow, err := _i.ArticleApprovalFlowsRepository.FindOne(clientId, flowId) + if err != nil { + return nil, err + } + + if flow == nil { + return nil, errors.New("approval flow not found") + } + + // Get next step + nextStep, err = _i.ApprovalWorkflowStepsRepository.GetNextStep(clientId, flow.WorkflowId, flow.CurrentStep) + if err != nil { + return nil, err + } + + return nextStep, nil +} diff --git a/app/module/article_approvals/service/article_approvals.service.go b/app/module/article_approvals/service/article_approvals.service.go index 5465f39..c61a395 100644 --- a/app/module/article_approvals/service/article_approvals.service.go +++ b/app/module/article_approvals/service/article_approvals.service.go @@ -78,7 +78,7 @@ func (_i *articleApprovalsService) Save(clientId *uuid.UUID, req request.Article approvalByUserLevelId := createdBy.UserLevelId approvalParentLevelId := createdBy.UserLevel.ParentLevelId - err = _i.ArticlesService.UpdateApproval(clientId, newReq.ArticleId, newReq.StatusId, int(approvalByUserLevelId), *newReq.ApprovalAtLevel, *approvalParentLevelId) + err = _i.ArticlesService.UpdateApproval(authToken, newReq.ArticleId, newReq.StatusId, int(approvalByUserLevelId), *newReq.ApprovalAtLevel, *approvalParentLevelId) if err != nil { return nil, err } diff --git a/app/module/article_categories/controller/article_categories.controller.go b/app/module/article_categories/controller/article_categories.controller.go index 03213ba..495a272 100644 --- a/app/module/article_categories/controller/article_categories.controller.go +++ b/app/module/article_categories/controller/article_categories.controller.go @@ -1,7 +1,6 @@ package controller import ( - "netidhub-saas-be/app/middleware" "netidhub-saas-be/app/module/article_categories/request" "netidhub-saas-be/app/module/article_categories/service" "netidhub-saas-be/utils/paginator" @@ -40,7 +39,7 @@ func NewArticleCategoriesController(articleCategoriesService service.ArticleCate // @Description API for getting all ArticleCategories // @Tags Article Categories // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param req query request.ArticleCategoriesQueryRequest false "query parameters" // @Param req query paginator.Pagination false "pagination parameters" @@ -56,7 +55,6 @@ func (_i *articleCategoriesController) All(c *fiber.Ctx) error { } authToken := c.Get("Authorization") - clientId := middleware.GetClientID(c) reqContext := request.ArticleCategoriesQueryRequestContext{ Title: c.Query("title"), @@ -68,7 +66,7 @@ func (_i *articleCategoriesController) All(c *fiber.Ctx) error { req := reqContext.ToParamRequest() req.Pagination = paginate - articleCategoriesData, paging, err := _i.articleCategoriesService.All(clientId, req, authToken) + articleCategoriesData, paging, err := _i.articleCategoriesService.All(authToken, req) if err != nil { return err } @@ -86,7 +84,7 @@ func (_i *articleCategoriesController) All(c *fiber.Ctx) error { // @Description API for getting one ArticleCategories // @Tags Article Categories // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param id path int true "ArticleCategories ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -99,9 +97,10 @@ func (_i *articleCategoriesController) Show(c *fiber.Ctx) error { return err } - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - articleCategoriesData, err := _i.articleCategoriesService.Show(clientId, uint(id)) + articleCategoriesData, err := _i.articleCategoriesService.Show(authToken, uint(id)) if err != nil { return err } @@ -118,7 +117,7 @@ func (_i *articleCategoriesController) Show(c *fiber.Ctx) error { // @Description API for getting one ArticleCategories // @Tags Article Categories // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param id path int true "ArticleCategories Old ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -131,9 +130,10 @@ func (_i *articleCategoriesController) ShowByOldId(c *fiber.Ctx) error { return err } - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - articleCategoriesData, err := _i.articleCategoriesService.ShowByOldId(clientId, uint(id)) + articleCategoriesData, err := _i.articleCategoriesService.ShowByOldId(authToken, uint(id)) if err != nil { return err } @@ -150,7 +150,7 @@ func (_i *articleCategoriesController) ShowByOldId(c *fiber.Ctx) error { // @Description API for getting one ArticleCategories // @Tags Article Categories // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param slug path string true "ArticleCategories Slug" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -159,9 +159,10 @@ func (_i *articleCategoriesController) ShowByOldId(c *fiber.Ctx) error { // @Router /article-categories/slug/{slug} [get] func (_i *articleCategoriesController) ShowBySlug(c *fiber.Ctx) error { slug := c.Params("slug") - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - articleCategoriesData, err := _i.articleCategoriesService.ShowBySlug(clientId, slug) + articleCategoriesData, err := _i.articleCategoriesService.ShowBySlug(authToken, slug) if err != nil { return err } @@ -178,8 +179,7 @@ func (_i *articleCategoriesController) ShowBySlug(c *fiber.Ctx) error { // @Description API for create ArticleCategories // @Tags Article Categories // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string true "Insert the Authorization" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param payload body request.ArticleCategoriesCreateRequest true "Required payload" // @Success 200 {object} response.Response @@ -194,9 +194,8 @@ func (_i *articleCategoriesController) Save(c *fiber.Ctx) error { } authToken := c.Get("Authorization") - clientId := middleware.GetClientID(c) - dataResult, err := _i.articleCategoriesService.Save(clientId, *req, authToken) + dataResult, err := _i.articleCategoriesService.Save(authToken, *req) if err != nil { return err } @@ -214,8 +213,7 @@ func (_i *articleCategoriesController) Save(c *fiber.Ctx) error { // @Tags Article Categories // @Security Bearer // @Produce json -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string true "Insert the Authorization" // @Param files formData file true "Upload thumbnail" // @Param id path int true "ArticleCategories ID" // @Success 200 {object} response.Response @@ -224,8 +222,9 @@ func (_i *articleCategoriesController) Save(c *fiber.Ctx) error { // @Failure 500 {object} response.InternalServerError // @Router /article-categories/thumbnail/{id} [post] func (_i *articleCategoriesController) SaveThumbnail(c *fiber.Ctx) error { - clientId := middleware.GetClientID(c) - err := _i.articleCategoriesService.SaveThumbnail(clientId, c) + // Get Authorization token from header + authToken := c.Get("Authorization") + err := _i.articleCategoriesService.SaveThumbnail(authToken, c) if err != nil { return err } @@ -241,8 +240,7 @@ func (_i *articleCategoriesController) SaveThumbnail(c *fiber.Ctx) error { // @Description API for update ArticleCategories // @Tags Article Categories // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string true "Insert the Authorization" // @Param payload body request.ArticleCategoriesUpdateRequest true "Required payload" // @Param id path int true "ArticleCategories ID" // @Success 200 {object} response.Response @@ -261,8 +259,9 @@ func (_i *articleCategoriesController) Update(c *fiber.Ctx) error { return err } - clientId := middleware.GetClientID(c) - err = _i.articleCategoriesService.Update(clientId, uint(id), *req) + // Get Authorization token from header + authToken := c.Get("Authorization") + err = _i.articleCategoriesService.Update(authToken, uint(id), *req) if err != nil { return err } @@ -278,8 +277,7 @@ func (_i *articleCategoriesController) Update(c *fiber.Ctx) error { // @Description API for delete ArticleCategories // @Tags Article Categories // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string true "Insert the Authorization" // @Param id path int true "ArticleCategories ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -292,8 +290,9 @@ func (_i *articleCategoriesController) Delete(c *fiber.Ctx) error { return err } - clientId := middleware.GetClientID(c) - err = _i.articleCategoriesService.Delete(clientId, uint(id)) + // Get Authorization token from header + authToken := c.Get("Authorization") + err = _i.articleCategoriesService.Delete(authToken, uint(id)) if err != nil { return err } @@ -309,7 +308,7 @@ func (_i *articleCategoriesController) Delete(c *fiber.Ctx) error { // @Description API for View Thumbnail of ArticleCategories // @Tags Article Categories // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param id path string true "ArticleCategories ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError diff --git a/app/module/article_categories/service/article_categories.service.go b/app/module/article_categories/service/article_categories.service.go index 78f0a3d..36bce4b 100644 --- a/app/module/article_categories/service/article_categories.service.go +++ b/app/module/article_categories/service/article_categories.service.go @@ -37,14 +37,14 @@ type articleCategoriesService struct { // ArticleCategoriesService define interface of IArticleCategoriesService type ArticleCategoriesService interface { - All(clientId *uuid.UUID, req request.ArticleCategoriesQueryRequest, authToken string) (articleCategories []*response.ArticleCategoriesResponse, paging paginator.Pagination, err error) - Show(clientId *uuid.UUID, id uint) (articleCategories *response.ArticleCategoriesResponse, err error) - ShowByOldId(clientId *uuid.UUID, id uint) (articleCategories *response.ArticleCategoriesResponse, err error) - ShowBySlug(clientId *uuid.UUID, slug string) (articleCategories *response.ArticleCategoriesResponse, err error) - Save(clientId *uuid.UUID, req request.ArticleCategoriesCreateRequest, authToken string) (articleCategories *entity.ArticleCategories, err error) - SaveThumbnail(clientId *uuid.UUID, c *fiber.Ctx) (err error) - Update(clientId *uuid.UUID, id uint, req request.ArticleCategoriesUpdateRequest) (err error) - Delete(clientId *uuid.UUID, id uint) error + All(authToken string, req request.ArticleCategoriesQueryRequest) (articleCategories []*response.ArticleCategoriesResponse, paging paginator.Pagination, err error) + Show(authToken string, id uint) (articleCategories *response.ArticleCategoriesResponse, err error) + ShowByOldId(authToken string, id uint) (articleCategories *response.ArticleCategoriesResponse, err error) + ShowBySlug(authToken string, slug string) (articleCategories *response.ArticleCategoriesResponse, err error) + Save(authToken string, req request.ArticleCategoriesCreateRequest) (articleCategories *entity.ArticleCategories, err error) + SaveThumbnail(authToken string, c *fiber.Ctx) (err error) + Update(authToken string, id uint, req request.ArticleCategoriesUpdateRequest) (err error) + Delete(authToken string, id uint) error Viewer(c *fiber.Ctx) error } @@ -61,7 +61,17 @@ func NewArticleCategoriesService(repo repository.ArticleCategoriesRepository, us } // All implement interface of ArticleCategoriesService -func (_i *articleCategoriesService) All(clientId *uuid.UUID, req request.ArticleCategoriesQueryRequest, authToken string) (articleCategoriess []*response.ArticleCategoriesResponse, paging paginator.Pagination, err error) { +func (_i *articleCategoriesService) All(authToken string, req request.ArticleCategoriesQueryRequest) (articleCategoriess []*response.ArticleCategoriesResponse, paging paginator.Pagination, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) if createdBy != nil { if createdBy.UserLevel.LevelNumber > 1 { @@ -82,7 +92,17 @@ func (_i *articleCategoriesService) All(clientId *uuid.UUID, req request.Article return } -func (_i *articleCategoriesService) Show(clientId *uuid.UUID, id uint) (articleCategories *response.ArticleCategoriesResponse, err error) { +func (_i *articleCategoriesService) Show(authToken string, id uint) (articleCategories *response.ArticleCategoriesResponse, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOne(clientId, id) if err != nil { return nil, err @@ -91,7 +111,17 @@ func (_i *articleCategoriesService) Show(clientId *uuid.UUID, id uint) (articleC return mapper.ArticleCategoriesResponseMapper(result, host), nil } -func (_i *articleCategoriesService) ShowByOldId(clientId *uuid.UUID, id uint) (articleCategories *response.ArticleCategoriesResponse, err error) { +func (_i *articleCategoriesService) ShowByOldId(authToken string, id uint) (articleCategories *response.ArticleCategoriesResponse, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOneByOldId(clientId, id) if err != nil { return nil, err @@ -100,7 +130,17 @@ func (_i *articleCategoriesService) ShowByOldId(clientId *uuid.UUID, id uint) (a return mapper.ArticleCategoriesResponseMapper(result, host), nil } -func (_i *articleCategoriesService) ShowBySlug(clientId *uuid.UUID, slug string) (articleCategories *response.ArticleCategoriesResponse, err error) { +func (_i *articleCategoriesService) ShowBySlug(authToken string, slug string) (articleCategories *response.ArticleCategoriesResponse, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOneBySlug(clientId, slug) if err != nil { return nil, err @@ -109,7 +149,17 @@ func (_i *articleCategoriesService) ShowBySlug(clientId *uuid.UUID, slug string) return mapper.ArticleCategoriesResponseMapper(result, host), nil } -func (_i *articleCategoriesService) Save(clientId *uuid.UUID, req request.ArticleCategoriesCreateRequest, authToken string) (articleCategories *entity.ArticleCategories, err error) { +func (_i *articleCategoriesService) Save(authToken string, req request.ArticleCategoriesCreateRequest) (articleCategories *entity.ArticleCategories, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + _i.Log.Info().Interface("data", req).Msg("") newReq := req.ToEntity() @@ -131,7 +181,17 @@ func (_i *articleCategoriesService) Save(clientId *uuid.UUID, req request.Articl return _i.Repo.Create(newReq) } -func (_i *articleCategoriesService) SaveThumbnail(clientId *uuid.UUID, c *fiber.Ctx) (err error) { +func (_i *articleCategoriesService) SaveThumbnail(authToken string, c *fiber.Ctx) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + id, err := strconv.ParseUint(c.Params("id"), 10, 0) if err != nil { return err @@ -195,7 +255,17 @@ func (_i *articleCategoriesService) SaveThumbnail(clientId *uuid.UUID, c *fiber. return } -func (_i *articleCategoriesService) Update(clientId *uuid.UUID, id uint, req request.ArticleCategoriesUpdateRequest) (err error) { +func (_i *articleCategoriesService) Update(authToken string, id uint, req request.ArticleCategoriesUpdateRequest) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + _i.Log.Info().Interface("data", req).Msg("") newReq := req.ToEntity() @@ -213,7 +283,17 @@ func (_i *articleCategoriesService) Update(clientId *uuid.UUID, id uint, req req return _i.Repo.Update(clientId, id, newReq) } -func (_i *articleCategoriesService) Delete(clientId *uuid.UUID, id uint) error { +func (_i *articleCategoriesService) Delete(authToken string, id uint) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOne(clientId, id) if err != nil { return err diff --git a/app/module/article_files/controller/article_files.controller.go b/app/module/article_files/controller/article_files.controller.go index 33f9271..d19169e 100644 --- a/app/module/article_files/controller/article_files.controller.go +++ b/app/module/article_files/controller/article_files.controller.go @@ -2,7 +2,6 @@ package controller import ( "fmt" - "netidhub-saas-be/app/middleware" "netidhub-saas-be/app/module/article_files/request" "netidhub-saas-be/app/module/article_files/service" "netidhub-saas-be/utils/paginator" @@ -11,10 +10,12 @@ import ( "strconv" "github.com/gofiber/fiber/v2" + "github.com/rs/zerolog" ) type articleFilesController struct { articleFilesService service.ArticleFilesService + Log zerolog.Logger } type ArticleFilesController interface { @@ -27,9 +28,10 @@ type ArticleFilesController interface { GetUploadStatus(c *fiber.Ctx) error } -func NewArticleFilesController(articleFilesService service.ArticleFilesService) ArticleFilesController { +func NewArticleFilesController(articleFilesService service.ArticleFilesService, log zerolog.Logger) ArticleFilesController { return &articleFilesController{ articleFilesService: articleFilesService, + Log: log, } } @@ -38,7 +40,7 @@ func NewArticleFilesController(articleFilesService service.ArticleFilesService) // @Description API for getting all ArticleFiles // @Tags Article Files // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param req query request.ArticleFilesQueryRequest false "query parameters" // @Param req query paginator.Pagination false "pagination parameters" // @Success 200 {object} response.Response @@ -47,8 +49,9 @@ func NewArticleFilesController(articleFilesService service.ArticleFilesService) // @Failure 500 {object} response.InternalServerError // @Router /article-files [get] func (_i *articleFilesController) All(c *fiber.Ctx) error { - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") paginate, err := paginator.Paginate(c) if err != nil { @@ -64,7 +67,7 @@ func (_i *articleFilesController) All(c *fiber.Ctx) error { req := reqContext.ToParamRequest() req.Pagination = paginate - articleFilesData, paging, err := _i.articleFilesService.All(clientId, req) + articleFilesData, paging, err := _i.articleFilesService.All(authToken, req) if err != nil { return err } @@ -82,7 +85,7 @@ func (_i *articleFilesController) All(c *fiber.Ctx) error { // @Description API for getting one ArticleFiles // @Tags Article Files // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "ArticleFiles ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -90,15 +93,16 @@ func (_i *articleFilesController) All(c *fiber.Ctx) error { // @Failure 500 {object} response.InternalServerError // @Router /article-files/{id} [get] func (_i *articleFilesController) Show(c *fiber.Ctx) error { - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") id, err := strconv.ParseUint(c.Params("id"), 10, 0) if err != nil { return err } - articleFilesData, err := _i.articleFilesService.Show(clientId, uint(id)) + articleFilesData, err := _i.articleFilesService.Show(authToken, uint(id)) if err != nil { return err } @@ -116,8 +120,7 @@ func (_i *articleFilesController) Show(c *fiber.Ctx) error { // @Tags Article Files // @Security Bearer // @Produce json -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param files formData file true "Upload file" multiple true // @Param articleId path int true "Article ID" // @Success 200 {object} response.Response @@ -126,15 +129,16 @@ func (_i *articleFilesController) Show(c *fiber.Ctx) error { // @Failure 500 {object} response.InternalServerError // @Router /article-files/{articleId} [post] func (_i *articleFilesController) Save(c *fiber.Ctx) error { - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") id, err := strconv.ParseUint(c.Params("articleId"), 10, 0) if err != nil { return err } - err = _i.articleFilesService.Save(clientId, c, uint(id)) + err = _i.articleFilesService.Save(authToken, c, uint(id)) if err != nil { return err } @@ -150,8 +154,7 @@ func (_i *articleFilesController) Save(c *fiber.Ctx) error { // @Description API for update ArticleFiles // @Tags Article Files // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param payload body request.ArticleFilesUpdateRequest true "Required payload" // @Param id path int true "ArticleFiles ID" // @Success 200 {object} response.Response @@ -160,8 +163,9 @@ func (_i *articleFilesController) Save(c *fiber.Ctx) error { // @Failure 500 {object} response.InternalServerError // @Router /article-files/{id} [put] func (_i *articleFilesController) Update(c *fiber.Ctx) error { - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") id, err := strconv.ParseUint(c.Params("id"), 10, 0) if err != nil { @@ -173,7 +177,7 @@ func (_i *articleFilesController) Update(c *fiber.Ctx) error { return err } - err = _i.articleFilesService.Update(clientId, uint(id), *req) + err = _i.articleFilesService.Update(authToken, uint(id), *req) if err != nil { return err } @@ -189,8 +193,7 @@ func (_i *articleFilesController) Update(c *fiber.Ctx) error { // @Description API for delete ArticleFiles // @Tags Article Files // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "ArticleFiles ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -198,15 +201,16 @@ func (_i *articleFilesController) Update(c *fiber.Ctx) error { // @Failure 500 {object} response.InternalServerError // @Router /article-files/{id} [delete] func (_i *articleFilesController) Delete(c *fiber.Ctx) error { - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") id, err := strconv.ParseUint(c.Params("id"), 10, 0) if err != nil { return err } - err = _i.articleFilesService.Delete(clientId, uint(id)) + err = _i.articleFilesService.Delete(authToken, uint(id)) if err != nil { return err } @@ -222,7 +226,7 @@ func (_i *articleFilesController) Delete(c *fiber.Ctx) error { // @Description API for Viewer ArticleFiles // @Tags Article Files // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param filename path string true "Article File Name" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -230,10 +234,11 @@ func (_i *articleFilesController) Delete(c *fiber.Ctx) error { // @Failure 500 {object} response.InternalServerError // @Router /article-files/viewer/{filename} [get] func (_i *articleFilesController) Viewer(c *fiber.Ctx) error { - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - return _i.articleFilesService.Viewer(clientId, c) + return _i.articleFilesService.Viewer(authToken, c) } // GetUploadStatus ArticleFiles diff --git a/app/module/article_files/controller/controller.go b/app/module/article_files/controller/controller.go index cfbf501..0ac9fa3 100644 --- a/app/module/article_files/controller/controller.go +++ b/app/module/article_files/controller/controller.go @@ -1,13 +1,16 @@ package controller -import "netidhub-saas-be/app/module/article_files/service" +import ( + "github.com/rs/zerolog" + "netidhub-saas-be/app/module/article_files/service" +) type Controller struct { ArticleFiles ArticleFilesController } -func NewController(ArticleFilesService service.ArticleFilesService) *Controller { +func NewController(ArticleFilesService service.ArticleFilesService, log zerolog.Logger) *Controller { return &Controller{ - ArticleFiles: NewArticleFilesController(ArticleFilesService), + ArticleFiles: NewArticleFilesController(ArticleFilesService, log), } } diff --git a/app/module/article_files/service/article_files.service.go b/app/module/article_files/service/article_files.service.go index 45dd437..027d956 100644 --- a/app/module/article_files/service/article_files.service.go +++ b/app/module/article_files/service/article_files.service.go @@ -16,9 +16,11 @@ import ( "netidhub-saas-be/app/module/article_files/repository" "netidhub-saas-be/app/module/article_files/request" "netidhub-saas-be/app/module/article_files/response" + usersRepository "netidhub-saas-be/app/module/users/repository" config "netidhub-saas-be/config/config" minioStorage "netidhub-saas-be/config/config" "netidhub-saas-be/utils/paginator" + utilSvc "netidhub-saas-be/utils/service" "os" "path/filepath" "strconv" @@ -30,6 +32,7 @@ import ( // ArticleFilesService type articleFilesService struct { Repo repository.ArticleFilesRepository + UsersRepo usersRepository.UsersRepository Log zerolog.Logger Cfg *config.Config MinioStorage *minioStorage.MinioStorage @@ -37,21 +40,22 @@ type articleFilesService struct { // ArticleFilesService define interface of IArticleFilesService type ArticleFilesService interface { - All(clientId *uuid.UUID, req request.ArticleFilesQueryRequest) (articleFiles []*response.ArticleFilesResponse, paging paginator.Pagination, err error) - Show(clientId *uuid.UUID, id uint) (articleFiles *response.ArticleFilesResponse, err error) - Save(clientId *uuid.UUID, c *fiber.Ctx, id uint) error - SaveAsync(clientId *uuid.UUID, c *fiber.Ctx, id uint) error - Update(clientId *uuid.UUID, id uint, req request.ArticleFilesUpdateRequest) (err error) + All(authToken string, req request.ArticleFilesQueryRequest) (articleFiles []*response.ArticleFilesResponse, paging paginator.Pagination, err error) + Show(authToken string, id uint) (articleFiles *response.ArticleFilesResponse, err error) + Save(authToken string, c *fiber.Ctx, id uint) error + SaveAsync(authToken string, c *fiber.Ctx, id uint) error + Update(authToken string, id uint, req request.ArticleFilesUpdateRequest) (err error) GetUploadStatus(c *fiber.Ctx) (progress int, err error) - Delete(clientId *uuid.UUID, id uint) error - Viewer(clientId *uuid.UUID, c *fiber.Ctx) error + Delete(authToken string, id uint) error + Viewer(authToken string, c *fiber.Ctx) error } // NewArticleFilesService init ArticleFilesService -func NewArticleFilesService(repo repository.ArticleFilesRepository, log zerolog.Logger, cfg *config.Config, minioStorage *minioStorage.MinioStorage) ArticleFilesService { +func NewArticleFilesService(repo repository.ArticleFilesRepository, log zerolog.Logger, cfg *config.Config, minioStorage *minioStorage.MinioStorage, usersRepo usersRepository.UsersRepository) ArticleFilesService { return &articleFilesService{ Repo: repo, + UsersRepo: usersRepo, Log: log, Cfg: cfg, MinioStorage: minioStorage, @@ -70,7 +74,17 @@ type progressWriter struct { } // All implement interface of ArticleFilesService -func (_i *articleFilesService) All(clientId *uuid.UUID, req request.ArticleFilesQueryRequest) (articleFiless []*response.ArticleFilesResponse, paging paginator.Pagination, err error) { +func (_i *articleFilesService) All(authToken string, req request.ArticleFilesQueryRequest) (articleFiless []*response.ArticleFilesResponse, paging paginator.Pagination, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + results, paging, err := _i.Repo.GetAll(clientId, req) if err != nil { return @@ -85,7 +99,17 @@ func (_i *articleFilesService) All(clientId *uuid.UUID, req request.ArticleFiles return } -func (_i *articleFilesService) Show(clientId *uuid.UUID, id uint) (articleFiles *response.ArticleFilesResponse, err error) { +func (_i *articleFilesService) Show(authToken string, id uint) (articleFiles *response.ArticleFilesResponse, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOne(clientId, id) if err != nil { return nil, err @@ -96,7 +120,17 @@ func (_i *articleFilesService) Show(clientId *uuid.UUID, id uint) (articleFiles return mapper.ArticleFilesResponseMapper(result, host), nil } -func (_i *articleFilesService) SaveAsync(clientId *uuid.UUID, c *fiber.Ctx, id uint) (err error) { +func (_i *articleFilesService) SaveAsync(authToken string, c *fiber.Ctx, id uint) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + bucketName := _i.MinioStorage.Cfg.ObjectStorage.MinioStorage.BucketName ctx := context.Background() @@ -195,7 +229,17 @@ func (_i *articleFilesService) SaveAsync(clientId *uuid.UUID, c *fiber.Ctx, id u return } -func (_i *articleFilesService) Save(clientId *uuid.UUID, c *fiber.Ctx, id uint) (err error) { +func (_i *articleFilesService) Save(authToken string, c *fiber.Ctx, id uint) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + bucketName := _i.MinioStorage.Cfg.ObjectStorage.MinioStorage.BucketName form, err := c.MultipartForm() @@ -277,12 +321,32 @@ func (_i *articleFilesService) Save(clientId *uuid.UUID, c *fiber.Ctx, id uint) return } -func (_i *articleFilesService) Update(clientId *uuid.UUID, id uint, req request.ArticleFilesUpdateRequest) (err error) { +func (_i *articleFilesService) Update(authToken string, id uint, req request.ArticleFilesUpdateRequest) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + _i.Log.Info().Interface("data", req).Msg("") return _i.Repo.Update(clientId, id, req.ToEntity()) } -func (_i *articleFilesService) Delete(clientId *uuid.UUID, id uint) error { +func (_i *articleFilesService) Delete(authToken string, id uint) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOne(clientId, id) if err != nil { return err @@ -291,7 +355,17 @@ func (_i *articleFilesService) Delete(clientId *uuid.UUID, id uint) error { return _i.Repo.Update(clientId, id, result) } -func (_i *articleFilesService) Viewer(clientId *uuid.UUID, c *fiber.Ctx) (err error) { +func (_i *articleFilesService) Viewer(authToken string, c *fiber.Ctx) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + filename := c.Params("filename") result, err := _i.Repo.FindByFilename(clientId, filename) if err != nil { diff --git a/app/module/articles/controller/articles.controller.go b/app/module/articles/controller/articles.controller.go index 86c24f3..82470d4 100644 --- a/app/module/articles/controller/articles.controller.go +++ b/app/module/articles/controller/articles.controller.go @@ -1,7 +1,6 @@ package controller import ( - "netidhub-saas-be/app/middleware" "netidhub-saas-be/app/module/articles/request" "netidhub-saas-be/app/module/articles/service" "netidhub-saas-be/utils/paginator" @@ -53,7 +52,6 @@ func NewArticlesController(articlesService service.ArticlesService, log zerolog. // @Description API for getting all Articles // @Tags Articles // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param req query request.ArticlesQueryRequest false "query parameters" // @Param req query paginator.Pagination false "pagination parameters" @@ -83,15 +81,11 @@ func (_i *articlesController) All(c *fiber.Ctx) error { req := reqContext.ToParamRequest() req.Pagination = paginate - // Get ClientId from context - clientId := middleware.GetClientID(c) - // Get Authorization token from header authToken := c.Get("Authorization") - _i.Log.Info().Interface("clientId", clientId).Msg("") _i.Log.Info().Str("authToken", authToken).Msg("") - articlesData, paging, err := _i.articlesService.All(clientId, authToken, req) + articlesData, paging, err := _i.articlesService.All(authToken, req) if err != nil { return err } @@ -109,8 +103,7 @@ func (_i *articlesController) All(c *fiber.Ctx) error { // @Description API for getting one Articles // @Tags Articles // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" -// @Param id path int true "Articles ID" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError // @Failure 401 {object} response.UnauthorizedError @@ -122,10 +115,11 @@ func (_i *articlesController) Show(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - articlesData, err := _i.articlesService.Show(clientId, uint(id)) + articlesData, err := _i.articlesService.Show(authToken, uint(id)) if err != nil { return err } @@ -142,8 +136,7 @@ func (_i *articlesController) Show(c *fiber.Ctx) error { // @Description API for getting one Articles // @Tags Articles // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" -// @Param id path int true "Articles Old ID" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError // @Failure 401 {object} response.UnauthorizedError @@ -155,10 +148,11 @@ func (_i *articlesController) ShowByOldId(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - articlesData, err := _i.articlesService.ShowByOldId(clientId, uint(id)) + articlesData, err := _i.articlesService.ShowByOldId(authToken, uint(id)) if err != nil { return err } @@ -175,8 +169,6 @@ func (_i *articlesController) ShowByOldId(c *fiber.Ctx) error { // @Description API for create Articles // @Tags Articles // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param payload body request.ArticlesCreateRequest true "Required payload" // @Success 200 {object} response.Response @@ -190,15 +182,11 @@ func (_i *articlesController) Save(c *fiber.Ctx) error { return err } + // Get Authorization token from header authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - // Get ClientId from context - clientId := middleware.GetClientID(c) - - _i.Log.Info().Interface("clientId", clientId).Msg("") - _i.Log.Info().Interface("authToken", authToken).Msg("") - - dataResult, err := _i.articlesService.Save(clientId, *req, authToken) + dataResult, err := _i.articlesService.Save(authToken, *req) if err != nil { return err } @@ -216,9 +204,7 @@ func (_i *articlesController) Save(c *fiber.Ctx) error { // @Tags Articles // @Security Bearer // @Produce json -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" -// @Param files formData file true "Upload thumbnail" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "Articles ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -226,10 +212,11 @@ func (_i *articlesController) Save(c *fiber.Ctx) error { // @Failure 500 {object} response.InternalServerError // @Router /articles/thumbnail/{id} [post] func (_i *articlesController) SaveThumbnail(c *fiber.Ctx) error { - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - err := _i.articlesService.SaveThumbnail(clientId, c) + err := _i.articlesService.SaveThumbnail(authToken, c) if err != nil { return err } @@ -245,9 +232,7 @@ func (_i *articlesController) SaveThumbnail(c *fiber.Ctx) error { // @Description API for update Articles // @Tags Articles // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" -// @Param payload body request.ArticlesUpdateRequest true "Required payload" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "Articles ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -265,10 +250,11 @@ func (_i *articlesController) Update(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - err = _i.articlesService.Update(clientId, uint(id), *req) + err = _i.articlesService.Update(authToken, uint(id), *req) if err != nil { return err } @@ -284,8 +270,7 @@ func (_i *articlesController) Update(c *fiber.Ctx) error { // @Description API for Update Banner Articles // @Tags Articles // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "Articles ID" // @Param isBanner query bool true "Articles Banner Status" // @Success 200 {object} response.Response @@ -304,10 +289,11 @@ func (_i *articlesController) UpdateBanner(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - err = _i.articlesService.UpdateBanner(clientId, uint(id), isBanner) + err = _i.articlesService.UpdateBanner(authToken, uint(id), isBanner) if err != nil { return err } @@ -323,8 +309,7 @@ func (_i *articlesController) UpdateBanner(c *fiber.Ctx) error { // @Description API for delete Articles // @Tags Articles // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "Articles ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -337,10 +322,11 @@ func (_i *articlesController) Delete(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - err = _i.articlesService.Delete(clientId, uint(id)) + err = _i.articlesService.Delete(authToken, uint(id)) if err != nil { return err } @@ -356,7 +342,7 @@ func (_i *articlesController) Delete(c *fiber.Ctx) error { // @Description API for View Thumbnail of Article // @Tags Articles // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param thumbnailName path string true "Articles Thumbnail Name" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -364,10 +350,11 @@ func (_i *articlesController) Delete(c *fiber.Ctx) error { // @Failure 500 {object} response.InternalServerError // @Router /articles/thumbnail/viewer/{thumbnailName} [get] func (_i *articlesController) Viewer(c *fiber.Ctx) error { - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - return _i.articlesService.Viewer(clientId, c) + return _i.articlesService.Viewer(authToken, c) } // SummaryStats Articles @@ -382,12 +369,11 @@ func (_i *articlesController) Viewer(c *fiber.Ctx) error { // @Failure 500 {object} response.InternalServerError // @Router /articles/statistic/summary [get] func (_i *articlesController) SummaryStats(c *fiber.Ctx) error { + // Get Authorization token from header authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - // Get ClientId from context - clientId := middleware.GetClientID(c) - - response, err := _i.articlesService.SummaryStats(clientId, authToken) + response, err := _i.articlesService.SummaryStats(authToken) if err != nil { return err } @@ -413,14 +399,14 @@ func (_i *articlesController) SummaryStats(c *fiber.Ctx) error { // @Failure 500 {object} response.InternalServerError // @Router /articles/statistic/user-levels [get] func (_i *articlesController) ArticlePerUserLevelStats(c *fiber.Ctx) error { + // Get Authorization token from header authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") + startDate := c.Query("startDate") endDate := c.Query("endDate") - // Get ClientId from context - clientId := middleware.GetClientID(c) - - response, err := _i.articlesService.ArticlePerUserLevelStats(clientId, authToken, &startDate, &endDate) + response, err := _i.articlesService.ArticlePerUserLevelStats(authToken, &startDate, &endDate) if err != nil { return err } @@ -445,17 +431,17 @@ func (_i *articlesController) ArticlePerUserLevelStats(c *fiber.Ctx) error { // @Failure 500 {object} response.InternalServerError // @Router /articles/statistic/monthly [get] func (_i *articlesController) ArticleMonthlyStats(c *fiber.Ctx) error { + // Get Authorization token from header authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") + year := c.Query("year") yearInt, err := strconv.Atoi(year) if err != nil { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) - - response, err := _i.articlesService.ArticleMonthlyStats(clientId, authToken, &yearInt) + response, err := _i.articlesService.ArticleMonthlyStats(authToken, &yearInt) if err != nil { return err } @@ -472,8 +458,7 @@ func (_i *articlesController) ArticleMonthlyStats(c *fiber.Ctx) error { // @Description API for Publish Schedule of Article // @Tags Articles // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id query int false "article id" // @Param date query string false "publish date" @@ -489,10 +474,11 @@ func (_i *articlesController) PublishScheduling(c *fiber.Ctx) error { } date := c.Query("date") - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - err = _i.articlesService.PublishScheduling(clientId, uint(id), date) + err = _i.articlesService.PublishScheduling(authToken, uint(id), date) if err != nil { return err } @@ -508,8 +494,7 @@ func (_i *articlesController) PublishScheduling(c *fiber.Ctx) error { // @Description API for submitting article for approval workflow // @Tags Articles // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "article id" // @Param req body request.SubmitForApprovalRequest false "approval request data" @@ -529,13 +514,11 @@ func (_i *articlesController) SubmitForApproval(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) - // Get Authorization token from header authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - err = _i.articlesService.SubmitForApproval(clientId, uint(id), authToken, req.WorkflowId) + err = _i.articlesService.SubmitForApproval(authToken, uint(id), req.WorkflowId) if err != nil { return err } @@ -551,7 +534,7 @@ func (_i *articlesController) SubmitForApproval(c *fiber.Ctx) error { // @Description API for getting article approval status and workflow progress // @Tags Articles // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "article id" // @Success 200 {object} response.Response @@ -565,10 +548,11 @@ func (_i *articlesController) GetApprovalStatus(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - response, err := _i.articlesService.GetApprovalStatus(clientId, uint(id)) + response, err := _i.articlesService.GetApprovalStatus(authToken, uint(id)) if err != nil { return err } @@ -585,7 +569,7 @@ func (_i *articlesController) GetApprovalStatus(c *fiber.Ctx) error { // @Description API for getting articles pending approval for current user level // @Tags Articles // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param page query int false "page number" // @Param limit query int false "items per page" @@ -614,13 +598,11 @@ func (_i *articlesController) GetPendingApprovals(c *fiber.Ctx) error { } } - // Get ClientId from context - clientId := middleware.GetClientID(c) - // Get Authorization token from header authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - response, paging, err := _i.articlesService.GetPendingApprovals(clientId, authToken, page, limit, typeId) // Updated with typeId filter + response, paging, err := _i.articlesService.GetPendingApprovals(authToken, page, limit, typeId) // Updated with typeId filter if err != nil { return err } @@ -638,7 +620,7 @@ func (_i *articlesController) GetPendingApprovals(c *fiber.Ctx) error { // @Description API for getting articles that are waiting for approval by the current user's level // @Tags Articles // @Security Bearer -// @Param X-Client-Key header string true "Client Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param page query int false "Page number" default(1) // @Param limit query int false "Items per page" default(10) @@ -658,13 +640,11 @@ func (_i *articlesController) GetArticlesWaitingForApproval(c *fiber.Ctx) error return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) - // Get Authorization token from header authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - responses, paging, err := _i.articlesService.GetArticlesWaitingForApproval(clientId, authToken, page, limit) + responses, paging, err := _i.articlesService.GetArticlesWaitingForApproval(authToken, page, limit) if err != nil { return err } diff --git a/app/module/articles/service/articles.service.go b/app/module/articles/service/articles.service.go index 8091d1e..7f2cfd8 100644 --- a/app/module/articles/service/articles.service.go +++ b/app/module/articles/service/articles.service.go @@ -55,34 +55,34 @@ type articlesService struct { // ArticlesService define interface of IArticlesService type ArticlesService interface { - All(clientId *uuid.UUID, authToken string, req request.ArticlesQueryRequest) (articles []*response.ArticlesResponse, paging paginator.Pagination, err error) - Show(clientId *uuid.UUID, id uint) (articles *response.ArticlesResponse, err error) - ShowByOldId(clientId *uuid.UUID, oldId uint) (articles *response.ArticlesResponse, err error) - Save(clientId *uuid.UUID, req request.ArticlesCreateRequest, authToken string) (articles *entity.Articles, err error) - SaveThumbnail(clientId *uuid.UUID, c *fiber.Ctx) (err error) - Update(clientId *uuid.UUID, id uint, req request.ArticlesUpdateRequest) (err error) - Delete(clientId *uuid.UUID, id uint) error - UpdateActivityCount(clientId *uuid.UUID, id uint, activityTypeId int) (err error) - UpdateApproval(clientId *uuid.UUID, id uint, statusId int, userLevelId int, userLevelNumber int, userParentLevelId int) (err error) - UpdateBanner(clientId *uuid.UUID, id uint, isBanner bool) error - Viewer(clientId *uuid.UUID, c *fiber.Ctx) error - SummaryStats(clientId *uuid.UUID, authToken string) (summaryStats *response.ArticleSummaryStats, err error) - ArticlePerUserLevelStats(clientId *uuid.UUID, authToken string, startDate *string, endDate *string) (articlePerUserLevelStats []*response.ArticlePerUserLevelStats, err error) - ArticleMonthlyStats(clientId *uuid.UUID, authToken string, year *int) (articleMonthlyStats []*response.ArticleMonthlyStats, err error) - PublishScheduling(clientId *uuid.UUID, id uint, publishSchedule string) error + All(authToken string, req request.ArticlesQueryRequest) (articles []*response.ArticlesResponse, paging paginator.Pagination, err error) + Show(authToken string, id uint) (articles *response.ArticlesResponse, err error) + ShowByOldId(authToken string, oldId uint) (articles *response.ArticlesResponse, err error) + Save(authToken string, req request.ArticlesCreateRequest) (articles *entity.Articles, err error) + SaveThumbnail(authToken string, c *fiber.Ctx) (err error) + Update(authToken string, id uint, req request.ArticlesUpdateRequest) (err error) + Delete(authToken string, id uint) error + UpdateActivityCount(authToken string, id uint, activityTypeId int) (err error) + UpdateApproval(authToken string, id uint, statusId int, userLevelId int, userLevelNumber int, userParentLevelId int) (err error) + UpdateBanner(authToken string, id uint, isBanner bool) error + Viewer(authToken string, c *fiber.Ctx) error + SummaryStats(authToken string) (summaryStats *response.ArticleSummaryStats, err error) + ArticlePerUserLevelStats(authToken string, startDate *string, endDate *string) (articlePerUserLevelStats []*response.ArticlePerUserLevelStats, err error) + ArticleMonthlyStats(authToken string, year *int) (articleMonthlyStats []*response.ArticleMonthlyStats, err error) + PublishScheduling(authToken string, id uint, publishSchedule string) error ExecuteScheduling() error // Dynamic approval system methods - SubmitForApproval(clientId *uuid.UUID, articleId uint, authToken string, workflowId *uint) error - GetApprovalStatus(clientId *uuid.UUID, articleId uint) (*response.ArticleApprovalStatusResponse, error) - GetArticlesWaitingForApproval(clientId *uuid.UUID, authToken string, page, limit int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error) - GetPendingApprovals(clientId *uuid.UUID, authToken string, page, limit int, typeId *int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error) // Updated with typeId filter + SubmitForApproval(authToken string, articleId uint, workflowId *uint) error + GetApprovalStatus(authToken string, articleId uint) (*response.ArticleApprovalStatusResponse, error) + GetArticlesWaitingForApproval(authToken string, page, limit int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error) + GetPendingApprovals(authToken string, page, limit int, typeId *int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error) // Updated with typeId filter // No-approval system methods - CheckApprovalRequired(clientId *uuid.UUID, articleId uint, userId uint, userLevelId uint) (bool, error) - AutoApproveArticle(clientId *uuid.UUID, articleId uint, reason string) error - GetClientApprovalSettings(clientId *uuid.UUID) (*response.ClientApprovalSettingsResponse, error) - SetArticleApprovalExempt(clientId *uuid.UUID, articleId uint, exempt bool, reason string) error + CheckApprovalRequired(authToken string, articleId uint, userId uint, userLevelId uint) (bool, error) + AutoApproveArticle(authToken string, articleId uint, reason string) error + GetClientApprovalSettings(authToken string) (*response.ClientApprovalSettingsResponse, error) + SetArticleApprovalExempt(authToken string, articleId uint, exempt bool, reason string) error } // NewArticlesService init ArticlesService @@ -116,12 +116,17 @@ func NewArticlesService( } // All implement interface of ArticlesService -func (_i *articlesService) All(clientId *uuid.UUID, authToken string, req request.ArticlesQueryRequest) (articless []*response.ArticlesResponse, paging paginator.Pagination, err error) { - // Extract userLevelId from authToken +func (_i *articlesService) All(authToken string, req request.ArticlesQueryRequest) (articless []*response.ArticlesResponse, paging paginator.Pagination, err error) { + // Extract clientId and userLevelId from authToken + var clientId *uuid.UUID var userLevelId *uint if authToken != "" { user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) if user != nil { + if user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } userLevelId = &user.UserLevelId _i.Log.Info().Interface("userLevelId", userLevelId).Msg("Extracted userLevelId from auth token") } @@ -154,7 +159,17 @@ func (_i *articlesService) All(clientId *uuid.UUID, authToken string, req reques return } -func (_i *articlesService) Show(clientId *uuid.UUID, id uint) (articles *response.ArticlesResponse, err error) { +func (_i *articlesService) Show(authToken string, id uint) (articles *response.ArticlesResponse, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOne(clientId, id) if err != nil { return nil, err @@ -165,7 +180,17 @@ func (_i *articlesService) Show(clientId *uuid.UUID, id uint) (articles *respons return mapper.ArticlesResponseMapper(_i.Log, host, clientId, result, _i.ArticleCategoriesRepo, _i.ArticleCategoryDetailsRepo, _i.ArticleFilesRepo, _i.UsersRepo), nil } -func (_i *articlesService) ShowByOldId(clientId *uuid.UUID, oldId uint) (articles *response.ArticlesResponse, err error) { +func (_i *articlesService) ShowByOldId(authToken string, oldId uint) (articles *response.ArticlesResponse, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindByOldId(clientId, oldId) if err != nil { return nil, err @@ -176,10 +201,20 @@ func (_i *articlesService) ShowByOldId(clientId *uuid.UUID, oldId uint) (article return mapper.ArticlesResponseMapper(_i.Log, host, clientId, result, _i.ArticleCategoriesRepo, _i.ArticleCategoryDetailsRepo, _i.ArticleFilesRepo, _i.UsersRepo), nil } -func (_i *articlesService) Save(clientId *uuid.UUID, req request.ArticlesCreateRequest, authToken string) (articles *entity.Articles, err error) { +func (_i *articlesService) Save(authToken string, req request.ArticlesCreateRequest) (articles *entity.Articles, err error) { _i.Log.Info().Interface("data", req).Msg("") newReq := req.ToEntity() + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + var userLevelNumber int var approvalLevelId int if req.CreatedById != nil { @@ -359,7 +394,16 @@ func (_i *articlesService) Save(clientId *uuid.UUID, req request.ArticlesCreateR return saveArticleRes, nil } -func (_i *articlesService) SaveThumbnail(clientId *uuid.UUID, c *fiber.Ctx) (err error) { +func (_i *articlesService) SaveThumbnail(authToken string, c *fiber.Ctx) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } id, err := strconv.ParseUint(c.Params("id"), 10, 0) if err != nil { @@ -432,10 +476,20 @@ func (_i *articlesService) SaveThumbnail(clientId *uuid.UUID, c *fiber.Ctx) (err return } -func (_i *articlesService) Update(clientId *uuid.UUID, id uint, req request.ArticlesUpdateRequest) (err error) { +func (_i *articlesService) Update(authToken string, id uint, req request.ArticlesUpdateRequest) (err error) { _i.Log.Info().Interface("data", req).Msg("") newReq := req.ToEntity() + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + if req.CreatedAt != nil { layout := "2006-01-02 15:04:05" parsedTime, err := time.Parse(layout, *req.CreatedAt) @@ -448,11 +502,31 @@ func (_i *articlesService) Update(clientId *uuid.UUID, id uint, req request.Arti return _i.Repo.UpdateSkipNull(clientId, id, newReq) } -func (_i *articlesService) Delete(clientId *uuid.UUID, id uint) error { +func (_i *articlesService) Delete(authToken string, id uint) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + return _i.Repo.Delete(clientId, id) } -func (_i *articlesService) Viewer(clientId *uuid.UUID, c *fiber.Ctx) (err error) { +func (_i *articlesService) Viewer(authToken string, c *fiber.Ctx) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + thumbnailName := c.Params("thumbnailName") emptyImage := "empty-image.jpg" @@ -513,7 +587,17 @@ func (_i *articlesService) Viewer(clientId *uuid.UUID, c *fiber.Ctx) (err error) return } -func (_i *articlesService) UpdateActivityCount(clientId *uuid.UUID, id uint, activityTypeId int) error { +func (_i *articlesService) UpdateActivityCount(authToken string, id uint, activityTypeId int) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOne(clientId, id) if err != nil { return err @@ -545,7 +629,17 @@ func (_i *articlesService) UpdateActivityCount(clientId *uuid.UUID, id uint, act return _i.Repo.Update(clientId, id, result) } -func (_i *articlesService) SummaryStats(clientId *uuid.UUID, authToken string) (summaryStats *response.ArticleSummaryStats, err error) { +func (_i *articlesService) SummaryStats(authToken string) (summaryStats *response.ArticleSummaryStats, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) result, err := _i.Repo.SummaryStats(clientId, user.ID) @@ -555,7 +649,17 @@ func (_i *articlesService) SummaryStats(clientId *uuid.UUID, authToken string) ( return result, nil } -func (_i *articlesService) ArticlePerUserLevelStats(clientId *uuid.UUID, authToken string, startDate *string, endDate *string) (articlePerUserLevelStats []*response.ArticlePerUserLevelStats, err error) { +func (_i *articlesService) ArticlePerUserLevelStats(authToken string, startDate *string, endDate *string) (articlePerUserLevelStats []*response.ArticlePerUserLevelStats, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) _i.Log.Info().Str("timestamp", time.Now(). @@ -587,7 +691,17 @@ func (_i *articlesService) ArticlePerUserLevelStats(clientId *uuid.UUID, authTok return result, nil } -func (_i *articlesService) ArticleMonthlyStats(clientId *uuid.UUID, authToken string, year *int) (articleMonthlyStats []*response.ArticleMonthlyStats, err error) { +func (_i *articlesService) ArticleMonthlyStats(authToken string, year *int) (articleMonthlyStats []*response.ArticleMonthlyStats, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) var userLevelId *uint @@ -605,7 +719,17 @@ func (_i *articlesService) ArticleMonthlyStats(clientId *uuid.UUID, authToken st return result, nil } -func (_i *articlesService) UpdateApproval(clientId *uuid.UUID, id uint, statusId int, userLevelId int, userLevelNumber int, userParentLevelId int) (err error) { +func (_i *articlesService) UpdateApproval(authToken string, id uint, statusId int, userLevelId int, userLevelNumber int, userParentLevelId int) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOne(clientId, id) if err != nil { return err @@ -658,7 +782,17 @@ func (_i *articlesService) UpdateApproval(clientId *uuid.UUID, id uint, statusId return } -func (_i *articlesService) PublishScheduling(clientId *uuid.UUID, id uint, publishSchedule string) error { +func (_i *articlesService) PublishScheduling(authToken string, id uint, publishSchedule string) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOne(clientId, id) if err != nil { return err @@ -667,7 +801,17 @@ func (_i *articlesService) PublishScheduling(clientId *uuid.UUID, id uint, publi return _i.Repo.Update(clientId, id, result) } -func (_i *articlesService) UpdateBanner(clientId *uuid.UUID, id uint, isBanner bool) error { +func (_i *articlesService) UpdateBanner(authToken string, id uint, isBanner bool) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOne(clientId, id) if err != nil { return err @@ -732,7 +876,17 @@ func getFileExtension(filename string) string { } // SubmitForApproval submits an article for approval using the dynamic workflow system -func (_i *articlesService) SubmitForApproval(clientId *uuid.UUID, articleId uint, authToken string, workflowId *uint) error { +func (_i *articlesService) SubmitForApproval(authToken string, articleId uint, workflowId *uint) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + // Extract user info from auth token user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) if user == nil { @@ -793,7 +947,17 @@ func (_i *articlesService) SubmitForApproval(clientId *uuid.UUID, articleId uint } // GetApprovalStatus gets the current approval status of an article -func (_i *articlesService) GetApprovalStatus(clientId *uuid.UUID, articleId uint) (*response.ArticleApprovalStatusResponse, error) { +func (_i *articlesService) GetApprovalStatus(authToken string, articleId uint) (*response.ArticleApprovalStatusResponse, error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + // Check if article exists _, err := _i.Repo.FindOne(clientId, articleId) if err != nil { @@ -872,7 +1036,17 @@ func (_i *articlesService) GetApprovalStatus(clientId *uuid.UUID, articleId uint } // GetPendingApprovals gets articles pending approval for a specific user level -func (_i *articlesService) GetPendingApprovals(clientId *uuid.UUID, authToken string, page, limit int, typeId *int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error) { +func (_i *articlesService) GetPendingApprovals(authToken string, page, limit int, typeId *int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + // Extract user info from auth token user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) if user == nil { @@ -966,7 +1140,17 @@ func (_i *articlesService) GetPendingApprovals(clientId *uuid.UUID, authToken st } // GetArticlesWaitingForApproval gets articles that are waiting for approval by a specific user level -func (_i *articlesService) GetArticlesWaitingForApproval(clientId *uuid.UUID, authToken string, page, limit int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error) { +func (_i *articlesService) GetArticlesWaitingForApproval(authToken string, page, limit int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + // Extract user info from auth token user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) if user == nil { @@ -1006,7 +1190,17 @@ func (_i *articlesService) GetArticlesWaitingForApproval(clientId *uuid.UUID, au } // CheckApprovalRequired checks if an article requires approval based on client settings -func (_i *articlesService) CheckApprovalRequired(clientId *uuid.UUID, articleId uint, userId uint, userLevelId uint) (bool, error) { +func (_i *articlesService) CheckApprovalRequired(authToken string, articleId uint, userId uint, userLevelId uint) (bool, error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + // Get article to check category and other properties article, err := _i.Repo.FindOne(clientId, articleId) if err != nil { @@ -1045,7 +1239,17 @@ func (_i *articlesService) CheckApprovalRequired(clientId *uuid.UUID, articleId } // AutoApproveArticle automatically approves an article (for no-approval scenarios) -func (_i *articlesService) AutoApproveArticle(clientId *uuid.UUID, articleId uint, reason string) error { +func (_i *articlesService) AutoApproveArticle(authToken string, articleId uint, reason string) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + article, err := _i.Repo.FindOne(clientId, articleId) if err != nil { return err @@ -1104,7 +1308,17 @@ func (_i *articlesService) AutoApproveArticle(clientId *uuid.UUID, articleId uin } // GetClientApprovalSettings gets the approval settings for a client -func (_i *articlesService) GetClientApprovalSettings(clientId *uuid.UUID) (*response.ClientApprovalSettingsResponse, error) { +func (_i *articlesService) GetClientApprovalSettings(authToken string) (*response.ClientApprovalSettingsResponse, error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + // This would require the ClientApprovalSettingsService // For now, return default settings return &response.ClientApprovalSettingsResponse{ @@ -1116,7 +1330,17 @@ func (_i *articlesService) GetClientApprovalSettings(clientId *uuid.UUID) (*resp } // SetArticleApprovalExempt sets whether an article is exempt from approval -func (_i *articlesService) SetArticleApprovalExempt(clientId *uuid.UUID, articleId uint, exempt bool, reason string) error { +func (_i *articlesService) SetArticleApprovalExempt(authToken string, articleId uint, exempt bool, reason string) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + updates := map[string]interface{}{ "approval_exempt": &exempt, } diff --git a/app/module/bookmarks/controller/bookmarks.controller.go b/app/module/bookmarks/controller/bookmarks.controller.go index a0e5ff7..4e57366 100644 --- a/app/module/bookmarks/controller/bookmarks.controller.go +++ b/app/module/bookmarks/controller/bookmarks.controller.go @@ -1,7 +1,6 @@ package controller import ( - "netidhub-saas-be/app/middleware" "netidhub-saas-be/app/module/bookmarks/request" "netidhub-saas-be/app/module/bookmarks/service" "netidhub-saas-be/utils/paginator" @@ -41,7 +40,7 @@ func NewBookmarksController(bookmarksService service.BookmarksService, log zerol // @Description API for getting all Bookmarks // @Tags Bookmarks // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param req query request.BookmarksQueryRequest false "query parameters" // @Param req query paginator.Pagination false "pagination parameters" @@ -62,15 +61,11 @@ func (_i *bookmarksController) All(c *fiber.Ctx) error { req := reqContext.ToParamRequest() req.Pagination = paginate - // Get ClientId from context - clientId := middleware.GetClientID(c) - - _i.Log.Info().Interface("clientId", clientId).Msg("") - // Get Authorization token from header authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - bookmarksData, paging, err := _i.bookmarksService.All(clientId, authToken, req) + bookmarksData, paging, err := _i.bookmarksService.All(authToken, req) if err != nil { return err } @@ -88,7 +83,7 @@ func (_i *bookmarksController) All(c *fiber.Ctx) error { // @Description API for getting Bookmark by ID // @Tags Bookmarks // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "Bookmark ID" // @Success 200 {object} response.Response @@ -105,12 +100,11 @@ func (_i *bookmarksController) Show(c *fiber.Ctx) error { }) } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - _i.Log.Info().Interface("clientId", clientId).Msg("") - - bookmarkData, err := _i.bookmarksService.Show(clientId, uint(id)) + bookmarkData, err := _i.bookmarksService.Show(authToken, uint(id)) if err != nil { return err } @@ -127,7 +121,7 @@ func (_i *bookmarksController) Show(c *fiber.Ctx) error { // @Description API for creating new Bookmark // @Tags Bookmarks // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param req body request.BookmarksCreateRequest true "Bookmark data" // @Success 200 {object} response.Response @@ -153,15 +147,11 @@ func (_i *bookmarksController) Save(c *fiber.Ctx) error { }) } - // Get ClientId from context - clientId := middleware.GetClientID(c) - // Get Authorization token from header authToken := c.Get("Authorization") - _i.Log.Info().Interface("clientId", clientId).Msg("") _i.Log.Info().Str("authToken", authToken).Msg("") - bookmarkData, err := _i.bookmarksService.Save(clientId, req, authToken) + bookmarkData, err := _i.bookmarksService.Save(authToken, req) if err != nil { return err } @@ -178,7 +168,7 @@ func (_i *bookmarksController) Save(c *fiber.Ctx) error { // @Description API for deleting Bookmark // @Tags Bookmarks // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "Bookmark ID" // @Success 200 {object} response.Response @@ -195,12 +185,11 @@ func (_i *bookmarksController) Delete(c *fiber.Ctx) error { }) } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - _i.Log.Info().Interface("clientId", clientId).Msg("") - - err = _i.bookmarksService.Delete(clientId, uint(id)) + err = _i.bookmarksService.Delete(authToken, uint(id)) if err != nil { return err } @@ -216,7 +205,7 @@ func (_i *bookmarksController) Delete(c *fiber.Ctx) error { // @Description API for getting Bookmarks by User ID // @Tags Bookmarks // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param req query request.BookmarksQueryRequest false "query parameters" // @Param req query paginator.Pagination false "pagination parameters" @@ -237,15 +226,11 @@ func (_i *bookmarksController) GetByUserId(c *fiber.Ctx) error { req := reqContext.ToParamRequest() req.Pagination = paginate - // Get ClientId from context - clientId := middleware.GetClientID(c) - // Get Authorization token from header authToken := c.Get("Authorization") - _i.Log.Info().Interface("clientId", clientId).Msg("") _i.Log.Info().Str("authToken", authToken).Msg("") - bookmarksData, paging, err := _i.bookmarksService.GetByUserId(clientId, authToken, req) + bookmarksData, paging, err := _i.bookmarksService.GetByUserId(authToken, req) if err != nil { return err } @@ -263,7 +248,7 @@ func (_i *bookmarksController) GetByUserId(c *fiber.Ctx) error { // @Description API for toggling bookmark status for an article // @Tags Bookmarks // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param articleId path int true "Article ID" // @Success 200 {object} response.Response @@ -280,15 +265,11 @@ func (_i *bookmarksController) ToggleBookmark(c *fiber.Ctx) error { }) } - // Get ClientId from context - clientId := middleware.GetClientID(c) - // Get Authorization token from header authToken := c.Get("Authorization") - _i.Log.Info().Interface("clientId", clientId).Msg("") _i.Log.Info().Str("authToken", authToken).Msg("") - isBookmarked, err := _i.bookmarksService.ToggleBookmark(clientId, authToken, uint(articleId)) + isBookmarked, err := _i.bookmarksService.ToggleBookmark(authToken, uint(articleId)) if err != nil { return err } @@ -313,7 +294,7 @@ func (_i *bookmarksController) ToggleBookmark(c *fiber.Ctx) error { // @Description API for getting bookmark summary including total count and recent bookmarks // @Tags Bookmarks // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -321,15 +302,11 @@ func (_i *bookmarksController) ToggleBookmark(c *fiber.Ctx) error { // @Failure 500 {object} response.InternalServerError // @Router /bookmarks/summary [get] func (_i *bookmarksController) GetBookmarkSummary(c *fiber.Ctx) error { - // Get ClientId from context - clientId := middleware.GetClientID(c) - // Get Authorization token from header authToken := c.Get("Authorization") - _i.Log.Info().Interface("clientId", clientId).Msg("") _i.Log.Info().Str("authToken", authToken).Msg("") - summaryData, err := _i.bookmarksService.GetBookmarkSummary(clientId, authToken) + summaryData, err := _i.bookmarksService.GetBookmarkSummary(authToken) if err != nil { return err } diff --git a/app/module/bookmarks/service/bookmarks.service.go b/app/module/bookmarks/service/bookmarks.service.go index 9e06ac6..e165c1b 100644 --- a/app/module/bookmarks/service/bookmarks.service.go +++ b/app/module/bookmarks/service/bookmarks.service.go @@ -26,13 +26,13 @@ type bookmarksService struct { // BookmarksService define interface of IBookmarksService type BookmarksService interface { - All(clientId *uuid.UUID, authToken string, req request.BookmarksQueryRequest) (bookmarks []*response.BookmarksResponse, paging paginator.Pagination, err error) - Show(clientId *uuid.UUID, id uint) (bookmark *response.BookmarksResponse, err error) - Save(clientId *uuid.UUID, req request.BookmarksCreateRequest, authToken string) (bookmark *entity.Bookmarks, err error) - Delete(clientId *uuid.UUID, id uint) error - GetByUserId(clientId *uuid.UUID, authToken string, req request.BookmarksQueryRequest) (bookmarks []*response.BookmarksResponse, paging paginator.Pagination, err error) - ToggleBookmark(clientId *uuid.UUID, authToken string, articleId uint) (isBookmarked bool, err error) - GetBookmarkSummary(clientId *uuid.UUID, authToken string) (summary *response.BookmarksSummaryResponse, err error) + All(authToken string, req request.BookmarksQueryRequest) (bookmarks []*response.BookmarksResponse, paging paginator.Pagination, err error) + Show(authToken string, id uint) (bookmark *response.BookmarksResponse, err error) + Save(authToken string, req request.BookmarksCreateRequest) (bookmark *entity.Bookmarks, err error) + Delete(authToken string, id uint) error + GetByUserId(authToken string, req request.BookmarksQueryRequest) (bookmarks []*response.BookmarksResponse, paging paginator.Pagination, err error) + ToggleBookmark(authToken string, articleId uint) (isBookmarked bool, err error) + GetBookmarkSummary(authToken string) (summary *response.BookmarksSummaryResponse, err error) } // NewBookmarksService init BookmarksService @@ -51,7 +51,17 @@ func NewBookmarksService( } // implement interface of IBookmarksService -func (_i *bookmarksService) All(clientId *uuid.UUID, authToken string, req request.BookmarksQueryRequest) (bookmarks []*response.BookmarksResponse, paging paginator.Pagination, err error) { +func (_i *bookmarksService) All(authToken string, req request.BookmarksQueryRequest) (bookmarks []*response.BookmarksResponse, paging paginator.Pagination, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) if user == nil { _i.Log.Error().Msg("User not found from auth token") @@ -74,7 +84,17 @@ func (_i *bookmarksService) All(clientId *uuid.UUID, authToken string, req reque return bookmarks, paging, nil } -func (_i *bookmarksService) Show(clientId *uuid.UUID, id uint) (bookmark *response.BookmarksResponse, err error) { +func (_i *bookmarksService) Show(authToken string, id uint) (bookmark *response.BookmarksResponse, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + bookmarkEntity, err := _i.Repo.FindOne(clientId, id) if err != nil { _i.Log.Error().Err(err).Msg("Failed to show bookmark") @@ -85,7 +105,17 @@ func (_i *bookmarksService) Show(clientId *uuid.UUID, id uint) (bookmark *respon return bookmark, nil } -func (_i *bookmarksService) Save(clientId *uuid.UUID, req request.BookmarksCreateRequest, authToken string) (bookmark *entity.Bookmarks, err error) { +func (_i *bookmarksService) Save(authToken string, req request.BookmarksCreateRequest) (bookmark *entity.Bookmarks, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + // Extract user info from auth token user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) if user == nil { @@ -118,7 +148,17 @@ func (_i *bookmarksService) Save(clientId *uuid.UUID, req request.BookmarksCreat return bookmark, nil } -func (_i *bookmarksService) Delete(clientId *uuid.UUID, id uint) error { +func (_i *bookmarksService) Delete(authToken string, id uint) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + err := _i.Repo.Delete(clientId, id) if err != nil { _i.Log.Error().Err(err).Msg("Failed to delete bookmark") @@ -128,7 +168,17 @@ func (_i *bookmarksService) Delete(clientId *uuid.UUID, id uint) error { return nil } -func (_i *bookmarksService) GetByUserId(clientId *uuid.UUID, authToken string, req request.BookmarksQueryRequest) (bookmarks []*response.BookmarksResponse, paging paginator.Pagination, err error) { +func (_i *bookmarksService) GetByUserId(authToken string, req request.BookmarksQueryRequest) (bookmarks []*response.BookmarksResponse, paging paginator.Pagination, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + // Extract user info from auth token user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) if user == nil { @@ -151,7 +201,17 @@ func (_i *bookmarksService) GetByUserId(clientId *uuid.UUID, authToken string, r return bookmarks, paging, nil } -func (_i *bookmarksService) ToggleBookmark(clientId *uuid.UUID, authToken string, articleId uint) (isBookmarked bool, err error) { +func (_i *bookmarksService) ToggleBookmark(authToken string, articleId uint) (isBookmarked bool, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + // Extract user info from auth token user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) if user == nil { @@ -194,7 +254,17 @@ func (_i *bookmarksService) ToggleBookmark(clientId *uuid.UUID, authToken string return true, nil // Bookmark added } -func (_i *bookmarksService) GetBookmarkSummary(clientId *uuid.UUID, authToken string) (summary *response.BookmarksSummaryResponse, err error) { +func (_i *bookmarksService) GetBookmarkSummary(authToken string) (summary *response.BookmarksSummaryResponse, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + // Extract user info from auth token user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) if user == nil { diff --git a/app/module/client_approval_settings/controller/client_approval_settings.controller.go b/app/module/client_approval_settings/controller/client_approval_settings.controller.go index 99cbbf5..9c7b31a 100644 --- a/app/module/client_approval_settings/controller/client_approval_settings.controller.go +++ b/app/module/client_approval_settings/controller/client_approval_settings.controller.go @@ -2,7 +2,6 @@ package controller import ( "fmt" - "netidhub-saas-be/app/middleware" "netidhub-saas-be/app/module/client_approval_settings/request" "netidhub-saas-be/app/module/client_approval_settings/service" utilRes "netidhub-saas-be/utils/response" @@ -47,7 +46,7 @@ func NewClientApprovalSettingsController( // @Description API for creating client approval settings // @Tags ClientApprovalSettings // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param payload body request.CreateClientApprovalSettingsRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -60,10 +59,10 @@ func (_i *clientApprovalSettingsController) CreateSettings(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - settings, err := _i.clientApprovalSettingsService.Create(clientId, *req) + settings, err := _i.clientApprovalSettingsService.Create(authToken, *req) if err != nil { return err } @@ -80,17 +79,17 @@ func (_i *clientApprovalSettingsController) CreateSettings(c *fiber.Ctx) error { // @Description API for getting client approval settings // @Tags ClientApprovalSettings // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError // @Failure 401 {object} response.UnauthorizedError // @Failure 500 {object} response.InternalServerError // @Router /client-approval-settings [get] func (_i *clientApprovalSettingsController) GetSettings(c *fiber.Ctx) error { - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - settings, err := _i.clientApprovalSettingsService.GetByClientId(clientId) + settings, err := _i.clientApprovalSettingsService.GetByClientId(authToken) if err != nil { return err } @@ -107,7 +106,7 @@ func (_i *clientApprovalSettingsController) GetSettings(c *fiber.Ctx) error { // @Description API for updating client approval settings // @Tags ClientApprovalSettings // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param payload body request.UpdateClientApprovalSettingsRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -120,10 +119,10 @@ func (_i *clientApprovalSettingsController) UpdateSettings(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - settings, err := _i.clientApprovalSettingsService.Update(clientId, *req) + settings, err := _i.clientApprovalSettingsService.Update(authToken, *req) if err != nil { return err } @@ -140,17 +139,17 @@ func (_i *clientApprovalSettingsController) UpdateSettings(c *fiber.Ctx) error { // @Description API for deleting client approval settings // @Tags ClientApprovalSettings // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError // @Failure 401 {object} response.UnauthorizedError // @Failure 500 {object} response.InternalServerError // @Router /client-approval-settings [delete] func (_i *clientApprovalSettingsController) DeleteSettings(c *fiber.Ctx) error { - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - err := _i.clientApprovalSettingsService.Delete(clientId) + err := _i.clientApprovalSettingsService.Delete(authToken) if err != nil { return err } @@ -166,7 +165,7 @@ func (_i *clientApprovalSettingsController) DeleteSettings(c *fiber.Ctx) error { // @Description API for toggling approval requirement on/off // @Tags ClientApprovalSettings // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param payload body request.ToggleApprovalRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -179,10 +178,10 @@ func (_i *clientApprovalSettingsController) ToggleApproval(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - err := _i.clientApprovalSettingsService.ToggleApprovalRequirement(clientId, req.RequiresApproval) + err := _i.clientApprovalSettingsService.ToggleApprovalRequirement(authToken, req.RequiresApproval) if err != nil { return err } @@ -203,7 +202,7 @@ func (_i *clientApprovalSettingsController) ToggleApproval(c *fiber.Ctx) error { // @Description API for enabling approval system with smooth transition // @Tags ClientApprovalSettings // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param payload body request.EnableApprovalRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -216,10 +215,10 @@ func (_i *clientApprovalSettingsController) EnableApproval(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - err := _i.clientApprovalSettingsService.EnableApprovalWithTransition(clientId, req.DefaultWorkflowId) + err := _i.clientApprovalSettingsService.EnableApprovalWithTransition(authToken, req.DefaultWorkflowId) if err != nil { return err } @@ -235,7 +234,7 @@ func (_i *clientApprovalSettingsController) EnableApproval(c *fiber.Ctx) error { // @Description API for disabling approval system and auto-publish pending articles // @Tags ClientApprovalSettings // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param payload body request.DisableApprovalRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -248,10 +247,10 @@ func (_i *clientApprovalSettingsController) DisableApproval(c *fiber.Ctx) error return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - err := _i.clientApprovalSettingsService.DisableApprovalWithAutoPublish(clientId, req.Reason) + err := _i.clientApprovalSettingsService.DisableApprovalWithAutoPublish(authToken, req.Reason) if err != nil { return err } @@ -267,7 +266,7 @@ func (_i *clientApprovalSettingsController) DisableApproval(c *fiber.Ctx) error // @Description API for setting default workflow for client // @Tags ClientApprovalSettings // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param payload body request.SetDefaultWorkflowRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -280,10 +279,10 @@ func (_i *clientApprovalSettingsController) SetDefaultWorkflow(c *fiber.Ctx) err return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - err := _i.clientApprovalSettingsService.SetDefaultWorkflow(clientId, req.WorkflowId) + err := _i.clientApprovalSettingsService.SetDefaultWorkflow(authToken, req.WorkflowId) if err != nil { return err } @@ -299,7 +298,7 @@ func (_i *clientApprovalSettingsController) SetDefaultWorkflow(c *fiber.Ctx) err // @Description API for adding/removing users from approval exemption // @Tags ClientApprovalSettings // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param action path string true "Action: add or remove" // @Param user_id path int true "User ID" // @Success 200 {object} response.Response @@ -320,13 +319,13 @@ func (_i *clientApprovalSettingsController) ManageExemptUsers(c *fiber.Ctx) erro return utilRes.ErrorBadRequest(c, "Invalid user ID format") } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") if action == "add" { - err = _i.clientApprovalSettingsService.AddExemptUser(clientId, uint(userId)) + err = _i.clientApprovalSettingsService.AddExemptUser(authToken, uint(userId)) } else { - err = _i.clientApprovalSettingsService.RemoveExemptUser(clientId, uint(userId)) + err = _i.clientApprovalSettingsService.RemoveExemptUser(authToken, uint(userId)) } if err != nil { @@ -344,7 +343,7 @@ func (_i *clientApprovalSettingsController) ManageExemptUsers(c *fiber.Ctx) erro // @Description API for adding/removing roles from approval exemption // @Tags ClientApprovalSettings // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param action path string true "Action: add or remove" // @Param role_id path int true "Role ID" // @Success 200 {object} response.Response @@ -365,13 +364,13 @@ func (_i *clientApprovalSettingsController) ManageExemptRoles(c *fiber.Ctx) erro return utilRes.ErrorBadRequest(c, "Invalid role ID format") } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") if action == "add" { - err = _i.clientApprovalSettingsService.AddExemptRole(clientId, uint(roleId)) + err = _i.clientApprovalSettingsService.AddExemptRole(authToken, uint(roleId)) } else { - err = _i.clientApprovalSettingsService.RemoveExemptRole(clientId, uint(roleId)) + err = _i.clientApprovalSettingsService.RemoveExemptRole(authToken, uint(roleId)) } if err != nil { @@ -389,7 +388,7 @@ func (_i *clientApprovalSettingsController) ManageExemptRoles(c *fiber.Ctx) erro // @Description API for adding/removing categories from approval exemption // @Tags ClientApprovalSettings // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string true "Insert the Authorization" // @Param action path string true "Action: add or remove" // @Param category_id path int true "Category ID" // @Success 200 {object} response.Response @@ -410,13 +409,13 @@ func (_i *clientApprovalSettingsController) ManageExemptCategories(c *fiber.Ctx) return utilRes.ErrorBadRequest(c, "Invalid category ID format") } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") if action == "add" { - err = _i.clientApprovalSettingsService.AddExemptCategory(clientId, uint(categoryId)) + err = _i.clientApprovalSettingsService.AddExemptCategory(authToken, uint(categoryId)) } else { - err = _i.clientApprovalSettingsService.RemoveExemptCategory(clientId, uint(categoryId)) + err = _i.clientApprovalSettingsService.RemoveExemptCategory(authToken, uint(categoryId)) } if err != nil { diff --git a/app/module/client_approval_settings/service/client_approval_settings.service.go b/app/module/client_approval_settings/service/client_approval_settings.service.go index 9ff8dd5..96a5bf9 100644 --- a/app/module/client_approval_settings/service/client_approval_settings.service.go +++ b/app/module/client_approval_settings/service/client_approval_settings.service.go @@ -7,6 +7,8 @@ import ( "netidhub-saas-be/app/module/client_approval_settings/repository" "netidhub-saas-be/app/module/client_approval_settings/request" "netidhub-saas-be/app/module/client_approval_settings/response" + usersRepository "netidhub-saas-be/app/module/users/repository" + utilSvc "netidhub-saas-be/utils/service" "github.com/google/uuid" "github.com/rs/zerolog" @@ -14,41 +16,58 @@ import ( type clientApprovalSettingsService struct { clientApprovalSettingsRepo repository.ClientApprovalSettingsRepository + UsersRepo usersRepository.UsersRepository Log zerolog.Logger } type ClientApprovalSettingsService interface { - GetByClientId(clientId *uuid.UUID) (*response.ClientApprovalSettingsResponse, error) - Create(clientId *uuid.UUID, req request.CreateClientApprovalSettingsRequest) (*response.ClientApprovalSettingsResponse, error) - Update(clientId *uuid.UUID, req request.UpdateClientApprovalSettingsRequest) (*response.ClientApprovalSettingsResponse, error) - Delete(clientId *uuid.UUID) error - ToggleApprovalRequirement(clientId *uuid.UUID, requiresApproval bool) error - SetDefaultWorkflow(clientId *uuid.UUID, workflowId *uint) error - AddExemptUser(clientId *uuid.UUID, userId uint) error - RemoveExemptUser(clientId *uuid.UUID, userId uint) error - AddExemptRole(clientId *uuid.UUID, roleId uint) error - RemoveExemptRole(clientId *uuid.UUID, roleId uint) error - AddExemptCategory(clientId *uuid.UUID, categoryId uint) error - RemoveExemptCategory(clientId *uuid.UUID, categoryId uint) error - CheckIfApprovalRequired(clientId *uuid.UUID, userId uint, userLevelId uint, categoryId uint, contentType string) (bool, error) + GetByClientId(authToken string) (*response.ClientApprovalSettingsResponse, error) + Create(authToken string, req request.CreateClientApprovalSettingsRequest) (*response.ClientApprovalSettingsResponse, error) + Update(authToken string, req request.UpdateClientApprovalSettingsRequest) (*response.ClientApprovalSettingsResponse, error) + Delete(authToken string) error + ToggleApprovalRequirement(authToken string, requiresApproval bool) error + SetDefaultWorkflow(authToken string, workflowId *uint) error + AddExemptUser(authToken string, userId uint) error + RemoveExemptUser(authToken string, userId uint) error + AddExemptRole(authToken string, roleId uint) error + RemoveExemptRole(authToken string, roleId uint) error + AddExemptCategory(authToken string, categoryId uint) error + RemoveExemptCategory(authToken string, categoryId uint) error + CheckIfApprovalRequired(authToken string, userId uint, userLevelId uint, categoryId uint, contentType string) (bool, error) // Enhanced methods for dynamic approval management - EnableApprovalWithTransition(clientId *uuid.UUID, defaultWorkflowId *uint) error - DisableApprovalWithAutoPublish(clientId *uuid.UUID, reason string) error - HandlePendingApprovalsOnDisable(clientId *uuid.UUID, action string) error // "auto_approve", "keep_pending", "reset_to_draft" + EnableApprovalWithTransition(authToken string, defaultWorkflowId *uint) error + DisableApprovalWithAutoPublish(authToken string, reason string) error + HandlePendingApprovalsOnDisable(authToken string, action string) error // "auto_approve", "keep_pending", "reset_to_draft" } func NewClientApprovalSettingsService( clientApprovalSettingsRepo repository.ClientApprovalSettingsRepository, + usersRepo usersRepository.UsersRepository, log zerolog.Logger, ) ClientApprovalSettingsService { return &clientApprovalSettingsService{ clientApprovalSettingsRepo: clientApprovalSettingsRepo, + UsersRepo: usersRepo, Log: log, } } -func (_i *clientApprovalSettingsService) GetByClientId(clientId *uuid.UUID) (*response.ClientApprovalSettingsResponse, error) { +func (_i *clientApprovalSettingsService) GetByClientId(authToken string) (*response.ClientApprovalSettingsResponse, error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, fmt.Errorf("clientId not found in auth token") + } + settings, err := _i.clientApprovalSettingsRepo.FindByClientId(*clientId) if err != nil { return nil, err @@ -72,7 +91,21 @@ func (_i *clientApprovalSettingsService) GetByClientId(clientId *uuid.UUID) (*re return mapper.ClientApprovalSettingsResponseMapper(_i.Log, clientId, settings), nil } -func (_i *clientApprovalSettingsService) Create(clientId *uuid.UUID, req request.CreateClientApprovalSettingsRequest) (*response.ClientApprovalSettingsResponse, error) { +func (_i *clientApprovalSettingsService) Create(authToken string, req request.CreateClientApprovalSettingsRequest) (*response.ClientApprovalSettingsResponse, error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, fmt.Errorf("clientId not found in auth token") + } + // Check if settings already exist existing, err := _i.clientApprovalSettingsRepo.FindByClientId(*clientId) if err != nil { @@ -104,7 +137,21 @@ func (_i *clientApprovalSettingsService) Create(clientId *uuid.UUID, req request return mapper.ClientApprovalSettingsResponseMapper(_i.Log, clientId, createdSettings), nil } -func (_i *clientApprovalSettingsService) Update(clientId *uuid.UUID, req request.UpdateClientApprovalSettingsRequest) (*response.ClientApprovalSettingsResponse, error) { +func (_i *clientApprovalSettingsService) Update(authToken string, req request.UpdateClientApprovalSettingsRequest) (*response.ClientApprovalSettingsResponse, error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, fmt.Errorf("clientId not found in auth token") + } + // Get existing settings settings, err := _i.clientApprovalSettingsRepo.FindByClientId(*clientId) if err != nil { @@ -152,11 +199,39 @@ func (_i *clientApprovalSettingsService) Update(clientId *uuid.UUID, req request return mapper.ClientApprovalSettingsResponseMapper(_i.Log, clientId, updatedSettings), nil } -func (_i *clientApprovalSettingsService) Delete(clientId *uuid.UUID) error { +func (_i *clientApprovalSettingsService) Delete(authToken string) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return fmt.Errorf("clientId not found in auth token") + } + return _i.clientApprovalSettingsRepo.Delete(clientId) } -func (_i *clientApprovalSettingsService) ToggleApprovalRequirement(clientId *uuid.UUID, requiresApproval bool) error { +func (_i *clientApprovalSettingsService) ToggleApprovalRequirement(authToken string, requiresApproval bool) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return fmt.Errorf("clientId not found in auth token") + } + settings, err := _i.clientApprovalSettingsRepo.FindByClientId(*clientId) if err != nil { return err @@ -171,7 +246,21 @@ func (_i *clientApprovalSettingsService) ToggleApprovalRequirement(clientId *uui return err } -func (_i *clientApprovalSettingsService) SetDefaultWorkflow(clientId *uuid.UUID, workflowId *uint) error { +func (_i *clientApprovalSettingsService) SetDefaultWorkflow(authToken string, workflowId *uint) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return fmt.Errorf("clientId not found in auth token") + } + settings, err := _i.clientApprovalSettingsRepo.FindByClientId(*clientId) if err != nil { return err @@ -186,31 +275,128 @@ func (_i *clientApprovalSettingsService) SetDefaultWorkflow(clientId *uuid.UUID, return err } -func (_i *clientApprovalSettingsService) AddExemptUser(clientId *uuid.UUID, userId uint) error { +func (_i *clientApprovalSettingsService) AddExemptUser(authToken string, userId uint) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return fmt.Errorf("clientId not found in auth token") + } + return _i.clientApprovalSettingsRepo.AddExemptUser(clientId, userId) } -func (_i *clientApprovalSettingsService) RemoveExemptUser(clientId *uuid.UUID, userId uint) error { +func (_i *clientApprovalSettingsService) RemoveExemptUser(authToken string, userId uint) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return fmt.Errorf("clientId not found in auth token") + } + return _i.clientApprovalSettingsRepo.RemoveExemptUser(clientId, userId) } -func (_i *clientApprovalSettingsService) AddExemptRole(clientId *uuid.UUID, roleId uint) error { +func (_i *clientApprovalSettingsService) AddExemptRole(authToken string, roleId uint) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return fmt.Errorf("clientId not found in auth token") + } + return _i.clientApprovalSettingsRepo.AddExemptRole(clientId, roleId) } -func (_i *clientApprovalSettingsService) RemoveExemptRole(clientId *uuid.UUID, roleId uint) error { +func (_i *clientApprovalSettingsService) RemoveExemptRole(authToken string, roleId uint) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return fmt.Errorf("clientId not found in auth token") + } + return _i.clientApprovalSettingsRepo.RemoveExemptRole(clientId, roleId) } -func (_i *clientApprovalSettingsService) AddExemptCategory(clientId *uuid.UUID, categoryId uint) error { +func (_i *clientApprovalSettingsService) AddExemptCategory(authToken string, categoryId uint) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return fmt.Errorf("clientId not found in auth token") + } + return _i.clientApprovalSettingsRepo.AddExemptCategory(clientId, categoryId) } -func (_i *clientApprovalSettingsService) RemoveExemptCategory(clientId *uuid.UUID, categoryId uint) error { +func (_i *clientApprovalSettingsService) RemoveExemptCategory(authToken string, categoryId uint) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return fmt.Errorf("clientId not found in auth token") + } + return _i.clientApprovalSettingsRepo.RemoveExemptCategory(clientId, categoryId) } -func (_i *clientApprovalSettingsService) CheckIfApprovalRequired(clientId *uuid.UUID, userId uint, userLevelId uint, categoryId uint, contentType string) (bool, error) { +func (_i *clientApprovalSettingsService) CheckIfApprovalRequired(authToken string, userId uint, userLevelId uint, categoryId uint, contentType string) (bool, error) { + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return true, fmt.Errorf("clientId not found in auth token") + } + settings, err := _i.clientApprovalSettingsRepo.FindActiveSettings(clientId) if err != nil { return true, err // Default to requiring approval on error @@ -264,7 +450,20 @@ func (_i *clientApprovalSettingsService) CheckIfApprovalRequired(clientId *uuid. return true, nil } -func (_i *clientApprovalSettingsService) EnableApprovalWithTransition(clientId *uuid.UUID, defaultWorkflowId *uint) error { +func (_i *clientApprovalSettingsService) EnableApprovalWithTransition(authToken string, defaultWorkflowId *uint) error { + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return fmt.Errorf("clientId not found in auth token") + } + settings, err := _i.clientApprovalSettingsRepo.FindByClientId(*clientId) if err != nil { return err @@ -291,7 +490,20 @@ func (_i *clientApprovalSettingsService) EnableApprovalWithTransition(clientId * return err } -func (_i *clientApprovalSettingsService) DisableApprovalWithAutoPublish(clientId *uuid.UUID, reason string) error { +func (_i *clientApprovalSettingsService) DisableApprovalWithAutoPublish(authToken string, reason string) error { + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return fmt.Errorf("clientId not found in auth token") + } + settings, err := _i.clientApprovalSettingsRepo.FindByClientId(*clientId) if err != nil { return err @@ -309,11 +521,11 @@ func (_i *clientApprovalSettingsService) DisableApprovalWithAutoPublish(clientId return err } -func (_i *clientApprovalSettingsService) HandlePendingApprovalsOnDisable(clientId *uuid.UUID, action string) error { +func (_i *clientApprovalSettingsService) HandlePendingApprovalsOnDisable(authToken string, action string) error { // This would typically interact with article approval flows // For now, just log the action _i.Log.Info(). - Str("client_id", clientId.String()). + Str("client_id", authToken). Str("action", action). Msg("Handling pending approvals on disable") diff --git a/app/module/clients/controller/clients.controller.go b/app/module/clients/controller/clients.controller.go index 9625cc3..9209db8 100644 --- a/app/module/clients/controller/clients.controller.go +++ b/app/module/clients/controller/clients.controller.go @@ -1,7 +1,6 @@ package controller import ( - "netidhub-saas-be/app/middleware" "netidhub-saas-be/app/module/clients/request" "netidhub-saas-be/app/module/clients/service" "netidhub-saas-be/utils/paginator" @@ -47,7 +46,6 @@ func NewClientsController(clientsService service.ClientsService, log zerolog.Log // @Description API for getting all Clients with hierarchy filtering // @Tags Clients // @Security Bearer -// @Param X-Client-Key header string true "Insert the X-Client-Key" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param name query string false "Filter by client name" // @Param clientType query string false "Filter by client type (parent_client, sub_client, standalone)" @@ -86,11 +84,11 @@ func (_i *clientsController) All(c *fiber.Ctx) error { req := reqContext.ToParamRequest() req.Pagination = paginate - // Get ClientId from context - clientId := middleware.GetClientID(c) - _i.Log.Info().Interface("clientId", clientId).Msg("") + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") - clientsData, paging, err := _i.clientsService.All(clientId, req) + clientsData, paging, err := _i.clientsService.All(authToken, req) if err != nil { return err } @@ -146,7 +144,7 @@ func (_i *clientsController) Show(c *fiber.Ctx) error { // @Failure 500 {object} response.InternalServerError // @Router /clients [post] func (_i *clientsController) Save(c *fiber.Ctx) error { - req := new(request.CreateClientRequest) + req := new(request.ClientsCreateRequest) if err := utilVal.ParseAndValidate(c, req); err != nil { return err } @@ -183,7 +181,7 @@ func (_i *clientsController) Update(c *fiber.Ctx) error { return err } - req := new(request.UpdateClientRequest) + req := new(request.ClientsUpdateRequest) if err := utilVal.ParseAndValidate(c, req); err != nil { return err } @@ -293,7 +291,7 @@ func (_i *clientsController) GetSubClients(c *fiber.Ctx) error { Pagination: &paginator.Pagination{Page: 1, Limit: 100}, } - subClients, _, err := _i.clientsService.All(nil, req) + subClients, _, err := _i.clientsService.All("", req) if err != nil { return utilRes.Resp(c, utilRes.Response{ Success: false, @@ -314,7 +312,7 @@ func (_i *clientsController) GetSubClients(c *fiber.Ctx) error { // @Tags Clients // @Security Bearer // @Param id path string true "Parent Client ID" -// @Param payload body request.CreateClientRequest true "Required payload" +// @Param payload body request.ClientsCreateRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError // @Failure 401 {object} response.UnauthorizedError @@ -329,7 +327,7 @@ func (_i *clientsController) CreateSubClient(c *fiber.Ctx) error { }) } - req := new(request.CreateClientRequest) + req := new(request.ClientsCreateRequest) if err := utilVal.ParseAndValidate(c, req); err != nil { return err } diff --git a/app/module/clients/request/clients.request.go b/app/module/clients/request/clients.request.go index 8c19dd7..1174b8a 100644 --- a/app/module/clients/request/clients.request.go +++ b/app/module/clients/request/clients.request.go @@ -10,8 +10,8 @@ import ( // REQUEST STRUCTS - Updated for Multi-Client Hierarchy Support (camelCase) // ======================================================================== -// CreateClientRequest for creating new client with hierarchy support -type CreateClientRequest struct { +// ClientsCreateRequest for creating new client with hierarchy support +type ClientsCreateRequest struct { Name string `json:"name" validate:"required"` Description *string `json:"description"` ClientType string `json:"clientType" validate:"required,oneof=parent_client sub_client standalone"` // Enum validation @@ -25,8 +25,8 @@ type CreateClientRequest struct { Settings *string `json:"settings"` } -// UpdateClientRequest for updating existing client -type UpdateClientRequest struct { +// ClientsUpdateRequest for updating existing client +type ClientsUpdateRequest struct { Name *string `json:"name"` Description *string `json:"description"` ClientType *string `json:"clientType" validate:"omitempty,oneof=parent_client sub_client standalone"` @@ -68,10 +68,10 @@ type MoveClientRequest struct { // BulkCreateSubClientsRequest for creating multiple sub-clients at once type BulkCreateSubClientsRequest struct { ParentClientId uuid.UUID `json:"parentClientId" validate:"required"` - SubClients []CreateSubClientDetail `json:"subClients" validate:"required,min=1,dive"` + SubClients []ClientsCreateSubClientDetail `json:"subClients" validate:"required,min=1,dive"` } -type CreateSubClientDetail struct { +type ClientsCreateSubClientDetail struct { Name string `json:"name" validate:"required"` Description *string `json:"description"` MaxUsers *int `json:"maxUsers"` diff --git a/app/module/clients/service/clients.service.go b/app/module/clients/service/clients.service.go index f27ce89..8e90bc4 100644 --- a/app/module/clients/service/clients.service.go +++ b/app/module/clients/service/clients.service.go @@ -25,14 +25,14 @@ type clientsService struct { // ClientsService define interface of IClientsService type ClientsService interface { - All(clientId *uuid.UUID, req request.ClientsQueryRequest) (clients []*response.ClientsResponse, paging paginator.Pagination, err error) + All(authToken string, req request.ClientsQueryRequest) (clients []*response.ClientsResponse, paging paginator.Pagination, err error) Show(id uuid.UUID) (clients *response.ClientsResponse, err error) - Save(req request.CreateClientRequest, authToken string) (clients *entity.Clients, err error) - Update(id uuid.UUID, req request.UpdateClientRequest) (err error) + Save(req request.ClientsCreateRequest, authToken string) (clients *entity.Clients, err error) + Update(id uuid.UUID, req request.ClientsUpdateRequest) (err error) Delete(id uuid.UUID) error // New hierarchy methods - CreateSubClient(parentId uuid.UUID, req request.CreateClientRequest) (*entity.Clients, error) + CreateSubClient(parentId uuid.UUID, req request.ClientsCreateRequest) (*entity.Clients, error) MoveClient(clientId uuid.UUID, req request.MoveClientRequest) error GetHierarchy(clientId uuid.UUID) (*response.ClientHierarchyResponse, error) GetClientStats(clientId uuid.UUID) (*response.ClientStatsResponse, error) @@ -50,7 +50,17 @@ func NewClientsService(repo repository.ClientsRepository, log zerolog.Logger, us } // All implement interface of ClientsService -func (_i *clientsService) All(clientId *uuid.UUID, req request.ClientsQueryRequest) (clientss []*response.ClientsResponse, paging paginator.Pagination, err error) { +func (_i *clientsService) All(authToken string, req request.ClientsQueryRequest) (clientss []*response.ClientsResponse, paging paginator.Pagination, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + results, paging, err := _i.Repo.GetAll(req) if err != nil { return @@ -72,7 +82,7 @@ func (_i *clientsService) Show(id uuid.UUID) (clients *response.ClientsResponse, return mapper.ClientsResponseMapper(result), nil } -func (_i *clientsService) Save(req request.CreateClientRequest, authToken string) (clients *entity.Clients, err error) { +func (_i *clientsService) Save(req request.ClientsCreateRequest, authToken string) (clients *entity.Clients, err error) { _i.Log.Info().Interface("data", req).Msg("") // Convert request to entity @@ -98,7 +108,7 @@ func (_i *clientsService) Save(req request.CreateClientRequest, authToken string return _i.Repo.Create(newReq) } -func (_i *clientsService) Update(id uuid.UUID, req request.UpdateClientRequest) (err error) { +func (_i *clientsService) Update(id uuid.UUID, req request.ClientsUpdateRequest) (err error) { _i.Log.Info().Interface("data", req).Msg("") // Convert request to entity @@ -132,7 +142,7 @@ func (_i *clientsService) Delete(id uuid.UUID) error { // ===================================================================== // CreateSubClient creates a client under a parent -func (_i *clientsService) CreateSubClient(parentId uuid.UUID, req request.CreateClientRequest) (*entity.Clients, error) { +func (_i *clientsService) CreateSubClient(parentId uuid.UUID, req request.ClientsCreateRequest) (*entity.Clients, error) { // Validate parent exists _, err := _i.Repo.FindOne(parentId) if err != nil { @@ -253,7 +263,7 @@ func (_i *clientsService) BulkCreateSubClients(req request.BulkCreateSubClientsR failed := 0 for i, subClientReq := range req.SubClients { - createReq := request.CreateClientRequest{ + createReq := request.ClientsCreateRequest{ Name: subClientReq.Name, Description: subClientReq.Description, ClientType: "sub_client", diff --git a/app/module/user_levels/controller/user_levels.controller.go b/app/module/user_levels/controller/user_levels.controller.go index 0c2030d..31990c9 100644 --- a/app/module/user_levels/controller/user_levels.controller.go +++ b/app/module/user_levels/controller/user_levels.controller.go @@ -1,7 +1,6 @@ package controller import ( - "netidhub-saas-be/app/middleware" "netidhub-saas-be/app/module/user_levels/request" "netidhub-saas-be/app/module/user_levels/service" "netidhub-saas-be/utils/paginator" @@ -39,7 +38,7 @@ func NewUserLevelsController(userLevelsService service.UserLevelsService) UserLe // @Description API for getting all UserLevels // @Tags UserLevels // @Security Bearer -// @Param X-Client-Key header string true "Client Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param req query request.UserLevelsQueryRequest false "query parameters" // @Param req query paginator.Pagination false "pagination parameters" // @Success 200 {object} response.Response @@ -62,10 +61,10 @@ func (_i *userLevelsController) All(c *fiber.Ctx) error { req := reqContext.ToParamRequest() req.Pagination = paginate - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - userLevelsData, paging, err := _i.userLevelsService.All(clientId, req) + userLevelsData, paging, err := _i.userLevelsService.All(authToken, req) if err != nil { return err } @@ -83,7 +82,7 @@ func (_i *userLevelsController) All(c *fiber.Ctx) error { // @Description API for getting one UserLevels // @Tags UserLevels // @Security Bearer -// @Param X-Client-Key header string true "Client Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "UserLevels ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -96,10 +95,10 @@ func (_i *userLevelsController) Show(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - userLevelsData, err := _i.userLevelsService.Show(clientId, uint(id)) + userLevelsData, err := _i.userLevelsService.Show(authToken, uint(id)) if err != nil { return err } @@ -115,7 +114,7 @@ func (_i *userLevelsController) Show(c *fiber.Ctx) error { // @Description API for getting one UserLevels // @Tags UserLevels // @Security Bearer -// @Param X-Client-Key header string true "Client Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param alias path string true "UserLevels Alias" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -125,10 +124,10 @@ func (_i *userLevelsController) Show(c *fiber.Ctx) error { func (_i *userLevelsController) ShowByAlias(c *fiber.Ctx) error { alias := c.Params("alias") - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - userLevelsData, err := _i.userLevelsService.ShowByAlias(clientId, alias) + userLevelsData, err := _i.userLevelsService.ShowByAlias(authToken, alias) if err != nil { return err } @@ -143,7 +142,7 @@ func (_i *userLevelsController) ShowByAlias(c *fiber.Ctx) error { // @Description API for create UserLevels // @Tags UserLevels // @Security Bearer -// @Param X-Client-Key header string true "Client Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param payload body request.UserLevelsCreateRequest true "Required payload" @@ -158,10 +157,10 @@ func (_i *userLevelsController) Save(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - dataResult, err := _i.userLevelsService.Save(clientId, *req) + dataResult, err := _i.userLevelsService.Save(authToken, *req) if err != nil { return err } @@ -178,7 +177,7 @@ func (_i *userLevelsController) Save(c *fiber.Ctx) error { // @Description API for update UserLevels // @Tags UserLevels // @Security Bearer -// @Param X-Client-Key header string true "Client Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param payload body request.UserLevelsUpdateRequest true "Required payload" @@ -199,10 +198,10 @@ func (_i *userLevelsController) Update(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - err = _i.userLevelsService.Update(clientId, uint(id), *req) + err = _i.userLevelsService.Update(authToken, uint(id), *req) if err != nil { return err } @@ -218,7 +217,7 @@ func (_i *userLevelsController) Update(c *fiber.Ctx) error { // @Description API for delete UserLevels // @Tags UserLevels // @Security Bearer -// @Param X-Client-Key header string true "Client Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" // @Param id path int true "UserLevels ID" @@ -234,10 +233,10 @@ func (_i *userLevelsController) Delete(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - err = _i.userLevelsService.Delete(clientId, uint(id)) + err = _i.userLevelsService.Delete(authToken, uint(id)) if err != nil { return err } @@ -253,7 +252,7 @@ func (_i *userLevelsController) Delete(c *fiber.Ctx) error { // @Description API for Enable Approval of Article // @Tags UserLevels // @Security Bearer -// @Param X-Client-Key header string true "Client Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param payload body request.UserLevelsApprovalRequest true "Required payload" @@ -268,8 +267,8 @@ func (_i *userLevelsController) EnableApproval(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") ids := strings.Split(req.Ids, ",") for _, id := range ids { @@ -277,7 +276,7 @@ func (_i *userLevelsController) EnableApproval(c *fiber.Ctx) error { if err != nil { return err } - err = _i.userLevelsService.EnableApproval(clientId, uint(idUint), req.IsApprovalActive) + err = _i.userLevelsService.EnableApproval(authToken, uint(idUint), req.IsApprovalActive) if err != nil { return err } diff --git a/app/module/user_levels/service/user_levels.service.go b/app/module/user_levels/service/user_levels.service.go index 745c999..920ba61 100644 --- a/app/module/user_levels/service/user_levels.service.go +++ b/app/module/user_levels/service/user_levels.service.go @@ -6,7 +6,9 @@ import ( "netidhub-saas-be/app/module/user_levels/repository" "netidhub-saas-be/app/module/user_levels/request" "netidhub-saas-be/app/module/user_levels/response" + usersRepository "netidhub-saas-be/app/module/users/repository" "netidhub-saas-be/utils/paginator" + utilSvc "netidhub-saas-be/utils/service" "github.com/google/uuid" "github.com/rs/zerolog" @@ -14,32 +16,44 @@ import ( // UserLevelsService type userLevelsService struct { - Repo repository.UserLevelsRepository - Log zerolog.Logger + Repo repository.UserLevelsRepository + UsersRepo usersRepository.UsersRepository + Log zerolog.Logger } // UserLevelsService define interface of IUserLevelsService type UserLevelsService interface { - All(clientId *uuid.UUID, req request.UserLevelsQueryRequest) (userLevels []*response.UserLevelsResponse, paging paginator.Pagination, err error) - Show(clientId *uuid.UUID, id uint) (userLevels *response.UserLevelsResponse, err error) - ShowByAlias(clientId *uuid.UUID, alias string) (userLevels *response.UserLevelsResponse, err error) - Save(clientId *uuid.UUID, req request.UserLevelsCreateRequest) (userLevels *entity.UserLevels, err error) - Update(clientId *uuid.UUID, id uint, req request.UserLevelsUpdateRequest) (err error) - Delete(clientId *uuid.UUID, id uint) error - EnableApproval(clientId *uuid.UUID, id uint, isApprovalActive bool) (err error) + All(authToken string, req request.UserLevelsQueryRequest) (userLevels []*response.UserLevelsResponse, paging paginator.Pagination, err error) + Show(authToken string, id uint) (userLevels *response.UserLevelsResponse, err error) + ShowByAlias(authToken string, alias string) (userLevels *response.UserLevelsResponse, err error) + Save(authToken string, req request.UserLevelsCreateRequest) (userLevels *entity.UserLevels, err error) + Update(authToken string, id uint, req request.UserLevelsUpdateRequest) (err error) + Delete(authToken string, id uint) error + EnableApproval(authToken string, id uint, isApprovalActive bool) (err error) } // NewUserLevelsService init UserLevelsService -func NewUserLevelsService(repo repository.UserLevelsRepository, log zerolog.Logger) UserLevelsService { +func NewUserLevelsService(repo repository.UserLevelsRepository, log zerolog.Logger, usersRepo usersRepository.UsersRepository) UserLevelsService { return &userLevelsService{ - Repo: repo, - Log: log, + Repo: repo, + UsersRepo: usersRepo, + Log: log, } } // All implement interface of UserLevelsService -func (_i *userLevelsService) All(clientId *uuid.UUID, req request.UserLevelsQueryRequest) (userLevelss []*response.UserLevelsResponse, paging paginator.Pagination, err error) { +func (_i *userLevelsService) All(authToken string, req request.UserLevelsQueryRequest) (userLevelss []*response.UserLevelsResponse, paging paginator.Pagination, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + results, paging, err := _i.Repo.GetAll(clientId, req) if err != nil { return @@ -52,7 +66,17 @@ func (_i *userLevelsService) All(clientId *uuid.UUID, req request.UserLevelsQuer return } -func (_i *userLevelsService) Show(clientId *uuid.UUID, id uint) (userLevels *response.UserLevelsResponse, err error) { +func (_i *userLevelsService) Show(authToken string, id uint) (userLevels *response.UserLevelsResponse, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOne(clientId, id) if err != nil { return nil, err @@ -61,7 +85,17 @@ func (_i *userLevelsService) Show(clientId *uuid.UUID, id uint) (userLevels *res return mapper.UserLevelsResponseMapper(result), nil } -func (_i *userLevelsService) ShowByAlias(clientId *uuid.UUID, alias string) (userLevels *response.UserLevelsResponse, err error) { +func (_i *userLevelsService) ShowByAlias(authToken string, alias string) (userLevels *response.UserLevelsResponse, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOneByAlias(clientId, alias) if err != nil { return nil, err @@ -70,7 +104,17 @@ func (_i *userLevelsService) ShowByAlias(clientId *uuid.UUID, alias string) (use return mapper.UserLevelsResponseMapper(result), nil } -func (_i *userLevelsService) Save(clientId *uuid.UUID, req request.UserLevelsCreateRequest) (userLevels *entity.UserLevels, err error) { +func (_i *userLevelsService) Save(authToken string, req request.UserLevelsCreateRequest) (userLevels *entity.UserLevels, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + _i.Log.Info().Interface("data", req).Msg("") entity := req.ToEntity() @@ -85,7 +129,17 @@ func (_i *userLevelsService) Save(clientId *uuid.UUID, req request.UserLevelsCre return saveUserLevelsRes, nil } -func (_i *userLevelsService) Update(clientId *uuid.UUID, id uint, req request.UserLevelsUpdateRequest) (err error) { +func (_i *userLevelsService) Update(authToken string, id uint, req request.UserLevelsUpdateRequest) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + //_i.Log.Info().Interface("data", req).Msg("") _i.Log.Info().Interface("data", req.ToEntity()).Msg("") @@ -97,7 +151,17 @@ func (_i *userLevelsService) Update(clientId *uuid.UUID, id uint, req request.Us return _i.Repo.Update(clientId, id, entity) } -func (_i *userLevelsService) Delete(clientId *uuid.UUID, id uint) error { +func (_i *userLevelsService) Delete(authToken string, id uint) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOne(clientId, id) if err != nil { return err @@ -108,7 +172,17 @@ func (_i *userLevelsService) Delete(clientId *uuid.UUID, id uint) error { return _i.Repo.Update(clientId, id, result) } -func (_i *userLevelsService) EnableApproval(clientId *uuid.UUID, id uint, isApprovalActive bool) (err error) { +func (_i *userLevelsService) EnableApproval(authToken string, id uint, isApprovalActive bool) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOne(clientId, id) if err != nil { return err diff --git a/app/module/users/controller/users.controller.go b/app/module/users/controller/users.controller.go index 98e88b7..b2a5fb9 100644 --- a/app/module/users/controller/users.controller.go +++ b/app/module/users/controller/users.controller.go @@ -1,7 +1,6 @@ package controller import ( - "netidhub-saas-be/app/middleware" "netidhub-saas-be/app/module/users/request" "netidhub-saas-be/app/module/users/service" "netidhub-saas-be/utils/paginator" @@ -48,8 +47,7 @@ func NewUsersController(usersService service.UsersService) UsersController { // @Description API for getting all Users // @Tags Users // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param req query request.UsersQueryRequest false "query parameters" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param req query paginator.Pagination false "pagination parameters" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -79,10 +77,10 @@ func (_i *usersController) All(c *fiber.Ctx) error { req := reqContext.ToParamRequest() req.Pagination = paginate - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - usersData, paging, err := _i.usersService.All(clientId, req) + usersData, paging, err := _i.usersService.All(authToken, req) if err != nil { return err } @@ -100,7 +98,7 @@ func (_i *usersController) All(c *fiber.Ctx) error { // @Description API for getting one Users // @Tags Users // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "Users ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -113,10 +111,10 @@ func (_i *usersController) Show(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - usersData, err := _i.usersService.Show(clientId, uint(id)) + usersData, err := _i.usersService.Show(authToken, uint(id)) if err != nil { return err } @@ -133,7 +131,7 @@ func (_i *usersController) Show(c *fiber.Ctx) error { // @Description API for getting one Users // @Tags Users // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param username path string true "Username" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -143,10 +141,10 @@ func (_i *usersController) Show(c *fiber.Ctx) error { func (_i *usersController) ShowByUsername(c *fiber.Ctx) error { username := c.Params("username") - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - usersData, err := _i.usersService.ShowByUsername(clientId, username) + usersData, err := _i.usersService.ShowByUsername(authToken, username) if err != nil { return err } @@ -163,7 +161,7 @@ func (_i *usersController) ShowByUsername(c *fiber.Ctx) error { // @Description API for ShowUserInfo // @Tags Users // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -173,10 +171,7 @@ func (_i *usersController) ShowByUsername(c *fiber.Ctx) error { func (_i *usersController) ShowInfo(c *fiber.Ctx) error { authToken := c.Get("Authorization") - // Get ClientId from context - clientId := middleware.GetClientID(c) - - dataResult, err := _i.usersService.ShowUserInfo(clientId, authToken) + dataResult, err := _i.usersService.ShowUserInfo(authToken) if err != nil { return err } @@ -193,8 +188,7 @@ func (_i *usersController) ShowInfo(c *fiber.Ctx) error { // @Description API for create Users // @Tags Users // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param payload body request.UsersCreateRequest true "Required payload" // @Success 200 {object} response.Response @@ -210,10 +204,7 @@ func (_i *usersController) Save(c *fiber.Ctx) error { authToken := c.Get("Authorization") - // Get ClientId from context - clientId := middleware.GetClientID(c) - - dataResult, err := _i.usersService.Save(clientId, *req, authToken) + dataResult, err := _i.usersService.Save(authToken, *req) if err != nil { return err } @@ -230,8 +221,7 @@ func (_i *usersController) Save(c *fiber.Ctx) error { // @Description API for update Users // @Tags Users // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "Users ID" // @Param payload body request.UsersUpdateRequest true "Required payload" // @Success 200 {object} response.Response @@ -250,10 +240,10 @@ func (_i *usersController) Update(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - err = _i.usersService.Update(clientId, uint(id), *req) + err = _i.usersService.Update(authToken, uint(id), *req) if err != nil { return err } @@ -269,7 +259,6 @@ func (_i *usersController) Update(c *fiber.Ctx) error { // @Description API for Login Users // @Tags Users // @Security Bearer -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" // @Param payload body request.UserLogin true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -303,7 +292,6 @@ func (_i *usersController) Login(c *fiber.Ctx) error { // @Description API for ParetoLogin Users // @Tags Users // @Security Bearer -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" // @Param payload body request.UserLogin true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -337,8 +325,7 @@ func (_i *usersController) ParetoLogin(c *fiber.Ctx) error { // @Description API for delete Users // @Tags Users // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param id path int true "Users ID" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -351,10 +338,10 @@ func (_i *usersController) Delete(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - err = _i.usersService.Delete(clientId, uint(id)) + err = _i.usersService.Delete(authToken, uint(id)) if err != nil { return err } @@ -370,8 +357,7 @@ func (_i *usersController) Delete(c *fiber.Ctx) error { // @Description API for SavePassword Users // @Tags Users // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param payload body request.UserSavePassword true "Required payload" // @Success 200 {object} response.Response @@ -387,10 +373,7 @@ func (_i *usersController) SavePassword(c *fiber.Ctx) error { authToken := c.Get("Authorization") - // Get ClientId from context - clientId := middleware.GetClientID(c) - - err := _i.usersService.SavePassword(clientId, *req, authToken) + err := _i.usersService.SavePassword(authToken, *req) if err != nil { return err } @@ -406,7 +389,6 @@ func (_i *usersController) SavePassword(c *fiber.Ctx) error { // @Description API for ResetPassword Users // @Tags Users // @Security Bearer -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" // @Param payload body request.UserResetPassword true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -435,8 +417,7 @@ func (_i *usersController) ResetPassword(c *fiber.Ctx) error { // @Description API for ForgotPassword Users // @Tags Users // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param payload body request.UserForgotPassword true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -449,10 +430,10 @@ func (_i *usersController) ForgotPassword(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - err := _i.usersService.ForgotPassword(clientId, *req) + err := _i.usersService.ForgotPassword(authToken, *req) if err != nil { return err } @@ -468,7 +449,6 @@ func (_i *usersController) ForgotPassword(c *fiber.Ctx) error { // @Description API for OtpRequest Users // @Tags Users // @Security Bearer -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" // @Param payload body request.UserOtpRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -497,7 +477,6 @@ func (_i *usersController) OtpRequest(c *fiber.Ctx) error { // @Description API for OtpValidation Users // @Tags Users // @Security Bearer -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" // @Param payload body request.UserOtpValidation true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -526,8 +505,7 @@ func (_i *usersController) OtpValidation(c *fiber.Ctx) error { // @Description API for Email Validation Users // @Tags Users // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param payload body request.UserEmailValidationRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -540,10 +518,10 @@ func (_i *usersController) EmailValidation(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - messageResponse, err := _i.usersService.EmailValidationPreLogin(clientId, *req) + messageResponse, err := _i.usersService.EmailValidationPreLogin(authToken, *req) if err != nil { return err } @@ -559,8 +537,7 @@ func (_i *usersController) EmailValidation(c *fiber.Ctx) error { // @Description API for Setup Email Users // @Tags Users // @Security Bearer -// @Param X-Client-Key header string false "Insert the X-Client-Key" -// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token" +// @Param Authorization header string false "Insert your access token" default(Bearer ) // @Param payload body request.UserEmailValidationRequest true "Required payload" // @Success 200 {object} response.Response // @Failure 400 {object} response.BadRequestError @@ -573,10 +550,10 @@ func (_i *usersController) SetupEmail(c *fiber.Ctx) error { return err } - // Get ClientId from context - clientId := middleware.GetClientID(c) + // Get Authorization token from header + authToken := c.Get("Authorization") - messageResponse, err := _i.usersService.SetupEmail(clientId, *req) + messageResponse, err := _i.usersService.SetupEmail(authToken, *req) if err != nil { return err } diff --git a/app/module/users/service/users.service.go b/app/module/users/service/users.service.go index b283824..9d6510d 100644 --- a/app/module/users/service/users.service.go +++ b/app/module/users/service/users.service.go @@ -34,20 +34,20 @@ type usersService struct { // UsersService define interface of IUsersService type UsersService interface { - All(clientId *uuid.UUID, req request.UsersQueryRequest) (users []*response.UsersResponse, paging paginator.Pagination, err error) - Show(clientId *uuid.UUID, id uint) (users *response.UsersResponse, err error) - ShowByUsername(clientId *uuid.UUID, username string) (users *response.UsersResponse, err error) - ShowUserInfo(clientId *uuid.UUID, authToken string) (users *response.UsersResponse, err error) - Save(clientId *uuid.UUID, req request.UsersCreateRequest, authToken string) (userReturn *users.Users, err error) + All(authToken string, req request.UsersQueryRequest) (users []*response.UsersResponse, paging paginator.Pagination, err error) + Show(authToken string, id uint) (users *response.UsersResponse, err error) + ShowByUsername(authToken string, username string) (users *response.UsersResponse, err error) + ShowUserInfo(authToken string) (users *response.UsersResponse, err error) + Save(authToken string, req request.UsersCreateRequest) (userReturn *users.Users, err error) Login(req request.UserLogin) (res *gocloak.JWT, err error) ParetoLogin(req request.UserLogin) (res *response.ParetoLoginResponse, err error) - Update(clientId *uuid.UUID, id uint, req request.UsersUpdateRequest) (err error) - Delete(clientId *uuid.UUID, id uint) error - SavePassword(clientId *uuid.UUID, req request.UserSavePassword, authToken string) (err error) + Update(authToken string, id uint, req request.UsersUpdateRequest) (err error) + Delete(authToken string, id uint) error + SavePassword(authToken string, req request.UserSavePassword) (err error) ResetPassword(req request.UserResetPassword) (err error) - ForgotPassword(clientId *uuid.UUID, req request.UserForgotPassword) (err error) - EmailValidationPreLogin(clientId *uuid.UUID, req request.UserEmailValidationRequest) (msgResponse *string, err error) - SetupEmail(clientId *uuid.UUID, req request.UserEmailValidationRequest) (msgResponse *string, err error) + ForgotPassword(authToken string, req request.UserForgotPassword) (err error) + EmailValidationPreLogin(authToken string, req request.UserEmailValidationRequest) (msgResponse *string, err error) + SetupEmail(authToken string, req request.UserEmailValidationRequest) (msgResponse *string, err error) OtpRequest(req request.UserOtpRequest) (err error) OtpValidation(req request.UserOtpValidation) (err error) SendLoginOtp(name string, email string, otp string) error @@ -67,7 +67,17 @@ func NewUsersService(repo repository.UsersRepository, userLevelsRepo userLevelsR } // All implement interface of UsersService -func (_i *usersService) All(clientId *uuid.UUID, req request.UsersQueryRequest) (users []*response.UsersResponse, paging paginator.Pagination, err error) { +func (_i *usersService) All(authToken string, req request.UsersQueryRequest) (users []*response.UsersResponse, paging paginator.Pagination, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.Repo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + results, paging, err := _i.Repo.GetAll(clientId, req) if err != nil { return @@ -80,7 +90,17 @@ func (_i *usersService) All(clientId *uuid.UUID, req request.UsersQueryRequest) return } -func (_i *usersService) Show(clientId *uuid.UUID, id uint) (users *response.UsersResponse, err error) { +func (_i *usersService) Show(authToken string, id uint) (users *response.UsersResponse, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.Repo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOne(clientId, id) if err != nil { return nil, err @@ -89,7 +109,17 @@ func (_i *usersService) Show(clientId *uuid.UUID, id uint) (users *response.User return mapper.UsersResponseMapper(result, _i.UserLevelsRepo, clientId), nil } -func (_i *usersService) ShowByUsername(clientId *uuid.UUID, username string) (users *response.UsersResponse, err error) { +func (_i *usersService) ShowByUsername(authToken string, username string) (users *response.UsersResponse, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.Repo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindByUsername(clientId, username) if err != nil { return nil, err @@ -98,13 +128,33 @@ func (_i *usersService) ShowByUsername(clientId *uuid.UUID, username string) (us return mapper.UsersResponseMapper(result, _i.UserLevelsRepo, clientId), nil } -func (_i *usersService) ShowUserInfo(clientId *uuid.UUID, authToken string) (users *response.UsersResponse, err error) { +func (_i *usersService) ShowUserInfo(authToken string) (users *response.UsersResponse, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.Repo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + userInfo := utilSvc.GetUserInfo(_i.Log, _i.Repo, authToken) return mapper.UsersResponseMapper(userInfo, _i.UserLevelsRepo, clientId), nil } -func (_i *usersService) Save(clientId *uuid.UUID, req request.UsersCreateRequest, authToken string) (userReturn *users.Users, err error) { +func (_i *usersService) Save(authToken string, req request.UsersCreateRequest) (userReturn *users.Users, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.Repo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + _i.Log.Info().Interface("data", req).Msg("") newReq := req.ToEntity() @@ -219,7 +269,17 @@ func (_i *usersService) ParetoLogin(req request.UserLogin) (res *response.Pareto return resLogin, nil } -func (_i *usersService) Update(clientId *uuid.UUID, id uint, req request.UsersUpdateRequest) (err error) { +func (_i *usersService) Update(authToken string, id uint, req request.UsersUpdateRequest) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.Repo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + _i.Log.Info().Interface("data", req).Msg("") newReq := req.ToEntity() @@ -239,7 +299,17 @@ func (_i *usersService) Update(clientId *uuid.UUID, id uint, req request.UsersUp return _i.Repo.Update(clientId, id, newReq) } -func (_i *usersService) Delete(clientId *uuid.UUID, id uint) error { +func (_i *usersService) Delete(authToken string, id uint) error { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.Repo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + result, err := _i.Repo.FindOne(clientId, id) if err != nil { return err @@ -250,7 +320,17 @@ func (_i *usersService) Delete(clientId *uuid.UUID, id uint) error { return _i.Repo.Update(clientId, id, result) } -func (_i *usersService) SavePassword(clientId *uuid.UUID, req request.UserSavePassword, authToken string) (err error) { +func (_i *usersService) SavePassword(authToken string, req request.UserSavePassword) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.Repo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + _i.Log.Info().Interface("data", req).Msg("") _i.Log.Info().Interface("AUTH TOKEN", authToken).Msg("") @@ -311,7 +391,17 @@ func (_i *usersService) ResetPassword(req request.UserResetPassword) (err error) } } -func (_i *usersService) ForgotPassword(clientId *uuid.UUID, req request.UserForgotPassword) (err error) { +func (_i *usersService) ForgotPassword(authToken string, req request.UserForgotPassword) (err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.Repo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + _i.Log.Info().Interface("data", req).Msg("") user, err := _i.Repo.FindByUsername(clientId, req.Username) @@ -408,7 +498,17 @@ func (_i *usersService) OtpValidation(req request.UserOtpValidation) (err error) } } -func (_i *usersService) EmailValidationPreLogin(clientId *uuid.UUID, req request.UserEmailValidationRequest) (msgResponse *string, err error) { +func (_i *usersService) EmailValidationPreLogin(authToken string, req request.UserEmailValidationRequest) (msgResponse *string, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.Repo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + _i.Log.Info().Interface("data", req).Msg("") var loginResponse *gocloak.JWT @@ -457,7 +557,17 @@ func (_i *usersService) EmailValidationPreLogin(clientId *uuid.UUID, req request return msgResponse, nil } -func (_i *usersService) SetupEmail(clientId *uuid.UUID, req request.UserEmailValidationRequest) (msgResponse *string, err error) { +func (_i *usersService) SetupEmail(authToken string, req request.UserEmailValidationRequest) (msgResponse *string, err error) { + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.Repo, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + _i.Log.Info().Interface("data", req).Msg("") var loginResponse *gocloak.JWT diff --git a/docs/MODULE_UPDATE_TEMPLATE.md b/docs/MODULE_UPDATE_TEMPLATE.md new file mode 100644 index 0000000..e7c9629 --- /dev/null +++ b/docs/MODULE_UPDATE_TEMPLATE.md @@ -0,0 +1,135 @@ +# Template untuk mengupdate Service Interface dan Implementation + +## 1. Service Interface Update + +**Before:** +```go +type ModuleService interface { + All(clientId *uuid.UUID, authToken string, req request.ModuleQueryRequest) (data []*response.ModuleResponse, paging paginator.Pagination, err error) + Show(clientId *uuid.UUID, id uint) (data *response.ModuleResponse, err error) + Save(clientId *uuid.UUID, req request.ModuleCreateRequest, authToken string) (data *entity.Module, err error) + Update(clientId *uuid.UUID, id uint, req request.ModuleUpdateRequest) (err error) + Delete(clientId *uuid.UUID, id uint) error +} +``` + +**After:** +```go +type ModuleService interface { + All(authToken string, req request.ModuleQueryRequest) (data []*response.ModuleResponse, paging paginator.Pagination, err error) + Show(authToken string, id uint) (data *response.ModuleResponse, err error) + Save(authToken string, req request.ModuleCreateRequest) (data *entity.Module, err error) + Update(authToken string, id uint, req request.ModuleUpdateRequest) (err error) + Delete(authToken string, id uint) error +} +``` + +## 2. Service Implementation Update + +**Before:** +```go +func (_i *moduleService) All(clientId *uuid.UUID, authToken string, req request.ModuleQueryRequest) (data []*response.ModuleResponse, paging paginator.Pagination, err error) { + // Extract userLevelId from authToken + var userLevelId *uint + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil { + userLevelId = &user.UserLevelId + } + } + + results, paging, err := _i.Repo.GetAll(clientId, userLevelId, req) + // ... rest of implementation +} +``` + +**After:** +```go +func (_i *moduleService) All(authToken string, req request.ModuleQueryRequest) (data []*response.ModuleResponse, paging paginator.Pagination, err error) { + // Extract clientId and userLevelId from authToken + var clientId *uuid.UUID + var userLevelId *uint + + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken) + if user != nil { + clientId = user.ClientId + userLevelId = &user.UserLevelId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + results, paging, err := _i.Repo.GetAll(clientId, userLevelId, req) + // ... rest of implementation +} +``` + +## 3. Controller Update + +**Before:** +```go +func (_i *moduleController) All(c *fiber.Ctx) error { + // ... pagination setup ... + + // Get ClientId from context + clientId := middleware.GetClientID(c) + + // Get Authorization token from header + authToken := c.Get("Authorization") + + data, paging, err := _i.moduleService.All(clientId, authToken, req) + // ... rest of implementation +} +``` + +**After:** +```go +func (_i *moduleController) All(c *fiber.Ctx) error { + // ... pagination setup ... + + // Get Authorization token from header + authToken := c.Get("Authorization") + _i.Log.Info().Str("authToken", authToken).Msg("") + + data, paging, err := _i.moduleService.All(authToken, req) + // ... rest of implementation +} +``` + +## 4. Swagger Documentation Update + +**Before:** +```go +// @Param X-Client-Key header string true "Insert the X-Client-Key" +// @Param Authorization header string false "Insert your access token" default(Bearer ) +``` + +**After:** +```go +// @Param Authorization header string false "Insert your access token" default(Bearer ) +``` + +## 5. Import Cleanup + +Remove unused middleware import: +```go +// Remove this line if no longer needed: +"netidhub-saas-be/app/middleware" +``` + +## 6. Key Changes Summary + +1. **Remove X-Client-Key header** from all Swagger documentation +2. **Remove GetClientID() calls** from controllers +3. **Update service interfaces** to use authToken instead of clientId parameter +4. **Update service implementations** to extract clientId from authToken using GetUserInfo() +5. **Remove middleware import** if no longer needed +6. **Update all method calls** to match new signatures + +## 7. Benefits + +- **Simpler API**: No need for X-Client-Key header +- **Auth-based**: clientId comes from authenticated user +- **Consistent**: Same pattern across all modules +- **Secure**: Tied to user authentication +- **Maintainable**: Less parameters to manage diff --git a/docs/swagger/docs.go b/docs/swagger/docs.go index ef8fe8d..b644b2a 100644 --- a/docs/swagger/docs.go +++ b/docs/swagger/docs.go @@ -1007,8 +1007,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1090,8 +1090,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1148,8 +1148,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1206,8 +1206,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1262,8 +1262,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1318,8 +1318,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1383,8 +1383,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1437,8 +1437,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1500,8 +1500,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1556,8 +1556,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1663,8 +1663,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1721,8 +1721,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true } @@ -1770,8 +1770,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1828,8 +1828,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1882,8 +1882,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1945,8 +1945,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2001,8 +2001,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2057,8 +2057,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2113,8 +2113,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2169,8 +2169,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2223,8 +2223,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2288,8 +2288,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2412,8 +2412,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2486,8 +2486,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2542,8 +2542,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2643,8 +2643,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2751,8 +2751,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2847,8 +2847,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2912,8 +2912,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2968,8 +2968,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -3024,8 +3024,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -3096,8 +3096,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -3168,8 +3168,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -3240,8 +3240,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -4636,9 +4636,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "string", @@ -4764,15 +4765,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "string", @@ -4834,9 +4830,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "integer", @@ -4889,9 +4886,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "string", @@ -4944,9 +4942,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "string", @@ -5002,15 +5001,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "file", @@ -5070,9 +5064,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "integer", @@ -5123,15 +5118,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "description": "Required payload", @@ -5191,15 +5181,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "integer", @@ -5949,8 +5934,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -6106,8 +6092,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -6164,14 +6151,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -6232,8 +6214,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -6285,14 +6268,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -6353,14 +6331,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -6810,13 +6783,6 @@ const docTemplate = `{ ], "summary": "Get all Articles", "parameters": [ - { - "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true - }, { "type": "string", "default": "Bearer \u003cAdd access token here\u003e", @@ -6959,18 +6925,6 @@ const docTemplate = `{ ], "summary": "Create Articles", "parameters": [ - { - "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, { "type": "string", "default": "Bearer \u003cAdd access token here\u003e", @@ -7031,14 +6985,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -7099,17 +7048,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true - }, - { - "type": "integer", - "description": "Articles Old ID", - "name": "id", - "in": "path", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" } ], "responses": { @@ -7155,8 +7097,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -7228,15 +7171,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -7467,8 +7404,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -7525,23 +7463,11 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, - { - "type": "file", - "description": "Upload thumbnail", - "name": "files", - "in": "formData", - "required": true - }, { "type": "integer", "description": "Articles ID", @@ -7593,10 +7519,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -7663,17 +7589,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true - }, - { - "type": "integer", - "description": "Articles ID", - "name": "id", - "in": "path", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" } ], "responses": { @@ -7717,25 +7636,11 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, - { - "description": "Required payload", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/request.ArticlesUpdateRequest" - } - }, { "type": "integer", "description": "Articles ID", @@ -7785,14 +7690,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -7846,8 +7746,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -7908,15 +7809,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -7985,10 +7880,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -8089,10 +7984,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -8154,10 +8049,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -8210,10 +8105,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -8273,10 +8168,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -8379,10 +8274,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -8440,10 +8335,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -8780,8 +8675,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true } @@ -8827,8 +8722,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -8883,8 +8778,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -8939,8 +8834,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true } @@ -8988,8 +8883,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -9046,8 +8941,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -9104,8 +8999,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -9162,8 +9057,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -9225,8 +9120,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -9288,8 +9183,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -9351,8 +9246,8 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -9401,61 +9296,96 @@ const docTemplate = `{ "Bearer": [] } ], - "description": "API for getting all Clients", + "description": "API for getting all Clients with hierarchy filtering", "tags": [ "Clients" ], "summary": "Get all Clients", "parameters": [ { - "type": "integer", - "name": "createdBy", - "in": "query" + "type": "string", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", + "description": "Filter by client name", "name": "name", "in": "query" }, { - "type": "integer", - "name": "count", - "in": "query" - }, - { - "type": "integer", - "name": "limit", - "in": "query" - }, - { - "type": "integer", - "name": "nextPage", + "type": "string", + "description": "Filter by client type (parent_client, sub_client, standalone)", + "name": "clientType", + "in": "query" + }, + { + "type": "string", + "description": "Filter by parent client ID", + "name": "parentClientId", + "in": "query" + }, + { + "type": "boolean", + "description": "Include all descendants", + "name": "includeSubClients", + "in": "query" + }, + { + "type": "boolean", + "description": "Only clients with children", + "name": "onlyParentClients", + "in": "query" + }, + { + "type": "boolean", + "description": "Only standalone clients", + "name": "onlyStandalone", + "in": "query" + }, + { + "type": "boolean", + "description": "Only root level clients", + "name": "onlyRootClients", + "in": "query" + }, + { + "type": "boolean", + "description": "Filter by active status", + "name": "isActive", + "in": "query" + }, + { + "type": "string", + "description": "Filter by creator ID", + "name": "createdById", "in": "query" }, { "type": "integer", + "description": "Page number", "name": "page", "in": "query" }, { "type": "integer", - "name": "previousPage", + "description": "Items per page", + "name": "limit", "in": "query" }, { "type": "string", + "description": "Sort field", "name": "sort", "in": "query" }, { "type": "string", + "description": "Sort direction (asc, desc)", "name": "sortBy", "in": "query" - }, - { - "type": "integer", - "name": "totalPage", - "in": "query" } ], "responses": { @@ -9542,6 +9472,57 @@ const docTemplate = `{ } } }, + "/clients/bulk-sub-clients": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for creating multiple sub-clients at once", + "tags": [ + "Clients" + ], + "summary": "Bulk create sub-clients", + "parameters": [ + { + "description": "Required payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.BulkCreateSubClientsRequest" + } + } + ], + "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" + } + } + } + } + }, "/clients/{id}": { "get": { "security": [ @@ -9694,6 +9675,267 @@ const docTemplate = `{ } } }, + "/clients/{id}/hierarchy": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for getting client tree structure", + "tags": [ + "Clients" + ], + "summary": "Get client hierarchy", + "parameters": [ + { + "type": "string", + "description": "Client ID", + "name": "id", + "in": "path", + "required": true + } + ], + "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" + } + } + } + } + }, + "/clients/{id}/move": { + "put": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for moving a client to different parent", + "tags": [ + "Clients" + ], + "summary": "Move client", + "parameters": [ + { + "type": "string", + "description": "Client ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Required payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.MoveClientRequest" + } + } + ], + "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" + } + } + } + } + }, + "/clients/{id}/stats": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for getting client statistics", + "tags": [ + "Clients" + ], + "summary": "Get client statistics", + "parameters": [ + { + "type": "string", + "description": "Client ID", + "name": "id", + "in": "path", + "required": true + } + ], + "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" + } + } + } + } + }, + "/clients/{id}/sub-clients": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for getting direct children of a client", + "tags": [ + "Clients" + ], + "summary": "Get sub-clients", + "parameters": [ + { + "type": "string", + "description": "Parent Client ID", + "name": "id", + "in": "path", + "required": true + } + ], + "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" + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for creating a client under a parent", + "tags": [ + "Clients" + ], + "summary": "Create sub-client", + "parameters": [ + { + "type": "string", + "description": "Parent Client ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Required payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.ClientsCreateRequest" + } + } + ], + "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" + } + } + } + } + }, "/custom-static-pages": { "get": { "security": [ @@ -13486,10 +13728,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "integer", @@ -13593,10 +13835,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -13664,10 +13906,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -13720,10 +13962,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -13791,10 +14033,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "integer", @@ -13845,10 +14087,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -13921,10 +14163,10 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -14859,70 +15101,11 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, - { - "type": "string", - "name": "email", - "in": "query" - }, - { - "type": "string", - "name": "fullname", - "in": "query" - }, - { - "type": "string", - "name": "genderType", - "in": "query" - }, - { - "type": "string", - "name": "identityGroup", - "in": "query" - }, - { - "type": "string", - "name": "identityGroupNumber", - "in": "query" - }, - { - "type": "string", - "name": "identityNumber", - "in": "query" - }, - { - "type": "string", - "name": "identityType", - "in": "query" - }, - { - "type": "string", - "name": "phoneNumber", - "in": "query" - }, - { - "type": "integer", - "name": "statusId", - "in": "query" - }, - { - "type": "integer", - "name": "userRoleId", - "in": "query" - }, - { - "type": "string", - "name": "username", - "in": "query" - }, - { - "type": "string", - "name": "workType", - "in": "query" - }, { "type": "integer", "name": "count", @@ -15005,14 +15188,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15075,8 +15253,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15130,14 +15309,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15193,14 +15367,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15256,8 +15425,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15309,12 +15479,6 @@ const docTemplate = `{ ], "summary": "Login Users", "parameters": [ - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, { "description": "Required payload", "name": "payload", @@ -15366,12 +15530,6 @@ const docTemplate = `{ ], "summary": "OtpRequest Users", "parameters": [ - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, { "description": "Required payload", "name": "payload", @@ -15423,12 +15581,6 @@ const docTemplate = `{ ], "summary": "OtpValidation Users", "parameters": [ - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, { "description": "Required payload", "name": "payload", @@ -15480,12 +15632,6 @@ const docTemplate = `{ ], "summary": "ParetoLogin Users", "parameters": [ - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, { "description": "Required payload", "name": "payload", @@ -15537,12 +15683,6 @@ const docTemplate = `{ ], "summary": "ResetPassword Users", "parameters": [ - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, { "description": "Required payload", "name": "payload", @@ -15596,14 +15736,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15666,14 +15801,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15729,8 +15859,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15784,14 +15915,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15852,14 +15978,9 @@ const docTemplate = `{ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15900,6 +16021,33 @@ const docTemplate = `{ } }, "definitions": { + "netidhub-saas-be_app_module_article_approval_flows_request.SubmitForApprovalRequest": { + "type": "object", + "required": [ + "articleId" + ], + "properties": { + "articleId": { + "type": "integer" + }, + "workflowId": { + "type": "integer" + } + } + }, + "netidhub-saas-be_app_module_articles_request.SubmitForApprovalRequest": { + "type": "object", + "properties": { + "message": { + "type": "string", + "maxLength": 500 + }, + "workflow_id": { + "type": "integer", + "minimum": 1 + } + } + }, "paginator.Pagination": { "type": "object", "properties": { @@ -16620,59 +16768,6 @@ const docTemplate = `{ } } }, - "request.ArticlesUpdateRequest": { - "type": "object", - "required": [ - "categoryIds", - "description", - "htmlDescription", - "slug", - "tags", - "title", - "typeId" - ], - "properties": { - "aiArticleId": { - "type": "integer" - }, - "categoryIds": { - "type": "string" - }, - "createdAt": { - "type": "string" - }, - "createdById": { - "type": "integer" - }, - "description": { - "type": "string" - }, - "htmlDescription": { - "type": "string" - }, - "isDraft": { - "type": "boolean" - }, - "isPublish": { - "type": "boolean" - }, - "slug": { - "type": "string" - }, - "statusId": { - "type": "integer" - }, - "tags": { - "type": "string" - }, - "title": { - "type": "string" - }, - "typeId": { - "type": "integer" - } - } - }, "request.BookmarksCreateRequest": { "type": "object", "required": [ @@ -16704,6 +16799,25 @@ const docTemplate = `{ } } }, + "request.BulkCreateSubClientsRequest": { + "type": "object", + "required": [ + "parentClientId", + "subClients" + ], + "properties": { + "parentClientId": { + "type": "string" + }, + "subClients": { + "type": "array", + "minItems": 1, + "items": { + "$ref": "#/definitions/request.ClientsCreateSubClientDetail" + } + } + } + }, "request.BulkProcessApprovalRequest": { "type": "object", "required": [ @@ -16782,10 +16896,55 @@ const docTemplate = `{ "request.ClientsCreateRequest": { "type": "object", "required": [ + "clientType", "name" ], "properties": { - "createdById": { + "clientType": { + "description": "Enum validation", + "type": "string", + "enum": [ + "parent_client", + "sub_client", + "standalone" + ] + }, + "description": { + "type": "string" + }, + "maxStorage": { + "type": "integer" + }, + "maxUsers": { + "description": "Resource limits", + "type": "integer" + }, + "name": { + "type": "string" + }, + "parentClientId": { + "description": "Optional: only for sub_client type", + "type": "string" + }, + "settings": { + "description": "Custom settings (JSON string)", + "type": "string" + } + } + }, + "request.ClientsCreateSubClientDetail": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "description": { + "type": "string" + }, + "maxStorage": { + "type": "integer" + }, + "maxUsers": { "type": "integer" }, "name": { @@ -16795,15 +16954,37 @@ const docTemplate = `{ }, "request.ClientsUpdateRequest": { "type": "object", - "required": [ - "name" - ], "properties": { - "createdById": { + "clientType": { + "type": "string", + "enum": [ + "parent_client", + "sub_client", + "standalone" + ] + }, + "description": { + "type": "string" + }, + "isActive": { + "type": "boolean" + }, + "maxStorage": { + "type": "integer" + }, + "maxUsers": { + "description": "Resource limits", "type": "integer" }, "name": { "type": "string" + }, + "parentClientId": { + "type": "string" + }, + "settings": { + "description": "Custom settings", + "type": "string" } } }, @@ -17188,6 +17369,15 @@ const docTemplate = `{ } } }, + "request.MoveClientRequest": { + "type": "object", + "properties": { + "targetParentId": { + "description": "null = move to root (standalone)", + "type": "string" + } + } + }, "request.ProcessApprovalRequest": { "type": "object", "required": [ @@ -18011,33 +18201,6 @@ const docTemplate = `{ "example": false } } - }, - "netidhub-saas-be_app_module_article_approval_flows_request.SubmitForApprovalRequest": { - "type": "object", - "required": [ - "articleId" - ], - "properties": { - "articleId": { - "type": "integer" - }, - "workflowId": { - "type": "integer" - } - } - }, - "netidhub-saas-be_app_module_articles_request.SubmitForApprovalRequest": { - "type": "object", - "properties": { - "message": { - "type": "string", - "maxLength": 500 - }, - "workflow_id": { - "type": "integer", - "minimum": 1 - } - } } } }` diff --git a/docs/swagger/swagger.json b/docs/swagger/swagger.json index ddb72a2..40e2558 100644 --- a/docs/swagger/swagger.json +++ b/docs/swagger/swagger.json @@ -996,8 +996,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1079,8 +1079,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1137,8 +1137,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1195,8 +1195,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1251,8 +1251,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1307,8 +1307,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1372,8 +1372,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1426,8 +1426,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1489,8 +1489,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1545,8 +1545,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1652,8 +1652,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1710,8 +1710,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true } @@ -1759,8 +1759,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1817,8 +1817,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1871,8 +1871,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1934,8 +1934,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -1990,8 +1990,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2046,8 +2046,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2102,8 +2102,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2158,8 +2158,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2212,8 +2212,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2277,8 +2277,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2401,8 +2401,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2475,8 +2475,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2531,8 +2531,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2632,8 +2632,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2740,8 +2740,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2836,8 +2836,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2901,8 +2901,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -2957,8 +2957,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -3013,8 +3013,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -3085,8 +3085,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -3157,8 +3157,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -3229,8 +3229,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -4625,9 +4625,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "string", @@ -4753,15 +4754,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "string", @@ -4823,9 +4819,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "integer", @@ -4878,9 +4875,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "string", @@ -4933,9 +4931,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "string", @@ -4991,15 +4990,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "file", @@ -5059,9 +5053,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "integer", @@ -5112,15 +5107,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "description": "Required payload", @@ -5180,15 +5170,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" + "description": "Insert the Authorization", + "name": "Authorization", + "in": "header", + "required": true }, { "type": "integer", @@ -5938,8 +5923,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -6095,8 +6081,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -6153,14 +6140,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -6221,8 +6203,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -6274,14 +6257,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -6342,14 +6320,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -6799,13 +6772,6 @@ ], "summary": "Get all Articles", "parameters": [ - { - "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true - }, { "type": "string", "default": "Bearer \u003cAdd access token here\u003e", @@ -6948,18 +6914,6 @@ ], "summary": "Create Articles", "parameters": [ - { - "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, { "type": "string", "default": "Bearer \u003cAdd access token here\u003e", @@ -7020,14 +6974,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -7088,17 +7037,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true - }, - { - "type": "integer", - "description": "Articles Old ID", - "name": "id", - "in": "path", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" } ], "responses": { @@ -7144,8 +7086,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -7217,15 +7160,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -7456,8 +7393,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -7514,23 +7452,11 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, - { - "type": "file", - "description": "Upload thumbnail", - "name": "files", - "in": "formData", - "required": true - }, { "type": "integer", "description": "Articles ID", @@ -7582,10 +7508,10 @@ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -7652,17 +7578,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true - }, - { - "type": "integer", - "description": "Articles ID", - "name": "id", - "in": "path", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" } ], "responses": { @@ -7706,25 +7625,11 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, - { - "description": "Required payload", - "name": "payload", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/request.ArticlesUpdateRequest" - } - }, { "type": "integer", "description": "Articles ID", @@ -7774,14 +7679,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -7835,8 +7735,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -7897,15 +7798,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -7974,10 +7869,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -8078,10 +7973,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -8143,10 +8038,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -8199,10 +8094,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -8262,10 +8157,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -8368,10 +8263,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -8429,10 +8324,10 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -8769,8 +8664,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true } @@ -8816,8 +8711,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -8872,8 +8767,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -8928,8 +8823,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true } @@ -8977,8 +8872,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -9035,8 +8930,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -9093,8 +8988,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -9151,8 +9046,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -9214,8 +9109,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -9277,8 +9172,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -9340,8 +9235,8 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "description": "Insert the Authorization", + "name": "Authorization", "in": "header", "required": true }, @@ -9390,61 +9285,96 @@ "Bearer": [] } ], - "description": "API for getting all Clients", + "description": "API for getting all Clients with hierarchy filtering", "tags": [ "Clients" ], "summary": "Get all Clients", "parameters": [ { - "type": "integer", - "name": "createdBy", - "in": "query" + "type": "string", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", + "description": "Filter by client name", "name": "name", "in": "query" }, { - "type": "integer", - "name": "count", - "in": "query" - }, - { - "type": "integer", - "name": "limit", - "in": "query" - }, - { - "type": "integer", - "name": "nextPage", + "type": "string", + "description": "Filter by client type (parent_client, sub_client, standalone)", + "name": "clientType", + "in": "query" + }, + { + "type": "string", + "description": "Filter by parent client ID", + "name": "parentClientId", + "in": "query" + }, + { + "type": "boolean", + "description": "Include all descendants", + "name": "includeSubClients", + "in": "query" + }, + { + "type": "boolean", + "description": "Only clients with children", + "name": "onlyParentClients", + "in": "query" + }, + { + "type": "boolean", + "description": "Only standalone clients", + "name": "onlyStandalone", + "in": "query" + }, + { + "type": "boolean", + "description": "Only root level clients", + "name": "onlyRootClients", + "in": "query" + }, + { + "type": "boolean", + "description": "Filter by active status", + "name": "isActive", + "in": "query" + }, + { + "type": "string", + "description": "Filter by creator ID", + "name": "createdById", "in": "query" }, { "type": "integer", + "description": "Page number", "name": "page", "in": "query" }, { "type": "integer", - "name": "previousPage", + "description": "Items per page", + "name": "limit", "in": "query" }, { "type": "string", + "description": "Sort field", "name": "sort", "in": "query" }, { "type": "string", + "description": "Sort direction (asc, desc)", "name": "sortBy", "in": "query" - }, - { - "type": "integer", - "name": "totalPage", - "in": "query" } ], "responses": { @@ -9531,6 +9461,57 @@ } } }, + "/clients/bulk-sub-clients": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for creating multiple sub-clients at once", + "tags": [ + "Clients" + ], + "summary": "Bulk create sub-clients", + "parameters": [ + { + "description": "Required payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.BulkCreateSubClientsRequest" + } + } + ], + "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" + } + } + } + } + }, "/clients/{id}": { "get": { "security": [ @@ -9683,6 +9664,267 @@ } } }, + "/clients/{id}/hierarchy": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for getting client tree structure", + "tags": [ + "Clients" + ], + "summary": "Get client hierarchy", + "parameters": [ + { + "type": "string", + "description": "Client ID", + "name": "id", + "in": "path", + "required": true + } + ], + "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" + } + } + } + } + }, + "/clients/{id}/move": { + "put": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for moving a client to different parent", + "tags": [ + "Clients" + ], + "summary": "Move client", + "parameters": [ + { + "type": "string", + "description": "Client ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Required payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.MoveClientRequest" + } + } + ], + "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" + } + } + } + } + }, + "/clients/{id}/stats": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for getting client statistics", + "tags": [ + "Clients" + ], + "summary": "Get client statistics", + "parameters": [ + { + "type": "string", + "description": "Client ID", + "name": "id", + "in": "path", + "required": true + } + ], + "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" + } + } + } + } + }, + "/clients/{id}/sub-clients": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for getting direct children of a client", + "tags": [ + "Clients" + ], + "summary": "Get sub-clients", + "parameters": [ + { + "type": "string", + "description": "Parent Client ID", + "name": "id", + "in": "path", + "required": true + } + ], + "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" + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "API for creating a client under a parent", + "tags": [ + "Clients" + ], + "summary": "Create sub-client", + "parameters": [ + { + "type": "string", + "description": "Parent Client ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Required payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.ClientsCreateRequest" + } + } + ], + "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" + } + } + } + } + }, "/custom-static-pages": { "get": { "security": [ @@ -13475,10 +13717,10 @@ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "integer", @@ -13582,10 +13824,10 @@ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -13653,10 +13895,10 @@ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -13709,10 +13951,10 @@ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -13780,10 +14022,10 @@ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "integer", @@ -13834,10 +14076,10 @@ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -13910,10 +14152,10 @@ "parameters": [ { "type": "string", - "description": "Client Key", - "name": "X-Client-Key", - "in": "header", - "required": true + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", + "in": "header" }, { "type": "string", @@ -14848,70 +15090,11 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, - { - "type": "string", - "name": "email", - "in": "query" - }, - { - "type": "string", - "name": "fullname", - "in": "query" - }, - { - "type": "string", - "name": "genderType", - "in": "query" - }, - { - "type": "string", - "name": "identityGroup", - "in": "query" - }, - { - "type": "string", - "name": "identityGroupNumber", - "in": "query" - }, - { - "type": "string", - "name": "identityNumber", - "in": "query" - }, - { - "type": "string", - "name": "identityType", - "in": "query" - }, - { - "type": "string", - "name": "phoneNumber", - "in": "query" - }, - { - "type": "integer", - "name": "statusId", - "in": "query" - }, - { - "type": "integer", - "name": "userRoleId", - "in": "query" - }, - { - "type": "string", - "name": "username", - "in": "query" - }, - { - "type": "string", - "name": "workType", - "in": "query" - }, { "type": "integer", "name": "count", @@ -14994,14 +15177,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15064,8 +15242,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15119,14 +15298,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15182,14 +15356,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15245,8 +15414,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15298,12 +15468,6 @@ ], "summary": "Login Users", "parameters": [ - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, { "description": "Required payload", "name": "payload", @@ -15355,12 +15519,6 @@ ], "summary": "OtpRequest Users", "parameters": [ - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, { "description": "Required payload", "name": "payload", @@ -15412,12 +15570,6 @@ ], "summary": "OtpValidation Users", "parameters": [ - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, { "description": "Required payload", "name": "payload", @@ -15469,12 +15621,6 @@ ], "summary": "ParetoLogin Users", "parameters": [ - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, { "description": "Required payload", "name": "payload", @@ -15526,12 +15672,6 @@ ], "summary": "ResetPassword Users", "parameters": [ - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", - "in": "header" - }, { "description": "Required payload", "name": "payload", @@ -15585,14 +15725,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15655,14 +15790,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15718,8 +15848,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15773,14 +15904,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15841,14 +15967,9 @@ "parameters": [ { "type": "string", - "description": "Insert the X-Client-Key", - "name": "X-Client-Key", - "in": "header" - }, - { - "type": "string", - "description": "Insert the X-Csrf-Token", - "name": "X-Csrf-Token", + "default": "Bearer \u003cAdd access token here\u003e", + "description": "Insert your access token", + "name": "Authorization", "in": "header" }, { @@ -15889,6 +16010,33 @@ } }, "definitions": { + "netidhub-saas-be_app_module_article_approval_flows_request.SubmitForApprovalRequest": { + "type": "object", + "required": [ + "articleId" + ], + "properties": { + "articleId": { + "type": "integer" + }, + "workflowId": { + "type": "integer" + } + } + }, + "netidhub-saas-be_app_module_articles_request.SubmitForApprovalRequest": { + "type": "object", + "properties": { + "message": { + "type": "string", + "maxLength": 500 + }, + "workflow_id": { + "type": "integer", + "minimum": 1 + } + } + }, "paginator.Pagination": { "type": "object", "properties": { @@ -16609,59 +16757,6 @@ } } }, - "request.ArticlesUpdateRequest": { - "type": "object", - "required": [ - "categoryIds", - "description", - "htmlDescription", - "slug", - "tags", - "title", - "typeId" - ], - "properties": { - "aiArticleId": { - "type": "integer" - }, - "categoryIds": { - "type": "string" - }, - "createdAt": { - "type": "string" - }, - "createdById": { - "type": "integer" - }, - "description": { - "type": "string" - }, - "htmlDescription": { - "type": "string" - }, - "isDraft": { - "type": "boolean" - }, - "isPublish": { - "type": "boolean" - }, - "slug": { - "type": "string" - }, - "statusId": { - "type": "integer" - }, - "tags": { - "type": "string" - }, - "title": { - "type": "string" - }, - "typeId": { - "type": "integer" - } - } - }, "request.BookmarksCreateRequest": { "type": "object", "required": [ @@ -16693,6 +16788,25 @@ } } }, + "request.BulkCreateSubClientsRequest": { + "type": "object", + "required": [ + "parentClientId", + "subClients" + ], + "properties": { + "parentClientId": { + "type": "string" + }, + "subClients": { + "type": "array", + "minItems": 1, + "items": { + "$ref": "#/definitions/request.ClientsCreateSubClientDetail" + } + } + } + }, "request.BulkProcessApprovalRequest": { "type": "object", "required": [ @@ -16771,10 +16885,55 @@ "request.ClientsCreateRequest": { "type": "object", "required": [ + "clientType", "name" ], "properties": { - "createdById": { + "clientType": { + "description": "Enum validation", + "type": "string", + "enum": [ + "parent_client", + "sub_client", + "standalone" + ] + }, + "description": { + "type": "string" + }, + "maxStorage": { + "type": "integer" + }, + "maxUsers": { + "description": "Resource limits", + "type": "integer" + }, + "name": { + "type": "string" + }, + "parentClientId": { + "description": "Optional: only for sub_client type", + "type": "string" + }, + "settings": { + "description": "Custom settings (JSON string)", + "type": "string" + } + } + }, + "request.ClientsCreateSubClientDetail": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "description": { + "type": "string" + }, + "maxStorage": { + "type": "integer" + }, + "maxUsers": { "type": "integer" }, "name": { @@ -16784,15 +16943,37 @@ }, "request.ClientsUpdateRequest": { "type": "object", - "required": [ - "name" - ], "properties": { - "createdById": { + "clientType": { + "type": "string", + "enum": [ + "parent_client", + "sub_client", + "standalone" + ] + }, + "description": { + "type": "string" + }, + "isActive": { + "type": "boolean" + }, + "maxStorage": { + "type": "integer" + }, + "maxUsers": { + "description": "Resource limits", "type": "integer" }, "name": { "type": "string" + }, + "parentClientId": { + "type": "string" + }, + "settings": { + "description": "Custom settings", + "type": "string" } } }, @@ -17177,6 +17358,15 @@ } } }, + "request.MoveClientRequest": { + "type": "object", + "properties": { + "targetParentId": { + "description": "null = move to root (standalone)", + "type": "string" + } + } + }, "request.ProcessApprovalRequest": { "type": "object", "required": [ @@ -18000,33 +18190,6 @@ "example": false } } - }, - "netidhub-saas-be_app_module_article_approval_flows_request.SubmitForApprovalRequest": { - "type": "object", - "required": [ - "articleId" - ], - "properties": { - "articleId": { - "type": "integer" - }, - "workflowId": { - "type": "integer" - } - } - }, - "netidhub-saas-be_app_module_articles_request.SubmitForApprovalRequest": { - "type": "object", - "properties": { - "message": { - "type": "string", - "maxLength": 500 - }, - "workflow_id": { - "type": "integer", - "minimum": 1 - } - } } } } \ No newline at end of file diff --git a/docs/swagger/swagger.yaml b/docs/swagger/swagger.yaml index c2d920a..0034baf 100644 --- a/docs/swagger/swagger.yaml +++ b/docs/swagger/swagger.yaml @@ -1,4 +1,22 @@ definitions: + netidhub-saas-be_app_module_article_approval_flows_request.SubmitForApprovalRequest: + properties: + articleId: + type: integer + workflowId: + type: integer + required: + - articleId + type: object + netidhub-saas-be_app_module_articles_request.SubmitForApprovalRequest: + properties: + message: + maxLength: 500 + type: string + workflow_id: + minimum: 1 + type: integer + type: object paginator.Pagination: properties: count: @@ -492,43 +510,6 @@ definitions: - title - typeId type: object - request.ArticlesUpdateRequest: - properties: - aiArticleId: - type: integer - categoryIds: - type: string - createdAt: - type: string - createdById: - type: integer - description: - type: string - htmlDescription: - type: string - isDraft: - type: boolean - isPublish: - type: boolean - slug: - type: string - statusId: - type: integer - tags: - type: string - title: - type: string - typeId: - type: integer - required: - - categoryIds - - description - - htmlDescription - - slug - - tags - - title - - typeId - type: object request.BookmarksCreateRequest: properties: articleId: @@ -550,6 +531,19 @@ definitions: - steps - workflowId type: object + request.BulkCreateSubClientsRequest: + properties: + parentClientId: + type: string + subClients: + items: + $ref: '#/definitions/request.ClientsCreateSubClientDetail' + minItems: 1 + type: array + required: + - parentClientId + - subClients + type: object request.BulkProcessApprovalRequest: properties: approvalStatusId: @@ -605,7 +599,39 @@ definitions: type: object request.ClientsCreateRequest: properties: - createdById: + clientType: + description: Enum validation + enum: + - parent_client + - sub_client + - standalone + type: string + description: + type: string + maxStorage: + type: integer + maxUsers: + description: Resource limits + type: integer + name: + type: string + parentClientId: + description: 'Optional: only for sub_client type' + type: string + settings: + description: Custom settings (JSON string) + type: string + required: + - clientType + - name + type: object + request.ClientsCreateSubClientDetail: + properties: + description: + type: string + maxStorage: + type: integer + maxUsers: type: integer name: type: string @@ -614,12 +640,28 @@ definitions: type: object request.ClientsUpdateRequest: properties: - createdById: + clientType: + enum: + - parent_client + - sub_client + - standalone + type: string + description: + type: string + isActive: + type: boolean + maxStorage: + type: integer + maxUsers: + description: Resource limits type: integer name: type: string - required: - - name + parentClientId: + type: string + settings: + description: Custom settings + type: string type: object request.CreateApprovalWorkflowStepsRequest: properties: @@ -885,6 +927,12 @@ definitions: - pathUrl - statusId type: object + request.MoveClientRequest: + properties: + targetParentId: + description: null = move to root (standalone) + type: string + type: object request.ProcessApprovalRequest: properties: approvalStatusId: @@ -1448,24 +1496,6 @@ definitions: example: false type: boolean type: object - netidhub-saas-be_app_module_article_approval_flows_request.SubmitForApprovalRequest: - properties: - articleId: - type: integer - workflowId: - type: integer - required: - - articleId - type: object - netidhub-saas-be_app_module_articles_request.SubmitForApprovalRequest: - properties: - message: - maxLength: 500 - type: string - workflow_id: - minimum: 1 - type: integer - type: object info: contact: {} paths: @@ -2094,9 +2124,9 @@ paths: get: description: API for getting all ApprovalWorkflowSteps parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: Workflow ID filter @@ -2148,9 +2178,9 @@ paths: post: description: API for saving ApprovalWorkflowSteps parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: Required payload @@ -2185,9 +2215,9 @@ paths: delete: description: API for deleting ApprovalWorkflowSteps parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: ApprovalWorkflowSteps ID @@ -2220,9 +2250,9 @@ paths: get: description: API for getting one ApprovalWorkflowSteps parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: ApprovalWorkflowSteps ID @@ -2255,9 +2285,9 @@ paths: put: description: API for updating ApprovalWorkflowSteps parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: ApprovalWorkflowSteps ID @@ -2297,9 +2327,9 @@ paths: post: description: API for bulk creating ApprovalWorkflowSteps parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: Required payload @@ -2334,9 +2364,9 @@ paths: get: description: API for getting ApprovalWorkflowSteps by Role ID parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: Role ID @@ -2370,9 +2400,9 @@ paths: get: description: API for getting ApprovalWorkflowSteps by Workflow ID parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: Workflow ID @@ -2406,9 +2436,9 @@ paths: put: description: API for reordering ApprovalWorkflowSteps parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: Workflow ID @@ -2448,9 +2478,9 @@ paths: get: description: API for getting all ApprovalWorkflows parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - in: query @@ -2514,9 +2544,9 @@ paths: post: description: API for saving ApprovalWorkflows parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: Required payload @@ -2551,9 +2581,9 @@ paths: delete: description: API for deleting ApprovalWorkflows parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: ApprovalWorkflows ID @@ -2586,9 +2616,9 @@ paths: get: description: API for getting one ApprovalWorkflows parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: ApprovalWorkflows ID @@ -2621,9 +2651,9 @@ paths: put: description: API for updating ApprovalWorkflows parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: ApprovalWorkflows ID @@ -2663,9 +2693,9 @@ paths: put: description: API for activating ApprovalWorkflows parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: ApprovalWorkflows ID @@ -2699,9 +2729,9 @@ paths: put: description: API for deactivating ApprovalWorkflows parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: ApprovalWorkflows ID @@ -2735,9 +2765,9 @@ paths: put: description: API for setting default ApprovalWorkflows parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: ApprovalWorkflows ID @@ -2771,9 +2801,9 @@ paths: get: description: API for getting ApprovalWorkflows with steps parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: ApprovalWorkflows ID @@ -2806,9 +2836,9 @@ paths: put: description: API for updating ApprovalWorkflows with steps parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: ApprovalWorkflows ID @@ -2848,9 +2878,9 @@ paths: get: description: API for getting default ApprovalWorkflows parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string responses: @@ -2879,9 +2909,9 @@ paths: post: description: API for creating ApprovalWorkflows with steps parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: ApprovalWorkflows with steps data @@ -2916,9 +2946,9 @@ paths: get: description: API for getting all ArticleApprovalFlows parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - in: query @@ -2992,9 +3022,9 @@ paths: get: description: API for getting one ArticleApprovalFlows parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: ArticleApprovalFlows ID @@ -3028,9 +3058,9 @@ paths: put: description: API for approving article parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - default: Bearer @@ -3075,9 +3105,9 @@ paths: put: description: API for rejecting article parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - default: Bearer @@ -3122,9 +3152,9 @@ paths: put: description: API for requesting revision for article parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - default: Bearer @@ -3169,9 +3199,9 @@ paths: put: description: API for resubmitting article after revision parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - default: Bearer @@ -3216,9 +3246,9 @@ paths: get: description: API for getting approval analytics parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - default: Bearer @@ -3264,9 +3294,9 @@ paths: get: description: API for getting dashboard statistics parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - default: Bearer @@ -3300,9 +3330,9 @@ paths: get: description: API for getting approval history parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: Article ID filter @@ -3363,9 +3393,9 @@ paths: get: description: API for getting my approval queue parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - default: Bearer @@ -3431,9 +3461,9 @@ paths: get: description: API for getting pending approvals parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - default: Bearer @@ -3491,9 +3521,9 @@ paths: post: description: API for submitting article for approval parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - default: Bearer @@ -3533,9 +3563,9 @@ paths: get: description: API for getting workload statistics parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - default: Bearer @@ -4415,9 +4445,10 @@ paths: get: description: API for getting all ArticleCategories parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization + required: true type: string - default: Bearer description: Insert your access token @@ -4494,13 +4525,10 @@ paths: post: description: API for create ArticleCategories parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization + required: true type: string - default: Bearer description: Insert your access token @@ -4539,13 +4567,10 @@ paths: delete: description: API for delete ArticleCategories parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization + required: true type: string - description: ArticleCategories ID in: path @@ -4577,9 +4602,10 @@ paths: get: description: API for getting one ArticleCategories parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization + required: true type: string - description: ArticleCategories ID in: path @@ -4611,13 +4637,10 @@ paths: put: description: API for update ArticleCategories parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization + required: true type: string - description: Required payload in: body @@ -4656,9 +4679,10 @@ paths: get: description: API for getting one ArticleCategories parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization + required: true type: string - description: ArticleCategories Old ID in: path @@ -4691,9 +4715,10 @@ paths: get: description: API for getting one ArticleCategories parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization + required: true type: string - description: ArticleCategories Slug in: path @@ -4726,13 +4751,10 @@ paths: post: description: API for Upload ArticleCategories Thumbnail parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization + required: true type: string - description: Upload thumbnail in: formData @@ -4772,9 +4794,10 @@ paths: get: description: API for View Thumbnail of ArticleCategories parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization + required: true type: string - description: ArticleCategories ID in: path @@ -5250,9 +5273,10 @@ paths: get: description: API for getting all ArticleFiles parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key + name: Authorization type: string - in: query name: articleId @@ -5316,13 +5340,10 @@ paths: post: description: API for create ArticleFiles parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization type: string - description: Upload file in: formData @@ -5362,13 +5383,10 @@ paths: delete: description: API for delete ArticleFiles parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization type: string - description: ArticleFiles ID in: path @@ -5400,9 +5418,10 @@ paths: get: description: API for getting one ArticleFiles parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key + name: Authorization type: string - description: ArticleFiles ID in: path @@ -5434,13 +5453,10 @@ paths: put: description: API for update ArticleFiles parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization type: string - description: Required payload in: body @@ -5510,9 +5526,10 @@ paths: get: description: API for Viewer ArticleFiles parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key + name: Authorization type: string - description: Article File Name in: path @@ -5795,11 +5812,6 @@ paths: get: description: API for getting all Articles parameters: - - description: Insert the X-Client-Key - in: header - name: X-Client-Key - required: true - type: string - default: Bearer description: Insert your access token in: header @@ -5887,14 +5899,6 @@ paths: post: description: API for create Articles parameters: - - description: Insert the X-Client-Key - in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token - type: string - default: Bearer description: Insert your access token in: header @@ -5932,13 +5936,10 @@ paths: delete: description: API for delete Articles parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization type: string - description: Articles ID in: path @@ -5970,16 +5971,11 @@ paths: get: description: API for getting one Articles parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - - description: Articles ID - in: path - name: id - required: true - type: integer responses: "200": description: OK @@ -6005,20 +6001,11 @@ paths: put: description: API for update Articles parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key + name: Authorization type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token - type: string - - description: Required payload - in: body - name: payload - required: true - schema: - $ref: '#/definitions/request.ArticlesUpdateRequest' - description: Articles ID in: path name: id @@ -6050,9 +6037,10 @@ paths: get: description: API for getting article approval status and workflow progress parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key + name: Authorization type: string - default: Bearer description: Insert your access token @@ -6090,14 +6078,10 @@ paths: post: description: API for submitting article for approval workflow parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization type: string - default: Bearer description: Insert your access token @@ -6140,13 +6124,10 @@ paths: put: description: API for Update Banner Articles parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization type: string - description: Articles ID in: path @@ -6184,16 +6165,11 @@ paths: get: description: API for getting one Articles parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - - description: Articles Old ID - in: path - name: id - required: true - type: integer responses: "200": description: OK @@ -6220,9 +6196,10 @@ paths: get: description: API for getting articles pending approval for current user level parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key + name: Authorization type: string - default: Bearer description: Insert your access token @@ -6267,14 +6244,10 @@ paths: post: description: API for Publish Schedule of Article parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization type: string - default: Bearer description: Insert your access token @@ -6420,19 +6393,11 @@ paths: post: description: API for Save Thumbnail of Articles parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key + name: Authorization type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token - type: string - - description: Upload thumbnail - in: formData - name: files - required: true - type: file - description: Articles ID in: path name: id @@ -6466,9 +6431,10 @@ paths: get: description: API for View Thumbnail of Article parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key + name: Authorization type: string - description: Articles Thumbnail Name in: path @@ -6502,10 +6468,10 @@ paths: description: API for getting articles that are waiting for approval by the current user's level parameters: - - description: Client Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - default: Bearer description: Insert your access token @@ -6548,10 +6514,10 @@ paths: get: description: API for getting all Bookmarks parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - default: Bearer description: Insert your access token @@ -6613,10 +6579,10 @@ paths: post: description: API for creating new Bookmark parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - default: Bearer description: Insert your access token @@ -6655,10 +6621,10 @@ paths: delete: description: API for deleting Bookmark parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - default: Bearer description: Insert your access token @@ -6695,10 +6661,10 @@ paths: get: description: API for getting Bookmark by ID parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - default: Bearer description: Insert your access token @@ -6737,10 +6703,10 @@ paths: description: API for getting bookmark summary including total count and recent bookmarks parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - default: Bearer description: Insert your access token @@ -6773,10 +6739,10 @@ paths: post: description: API for toggling bookmark status for an article parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - default: Bearer description: Insert your access token @@ -6814,10 +6780,10 @@ paths: get: description: API for getting Bookmarks by User ID parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - default: Bearer description: Insert your access token @@ -7057,9 +7023,9 @@ paths: delete: description: API for deleting client approval settings parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string responses: @@ -7087,9 +7053,9 @@ paths: get: description: API for getting client approval settings parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string responses: @@ -7117,9 +7083,9 @@ paths: post: description: API for creating client approval settings parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: Required payload @@ -7153,9 +7119,9 @@ paths: put: description: API for updating client approval settings parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: Required payload @@ -7190,9 +7156,9 @@ paths: post: description: API for setting default workflow for client parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: Required payload @@ -7227,9 +7193,9 @@ paths: post: description: API for disabling approval system and auto-publish pending articles parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: Required payload @@ -7264,9 +7230,9 @@ paths: post: description: API for enabling approval system with smooth transition parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: Required payload @@ -7301,9 +7267,9 @@ paths: post: description: API for adding/removing categories from approval exemption parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: 'Action: add or remove' @@ -7342,9 +7308,9 @@ paths: post: description: API for adding/removing roles from approval exemption parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: 'Action: add or remove' @@ -7383,9 +7349,9 @@ paths: post: description: API for adding/removing users from approval exemption parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: 'Action: add or remove' @@ -7424,9 +7390,9 @@ paths: post: description: API for toggling approval requirement on/off parameters: - - description: Insert the X-Client-Key + - description: Insert the Authorization in: header - name: X-Client-Key + name: Authorization required: true type: string - description: Required payload @@ -7459,38 +7425,65 @@ paths: - ClientApprovalSettings /clients: get: - description: API for getting all Clients + description: API for getting all Clients with hierarchy filtering parameters: - - in: query - name: createdBy - type: integer - - in: query + - default: Bearer + description: Insert your access token + in: header + name: Authorization + type: string + - description: Filter by client name + in: query name: name type: string - - in: query - name: count - type: integer - - in: query - name: limit - type: integer - - in: query - name: nextPage - type: integer - - in: query + - description: Filter by client type (parent_client, sub_client, standalone) + in: query + name: clientType + type: string + - description: Filter by parent client ID + in: query + name: parentClientId + type: string + - description: Include all descendants + in: query + name: includeSubClients + type: boolean + - description: Only clients with children + in: query + name: onlyParentClients + type: boolean + - description: Only standalone clients + in: query + name: onlyStandalone + type: boolean + - description: Only root level clients + in: query + name: onlyRootClients + type: boolean + - description: Filter by active status + in: query + name: isActive + type: boolean + - description: Filter by creator ID + in: query + name: createdById + type: string + - description: Page number + in: query name: page type: integer - - in: query - name: previousPage + - description: Items per page + in: query + name: limit type: integer - - in: query + - description: Sort field + in: query name: sort type: string - - in: query + - description: Sort direction (asc, desc) + in: query name: sortBy type: string - - in: query - name: totalPage - type: integer responses: "200": description: OK @@ -7646,6 +7639,204 @@ paths: summary: update Clients tags: - Clients + /clients/{id}/hierarchy: + get: + description: API for getting client tree structure + parameters: + - description: Client ID + in: path + name: id + required: true + type: string + 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: Get client hierarchy + tags: + - Clients + /clients/{id}/move: + put: + description: API for moving a client to different parent + parameters: + - description: Client ID + in: path + name: id + required: true + type: string + - description: Required payload + in: body + name: payload + required: true + schema: + $ref: '#/definitions/request.MoveClientRequest' + 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: Move client + tags: + - Clients + /clients/{id}/stats: + get: + description: API for getting client statistics + parameters: + - description: Client ID + in: path + name: id + required: true + type: string + 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: Get client statistics + tags: + - Clients + /clients/{id}/sub-clients: + get: + description: API for getting direct children of a client + parameters: + - description: Parent Client ID + in: path + name: id + required: true + type: string + 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: Get sub-clients + tags: + - Clients + post: + description: API for creating a client under a parent + parameters: + - description: Parent Client ID + in: path + name: id + required: true + type: string + - description: Required payload + in: body + name: payload + required: true + schema: + $ref: '#/definitions/request.ClientsCreateRequest' + 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: Create sub-client + tags: + - Clients + /clients/bulk-sub-clients: + post: + description: API for creating multiple sub-clients at once + parameters: + - description: Required payload + in: body + name: payload + required: true + schema: + $ref: '#/definitions/request.BulkCreateSubClientsRequest' + 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: Bulk create sub-clients + tags: + - Clients /custom-static-pages: get: description: API for getting all CustomStaticPages @@ -10046,10 +10237,10 @@ paths: get: description: API for getting all UserLevels parameters: - - description: Client Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - in: query name: levelNumber @@ -10112,10 +10303,10 @@ paths: post: description: API for create UserLevels parameters: - - description: Client Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - description: Insert the X-Csrf-Token in: header @@ -10158,10 +10349,10 @@ paths: delete: description: API for delete UserLevels parameters: - - description: Client Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - default: Bearer description: Insert your access token @@ -10206,10 +10397,10 @@ paths: get: description: API for getting one UserLevels parameters: - - description: Client Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - description: UserLevels ID in: path @@ -10241,10 +10432,10 @@ paths: put: description: API for update UserLevels parameters: - - description: Client Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - description: Insert the X-Csrf-Token in: header @@ -10292,10 +10483,10 @@ paths: get: description: API for getting one UserLevels parameters: - - description: Client Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - description: UserLevels Alias in: path @@ -10328,10 +10519,10 @@ paths: post: description: API for Enable Approval of Article parameters: - - description: Client Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - required: true + name: Authorization type: string - description: Insert the X-Csrf-Token in: header @@ -10922,45 +11113,10 @@ paths: get: description: API for getting all Users parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - type: string - - in: query - name: email - type: string - - in: query - name: fullname - type: string - - in: query - name: genderType - type: string - - in: query - name: identityGroup - type: string - - in: query - name: identityGroupNumber - type: string - - in: query - name: identityNumber - type: string - - in: query - name: identityType - type: string - - in: query - name: phoneNumber - type: string - - in: query - name: statusId - type: integer - - in: query - name: userRoleId - type: integer - - in: query - name: username - type: string - - in: query - name: workType + name: Authorization type: string - in: query name: count @@ -11011,13 +11167,10 @@ paths: post: description: API for create Users parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization type: string - default: Bearer description: Insert your access token @@ -11056,13 +11209,10 @@ paths: delete: description: API for delete Users parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization type: string - description: Users ID in: path @@ -11094,13 +11244,10 @@ paths: put: description: API for update Users parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization type: string - description: Users ID in: path @@ -11139,9 +11286,10 @@ paths: get: description: API for getting one Users parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key + name: Authorization type: string - description: Users ID in: path @@ -11174,13 +11322,10 @@ paths: post: description: API for Email Validation Users parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization type: string - description: Required payload in: body @@ -11214,13 +11359,10 @@ paths: post: description: API for ForgotPassword Users parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization type: string - description: Required payload in: body @@ -11254,9 +11396,10 @@ paths: get: description: API for ShowUserInfo parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key + name: Authorization type: string - default: Bearer description: Insert your access token @@ -11289,10 +11432,6 @@ paths: post: description: API for Login Users parameters: - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token - type: string - description: Required payload in: body name: payload @@ -11325,10 +11464,6 @@ paths: post: description: API for OtpRequest Users parameters: - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token - type: string - description: Required payload in: body name: payload @@ -11361,10 +11496,6 @@ paths: post: description: API for OtpValidation Users parameters: - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token - type: string - description: Required payload in: body name: payload @@ -11397,10 +11528,6 @@ paths: post: description: API for ParetoLogin Users parameters: - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token - type: string - description: Required payload in: body name: payload @@ -11433,10 +11560,6 @@ paths: post: description: API for ResetPassword Users parameters: - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token - type: string - description: Required payload in: body name: payload @@ -11469,13 +11592,10 @@ paths: post: description: API for SavePassword Users parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization type: string - default: Bearer description: Insert your access token @@ -11514,13 +11634,10 @@ paths: post: description: API for Setup Email Users parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key - type: string - - description: Insert the X-Csrf-Token - in: header - name: X-Csrf-Token + name: Authorization type: string - description: Required payload in: body @@ -11554,9 +11671,10 @@ paths: get: description: API for getting one Users parameters: - - description: Insert the X-Client-Key + - default: Bearer + description: Insert your access token in: header - name: X-Client-Key + name: Authorization type: string - description: Username in: path diff --git a/fix_all_article_approval_flows.ps1 b/fix_all_article_approval_flows.ps1 new file mode 100644 index 0000000..14a2592 --- /dev/null +++ b/fix_all_article_approval_flows.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final.ps1 b/fix_all_article_approval_flows_final.ps1 new file mode 100644 index 0000000..eecc094 --- /dev/null +++ b/fix_all_article_approval_flows_final.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final10.ps1 b/fix_all_article_approval_flows_final10.ps1 new file mode 100644 index 0000000..a2a8afb --- /dev/null +++ b/fix_all_article_approval_flows_final10.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final10.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final11.ps1 b/fix_all_article_approval_flows_final11.ps1 new file mode 100644 index 0000000..f23372c --- /dev/null +++ b/fix_all_article_approval_flows_final11.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final11.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final12.ps1 b/fix_all_article_approval_flows_final12.ps1 new file mode 100644 index 0000000..63760fd --- /dev/null +++ b/fix_all_article_approval_flows_final12.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final12.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final13.ps1 b/fix_all_article_approval_flows_final13.ps1 new file mode 100644 index 0000000..0538491 --- /dev/null +++ b/fix_all_article_approval_flows_final13.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final13.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final14.ps1 b/fix_all_article_approval_flows_final14.ps1 new file mode 100644 index 0000000..39e3bc6 --- /dev/null +++ b/fix_all_article_approval_flows_final14.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final14.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final15.ps1 b/fix_all_article_approval_flows_final15.ps1 new file mode 100644 index 0000000..cfffe99 --- /dev/null +++ b/fix_all_article_approval_flows_final15.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final15.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final16.ps1 b/fix_all_article_approval_flows_final16.ps1 new file mode 100644 index 0000000..f9426f8 --- /dev/null +++ b/fix_all_article_approval_flows_final16.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final16.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final2.ps1 b/fix_all_article_approval_flows_final2.ps1 new file mode 100644 index 0000000..0ad929d --- /dev/null +++ b/fix_all_article_approval_flows_final2.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final2.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final3.ps1 b/fix_all_article_approval_flows_final3.ps1 new file mode 100644 index 0000000..7aa7658 --- /dev/null +++ b/fix_all_article_approval_flows_final3.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final3.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final4.ps1 b/fix_all_article_approval_flows_final4.ps1 new file mode 100644 index 0000000..6f5cba4 --- /dev/null +++ b/fix_all_article_approval_flows_final4.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final4.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final5.ps1 b/fix_all_article_approval_flows_final5.ps1 new file mode 100644 index 0000000..4ff6969 --- /dev/null +++ b/fix_all_article_approval_flows_final5.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final5.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final6.ps1 b/fix_all_article_approval_flows_final6.ps1 new file mode 100644 index 0000000..f2d9526 --- /dev/null +++ b/fix_all_article_approval_flows_final6.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final6.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final7.ps1 b/fix_all_article_approval_flows_final7.ps1 new file mode 100644 index 0000000..b0433a6 --- /dev/null +++ b/fix_all_article_approval_flows_final7.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final7.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final8.ps1 b/fix_all_article_approval_flows_final8.ps1 new file mode 100644 index 0000000..e67a058 --- /dev/null +++ b/fix_all_article_approval_flows_final8.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final8.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_article_approval_flows_final9.ps1 b/fix_all_article_approval_flows_final9.ps1 new file mode 100644 index 0000000..bb0382e --- /dev/null +++ b/fix_all_article_approval_flows_final9.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_all_article_approval_flows_final9.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All remaining clientId issues fixed." diff --git a/fix_all_clientid.ps1 b/fix_all_clientid.ps1 new file mode 100644 index 0000000..aca5640 --- /dev/null +++ b/fix_all_clientid.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues +# Usage: .\fix_all_clientid.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All clientId issues fixed." diff --git a/fix_article_approval_flows_clientid.ps1 b/fix_article_approval_flows_clientid.ps1 new file mode 100644 index 0000000..2691a6e --- /dev/null +++ b/fix_article_approval_flows_clientid.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all clientId issues in article_approval_flows +# Usage: .\fix_article_approval_flows_clientid.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing all clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "All clientId issues fixed." diff --git a/fix_remaining_article_approval_flows.ps1 b/fix_remaining_article_approval_flows.ps1 new file mode 100644 index 0000000..1c41537 --- /dev/null +++ b/fix_remaining_article_approval_flows.ps1 @@ -0,0 +1,59 @@ +# PowerShell script to fix all remaining clientId issues in article_approval_flows +# Usage: .\fix_remaining_article_approval_flows.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find all methods that use clientId but don't have extraction logic +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "Remaining clientId issues fixed." diff --git a/fix_remaining_clientid.ps1 b/fix_remaining_clientid.ps1 new file mode 100644 index 0000000..e2099e7 --- /dev/null +++ b/fix_remaining_clientid.ps1 @@ -0,0 +1,61 @@ +# PowerShell script to fix remaining clientId issues +# Usage: .\fix_remaining_clientid.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Fixing remaining clientId issues in: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Find methods that don't have clientId extraction logic but use clientId +$MethodPattern = 'func \(_i \*(\w+)Service\) (\w+)\(authToken string, ([^)]+)\) \{[^}]*return _i\.(\w+)Repository\.(\w+)\(clientId,' + +$Matches = [regex]::Matches($Content, $MethodPattern) + +foreach ($Match in $Matches) { + $ServiceName = $Match.Groups[1].Value + $MethodName = $Match.Groups[2].Value + $Parameters = $Match.Groups[3].Value + $RepositoryName = $Match.Groups[4].Value + $RepositoryMethod = $Match.Groups[5].Value + + Write-Host "Fixing method: $MethodName" + + # Create the clientId extraction logic + $ExtractionLogic = @" + // Extract clientId from authToken + var clientId *uuid.UUID + if authToken != "" { + user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepository, authToken) + if user != nil && user.ClientId != nil { + clientId = user.ClientId + _i.Log.Info().Interface("clientId", clientId).Msg("Extracted clientId from auth token") + } + } + + if clientId == nil { + return nil, errors.New("clientId not found in auth token") + } + +"@ + + # Replace the method opening with extraction logic + $OldMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {" + $NewMethodStart = "func (_i *${ServiceName}Service) ${MethodName}(authToken string, ${Parameters}) {${ExtractionLogic}" + + $Content = $Content -replace [regex]::Escape($OldMethodStart), $NewMethodStart +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "Remaining clientId issues fixed." diff --git a/replace_clientid_calls.ps1 b/replace_clientid_calls.ps1 new file mode 100644 index 0000000..9c2af70 --- /dev/null +++ b/replace_clientid_calls.ps1 @@ -0,0 +1,43 @@ +# PowerShell script to replace clientId with authToken in method calls +# Usage: .\replace_clientid_calls.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Replacing clientId with authToken in method calls: $FilePath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Replace patterns where clientId is used as parameter to other methods +$Replacements = @( + @{ + Pattern = '_i\.ValidateStepOrder\(clientId, ' + Replacement = '_i.ValidateStepOrder(authToken, ' + }, + @{ + Pattern = '_i\.ValidateStep\(clientId, ' + Replacement = '_i.ValidateStep(authToken, ' + }, + @{ + Pattern = '_i\.CanDeleteStep\(clientId, ' + Replacement = '_i.CanDeleteStep(authToken, ' + } +) + +foreach ($Replacement in $Replacements) { + $Content = $Content -replace $Replacement.Pattern, $Replacement.Replacement + Write-Host "Replaced: $($Replacement.Pattern)" +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "ClientId method calls replaced with authToken." diff --git a/scripts/update_modules_remove_x_client_key.sh b/scripts/update_modules_remove_x_client_key.sh new file mode 100644 index 0000000..099c4fe --- /dev/null +++ b/scripts/update_modules_remove_x_client_key.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +# Script to remove X-Client-Key and GetClientID from all modules +# Replace with auth token approach + +echo "Starting update of all modules to remove X-Client-Key..." + +# List of modules to update +modules=( + "articles" + "users" + "article_categories" + "magazines" + "schedules" + "subscription" + "user_levels" + "feedbacks" + "advertisement" + "article_comments" + "article_approvals" + "article_approval_flows" + "client_approval_settings" + "bookmarks" + "approval_workflows" + "article_files" + "custom_static_pages" + "article_approval_step_logs" + "approval_workflow_steps" + "activity_logs" +) + +for module in "${modules[@]}"; do + echo "Updating module: $module" + + controller_file="app/module/$module/controller/${module}.controller.go" + + if [ -f "$controller_file" ]; then + echo " - Updating controller: $controller_file" + + # Remove X-Client-Key from Swagger docs + sed -i 's|// @Param X-Client-Key header string true "Insert the X-Client-Key"||g' "$controller_file" + sed -i 's|// @Param X-Client-Key header string false "Insert the X-Client-Key"||g' "$controller_file" + + # Remove GetClientID calls + sed -i 's|clientId := middleware\.GetClientID(c)||g' "$controller_file" + sed -i 's|// Get ClientId from context||g' "$controller_file" + + # Remove middleware import if no longer needed + if ! grep -q "middleware\." "$controller_file"; then + sed -i '/"netidhub-saas-be\/app\/middleware"/d' "$controller_file" + fi + + echo " - Updated: $controller_file" + else + echo " - Controller not found: $controller_file" + fi +done + +echo "Update completed!" +echo "" +echo "Manual steps required:" +echo "1. Update service interfaces to use authToken instead of clientId" +echo "2. Update service implementations to extract clientId from authToken" +echo "3. Update repository calls to use extracted clientId" +echo "4. Test all endpoints" diff --git a/update_service_methods.ps1 b/update_service_methods.ps1 new file mode 100644 index 0000000..b04b116 --- /dev/null +++ b/update_service_methods.ps1 @@ -0,0 +1,44 @@ +# PowerShell script to update service method signatures +# Usage: .\update_service_methods.ps1 + +param( + [Parameter(Mandatory=$true)] + [string]$FilePath +) + +if (-not (Test-Path $FilePath)) { + Write-Error "File not found: $FilePath" + exit 1 +} + +Write-Host "Updating service methods in: $FilePath" + +# Create backup +$BackupPath = "$FilePath.backup" +Copy-Item $FilePath $BackupPath +Write-Host "Backup created at: $BackupPath" + +# Read file content +$Content = Get-Content $FilePath -Raw + +# Update method signatures - replace clientId *uuid.UUID with authToken string +$Patterns = @( + @{ + Pattern = 'func \(_i \*(\w+)Service\) (\w+)\(clientId \*uuid\.UUID, ' + Replacement = 'func (_i *$1Service) $2(authToken string, ' + }, + @{ + Pattern = 'func \(_i \*(\w+)Service\) (\w+)\(clientId \*uuid\.UUID\) ' + Replacement = 'func (_i *$1Service) $2(authToken string) ' + } +) + +foreach ($Pattern in $Patterns) { + $Content = $Content -replace $Pattern.Pattern, $Pattern.Replacement +} + +# Write updated content +Set-Content $FilePath $Content -NoNewline + +Write-Host "Service method signatures updated." +Write-Host "Please review the changes and add clientId extraction logic manually." diff --git a/update_service_methods.sh b/update_service_methods.sh new file mode 100644 index 0000000..200bb1a --- /dev/null +++ b/update_service_methods.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Script to update all service methods from clientId *uuid.UUID to authToken string +# Usage: ./update_service_methods.sh + +if [ $# -eq 0 ]; then + echo "Usage: ./update_service_methods.sh " + exit 1 +fi + +FILE_PATH=$1 + +if [ ! -f "$FILE_PATH" ]; then + echo "File not found: $FILE_PATH" + exit 1 +fi + +echo "Updating service methods in: $FILE_PATH" + +# Create backup +cp "$FILE_PATH" "${FILE_PATH}.backup" + +# Update method signatures +sed -i 's/func (_i \*[a-zA-Z]*Service) \([A-Za-z]*\)(clientId \*uuid\.UUID, /func (_i *\1Service) \2(authToken string, /g' "$FILE_PATH" + +# Add clientId extraction logic to each method +# This is a simplified approach - in practice, you'd need more sophisticated sed patterns + +echo "Service methods updated. Please review the changes and add clientId extraction logic manually." +echo "Backup created at: ${FILE_PATH}.backup"