feat: update articles

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

View File

@ -64,6 +64,7 @@ type ArticlesUpdateRequest struct {
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"`
CreatedAt *string `json:"createdAt"`
CreatedById *uint `json:"createdById"` CreatedById *uint `json:"createdById"`
AiArticleId *int `json:"aiArticleId"` AiArticleId *int `json:"aiArticleId"`
IsPublish *bool `json:"isPublish"` IsPublish *bool `json:"isPublish"`

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: