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"` IsDraft *bool `json:"is_draft" gorm:"type:bool;default:false"`
DraftedAt *time.Time `json:"drafted_at" gorm:"type:timestamp"` DraftedAt *time.Time `json:"drafted_at" gorm:"type:timestamp"`
PublishSchedule *string `json:"publish_schedule" gorm:"type:varchar"` 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"` ClientId *uuid.UUID `json:"client_id" gorm:"type:UUID"`
IsActive *bool `json:"is_active" gorm:"type:bool;default:true"` IsActive *bool `json:"is_active" gorm:"type:bool;default:true"`
CreatedAt time.Time `json:"created_at" gorm:"default:now()"` 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"), IsPublish: c.Query("isPublish"),
IsDraft: c.Query("isDraft"), IsDraft: c.Query("isDraft"),
IsBanner: c.Query("isBanner"), IsBanner: c.Query("isBanner"),
CustomCreatorName: c.Query("customCreatorName"),
Source: c.Query("source"),
StartDate: c.Query("startDate"),
EndDate: c.Query("endDate"),
} }
req := reqContext.ToParamRequest() req := reqContext.ToParamRequest()
req.Pagination = paginate req.Pagination = paginate

View File

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

View File

@ -140,6 +140,21 @@ func (_i *articlesRepository) GetAll(clientId *uuid.UUID, userLevelId *uint, req
if req.CreatedById != nil { if req.CreatedById != nil {
query = query.Where("articles.created_by_id = ?", req.CreatedById) 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 // Count total records
query.Count(&count) query.Count(&count)

View File

@ -24,6 +24,10 @@ type ArticlesQueryRequest struct {
IsBanner *bool `json:"isBanner"` IsBanner *bool `json:"isBanner"`
IsPublish *bool `json:"isPublish"` IsPublish *bool `json:"isPublish"`
IsDraft *bool `json:"isDraft"` 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"` Pagination *paginator.Pagination `json:"pagination"`
} }
@ -41,6 +45,8 @@ type ArticlesCreateRequest struct {
IsPublish *bool `json:"isPublish"` IsPublish *bool `json:"isPublish"`
IsDraft *bool `json:"isDraft"` IsDraft *bool `json:"isDraft"`
OldId *uint `json:"oldId"` OldId *uint `json:"oldId"`
Source *string `json:"source"`
CustomCreatorName *string `json:"customCreatorName"`
} }
func (req ArticlesCreateRequest) ToEntity() *entity.Articles { func (req ArticlesCreateRequest) ToEntity() *entity.Articles {
@ -55,6 +61,8 @@ func (req ArticlesCreateRequest) ToEntity() *entity.Articles {
IsPublish: req.IsPublish, IsPublish: req.IsPublish,
IsDraft: req.IsDraft, IsDraft: req.IsDraft,
OldId: req.OldId, OldId: req.OldId,
Source: req.Source,
CustomCreatorName: req.CustomCreatorName,
} }
} }
@ -72,6 +80,8 @@ type ArticlesUpdateRequest struct {
IsPublish *bool `json:"isPublish"` IsPublish *bool `json:"isPublish"`
IsDraft *bool `json:"isDraft"` IsDraft *bool `json:"isDraft"`
StatusId *int `json:"statusId"` StatusId *int `json:"statusId"`
Source *string `json:"source"`
CustomCreatorName *string `json:"customCreatorName"`
} }
func (req ArticlesUpdateRequest) ToEntity() *entity.Articles { func (req ArticlesUpdateRequest) ToEntity() *entity.Articles {
@ -87,6 +97,8 @@ func (req ArticlesUpdateRequest) ToEntity() *entity.Articles {
AiArticleId: req.AiArticleId, AiArticleId: req.AiArticleId,
IsPublish: req.IsPublish, IsPublish: req.IsPublish,
IsDraft: req.IsDraft, IsDraft: req.IsDraft,
Source: req.Source,
CustomCreatorName: req.CustomCreatorName,
UpdatedAt: time.Now(), UpdatedAt: time.Now(),
} }
} else { } else {
@ -102,6 +114,8 @@ func (req ArticlesUpdateRequest) ToEntity() *entity.Articles {
AiArticleId: req.AiArticleId, AiArticleId: req.AiArticleId,
IsPublish: req.IsPublish, IsPublish: req.IsPublish,
IsDraft: req.IsDraft, IsDraft: req.IsDraft,
Source: req.Source,
CustomCreatorName: req.CustomCreatorName,
UpdatedAt: time.Now(), UpdatedAt: time.Now(),
} }
} }
@ -119,6 +133,10 @@ type ArticlesQueryRequestContext struct {
IsPublish string `json:"isPublish"` IsPublish string `json:"isPublish"`
IsDraft string `json:"isDraft"` IsDraft string `json:"isDraft"`
StatusId string `json:"statusId"` 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 { func (req ArticlesQueryRequestContext) ToParamRequest() ArticlesQueryRequest {
@ -179,6 +197,22 @@ func (req ArticlesQueryRequestContext) ToParamRequest() ArticlesQueryRequest {
request.CreatedById = &createdById 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 return request
} }

View File

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

View File

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

View File

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

View File

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