feat: update articles filter and fields

This commit is contained in:
hanif salafi 2025-10-08 07:52:29 +07:00
parent fb6c8ca592
commit 5258f20df1
9 changed files with 298 additions and 154 deletions

View File

@ -38,6 +38,8 @@ type Articles struct {
IsDraft *bool `json:"is_draft" gorm:"type:bool;default:false"`
DraftedAt *time.Time `json:"drafted_at" gorm:"type:timestamp"`
PublishSchedule *string `json:"publish_schedule" gorm:"type:varchar"`
Source *string `json:"source" gorm:"type:varchar"`
CustomCreatorName *string `json:"custom_creator_name" gorm:"type:varchar"`
ClientId *uuid.UUID `json:"client_id" gorm:"type:UUID"`
IsActive *bool `json:"is_active" gorm:"type:bool;default:true"`
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`

View File

@ -79,6 +79,10 @@ func (_i *articlesController) All(c *fiber.Ctx) error {
IsPublish: c.Query("isPublish"),
IsDraft: c.Query("isDraft"),
IsBanner: c.Query("isBanner"),
CustomCreatorName: c.Query("customCreatorName"),
Source: c.Query("source"),
StartDate: c.Query("startDate"),
EndDate: c.Query("endDate"),
}
req := reqContext.ToParamRequest()
req.Pagination = paginate

View File

@ -1,8 +1,6 @@
package mapper
import (
"github.com/google/uuid"
"github.com/rs/zerolog"
"web-medols-be/app/database/entity"
articleCategoriesMapper "web-medols-be/app/module/article_categories/mapper"
articleCategoriesRepository "web-medols-be/app/module/article_categories/repository"
@ -13,6 +11,9 @@ import (
articleFilesResponse "web-medols-be/app/module/article_files/response"
res "web-medols-be/app/module/articles/response"
usersRepository "web-medols-be/app/module/users/repository"
"github.com/google/uuid"
"github.com/rs/zerolog"
)
func ArticlesResponseMapper(
@ -76,6 +77,8 @@ func ArticlesResponseMapper(
IsPublish: articlesReq.IsPublish,
PublishedAt: articlesReq.PublishedAt,
IsActive: articlesReq.IsActive,
Source: articlesReq.Source,
CustomCreatorName: articlesReq.CustomCreatorName,
CreatedAt: articlesReq.CreatedAt,
UpdatedAt: articlesReq.UpdatedAt,
ArticleFiles: articleFilesArr,

View File

@ -140,6 +140,21 @@ func (_i *articlesRepository) GetAll(clientId *uuid.UUID, userLevelId *uint, req
if req.CreatedById != nil {
query = query.Where("articles.created_by_id = ?", req.CreatedById)
}
if req.Source != nil && *req.Source != "" {
source := strings.ToLower(*req.Source)
query = query.Where("LOWER(articles.source) = ?", strings.ToLower(source))
}
if req.CustomCreatorName != nil && *req.CustomCreatorName != "" {
customCreatorName := strings.ToLower(*req.CustomCreatorName)
query = query.Where("LOWER(articles.custom_creator_name) LIKE ?", "%"+strings.ToLower(customCreatorName)+"%")
}
if req.StartDate != nil {
query = query.Where("DATE(articles.created_at) >= ?", req.StartDate.Format("2006-01-02"))
}
if req.EndDate != nil {
query = query.Where("DATE(articles.created_at) <= ?", req.EndDate.Format("2006-01-02"))
}
// Count total records
query.Count(&count)

View File

@ -24,6 +24,10 @@ type ArticlesQueryRequest struct {
IsBanner *bool `json:"isBanner"`
IsPublish *bool `json:"isPublish"`
IsDraft *bool `json:"isDraft"`
Source *string `json:"source"`
CustomCreatorName *string `json:"customCreatorName"`
StartDate *time.Time `json:"startDate"`
EndDate *time.Time `json:"endDate"`
Pagination *paginator.Pagination `json:"pagination"`
}
@ -41,6 +45,8 @@ type ArticlesCreateRequest struct {
IsPublish *bool `json:"isPublish"`
IsDraft *bool `json:"isDraft"`
OldId *uint `json:"oldId"`
Source *string `json:"source"`
CustomCreatorName *string `json:"customCreatorName"`
}
func (req ArticlesCreateRequest) ToEntity() *entity.Articles {
@ -55,6 +61,8 @@ func (req ArticlesCreateRequest) ToEntity() *entity.Articles {
IsPublish: req.IsPublish,
IsDraft: req.IsDraft,
OldId: req.OldId,
Source: req.Source,
CustomCreatorName: req.CustomCreatorName,
}
}
@ -72,6 +80,8 @@ type ArticlesUpdateRequest struct {
IsPublish *bool `json:"isPublish"`
IsDraft *bool `json:"isDraft"`
StatusId *int `json:"statusId"`
Source *string `json:"source"`
CustomCreatorName *string `json:"customCreatorName"`
}
func (req ArticlesUpdateRequest) ToEntity() *entity.Articles {
@ -87,6 +97,8 @@ func (req ArticlesUpdateRequest) ToEntity() *entity.Articles {
AiArticleId: req.AiArticleId,
IsPublish: req.IsPublish,
IsDraft: req.IsDraft,
Source: req.Source,
CustomCreatorName: req.CustomCreatorName,
UpdatedAt: time.Now(),
}
} else {
@ -102,6 +114,8 @@ func (req ArticlesUpdateRequest) ToEntity() *entity.Articles {
AiArticleId: req.AiArticleId,
IsPublish: req.IsPublish,
IsDraft: req.IsDraft,
Source: req.Source,
CustomCreatorName: req.CustomCreatorName,
UpdatedAt: time.Now(),
}
}
@ -119,6 +133,10 @@ type ArticlesQueryRequestContext struct {
IsPublish string `json:"isPublish"`
IsDraft string `json:"isDraft"`
StatusId string `json:"statusId"`
Source string `json:"source"`
CustomCreatorName string `json:"customCreatorName"`
StartDate string `json:"startDate"`
EndDate string `json:"endDate"`
}
func (req ArticlesQueryRequestContext) ToParamRequest() ArticlesQueryRequest {
@ -179,6 +197,22 @@ func (req ArticlesQueryRequestContext) ToParamRequest() ArticlesQueryRequest {
request.CreatedById = &createdById
}
}
if source := req.Source; source != "" {
request.Source = &source
}
if customCreatorName := req.CustomCreatorName; customCreatorName != "" {
request.CustomCreatorName = &customCreatorName
}
if startDateStr := req.StartDate; startDateStr != "" {
if startDate, err := time.Parse("2006-01-02", startDateStr); err == nil {
request.StartDate = &startDate
}
}
if endDateStr := req.EndDate; endDateStr != "" {
if endDate, err := time.Parse("2006-01-02", endDateStr); err == nil {
request.EndDate = &endDate
}
}
return request
}

View File

@ -30,6 +30,8 @@ type ArticlesResponse struct {
IsPublish *bool `json:"isPublish"`
PublishedAt *time.Time `json:"publishedAt"`
IsActive *bool `json:"isActive"`
Source *string `json:"source"`
CustomCreatorName *string `json:"customCreatorName"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`

View File

@ -6839,11 +6839,21 @@ const docTemplate = `{
"name": "createdById",
"in": "query"
},
{
"type": "string",
"name": "customCreatorName",
"in": "query"
},
{
"type": "string",
"name": "description",
"in": "query"
},
{
"type": "string",
"name": "endDate",
"in": "query"
},
{
"type": "boolean",
"name": "isBanner",
@ -6859,6 +6869,16 @@ const docTemplate = `{
"name": "isPublish",
"in": "query"
},
{
"type": "string",
"name": "source",
"in": "query"
},
{
"type": "string",
"name": "startDate",
"in": "query"
},
{
"type": "integer",
"name": "statusId",
@ -16591,6 +16611,9 @@ const docTemplate = `{
"createdById": {
"type": "integer"
},
"customCreatorName": {
"type": "string"
},
"description": {
"type": "string"
},
@ -16609,6 +16632,9 @@ const docTemplate = `{
"slug": {
"type": "string"
},
"source": {
"type": "string"
},
"tags": {
"type": "string"
},
@ -16644,6 +16670,9 @@ const docTemplate = `{
"createdById": {
"type": "integer"
},
"customCreatorName": {
"type": "string"
},
"description": {
"type": "string"
},
@ -16659,6 +16688,9 @@ const docTemplate = `{
"slug": {
"type": "string"
},
"source": {
"type": "string"
},
"statusId": {
"type": "integer"
},

View File

@ -6828,11 +6828,21 @@
"name": "createdById",
"in": "query"
},
{
"type": "string",
"name": "customCreatorName",
"in": "query"
},
{
"type": "string",
"name": "description",
"in": "query"
},
{
"type": "string",
"name": "endDate",
"in": "query"
},
{
"type": "boolean",
"name": "isBanner",
@ -6848,6 +6858,16 @@
"name": "isPublish",
"in": "query"
},
{
"type": "string",
"name": "source",
"in": "query"
},
{
"type": "string",
"name": "startDate",
"in": "query"
},
{
"type": "integer",
"name": "statusId",
@ -16580,6 +16600,9 @@
"createdById": {
"type": "integer"
},
"customCreatorName": {
"type": "string"
},
"description": {
"type": "string"
},
@ -16598,6 +16621,9 @@
"slug": {
"type": "string"
},
"source": {
"type": "string"
},
"tags": {
"type": "string"
},
@ -16633,6 +16659,9 @@
"createdById": {
"type": "integer"
},
"customCreatorName": {
"type": "string"
},
"description": {
"type": "string"
},
@ -16648,6 +16677,9 @@
"slug": {
"type": "string"
},
"source": {
"type": "string"
},
"statusId": {
"type": "integer"
},

View File

@ -465,6 +465,8 @@ definitions:
type: string
createdById:
type: integer
customCreatorName:
type: string
description:
type: string
htmlDescription:
@ -477,6 +479,8 @@ definitions:
type: integer
slug:
type: string
source:
type: string
tags:
type: string
title:
@ -502,6 +506,8 @@ definitions:
type: string
createdById:
type: integer
customCreatorName:
type: string
description:
type: string
htmlDescription:
@ -512,6 +518,8 @@ definitions:
type: boolean
slug:
type: string
source:
type: string
statusId:
type: integer
tags:
@ -5814,9 +5822,15 @@ paths:
- in: query
name: createdById
type: integer
- in: query
name: customCreatorName
type: string
- in: query
name: description
type: string
- in: query
name: endDate
type: string
- in: query
name: isBanner
type: boolean
@ -5826,6 +5840,12 @@ paths:
- in: query
name: isPublish
type: boolean
- in: query
name: source
type: string
- in: query
name: startDate
type: string
- in: query
name: statusId
type: integer