feat: update approval articles
This commit is contained in:
parent
37e9622757
commit
e39a8d442a
|
|
@ -51,6 +51,13 @@ func (_i *ArticlesRouter) RegisterArticlesRoutes() {
|
||||||
_i.App.Route("/articles", func(router fiber.Router) {
|
_i.App.Route("/articles", func(router fiber.Router) {
|
||||||
// Add user middleware to extract user level from JWT token
|
// Add user middleware to extract user level from JWT token
|
||||||
router.Use(middleware.UserMiddleware(_i.UsersRepo))
|
router.Use(middleware.UserMiddleware(_i.UsersRepo))
|
||||||
|
|
||||||
|
// Dynamic approval system routes
|
||||||
|
router.Post("/:id/submit-approval", articlesController.SubmitForApproval)
|
||||||
|
router.Get("/:id/approval-status", articlesController.GetApprovalStatus)
|
||||||
|
router.Get("/pending-approval", articlesController.GetPendingApprovals)
|
||||||
|
router.Get("/waiting-for-approval", articlesController.GetArticlesWaitingForApproval)
|
||||||
|
|
||||||
router.Get("/", articlesController.All)
|
router.Get("/", articlesController.All)
|
||||||
router.Get("/old-id/:id", articlesController.ShowByOldId)
|
router.Get("/old-id/:id", articlesController.ShowByOldId)
|
||||||
router.Get("/:id", articlesController.Show)
|
router.Get("/:id", articlesController.Show)
|
||||||
|
|
@ -64,11 +71,5 @@ func (_i *ArticlesRouter) RegisterArticlesRoutes() {
|
||||||
router.Get("/statistic/summary", articlesController.SummaryStats)
|
router.Get("/statistic/summary", articlesController.SummaryStats)
|
||||||
router.Get("/statistic/user-levels", articlesController.ArticlePerUserLevelStats)
|
router.Get("/statistic/user-levels", articlesController.ArticlePerUserLevelStats)
|
||||||
router.Get("/statistic/monthly", articlesController.ArticleMonthlyStats)
|
router.Get("/statistic/monthly", articlesController.ArticleMonthlyStats)
|
||||||
|
|
||||||
// Dynamic approval system routes
|
|
||||||
router.Post("/:id/submit-approval", articlesController.SubmitForApproval)
|
|
||||||
router.Get("/:id/approval-status", articlesController.GetApprovalStatus)
|
|
||||||
router.Get("/pending-approval", articlesController.GetPendingApprovals)
|
|
||||||
router.Get("/waiting-for-approval", articlesController.GetArticlesWaitingForApproval)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -532,10 +532,10 @@ func (_i *articlesController) SubmitForApproval(c *fiber.Ctx) error {
|
||||||
// Get ClientId from context
|
// Get ClientId from context
|
||||||
clientId := middleware.GetClientID(c)
|
clientId := middleware.GetClientID(c)
|
||||||
|
|
||||||
// Get user ID from token (you'll need to implement this based on your auth system)
|
// Get Authorization token from header
|
||||||
userId := uint(1) // TODO: Get from JWT token
|
authToken := c.Get("Authorization")
|
||||||
|
|
||||||
err = _i.articlesService.SubmitForApproval(clientId, uint(id), userId, req.WorkflowId)
|
err = _i.articlesService.SubmitForApproval(clientId, uint(id), authToken, req.WorkflowId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -608,10 +608,10 @@ func (_i *articlesController) GetPendingApprovals(c *fiber.Ctx) error {
|
||||||
// Get ClientId from context
|
// Get ClientId from context
|
||||||
clientId := middleware.GetClientID(c)
|
clientId := middleware.GetClientID(c)
|
||||||
|
|
||||||
// Get user level ID from token (you'll need to implement this based on your auth system)
|
// Get Authorization token from header
|
||||||
userLevelId := uint(1) // TODO: Get from JWT token
|
authToken := c.Get("Authorization")
|
||||||
|
|
||||||
response, paging, err := _i.articlesService.GetPendingApprovals(clientId, userLevelId, page, limit)
|
response, paging, err := _i.articlesService.GetPendingApprovals(clientId, authToken, page, limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -630,6 +630,7 @@ func (_i *articlesController) GetPendingApprovals(c *fiber.Ctx) error {
|
||||||
// @Tags Articles
|
// @Tags Articles
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param X-Client-Key header string true "Client Key"
|
// @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 page query int false "Page number" default(1)
|
// @Param page query int false "Page number" default(1)
|
||||||
// @Param limit query int false "Items per page" default(10)
|
// @Param limit query int false "Items per page" default(10)
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
|
|
@ -651,10 +652,10 @@ func (_i *articlesController) GetArticlesWaitingForApproval(c *fiber.Ctx) error
|
||||||
// Get ClientId from context
|
// Get ClientId from context
|
||||||
clientId := middleware.GetClientID(c)
|
clientId := middleware.GetClientID(c)
|
||||||
|
|
||||||
// Get user level from middleware
|
// Get Authorization token from header
|
||||||
userLevelId := middleware.GetUserLevelID(c)
|
authToken := c.Get("Authorization")
|
||||||
|
|
||||||
responses, paging, err := _i.articlesService.GetArticlesWaitingForApproval(clientId, *userLevelId, page, limit)
|
responses, paging, err := _i.articlesService.GetArticlesWaitingForApproval(clientId, authToken, page, limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,10 +73,10 @@ type ArticlesService interface {
|
||||||
ExecuteScheduling() error
|
ExecuteScheduling() error
|
||||||
|
|
||||||
// Dynamic approval system methods
|
// Dynamic approval system methods
|
||||||
SubmitForApproval(clientId *uuid.UUID, articleId uint, submittedById uint, workflowId *uint) error
|
SubmitForApproval(clientId *uuid.UUID, articleId uint, authToken string, workflowId *uint) error
|
||||||
GetApprovalStatus(clientId *uuid.UUID, articleId uint) (*response.ArticleApprovalStatusResponse, error)
|
GetApprovalStatus(clientId *uuid.UUID, articleId uint) (*response.ArticleApprovalStatusResponse, error)
|
||||||
GetArticlesWaitingForApproval(clientId *uuid.UUID, userLevelId uint, page, limit int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error)
|
GetArticlesWaitingForApproval(clientId *uuid.UUID, authToken string, page, limit int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error)
|
||||||
GetPendingApprovals(clientId *uuid.UUID, userLevelId uint, page, limit int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error)
|
GetPendingApprovals(clientId *uuid.UUID, authToken string, page, limit int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error)
|
||||||
|
|
||||||
// No-approval system methods
|
// No-approval system methods
|
||||||
CheckApprovalRequired(clientId *uuid.UUID, articleId uint, userId uint, userLevelId uint) (bool, error)
|
CheckApprovalRequired(clientId *uuid.UUID, articleId uint, userId uint, userLevelId uint) (bool, error)
|
||||||
|
|
@ -732,7 +732,13 @@ func getFileExtension(filename string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubmitForApproval submits an article for approval using the dynamic workflow system
|
// SubmitForApproval submits an article for approval using the dynamic workflow system
|
||||||
func (_i *articlesService) SubmitForApproval(clientId *uuid.UUID, articleId uint, submittedById uint, workflowId *uint) error {
|
func (_i *articlesService) SubmitForApproval(clientId *uuid.UUID, articleId uint, authToken string, workflowId *uint) error {
|
||||||
|
// Extract user info from auth token
|
||||||
|
user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||||
|
if user == nil {
|
||||||
|
return errors.New("user not found from auth token")
|
||||||
|
}
|
||||||
|
|
||||||
// Check if article exists
|
// Check if article exists
|
||||||
article, err := _i.Repo.FindOne(clientId, articleId)
|
article, err := _i.Repo.FindOne(clientId, articleId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -761,7 +767,7 @@ func (_i *articlesService) SubmitForApproval(clientId *uuid.UUID, articleId uint
|
||||||
CurrentStep: 1,
|
CurrentStep: 1,
|
||||||
StatusId: 1, // 1 = In Progress
|
StatusId: 1, // 1 = In Progress
|
||||||
ClientId: clientId,
|
ClientId: clientId,
|
||||||
SubmittedById: submittedById,
|
SubmittedById: user.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = _i.ArticleApprovalFlowsRepo.Create(clientId, approvalFlow)
|
_, err = _i.ArticleApprovalFlowsRepo.Create(clientId, approvalFlow)
|
||||||
|
|
@ -866,9 +872,15 @@ func (_i *articlesService) GetApprovalStatus(clientId *uuid.UUID, articleId uint
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPendingApprovals gets articles pending approval for a specific user level
|
// GetPendingApprovals gets articles pending approval for a specific user level
|
||||||
func (_i *articlesService) GetPendingApprovals(clientId *uuid.UUID, userLevelId uint, page, limit int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error) {
|
func (_i *articlesService) GetPendingApprovals(clientId *uuid.UUID, authToken string, page, limit int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error) {
|
||||||
|
// Extract user info from auth token
|
||||||
|
user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||||
|
if user == nil {
|
||||||
|
return nil, paginator.Pagination{}, errors.New("user not found from auth token")
|
||||||
|
}
|
||||||
|
|
||||||
// Get pending approvals for the user level
|
// Get pending approvals for the user level
|
||||||
approvalFlows, paging, err := _i.ArticleApprovalFlowsRepo.GetPendingApprovalsByUserLevel(clientId, userLevelId, page, limit)
|
approvalFlows, paging, err := _i.ArticleApprovalFlowsRepo.GetPendingApprovalsByUserLevel(clientId, user.UserLevelId, page, limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, paging, err
|
return nil, paging, err
|
||||||
}
|
}
|
||||||
|
|
@ -948,7 +960,13 @@ func (_i *articlesService) GetPendingApprovals(clientId *uuid.UUID, userLevelId
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetArticlesWaitingForApproval gets articles that are waiting for approval by a specific user level
|
// GetArticlesWaitingForApproval gets articles that are waiting for approval by a specific user level
|
||||||
func (_i *articlesService) GetArticlesWaitingForApproval(clientId *uuid.UUID, userLevelId uint, page, limit int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error) {
|
func (_i *articlesService) GetArticlesWaitingForApproval(clientId *uuid.UUID, authToken string, page, limit int) ([]*response.ArticleApprovalQueueResponse, paginator.Pagination, error) {
|
||||||
|
// Extract user info from auth token
|
||||||
|
user := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||||
|
if user == nil {
|
||||||
|
return nil, paginator.Pagination{}, errors.New("user not found from auth token")
|
||||||
|
}
|
||||||
|
|
||||||
// Use the existing repository method with proper filtering
|
// Use the existing repository method with proper filtering
|
||||||
pagination := paginator.Pagination{
|
pagination := paginator.Pagination{
|
||||||
Page: page,
|
Page: page,
|
||||||
|
|
@ -958,7 +976,7 @@ func (_i *articlesService) GetArticlesWaitingForApproval(clientId *uuid.UUID, us
|
||||||
Pagination: &pagination,
|
Pagination: &pagination,
|
||||||
}
|
}
|
||||||
|
|
||||||
articles, paging, err := _i.Repo.GetAll(clientId, &userLevelId, req)
|
articles, paging, err := _i.Repo.GetAll(clientId, &user.UserLevelId, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, paging, err
|
return nil, paging, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7592,6 +7592,13 @@ const docTemplate = `{
|
||||||
"in": "header",
|
"in": "header",
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"default": "Bearer \u003cAdd access token here\u003e",
|
||||||
|
"description": "Insert your access token",
|
||||||
|
"name": "Authorization",
|
||||||
|
"in": "header"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"default": 1,
|
"default": 1,
|
||||||
|
|
|
||||||
|
|
@ -7581,6 +7581,13 @@
|
||||||
"in": "header",
|
"in": "header",
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"default": "Bearer \u003cAdd access token here\u003e",
|
||||||
|
"description": "Insert your access token",
|
||||||
|
"name": "Authorization",
|
||||||
|
"in": "header"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"default": 1,
|
"default": 1,
|
||||||
|
|
|
||||||
|
|
@ -6507,6 +6507,11 @@ paths:
|
||||||
name: X-Client-Key
|
name: X-Client-Key
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
|
- default: Bearer <Add access token here>
|
||||||
|
description: Insert your access token
|
||||||
|
in: header
|
||||||
|
name: Authorization
|
||||||
|
type: string
|
||||||
- default: 1
|
- default: 1
|
||||||
description: Page number
|
description: Page number
|
||||||
in: query
|
in: query
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue