feat: update article save

This commit is contained in:
hanif salafi 2025-02-13 22:32:59 +07:00
parent 6bda515c2e
commit 84a678e499
7 changed files with 41 additions and 15 deletions

View File

@ -1,13 +1,16 @@
package controller
import "go-humas-be/app/module/articles/service"
import (
"github.com/rs/zerolog"
"go-humas-be/app/module/articles/service"
)
type Controller struct {
Articles ArticlesController
}
func NewController(ArticlesService service.ArticlesService) *Controller {
func NewController(ArticlesService service.ArticlesService, log zerolog.Logger) *Controller {
return &Controller{
Articles: NewArticlesController(ArticlesService),
Articles: NewArticlesController(ArticlesService, log),
}
}

View File

@ -77,6 +77,10 @@ func (_i *articlesRepository) GetAll(req request.ArticlesQueryRequest) (articles
direction = "DESC"
}
query.Order(fmt.Sprintf("%s %s", req.Pagination.SortBy, direction))
} else {
direction := "DESC"
sortBy := "created_at"
query.Order(fmt.Sprintf("%s %s", sortBy, direction))
}
req.Pagination.Count = count

View File

@ -33,6 +33,7 @@ type ArticlesCreateRequest struct {
TypeId int `json:"typeId" validate:"required"`
Tags string `json:"tags" validate:"required"`
AiArticleId *int `json:"aiArticleId"`
CreatedAt *string `json:"createdAt"`
IsPublish *bool `json:"isPublish"`
IsDraft *bool `json:"isDraft"`
OldId *uint `json:"oldId"`

View File

@ -3,6 +3,7 @@ package service
import (
"context"
"errors"
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/minio/minio-go/v7"
"github.com/rs/zerolog"
@ -136,6 +137,15 @@ func (_i *articlesService) Save(req request.ArticlesCreateRequest, authToken str
newReq.DraftedAt = nil
}
if req.CreatedAt != nil {
layout := "2006-01-02 15:04:05"
parsedTime, err := time.Parse(layout, *req.CreatedAt)
if err != nil {
return nil, fmt.Errorf("Error parsing time:", err)
}
newReq.CreatedAt = parsedTime
}
saveArticleRes, err := _i.Repo.Create(newReq)
if err != nil {
return nil, err

View File

@ -7564,6 +7564,9 @@ const docTemplate = `{
"categoryIds": {
"type": "string"
},
"createdAt": {
"type": "string"
},
"description": {
"type": "string"
},

View File

@ -7553,6 +7553,9 @@
"categoryIds": {
"type": "string"
},
"createdAt": {
"type": "string"
},
"description": {
"type": "string"
},

View File

@ -225,6 +225,8 @@ definitions:
type: integer
categoryIds:
type: string
createdAt:
type: string
description:
type: string
htmlDescription: