2025-09-28 01:53:09 +00:00
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2025-09-30 13:34:56 +00:00
|
|
|
"netidhub-saas-be/app/module/client_approval_settings/request"
|
|
|
|
|
"netidhub-saas-be/app/module/client_approval_settings/service"
|
|
|
|
|
utilRes "netidhub-saas-be/utils/response"
|
|
|
|
|
utilVal "netidhub-saas-be/utils/validator"
|
2025-09-28 01:53:09 +00:00
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type clientApprovalSettingsController struct {
|
|
|
|
|
clientApprovalSettingsService service.ClientApprovalSettingsService
|
|
|
|
|
Log zerolog.Logger
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ClientApprovalSettingsController interface {
|
|
|
|
|
CreateSettings(c *fiber.Ctx) error
|
|
|
|
|
GetSettings(c *fiber.Ctx) error
|
|
|
|
|
UpdateSettings(c *fiber.Ctx) error
|
|
|
|
|
DeleteSettings(c *fiber.Ctx) error
|
|
|
|
|
ToggleApproval(c *fiber.Ctx) error
|
|
|
|
|
EnableApproval(c *fiber.Ctx) error
|
|
|
|
|
DisableApproval(c *fiber.Ctx) error
|
|
|
|
|
SetDefaultWorkflow(c *fiber.Ctx) error
|
|
|
|
|
ManageExemptUsers(c *fiber.Ctx) error
|
|
|
|
|
ManageExemptRoles(c *fiber.Ctx) error
|
|
|
|
|
ManageExemptCategories(c *fiber.Ctx) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewClientApprovalSettingsController(
|
|
|
|
|
clientApprovalSettingsService service.ClientApprovalSettingsService,
|
|
|
|
|
log zerolog.Logger,
|
|
|
|
|
) ClientApprovalSettingsController {
|
|
|
|
|
return &clientApprovalSettingsController{
|
|
|
|
|
clientApprovalSettingsService: clientApprovalSettingsService,
|
|
|
|
|
Log: log,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateSettings ClientApprovalSettings
|
|
|
|
|
// @Summary Create Client Approval Settings
|
|
|
|
|
// @Description API for creating client approval settings
|
|
|
|
|
// @Tags ClientApprovalSettings
|
|
|
|
|
// @Security Bearer
|
2025-10-01 03:10:18 +00:00
|
|
|
// @Param Authorization header string true "Insert the Authorization"
|
2025-09-28 01:53:09 +00:00
|
|
|
// @Param payload body request.CreateClientApprovalSettingsRequest true "Required payload"
|
|
|
|
|
// @Success 200 {object} response.Response
|
|
|
|
|
// @Failure 400 {object} response.BadRequestError
|
|
|
|
|
// @Failure 401 {object} response.UnauthorizedError
|
|
|
|
|
// @Failure 500 {object} response.InternalServerError
|
|
|
|
|
// @Router /client-approval-settings [post]
|
|
|
|
|
func (_i *clientApprovalSettingsController) CreateSettings(c *fiber.Ctx) error {
|
|
|
|
|
req := new(request.CreateClientApprovalSettingsRequest)
|
|
|
|
|
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
// Get Authorization token from header
|
|
|
|
|
authToken := c.Get("Authorization")
|
2025-09-28 01:53:09 +00:00
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
settings, err := _i.clientApprovalSettingsService.Create(authToken, *req)
|
2025-09-28 01:53:09 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return utilRes.Resp(c, utilRes.Response{
|
|
|
|
|
Success: true,
|
|
|
|
|
Messages: utilRes.Messages{"Client approval settings created successfully"},
|
|
|
|
|
Data: settings,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetSettings ClientApprovalSettings
|
|
|
|
|
// @Summary Get Client Approval Settings
|
|
|
|
|
// @Description API for getting client approval settings
|
|
|
|
|
// @Tags ClientApprovalSettings
|
|
|
|
|
// @Security Bearer
|
2025-10-01 03:10:18 +00:00
|
|
|
// @Param Authorization header string true "Insert the Authorization"
|
2025-09-28 01:53:09 +00:00
|
|
|
// @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 {
|
2025-10-01 03:10:18 +00:00
|
|
|
// Get Authorization token from header
|
|
|
|
|
authToken := c.Get("Authorization")
|
2025-09-28 01:53:09 +00:00
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
settings, err := _i.clientApprovalSettingsService.GetByClientId(authToken)
|
2025-09-28 01:53:09 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return utilRes.Resp(c, utilRes.Response{
|
|
|
|
|
Success: true,
|
|
|
|
|
Messages: utilRes.Messages{"Client approval settings successfully retrieved"},
|
|
|
|
|
Data: settings,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateSettings ClientApprovalSettings
|
|
|
|
|
// @Summary Update Client Approval Settings
|
|
|
|
|
// @Description API for updating client approval settings
|
|
|
|
|
// @Tags ClientApprovalSettings
|
|
|
|
|
// @Security Bearer
|
2025-10-01 03:10:18 +00:00
|
|
|
// @Param Authorization header string true "Insert the Authorization"
|
2025-09-28 01:53:09 +00:00
|
|
|
// @Param payload body request.UpdateClientApprovalSettingsRequest true "Required payload"
|
|
|
|
|
// @Success 200 {object} response.Response
|
|
|
|
|
// @Failure 400 {object} response.BadRequestError
|
|
|
|
|
// @Failure 401 {object} response.UnauthorizedError
|
|
|
|
|
// @Failure 500 {object} response.InternalServerError
|
|
|
|
|
// @Router /client-approval-settings [put]
|
|
|
|
|
func (_i *clientApprovalSettingsController) UpdateSettings(c *fiber.Ctx) error {
|
|
|
|
|
req := new(request.UpdateClientApprovalSettingsRequest)
|
|
|
|
|
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
// Get Authorization token from header
|
|
|
|
|
authToken := c.Get("Authorization")
|
2025-09-28 01:53:09 +00:00
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
settings, err := _i.clientApprovalSettingsService.Update(authToken, *req)
|
2025-09-28 01:53:09 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return utilRes.Resp(c, utilRes.Response{
|
|
|
|
|
Success: true,
|
|
|
|
|
Messages: utilRes.Messages{"Client approval settings successfully updated"},
|
|
|
|
|
Data: settings,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteSettings ClientApprovalSettings
|
|
|
|
|
// @Summary Delete Client Approval Settings
|
|
|
|
|
// @Description API for deleting client approval settings
|
|
|
|
|
// @Tags ClientApprovalSettings
|
|
|
|
|
// @Security Bearer
|
2025-10-01 03:10:18 +00:00
|
|
|
// @Param Authorization header string true "Insert the Authorization"
|
2025-09-28 01:53:09 +00:00
|
|
|
// @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 {
|
2025-10-01 03:10:18 +00:00
|
|
|
// Get Authorization token from header
|
|
|
|
|
authToken := c.Get("Authorization")
|
2025-09-28 01:53:09 +00:00
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
err := _i.clientApprovalSettingsService.Delete(authToken)
|
2025-09-28 01:53:09 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return utilRes.Resp(c, utilRes.Response{
|
|
|
|
|
Success: true,
|
|
|
|
|
Messages: utilRes.Messages{"Client approval settings successfully deleted"},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ToggleApproval ClientApprovalSettings
|
|
|
|
|
// @Summary Toggle Approval Requirement
|
|
|
|
|
// @Description API for toggling approval requirement on/off
|
|
|
|
|
// @Tags ClientApprovalSettings
|
|
|
|
|
// @Security Bearer
|
2025-10-01 03:10:18 +00:00
|
|
|
// @Param Authorization header string true "Insert the Authorization"
|
2025-09-28 01:53:09 +00:00
|
|
|
// @Param payload body request.ToggleApprovalRequest true "Required payload"
|
|
|
|
|
// @Success 200 {object} response.Response
|
|
|
|
|
// @Failure 400 {object} response.BadRequestError
|
|
|
|
|
// @Failure 401 {object} response.UnauthorizedError
|
|
|
|
|
// @Failure 500 {object} response.InternalServerError
|
|
|
|
|
// @Router /client-approval-settings/toggle [post]
|
|
|
|
|
func (_i *clientApprovalSettingsController) ToggleApproval(c *fiber.Ctx) error {
|
|
|
|
|
req := new(request.ToggleApprovalRequest)
|
|
|
|
|
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
// Get Authorization token from header
|
|
|
|
|
authToken := c.Get("Authorization")
|
2025-09-28 01:53:09 +00:00
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
err := _i.clientApprovalSettingsService.ToggleApprovalRequirement(authToken, req.RequiresApproval)
|
2025-09-28 01:53:09 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
action := "enabled"
|
|
|
|
|
if !req.RequiresApproval {
|
|
|
|
|
action = "disabled with auto-publish"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return utilRes.Resp(c, utilRes.Response{
|
|
|
|
|
Success: true,
|
|
|
|
|
Messages: utilRes.Messages{fmt.Sprintf("Approval system successfully %s", action)},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EnableApproval ClientApprovalSettings
|
|
|
|
|
// @Summary Enable Approval System
|
|
|
|
|
// @Description API for enabling approval system with smooth transition
|
|
|
|
|
// @Tags ClientApprovalSettings
|
|
|
|
|
// @Security Bearer
|
2025-10-01 03:10:18 +00:00
|
|
|
// @Param Authorization header string true "Insert the Authorization"
|
2025-09-28 01:53:09 +00:00
|
|
|
// @Param payload body request.EnableApprovalRequest true "Required payload"
|
|
|
|
|
// @Success 200 {object} response.Response
|
|
|
|
|
// @Failure 400 {object} response.BadRequestError
|
|
|
|
|
// @Failure 401 {object} response.UnauthorizedError
|
|
|
|
|
// @Failure 500 {object} response.InternalServerError
|
|
|
|
|
// @Router /client-approval-settings/enable [post]
|
|
|
|
|
func (_i *clientApprovalSettingsController) EnableApproval(c *fiber.Ctx) error {
|
|
|
|
|
req := new(request.EnableApprovalRequest)
|
|
|
|
|
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
// Get Authorization token from header
|
|
|
|
|
authToken := c.Get("Authorization")
|
2025-09-28 01:53:09 +00:00
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
err := _i.clientApprovalSettingsService.EnableApprovalWithTransition(authToken, req.DefaultWorkflowId)
|
2025-09-28 01:53:09 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return utilRes.Resp(c, utilRes.Response{
|
|
|
|
|
Success: true,
|
|
|
|
|
Messages: utilRes.Messages{"Approval system successfully enabled with smooth transition"},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DisableApproval ClientApprovalSettings
|
|
|
|
|
// @Summary Disable Approval System
|
|
|
|
|
// @Description API for disabling approval system and auto-publish pending articles
|
|
|
|
|
// @Tags ClientApprovalSettings
|
|
|
|
|
// @Security Bearer
|
2025-10-01 03:10:18 +00:00
|
|
|
// @Param Authorization header string true "Insert the Authorization"
|
2025-09-28 01:53:09 +00:00
|
|
|
// @Param payload body request.DisableApprovalRequest true "Required payload"
|
|
|
|
|
// @Success 200 {object} response.Response
|
|
|
|
|
// @Failure 400 {object} response.BadRequestError
|
|
|
|
|
// @Failure 401 {object} response.UnauthorizedError
|
|
|
|
|
// @Failure 500 {object} response.InternalServerError
|
|
|
|
|
// @Router /client-approval-settings/disable [post]
|
|
|
|
|
func (_i *clientApprovalSettingsController) DisableApproval(c *fiber.Ctx) error {
|
|
|
|
|
req := new(request.DisableApprovalRequest)
|
|
|
|
|
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
// Get Authorization token from header
|
|
|
|
|
authToken := c.Get("Authorization")
|
2025-09-28 01:53:09 +00:00
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
err := _i.clientApprovalSettingsService.DisableApprovalWithAutoPublish(authToken, req.Reason)
|
2025-09-28 01:53:09 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return utilRes.Resp(c, utilRes.Response{
|
|
|
|
|
Success: true,
|
|
|
|
|
Messages: utilRes.Messages{"Approval system successfully disabled with auto-publish enabled"},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetDefaultWorkflow ClientApprovalSettings
|
|
|
|
|
// @Summary Set Default Workflow
|
|
|
|
|
// @Description API for setting default workflow for client
|
|
|
|
|
// @Tags ClientApprovalSettings
|
|
|
|
|
// @Security Bearer
|
2025-10-01 03:10:18 +00:00
|
|
|
// @Param Authorization header string true "Insert the Authorization"
|
2025-09-28 01:53:09 +00:00
|
|
|
// @Param payload body request.SetDefaultWorkflowRequest true "Required payload"
|
|
|
|
|
// @Success 200 {object} response.Response
|
|
|
|
|
// @Failure 400 {object} response.BadRequestError
|
|
|
|
|
// @Failure 401 {object} response.UnauthorizedError
|
|
|
|
|
// @Failure 500 {object} response.InternalServerError
|
|
|
|
|
// @Router /client-approval-settings/default-workflow [post]
|
|
|
|
|
func (_i *clientApprovalSettingsController) SetDefaultWorkflow(c *fiber.Ctx) error {
|
|
|
|
|
req := new(request.SetDefaultWorkflowRequest)
|
|
|
|
|
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
// Get Authorization token from header
|
|
|
|
|
authToken := c.Get("Authorization")
|
2025-09-28 01:53:09 +00:00
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
err := _i.clientApprovalSettingsService.SetDefaultWorkflow(authToken, req.WorkflowId)
|
2025-09-28 01:53:09 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return utilRes.Resp(c, utilRes.Response{
|
|
|
|
|
Success: true,
|
|
|
|
|
Messages: utilRes.Messages{"Default workflow successfully set"},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ManageExemptUsers ClientApprovalSettings
|
|
|
|
|
// @Summary Manage Exempt Users
|
|
|
|
|
// @Description API for adding/removing users from approval exemption
|
|
|
|
|
// @Tags ClientApprovalSettings
|
|
|
|
|
// @Security Bearer
|
2025-10-01 03:10:18 +00:00
|
|
|
// @Param Authorization header string true "Insert the Authorization"
|
2025-09-28 01:53:09 +00:00
|
|
|
// @Param action path string true "Action: add or remove"
|
|
|
|
|
// @Param user_id path int true "User ID"
|
|
|
|
|
// @Success 200 {object} response.Response
|
|
|
|
|
// @Failure 400 {object} response.BadRequestError
|
|
|
|
|
// @Failure 401 {object} response.UnauthorizedError
|
|
|
|
|
// @Failure 500 {object} response.InternalServerError
|
|
|
|
|
// @Router /client-approval-settings/exempt-users/{action}/{user_id} [post]
|
|
|
|
|
func (_i *clientApprovalSettingsController) ManageExemptUsers(c *fiber.Ctx) error {
|
|
|
|
|
action := c.Params("action")
|
|
|
|
|
userIdStr := c.Params("user_id")
|
|
|
|
|
|
|
|
|
|
if action != "add" && action != "remove" {
|
|
|
|
|
return utilRes.ErrorBadRequest(c, "Invalid action. Use 'add' or 'remove'")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userId, err := strconv.Atoi(userIdStr)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return utilRes.ErrorBadRequest(c, "Invalid user ID format")
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
// Get Authorization token from header
|
|
|
|
|
authToken := c.Get("Authorization")
|
2025-09-28 01:53:09 +00:00
|
|
|
|
|
|
|
|
if action == "add" {
|
2025-10-01 03:10:18 +00:00
|
|
|
err = _i.clientApprovalSettingsService.AddExemptUser(authToken, uint(userId))
|
2025-09-28 01:53:09 +00:00
|
|
|
} else {
|
2025-10-01 03:10:18 +00:00
|
|
|
err = _i.clientApprovalSettingsService.RemoveExemptUser(authToken, uint(userId))
|
2025-09-28 01:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return utilRes.Resp(c, utilRes.Response{
|
|
|
|
|
Success: true,
|
|
|
|
|
Messages: utilRes.Messages{fmt.Sprintf("User successfully %sd from approval exemption", action)},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ManageExemptRoles ClientApprovalSettings
|
|
|
|
|
// @Summary Manage Exempt Roles
|
|
|
|
|
// @Description API for adding/removing roles from approval exemption
|
|
|
|
|
// @Tags ClientApprovalSettings
|
|
|
|
|
// @Security Bearer
|
2025-10-01 03:10:18 +00:00
|
|
|
// @Param Authorization header string true "Insert the Authorization"
|
2025-09-28 01:53:09 +00:00
|
|
|
// @Param action path string true "Action: add or remove"
|
|
|
|
|
// @Param role_id path int true "Role ID"
|
|
|
|
|
// @Success 200 {object} response.Response
|
|
|
|
|
// @Failure 400 {object} response.BadRequestError
|
|
|
|
|
// @Failure 401 {object} response.UnauthorizedError
|
|
|
|
|
// @Failure 500 {object} response.InternalServerError
|
|
|
|
|
// @Router /client-approval-settings/exempt-roles/{action}/{role_id} [post]
|
|
|
|
|
func (_i *clientApprovalSettingsController) ManageExemptRoles(c *fiber.Ctx) error {
|
|
|
|
|
action := c.Params("action")
|
|
|
|
|
roleIdStr := c.Params("role_id")
|
|
|
|
|
|
|
|
|
|
if action != "add" && action != "remove" {
|
|
|
|
|
return utilRes.ErrorBadRequest(c, "Invalid action. Use 'add' or 'remove'")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
roleId, err := strconv.Atoi(roleIdStr)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return utilRes.ErrorBadRequest(c, "Invalid role ID format")
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
// Get Authorization token from header
|
|
|
|
|
authToken := c.Get("Authorization")
|
2025-09-28 01:53:09 +00:00
|
|
|
|
|
|
|
|
if action == "add" {
|
2025-10-01 03:10:18 +00:00
|
|
|
err = _i.clientApprovalSettingsService.AddExemptRole(authToken, uint(roleId))
|
2025-09-28 01:53:09 +00:00
|
|
|
} else {
|
2025-10-01 03:10:18 +00:00
|
|
|
err = _i.clientApprovalSettingsService.RemoveExemptRole(authToken, uint(roleId))
|
2025-09-28 01:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return utilRes.Resp(c, utilRes.Response{
|
|
|
|
|
Success: true,
|
|
|
|
|
Messages: utilRes.Messages{fmt.Sprintf("Role successfully %sd from approval exemption", action)},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ManageExemptCategories ClientApprovalSettings
|
|
|
|
|
// @Summary Manage Exempt Categories
|
|
|
|
|
// @Description API for adding/removing categories from approval exemption
|
|
|
|
|
// @Tags ClientApprovalSettings
|
|
|
|
|
// @Security Bearer
|
2025-10-01 03:10:18 +00:00
|
|
|
// @Param Authorization header string true "Insert the Authorization"
|
2025-09-28 01:53:09 +00:00
|
|
|
// @Param action path string true "Action: add or remove"
|
|
|
|
|
// @Param category_id path int true "Category ID"
|
|
|
|
|
// @Success 200 {object} response.Response
|
|
|
|
|
// @Failure 400 {object} response.BadRequestError
|
|
|
|
|
// @Failure 401 {object} response.UnauthorizedError
|
|
|
|
|
// @Failure 500 {object} response.InternalServerError
|
|
|
|
|
// @Router /client-approval-settings/exempt-categories/{action}/{category_id} [post]
|
|
|
|
|
func (_i *clientApprovalSettingsController) ManageExemptCategories(c *fiber.Ctx) error {
|
|
|
|
|
action := c.Params("action")
|
|
|
|
|
categoryIdStr := c.Params("category_id")
|
|
|
|
|
|
|
|
|
|
if action != "add" && action != "remove" {
|
|
|
|
|
return utilRes.ErrorBadRequest(c, "Invalid action. Use 'add' or 'remove'")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
categoryId, err := strconv.Atoi(categoryIdStr)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return utilRes.ErrorBadRequest(c, "Invalid category ID format")
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-01 03:10:18 +00:00
|
|
|
// Get Authorization token from header
|
|
|
|
|
authToken := c.Get("Authorization")
|
2025-09-28 01:53:09 +00:00
|
|
|
|
|
|
|
|
if action == "add" {
|
2025-10-01 03:10:18 +00:00
|
|
|
err = _i.clientApprovalSettingsService.AddExemptCategory(authToken, uint(categoryId))
|
2025-09-28 01:53:09 +00:00
|
|
|
} else {
|
2025-10-01 03:10:18 +00:00
|
|
|
err = _i.clientApprovalSettingsService.RemoveExemptCategory(authToken, uint(categoryId))
|
2025-09-28 01:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return utilRes.Resp(c, utilRes.Response{
|
|
|
|
|
Success: true,
|
|
|
|
|
Messages: utilRes.Messages{fmt.Sprintf("Category successfully %sd from approval exemption", action)},
|
|
|
|
|
})
|
|
|
|
|
}
|