feat: update article save
This commit is contained in:
parent
461e79a481
commit
dcf7ec8971
|
|
@ -1,13 +1,16 @@
|
||||||
package controller
|
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 {
|
type Controller struct {
|
||||||
Articles ArticlesController
|
Articles ArticlesController
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewController(ArticlesService service.ArticlesService) *Controller {
|
func NewController(ArticlesService service.ArticlesService, log zerolog.Logger) *Controller {
|
||||||
return &Controller{
|
return &Controller{
|
||||||
Articles: NewArticlesController(ArticlesService),
|
Articles: NewArticlesController(ArticlesService, log),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -77,6 +77,10 @@ func (_i *articlesRepository) GetAll(req request.ArticlesQueryRequest) (articles
|
||||||
direction = "DESC"
|
direction = "DESC"
|
||||||
}
|
}
|
||||||
query.Order(fmt.Sprintf("%s %s", req.Pagination.SortBy, direction))
|
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
|
req.Pagination.Count = count
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ type ArticlesCreateRequest struct {
|
||||||
TypeId int `json:"typeId" validate:"required"`
|
TypeId int `json:"typeId" validate:"required"`
|
||||||
Tags string `json:"tags" validate:"required"`
|
Tags string `json:"tags" validate:"required"`
|
||||||
AiArticleId *int `json:"aiArticleId"`
|
AiArticleId *int `json:"aiArticleId"`
|
||||||
|
CreatedAt *string `json:"createdAt"`
|
||||||
IsPublish *bool `json:"isPublish"`
|
IsPublish *bool `json:"isPublish"`
|
||||||
IsDraft *bool `json:"isDraft"`
|
IsDraft *bool `json:"isDraft"`
|
||||||
OldId *uint `json:"oldId"`
|
OldId *uint `json:"oldId"`
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package service
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
|
|
@ -136,6 +137,15 @@ func (_i *articlesService) Save(req request.ArticlesCreateRequest, authToken str
|
||||||
newReq.DraftedAt = nil
|
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)
|
saveArticleRes, err := _i.Repo.Create(newReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -7564,6 +7564,9 @@ const docTemplate = `{
|
||||||
"categoryIds": {
|
"categoryIds": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"createdAt": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"description": {
|
"description": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -7553,6 +7553,9 @@
|
||||||
"categoryIds": {
|
"categoryIds": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"createdAt": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"description": {
|
"description": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -225,6 +225,8 @@ definitions:
|
||||||
type: integer
|
type: integer
|
||||||
categoryIds:
|
categoryIds:
|
||||||
type: string
|
type: string
|
||||||
|
createdAt:
|
||||||
|
type: string
|
||||||
description:
|
description:
|
||||||
type: string
|
type: string
|
||||||
htmlDescription:
|
htmlDescription:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue