From 477d967f789a7220cd81c3d3234e33f834ebb9e1 Mon Sep 17 00:00:00 2001 From: hanif salafi Date: Mon, 24 Feb 2025 18:25:27 +0700 Subject: [PATCH] feat: update articles --- .../articles/request/articles.request.go | 25 ++++++++++--------- .../articles/service/articles.service.go | 13 +++++++++- docs/swagger/docs.go | 3 +++ docs/swagger/swagger.json | 3 +++ docs/swagger/swagger.yaml | 2 ++ 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/app/module/articles/request/articles.request.go b/app/module/articles/request/articles.request.go index 5956e5d..93753b2 100644 --- a/app/module/articles/request/articles.request.go +++ b/app/module/articles/request/articles.request.go @@ -57,18 +57,19 @@ func (req ArticlesCreateRequest) ToEntity() *entity.Articles { } type ArticlesUpdateRequest struct { - Title string `json:"title" validate:"required"` - Slug string `json:"slug" validate:"required"` - Description string `json:"description" validate:"required"` - HtmlDescription string `json:"htmlDescription" validate:"required"` - CategoryIds string `json:"categoryIds" validate:"required"` - TypeId int `json:"typeId" validate:"required"` - Tags string `json:"tags" validate:"required"` - CreatedById *uint `json:"createdById"` - AiArticleId *int `json:"aiArticleId"` - IsPublish *bool `json:"isPublish"` - IsDraft *bool `json:"isDraft"` - StatusId *int `json:"statusId"` + Title string `json:"title" validate:"required"` + Slug string `json:"slug" validate:"required"` + Description string `json:"description" validate:"required"` + HtmlDescription string `json:"htmlDescription" validate:"required"` + CategoryIds string `json:"categoryIds" validate:"required"` + TypeId int `json:"typeId" validate:"required"` + Tags string `json:"tags" validate:"required"` + CreatedAt *string `json:"createdAt"` + CreatedById *uint `json:"createdById"` + AiArticleId *int `json:"aiArticleId"` + IsPublish *bool `json:"isPublish"` + IsDraft *bool `json:"isDraft"` + StatusId *int `json:"statusId"` } func (req ArticlesUpdateRequest) ToEntity() *entity.Articles { diff --git a/app/module/articles/service/articles.service.go b/app/module/articles/service/articles.service.go index ddf82fb..6673999 100644 --- a/app/module/articles/service/articles.service.go +++ b/app/module/articles/service/articles.service.go @@ -339,7 +339,18 @@ func (_i *articlesService) SaveThumbnail(c *fiber.Ctx) (err error) { func (_i *articlesService) Update(id uint, req request.ArticlesUpdateRequest) (err error) { _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 { diff --git a/docs/swagger/docs.go b/docs/swagger/docs.go index 6e7ef3d..4fac14a 100644 --- a/docs/swagger/docs.go +++ b/docs/swagger/docs.go @@ -8387,6 +8387,9 @@ const docTemplate = `{ "categoryIds": { "type": "string" }, + "createdAt": { + "type": "string" + }, "createdById": { "type": "integer" }, diff --git a/docs/swagger/swagger.json b/docs/swagger/swagger.json index 7ccf6ca..717b816 100644 --- a/docs/swagger/swagger.json +++ b/docs/swagger/swagger.json @@ -8376,6 +8376,9 @@ "categoryIds": { "type": "string" }, + "createdAt": { + "type": "string" + }, "createdById": { "type": "integer" }, diff --git a/docs/swagger/swagger.yaml b/docs/swagger/swagger.yaml index b102ef0..505183a 100644 --- a/docs/swagger/swagger.yaml +++ b/docs/swagger/swagger.yaml @@ -299,6 +299,8 @@ definitions: type: integer categoryIds: type: string + createdAt: + type: string createdById: type: integer description: