feat: update article save
This commit is contained in:
parent
461e79a481
commit
dcf7ec8971
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"`
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -7564,6 +7564,9 @@ const docTemplate = `{
|
|||
"categoryIds": {
|
||||
"type": "string"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -7553,6 +7553,9 @@
|
|||
"categoryIds": {
|
||||
"type": "string"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -225,6 +225,8 @@ definitions:
|
|||
type: integer
|
||||
categoryIds:
|
||||
type: string
|
||||
createdAt:
|
||||
type: string
|
||||
description:
|
||||
type: string
|
||||
htmlDescription:
|
||||
|
|
|
|||
Loading…
Reference in New Issue