feat: update article filter by category
This commit is contained in:
parent
69be246c35
commit
29d8f5b3a2
|
|
@ -7,6 +7,7 @@ type ArticleCategories struct {
|
||||||
Title string `json:"title" gorm:"type:varchar"`
|
Title string `json:"title" gorm:"type:varchar"`
|
||||||
Description string `json:"description" gorm:"type:varchar"`
|
Description string `json:"description" gorm:"type:varchar"`
|
||||||
ThumbnailPath *string `json:"thumbnail_path" gorm:"type:varchar"`
|
ThumbnailPath *string `json:"thumbnail_path" gorm:"type:varchar"`
|
||||||
|
Slug *string `json:"slug" gorm:"type:varchar"`
|
||||||
ParentId *int `json:"parent_id" gorm:"type:int4"`
|
ParentId *int `json:"parent_id" gorm:"type:int4"`
|
||||||
Tags *string `json:"tags" gorm:"type:varchar"`
|
Tags *string `json:"tags" gorm:"type:varchar"`
|
||||||
Position *int `json:"position" gorm:"type:int4"`
|
Position *int `json:"position" gorm:"type:int4"`
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ type ArticleCategoriesRepository interface {
|
||||||
GetAll(req request.ArticleCategoriesQueryRequest) (articleCategoriess []*entity.ArticleCategories, paging paginator.Pagination, err error)
|
GetAll(req request.ArticleCategoriesQueryRequest) (articleCategoriess []*entity.ArticleCategories, paging paginator.Pagination, err error)
|
||||||
FindOne(id uint) (articleCategories *entity.ArticleCategories, err error)
|
FindOne(id uint) (articleCategories *entity.ArticleCategories, err error)
|
||||||
FindOneByOldId(id uint) (articleCategories *entity.ArticleCategories, err error)
|
FindOneByOldId(id uint) (articleCategories *entity.ArticleCategories, err error)
|
||||||
|
FindOneBySlug(slug string) (articleCategories *entity.ArticleCategories, err error)
|
||||||
Create(articleCategories *entity.ArticleCategories) (articleCategoriesReturn *entity.ArticleCategories, err error)
|
Create(articleCategories *entity.ArticleCategories) (articleCategoriesReturn *entity.ArticleCategories, err error)
|
||||||
Update(id uint, articleCategories *entity.ArticleCategories) (err error)
|
Update(id uint, articleCategories *entity.ArticleCategories) (err error)
|
||||||
Delete(id uint) (err error)
|
Delete(id uint) (err error)
|
||||||
|
|
@ -96,6 +97,14 @@ func (_i *articleCategoriesRepository) FindOneByOldId(id uint) (articleCategorie
|
||||||
return articleCategories, nil
|
return articleCategories, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (_i *articleCategoriesRepository) FindOneBySlug(slug string) (articleCategories *entity.ArticleCategories, err error) {
|
||||||
|
if err := _i.DB.DB.Where("slug = ?", slug).First(&articleCategories).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return articleCategories, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (_i *articleCategoriesRepository) Create(articleCategories *entity.ArticleCategories) (articleCategoriesReturn *entity.ArticleCategories, err error) {
|
func (_i *articleCategoriesRepository) Create(articleCategories *entity.ArticleCategories) (articleCategoriesReturn *entity.ArticleCategories, err error) {
|
||||||
result := _i.DB.DB.Create(articleCategories)
|
result := _i.DB.DB.Create(articleCategories)
|
||||||
return articleCategories, result.Error
|
return articleCategories, result.Error
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ type ArticleCategoriesCreateRequest struct {
|
||||||
Description string `json:"description" validate:"required"`
|
Description string `json:"description" validate:"required"`
|
||||||
StatusId int `json:"statusId" validate:"required"`
|
StatusId int `json:"statusId" validate:"required"`
|
||||||
Tags *string `json:"tags"`
|
Tags *string `json:"tags"`
|
||||||
|
Slug *string `json:"slug"`
|
||||||
ParentId *int `json:"parentId"`
|
ParentId *int `json:"parentId"`
|
||||||
OldCategoryId *uint `json:"oldCategoryId"`
|
OldCategoryId *uint `json:"oldCategoryId"`
|
||||||
}
|
}
|
||||||
|
|
@ -35,6 +36,7 @@ func (req ArticleCategoriesCreateRequest) ToEntity() *entity.ArticleCategories {
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Tags: req.Tags,
|
Tags: req.Tags,
|
||||||
ParentId: req.ParentId,
|
ParentId: req.ParentId,
|
||||||
|
Slug: req.Slug,
|
||||||
OldCategoryId: req.OldCategoryId,
|
OldCategoryId: req.OldCategoryId,
|
||||||
StatusId: req.StatusId,
|
StatusId: req.StatusId,
|
||||||
}
|
}
|
||||||
|
|
@ -46,6 +48,7 @@ type ArticleCategoriesUpdateRequest struct {
|
||||||
Description string `json:"description" validate:"required"`
|
Description string `json:"description" validate:"required"`
|
||||||
StatusId int `json:"statusId" validate:"required"`
|
StatusId int `json:"statusId" validate:"required"`
|
||||||
Tags *string `json:"tags"`
|
Tags *string `json:"tags"`
|
||||||
|
Slug *string `json:"slug"`
|
||||||
ParentId *int `json:"parentId"`
|
ParentId *int `json:"parentId"`
|
||||||
IsPublish *bool `json:"isPublish"`
|
IsPublish *bool `json:"isPublish"`
|
||||||
PublishedAt *time.Time `json:"publishedAt"`
|
PublishedAt *time.Time `json:"publishedAt"`
|
||||||
|
|
@ -57,6 +60,7 @@ func (req ArticleCategoriesUpdateRequest) ToEntity() *entity.ArticleCategories {
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
ParentId: req.ParentId,
|
ParentId: req.ParentId,
|
||||||
|
Slug: req.Slug,
|
||||||
Tags: req.Tags,
|
Tags: req.Tags,
|
||||||
StatusId: req.StatusId,
|
StatusId: req.StatusId,
|
||||||
IsPublish: req.IsPublish,
|
IsPublish: req.IsPublish,
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ func (_i *articlesController) All(c *fiber.Ctx) error {
|
||||||
Title: c.Query("title"),
|
Title: c.Query("title"),
|
||||||
Description: c.Query("description"),
|
Description: c.Query("description"),
|
||||||
Tags: c.Query("tags"),
|
Tags: c.Query("tags"),
|
||||||
|
Category: c.Query("category"),
|
||||||
CategoryId: c.Query("categoryId"),
|
CategoryId: c.Query("categoryId"),
|
||||||
TypeId: c.Query("typeId"),
|
TypeId: c.Query("typeId"),
|
||||||
StatusId: c.Query("statusId"),
|
StatusId: c.Query("statusId"),
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@ type ArticlesGeneric interface {
|
||||||
type ArticlesQueryRequest struct {
|
type ArticlesQueryRequest struct {
|
||||||
Title *string `json:"title"`
|
Title *string `json:"title"`
|
||||||
Description *string `json:"description"`
|
Description *string `json:"description"`
|
||||||
CategoryId *int `json:"categoryId"`
|
CategoryId *uint `json:"categoryId"`
|
||||||
|
Category *string `json:"category"`
|
||||||
TypeId *int `json:"typeId"`
|
TypeId *int `json:"typeId"`
|
||||||
Tags *string `json:"tags"`
|
Tags *string `json:"tags"`
|
||||||
CreatedById *int `json:"createdById"`
|
CreatedById *int `json:"createdById"`
|
||||||
|
|
@ -107,6 +108,7 @@ type ArticlesQueryRequestContext struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
CategoryId string `json:"categoryId"`
|
CategoryId string `json:"categoryId"`
|
||||||
|
Category string `json:"category"`
|
||||||
TypeId string `json:"typeId"`
|
TypeId string `json:"typeId"`
|
||||||
Tags string `json:"tags"`
|
Tags string `json:"tags"`
|
||||||
CreatedById string `json:"createdById"`
|
CreatedById string `json:"createdById"`
|
||||||
|
|
@ -124,10 +126,14 @@ func (req ArticlesQueryRequestContext) ToParamRequest() ArticlesQueryRequest {
|
||||||
if description := req.Description; description != "" {
|
if description := req.Description; description != "" {
|
||||||
request.Description = &description
|
request.Description = &description
|
||||||
}
|
}
|
||||||
|
if category := req.Category; category != "" {
|
||||||
|
request.Category = &category
|
||||||
|
}
|
||||||
if categoryIdStr := req.CategoryId; categoryIdStr != "" {
|
if categoryIdStr := req.CategoryId; categoryIdStr != "" {
|
||||||
categoryId, err := strconv.Atoi(categoryIdStr)
|
categoryId, err := strconv.Atoi(categoryIdStr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
request.CategoryId = &categoryId
|
categoryIdUint := uint(categoryId)
|
||||||
|
request.CategoryId = &categoryIdUint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if typeIdStr := req.TypeId; typeIdStr != "" {
|
if typeIdStr := req.TypeId; typeIdStr != "" {
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,14 @@ func NewArticlesService(
|
||||||
|
|
||||||
// All implement interface of ArticlesService
|
// All implement interface of ArticlesService
|
||||||
func (_i *articlesService) All(req request.ArticlesQueryRequest) (articless []*response.ArticlesResponse, paging paginator.Pagination, err error) {
|
func (_i *articlesService) All(req request.ArticlesQueryRequest) (articless []*response.ArticlesResponse, paging paginator.Pagination, err error) {
|
||||||
|
if req.Category != nil {
|
||||||
|
findCategory, err := _i.ArticleCategoriesRepo.FindOneBySlug(*req.Category)
|
||||||
|
if err != nil {
|
||||||
|
return nil, paging, err
|
||||||
|
}
|
||||||
|
req.CategoryId = &findCategory.ID
|
||||||
|
}
|
||||||
|
|
||||||
results, paging, err := _i.Repo.GetAll(req)
|
results, paging, err := _i.Repo.GetAll(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -2163,6 +2163,11 @@ const docTemplate = `{
|
||||||
],
|
],
|
||||||
"summary": "Get all Articles",
|
"summary": "Get all Articles",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"name": "category",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"name": "categoryId",
|
"name": "categoryId",
|
||||||
|
|
@ -7416,6 +7421,9 @@ const docTemplate = `{
|
||||||
"parentId": {
|
"parentId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
"slug": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"statusId": {
|
"statusId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
|
@ -7451,6 +7459,9 @@ const docTemplate = `{
|
||||||
"publishedAt": {
|
"publishedAt": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"slug": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"statusId": {
|
"statusId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -2152,6 +2152,11 @@
|
||||||
],
|
],
|
||||||
"summary": "Get all Articles",
|
"summary": "Get all Articles",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"name": "category",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"name": "categoryId",
|
"name": "categoryId",
|
||||||
|
|
@ -7405,6 +7410,9 @@
|
||||||
"parentId": {
|
"parentId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
"slug": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"statusId": {
|
"statusId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
|
@ -7440,6 +7448,9 @@
|
||||||
"publishedAt": {
|
"publishedAt": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"slug": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"statusId": {
|
"statusId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,8 @@ definitions:
|
||||||
type: integer
|
type: integer
|
||||||
parentId:
|
parentId:
|
||||||
type: integer
|
type: integer
|
||||||
|
slug:
|
||||||
|
type: string
|
||||||
statusId:
|
statusId:
|
||||||
type: integer
|
type: integer
|
||||||
tags:
|
tags:
|
||||||
|
|
@ -80,6 +82,8 @@ definitions:
|
||||||
type: integer
|
type: integer
|
||||||
publishedAt:
|
publishedAt:
|
||||||
type: string
|
type: string
|
||||||
|
slug:
|
||||||
|
type: string
|
||||||
statusId:
|
statusId:
|
||||||
type: integer
|
type: integer
|
||||||
tags:
|
tags:
|
||||||
|
|
@ -2140,6 +2144,9 @@ paths:
|
||||||
get:
|
get:
|
||||||
description: API for getting all Articles
|
description: API for getting all Articles
|
||||||
parameters:
|
parameters:
|
||||||
|
- in: query
|
||||||
|
name: category
|
||||||
|
type: string
|
||||||
- in: query
|
- in: query
|
||||||
name: categoryId
|
name: categoryId
|
||||||
type: integer
|
type: integer
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue