major update
This commit is contained in:
parent
53e56ea285
commit
a18d5991b7
|
|
@ -0,0 +1,66 @@
|
|||
# PowerShell script to add clientId extraction logic to service methods
|
||||
# Usage: .\add_clientid_extraction.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to add clientId extraction to remaining methods
|
||||
# Usage: .\add_clientid_to_remaining.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <Add access token here>)
|
||||
// @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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"`
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param X-Csrf-Token header string false "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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 <Add access token here>)
|
||||
// @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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <Add access token here>)
|
||||
```
|
||||
|
||||
**After:**
|
||||
```go
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
```
|
||||
|
||||
## 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
|
||||
1373
docs/swagger/docs.go
1373
docs/swagger/docs.go
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final10.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final11.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final12.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final13.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final14.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final15.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final16.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final2.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final3.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final4.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final5.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final6.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final7.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final8.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_all_article_approval_flows_final9.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues
|
||||
# Usage: .\fix_all_clientid.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all clientId issues in article_approval_flows
|
||||
# Usage: .\fix_article_approval_flows_clientid.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
# PowerShell script to fix all remaining clientId issues in article_approval_flows
|
||||
# Usage: .\fix_remaining_article_approval_flows.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
# PowerShell script to fix remaining clientId issues
|
||||
# Usage: .\fix_remaining_clientid.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
# PowerShell script to replace clientId with authToken in method calls
|
||||
# Usage: .\replace_clientid_calls.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -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"
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
# PowerShell script to update service method signatures
|
||||
# Usage: .\update_service_methods.ps1 <file_path>
|
||||
|
||||
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."
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Script to update all service methods from clientId *uuid.UUID to authToken string
|
||||
# Usage: ./update_service_methods.sh <file_path>
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Usage: ./update_service_methods.sh <file_path>"
|
||||
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"
|
||||
Loading…
Reference in New Issue