medol-be/app/module/articles/controller/articles.controller.go

669 lines
22 KiB
Go
Raw Normal View History

2024-03-05 19:15:53 +00:00
package controller
import (
"strconv"
2025-07-02 06:03:52 +00:00
"web-medols-be/app/middleware"
"web-medols-be/app/module/articles/request"
"web-medols-be/app/module/articles/service"
"web-medols-be/utils/paginator"
2024-03-05 19:15:53 +00:00
"github.com/gofiber/fiber/v2"
"github.com/rs/zerolog"
2025-07-02 06:03:52 +00:00
utilRes "web-medols-be/utils/response"
utilVal "web-medols-be/utils/validator"
2024-03-05 19:15:53 +00:00
)
type articlesController struct {
articlesService service.ArticlesService
2025-07-02 06:03:52 +00:00
Log zerolog.Logger
2024-03-05 19:15:53 +00:00
}
type ArticlesController interface {
All(c *fiber.Ctx) error
Show(c *fiber.Ctx) error
2025-05-14 16:54:21 +00:00
ShowByOldId(c *fiber.Ctx) error
2024-03-05 19:15:53 +00:00
Save(c *fiber.Ctx) error
SaveThumbnail(c *fiber.Ctx) error
2024-03-05 19:15:53 +00:00
Update(c *fiber.Ctx) error
UpdateBanner(c *fiber.Ctx) error
2024-03-05 19:15:53 +00:00
Delete(c *fiber.Ctx) error
Viewer(c *fiber.Ctx) error
2025-02-15 01:56:13 +00:00
SummaryStats(c *fiber.Ctx) error
2025-02-15 10:23:39 +00:00
ArticlePerUserLevelStats(c *fiber.Ctx) error
ArticleMonthlyStats(c *fiber.Ctx) error
2025-02-24 05:28:06 +00:00
PublishScheduling(c *fiber.Ctx) error
// Dynamic approval system methods
SubmitForApproval(c *fiber.Ctx) error
GetApprovalStatus(c *fiber.Ctx) error
GetPendingApprovals(c *fiber.Ctx) error
GetArticlesWaitingForApproval(c *fiber.Ctx) error
2024-03-05 19:15:53 +00:00
}
2025-07-02 06:03:52 +00:00
func NewArticlesController(articlesService service.ArticlesService, log zerolog.Logger) ArticlesController {
2024-03-05 19:15:53 +00:00
return &articlesController{
articlesService: articlesService,
2025-07-02 06:03:52 +00:00
Log: log,
2024-03-05 19:15:53 +00:00
}
}
2024-03-31 15:19:45 +00:00
// All Articles
2024-03-05 19:15:53 +00:00
// @Summary Get all Articles
// @Description API for getting all Articles
2024-03-31 15:19:45 +00:00
// @Tags Articles
2024-03-05 19:15:53 +00:00
// @Security Bearer
2025-07-02 06:03:52 +00:00
// @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>)
2024-03-31 15:19:45 +00:00
// @Param req query request.ArticlesQueryRequest false "query parameters"
// @Param req query paginator.Pagination false "pagination parameters"
2024-03-05 19:15:53 +00:00
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
2024-03-05 19:15:53 +00:00
// @Router /articles [get]
func (_i *articlesController) All(c *fiber.Ctx) error {
paginate, err := paginator.Paginate(c)
if err != nil {
return err
}
reqContext := request.ArticlesQueryRequestContext{
Title: c.Query("title"),
Description: c.Query("description"),
Tags: c.Query("tags"),
Category: c.Query("category"),
CategoryId: c.Query("categoryId"),
TypeId: c.Query("typeId"),
StatusId: c.Query("statusId"),
IsPublish: c.Query("isPublish"),
IsDraft: c.Query("isDraft"),
2025-04-07 02:46:48 +00:00
IsBanner: c.Query("isBanner"),
}
req := reqContext.ToParamRequest()
2024-03-05 19:15:53 +00:00
req.Pagination = paginate
2025-07-02 06:03:52 +00:00
// Get ClientId from context
clientId := middleware.GetClientID(c)
// Get Authorization token from header
authToken := c.Get("Authorization")
2025-07-02 06:03:52 +00:00
_i.Log.Info().Interface("clientId", clientId).Msg("")
_i.Log.Info().Str("authToken", authToken).Msg("")
2025-07-02 06:03:52 +00:00
articlesData, paging, err := _i.articlesService.All(clientId, authToken, req)
2024-03-05 19:15:53 +00:00
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
2024-03-31 15:19:45 +00:00
Success: true,
2024-03-05 19:15:53 +00:00
Messages: utilRes.Messages{"Articles list successfully retrieved"},
Data: articlesData,
Meta: paging,
})
}
2024-03-31 15:19:45 +00:00
// Show Articles
2024-03-05 19:15:53 +00:00
// @Summary Get one Articles
// @Description API for getting one Articles
2024-03-31 15:19:45 +00:00
// @Tags Articles
2024-03-05 19:15:53 +00:00
// @Security Bearer
2025-09-17 02:11:13 +00:00
// @Param X-Client-Key header string true "Insert the X-Client-Key"
2024-03-05 19:15:53 +00:00
// @Param id path int true "Articles ID"
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
2024-03-05 19:15:53 +00:00
// @Router /articles/{id} [get]
func (_i *articlesController) Show(c *fiber.Ctx) error {
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
if err != nil {
return err
}
2025-07-02 06:03:52 +00:00
// Get ClientId from context
clientId := middleware.GetClientID(c)
articlesData, err := _i.articlesService.Show(clientId, uint(id))
2024-03-05 19:15:53 +00:00
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
2024-03-31 15:19:45 +00:00
Success: true,
2024-03-05 19:15:53 +00:00
Messages: utilRes.Messages{"Articles successfully retrieved"},
2025-05-14 16:54:21 +00:00
Data: articlesData,
})
}
// ShowByOldId Articles
// @Summary Get one Articles
// @Description API for getting one Articles
// @Tags Articles
// @Security Bearer
2025-09-17 02:11:13 +00:00
// @Param X-Client-Key header string true "Insert the X-Client-Key"
2025-05-14 16:54:21 +00:00
// @Param id path int true "Articles Old ID"
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
// @Router /articles/old-id/{id} [get]
func (_i *articlesController) ShowByOldId(c *fiber.Ctx) error {
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
if err != nil {
return err
}
2025-07-02 06:03:52 +00:00
// Get ClientId from context
clientId := middleware.GetClientID(c)
articlesData, err := _i.articlesService.ShowByOldId(clientId, uint(id))
2025-05-14 16:54:21 +00:00
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
Success: true,
Messages: utilRes.Messages{"Articles successfully retrieved"},
2024-03-05 19:15:53 +00:00
Data: articlesData,
})
}
2024-03-31 15:19:45 +00:00
// Save Articles
2024-03-05 19:15:53 +00:00
// @Summary Create Articles
// @Description API for create Articles
2024-03-31 15:19:45 +00:00
// @Tags Articles
2024-03-05 19:15:53 +00:00
// @Security Bearer
2025-07-03 06:28:32 +00:00
// @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>)
2024-03-31 15:19:45 +00:00
// @Param payload body request.ArticlesCreateRequest true "Required payload"
2024-03-05 19:15:53 +00:00
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
2024-03-05 19:15:53 +00:00
// @Router /articles [post]
func (_i *articlesController) Save(c *fiber.Ctx) error {
req := new(request.ArticlesCreateRequest)
if err := utilVal.ParseAndValidate(c, req); err != nil {
return err
}
authToken := c.Get("Authorization")
2025-07-02 06:03:52 +00:00
// Get ClientId from context
clientId := middleware.GetClientID(c)
_i.Log.Info().Interface("clientId", clientId).Msg("")
_i.Log.Info().Interface("authToken", authToken).Msg("")
2025-07-02 06:03:52 +00:00
dataResult, err := _i.articlesService.Save(clientId, *req, authToken)
2024-03-05 19:15:53 +00:00
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
2024-03-31 15:19:45 +00:00
Success: true,
2024-03-05 19:15:53 +00:00
Messages: utilRes.Messages{"Articles successfully created"},
Data: dataResult,
})
}
// SaveThumbnail Articles
// @Summary Save Thumbnail Articles
// @Description API for Save Thumbnail of Articles
// @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 id path int true "Articles ID"
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
// @Router /articles/thumbnail/{id} [post]
func (_i *articlesController) SaveThumbnail(c *fiber.Ctx) error {
2025-07-02 06:03:52 +00:00
// Get ClientId from context
clientId := middleware.GetClientID(c)
err := _i.articlesService.SaveThumbnail(clientId, c)
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
Success: true,
Messages: utilRes.Messages{"Thumbnail of Articles successfully created"},
2024-03-05 19:15:53 +00:00
})
}
2024-03-31 15:19:45 +00:00
// Update Articles
2024-04-29 18:17:25 +00:00
// @Summary Update Articles
2024-03-05 19:15:53 +00:00
// @Description API for update Articles
2024-03-31 15:19:45 +00:00
// @Tags Articles
2024-03-05 19:15:53 +00:00
// @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"
2024-03-31 15:19:45 +00:00
// @Param payload body request.ArticlesUpdateRequest true "Required payload"
2024-03-05 19:15:53 +00:00
// @Param id path int true "Articles ID"
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
2024-03-05 19:15:53 +00:00
// @Router /articles/{id} [put]
func (_i *articlesController) Update(c *fiber.Ctx) error {
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
if err != nil {
return err
}
req := new(request.ArticlesUpdateRequest)
if err := utilVal.ParseAndValidate(c, req); err != nil {
return err
}
2025-07-02 06:03:52 +00:00
// Get ClientId from context
clientId := middleware.GetClientID(c)
err = _i.articlesService.Update(clientId, uint(id), *req)
2024-03-05 19:15:53 +00:00
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
2024-03-31 15:19:45 +00:00
Success: true,
2024-03-05 19:15:53 +00:00
Messages: utilRes.Messages{"Articles successfully updated"},
})
}
// UpdateBanner Articles
// @Summary Update Banner Articles
// @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 id path int true "Articles ID"
2025-04-07 02:54:28 +00:00
// @Param isBanner query bool true "Articles Banner Status"
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
// @Router /articles/banner/{id} [put]
func (_i *articlesController) UpdateBanner(c *fiber.Ctx) error {
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
if err != nil {
return err
}
2025-04-07 02:54:28 +00:00
isBanner, err := strconv.ParseBool(c.Query("isBanner"))
if err != nil {
return err
}
2025-07-02 06:03:52 +00:00
// Get ClientId from context
clientId := middleware.GetClientID(c)
err = _i.articlesService.UpdateBanner(clientId, uint(id), isBanner)
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
Success: true,
Messages: utilRes.Messages{"Articles successfully banner updated"},
})
}
2024-03-31 15:19:45 +00:00
// Delete Articles
2024-04-29 18:17:25 +00:00
// @Summary Delete Articles
2024-03-05 19:15:53 +00:00
// @Description API for delete Articles
2024-03-31 15:19:45 +00:00
// @Tags Articles
2024-03-05 19:15:53 +00:00
// @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"
2024-03-05 19:15:53 +00:00
// @Param id path int true "Articles ID"
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
2024-03-05 19:15:53 +00:00
// @Router /articles/{id} [delete]
func (_i *articlesController) Delete(c *fiber.Ctx) error {
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
if err != nil {
return err
}
2025-07-02 06:03:52 +00:00
// Get ClientId from context
clientId := middleware.GetClientID(c)
err = _i.articlesService.Delete(clientId, uint(id))
2024-03-05 19:15:53 +00:00
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
2024-03-31 15:19:45 +00:00
Success: true,
2024-03-05 19:15:53 +00:00
Messages: utilRes.Messages{"Articles successfully deleted"},
})
}
// Viewer Articles
// @Summary Viewer Articles Thumbnail
// @Description API for View Thumbnail of Article
// @Tags Articles
// @Security Bearer
// @Param X-Client-Key header string false "Insert the X-Client-Key"
// @Param thumbnailName path string true "Articles Thumbnail Name"
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
// @Router /articles/thumbnail/viewer/{thumbnailName} [get]
func (_i *articlesController) Viewer(c *fiber.Ctx) error {
2025-07-02 06:03:52 +00:00
// Get ClientId from context
clientId := middleware.GetClientID(c)
return _i.articlesService.Viewer(clientId, c)
}
2025-02-15 01:56:13 +00:00
// SummaryStats Articles
// @Summary SummaryStats Articles
// @Description API for Summary Stats of Article
// @Tags Articles
// @Security Bearer
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
2025-02-15 01:56:13 +00:00
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
// @Router /articles/statistic/summary [get]
func (_i *articlesController) SummaryStats(c *fiber.Ctx) error {
authToken := c.Get("Authorization")
2025-07-02 06:03:52 +00:00
// Get ClientId from context
clientId := middleware.GetClientID(c)
response, err := _i.articlesService.SummaryStats(clientId, authToken)
2025-02-15 01:56:13 +00:00
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
Success: true,
Messages: utilRes.Messages{"Summary Stats of Articles successfully retrieved"},
Data: response,
})
}
2025-02-15 10:23:39 +00:00
// ArticlePerUserLevelStats Articles
// @Summary ArticlePerUserLevelStats Articles
// @Description API for ArticlePerUserLevelStats of Article
// @Tags Articles
// @Security Bearer
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
2025-02-15 10:23:39 +00:00
// @Param startDate query string false "start date"
// @Param endDate query string false "start date"
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
// @Router /articles/statistic/user-levels [get]
func (_i *articlesController) ArticlePerUserLevelStats(c *fiber.Ctx) error {
authToken := c.Get("Authorization")
startDate := c.Query("startDate")
endDate := c.Query("endDate")
2025-07-02 06:03:52 +00:00
// Get ClientId from context
clientId := middleware.GetClientID(c)
response, err := _i.articlesService.ArticlePerUserLevelStats(clientId, authToken, &startDate, &endDate)
2025-02-15 10:23:39 +00:00
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
Success: true,
Messages: utilRes.Messages{"ArticlePerUserLevelStats of Articles successfully retrieved"},
Data: response,
})
}
// ArticleMonthlyStats Articles
// @Summary ArticleMonthlyStats Articles
// @Description API for ArticleMonthlyStats of Article
// @Tags Articles
// @Security Bearer
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
2025-02-15 10:23:39 +00:00
// @Param year query int false "year"
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
// @Router /articles/statistic/monthly [get]
func (_i *articlesController) ArticleMonthlyStats(c *fiber.Ctx) error {
authToken := c.Get("Authorization")
year := c.Query("year")
yearInt, err := strconv.Atoi(year)
if err != nil {
return err
}
2025-07-02 06:03:52 +00:00
// Get ClientId from context
clientId := middleware.GetClientID(c)
response, err := _i.articlesService.ArticleMonthlyStats(clientId, authToken, &yearInt)
2025-02-15 10:23:39 +00:00
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
Success: true,
Messages: utilRes.Messages{"ArticleMonthlyStats of Articles successfully retrieved"},
Data: response,
})
}
2025-02-24 05:28:06 +00:00
// PublishScheduling Articles
// @Summary PublishScheduling Articles
// @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>)
2025-02-24 05:28:06 +00:00
// @Param id query int false "article id"
// @Param date query string false "publish date"
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
// @Router /articles/publish-scheduling [post]
func (_i *articlesController) PublishScheduling(c *fiber.Ctx) error {
id, err := strconv.ParseUint(c.Query("id"), 10, 0)
if err != nil {
return err
}
date := c.Query("date")
2025-07-02 06:03:52 +00:00
// Get ClientId from context
clientId := middleware.GetClientID(c)
err = _i.articlesService.PublishScheduling(clientId, uint(id), date)
2025-02-24 05:28:06 +00:00
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
Success: true,
Messages: utilRes.Messages{"Publish Scheduling of Articles successfully saved"},
})
}
// SubmitForApproval Articles
// @Summary Submit Article for Approval
// @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 id path int true "article id"
// @Param req body request.SubmitForApprovalRequest false "approval request data"
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
// @Router /articles/{id}/submit-approval [post]
func (_i *articlesController) SubmitForApproval(c *fiber.Ctx) error {
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
if err != nil {
return err
}
var req request.SubmitForApprovalRequest
if err := c.BodyParser(&req); err != nil {
return err
}
// Get ClientId from context
clientId := middleware.GetClientID(c)
// Get user ID from token (you'll need to implement this based on your auth system)
userId := uint(1) // TODO: Get from JWT token
err = _i.articlesService.SubmitForApproval(clientId, uint(id), userId, req.WorkflowId)
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
Success: true,
Messages: utilRes.Messages{"Article successfully submitted for approval"},
})
}
// GetApprovalStatus Articles
// @Summary Get Article Approval Status
// @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 id path int true "article id"
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
// @Router /articles/{id}/approval-status [get]
func (_i *articlesController) GetApprovalStatus(c *fiber.Ctx) error {
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
if err != nil {
return err
}
// Get ClientId from context
clientId := middleware.GetClientID(c)
response, err := _i.articlesService.GetApprovalStatus(clientId, uint(id))
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
Success: true,
Messages: utilRes.Messages{"Article approval status successfully retrieved"},
Data: response,
})
}
// GetPendingApprovals Articles
// @Summary Get Pending Approvals
// @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 page query int false "page number"
// @Param limit query int false "items per page"
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
// @Router /articles/pending-approval [get]
func (_i *articlesController) GetPendingApprovals(c *fiber.Ctx) error {
page, err := strconv.Atoi(c.Query("page", "1"))
if err != nil {
page = 1
}
limit, err := strconv.Atoi(c.Query("limit", "10"))
if err != nil {
limit = 10
}
// Get ClientId from context
clientId := middleware.GetClientID(c)
// Get user level ID from token (you'll need to implement this based on your auth system)
userLevelId := uint(1) // TODO: Get from JWT token
response, paging, err := _i.articlesService.GetPendingApprovals(clientId, userLevelId, page, limit)
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
Success: true,
Messages: utilRes.Messages{"Pending approvals successfully retrieved"},
Data: response,
Meta: paging,
})
}
// GetArticlesWaitingForApproval
// @Summary Get articles waiting for approval by current user level
// @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 page query int false "Page number" default(1)
// @Param limit query int false "Items per page" default(10)
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
// @Router /articles/waiting-for-approval [get]
func (_i *articlesController) GetArticlesWaitingForApproval(c *fiber.Ctx) error {
page, err := strconv.Atoi(c.Query("page", "1"))
if err != nil {
return err
}
limit, err := strconv.Atoi(c.Query("limit", "10"))
if err != nil {
return err
}
// Get ClientId from context
clientId := middleware.GetClientID(c)
// Get user level from middleware
userLevelId := middleware.GetUserLevelID(c)
responses, paging, err := _i.articlesService.GetArticlesWaitingForApproval(clientId, *userLevelId, page, limit)
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
Success: true,
Messages: utilRes.Messages{"Articles waiting for approval retrieved successfully"},
Data: responses,
Meta: paging,
})
}