feat: update articles

This commit is contained in:
hanif salafi 2025-02-24 18:25:27 +07:00
parent 4390248c0e
commit 477d967f78
5 changed files with 33 additions and 13 deletions

View File

@ -57,18 +57,19 @@ func (req ArticlesCreateRequest) ToEntity() *entity.Articles {
} }
type ArticlesUpdateRequest struct { type ArticlesUpdateRequest struct {
Title string `json:"title" validate:"required"` Title string `json:"title" validate:"required"`
Slug string `json:"slug" validate:"required"` Slug string `json:"slug" validate:"required"`
Description string `json:"description" validate:"required"` Description string `json:"description" validate:"required"`
HtmlDescription string `json:"htmlDescription" validate:"required"` HtmlDescription string `json:"htmlDescription" validate:"required"`
CategoryIds string `json:"categoryIds" validate:"required"` CategoryIds string `json:"categoryIds" validate:"required"`
TypeId int `json:"typeId" validate:"required"` TypeId int `json:"typeId" validate:"required"`
Tags string `json:"tags" validate:"required"` Tags string `json:"tags" validate:"required"`
CreatedById *uint `json:"createdById"` CreatedAt *string `json:"createdAt"`
AiArticleId *int `json:"aiArticleId"` CreatedById *uint `json:"createdById"`
IsPublish *bool `json:"isPublish"` AiArticleId *int `json:"aiArticleId"`
IsDraft *bool `json:"isDraft"` IsPublish *bool `json:"isPublish"`
StatusId *int `json:"statusId"` IsDraft *bool `json:"isDraft"`
StatusId *int `json:"statusId"`
} }
func (req ArticlesUpdateRequest) ToEntity() *entity.Articles { func (req ArticlesUpdateRequest) ToEntity() *entity.Articles {

View File

@ -339,7 +339,18 @@ func (_i *articlesService) SaveThumbnail(c *fiber.Ctx) (err error) {
func (_i *articlesService) Update(id uint, req request.ArticlesUpdateRequest) (err error) { func (_i *articlesService) Update(id uint, req request.ArticlesUpdateRequest) (err error) {
_i.Log.Info().Interface("data", req).Msg("") _i.Log.Info().Interface("data", req).Msg("")
return _i.Repo.Update(id, req.ToEntity()) newReq := req.ToEntity()
if req.CreatedAt != nil {
layout := "2006-01-02 15:04:05"
parsedTime, err := time.Parse(layout, *req.CreatedAt)
if err != nil {
return fmt.Errorf("Error parsing time:", err)
}
newReq.CreatedAt = parsedTime
}
return _i.Repo.Update(id, newReq)
} }
func (_i *articlesService) Delete(id uint) error { func (_i *articlesService) Delete(id uint) error {

View File

@ -8387,6 +8387,9 @@ const docTemplate = `{
"categoryIds": { "categoryIds": {
"type": "string" "type": "string"
}, },
"createdAt": {
"type": "string"
},
"createdById": { "createdById": {
"type": "integer" "type": "integer"
}, },

View File

@ -8376,6 +8376,9 @@
"categoryIds": { "categoryIds": {
"type": "string" "type": "string"
}, },
"createdAt": {
"type": "string"
},
"createdById": { "createdById": {
"type": "integer" "type": "integer"
}, },

View File

@ -299,6 +299,8 @@ definitions:
type: integer type: integer
categoryIds: categoryIds:
type: string type: string
createdAt:
type: string
createdById: createdById:
type: integer type: integer
description: description: