feat: update articles

This commit is contained in:
hanif salafi 2025-05-14 23:54:21 +07:00
parent 335e88fd6d
commit 0d7d08ce6b
10 changed files with 183 additions and 7 deletions

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -45,6 +45,7 @@ func (_i *ArticlesRouter) RegisterArticlesRoutes() {
// define routes
_i.App.Route("/articles", func(router fiber.Router) {
router.Get("/", articlesController.All)
router.Get("/old-id/:id", articlesController.ShowByOldId)
router.Get("/:id", articlesController.Show)
router.Post("/", articlesController.Save)
router.Put("/:id", articlesController.Update)

View File

@ -18,6 +18,7 @@ type articlesController struct {
type ArticlesController interface {
All(c *fiber.Ctx) error
Show(c *fiber.Ctx) error
ShowByOldId(c *fiber.Ctx) error
Save(c *fiber.Ctx) error
SaveThumbnail(c *fiber.Ctx) error
Update(c *fiber.Ctx) error
@ -111,6 +112,35 @@ func (_i *articlesController) Show(c *fiber.Ctx) error {
})
}
// ShowByOldId Articles
// @Summary Get one Articles
// @Description API for getting one Articles
// @Tags Articles
// @Security Bearer
// @Param id path int true "Articles Old ID"
// @Success 200 {object} response.Response
// @Failure 400 {object} response.BadRequestError
// @Failure 401 {object} response.UnauthorizedError
// @Failure 500 {object} response.InternalServerError
// @Router /articles/old-id/{id} [get]
func (_i *articlesController) ShowByOldId(c *fiber.Ctx) error {
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
if err != nil {
return err
}
articlesData, err := _i.articlesService.ShowByOldId(uint(id))
if err != nil {
return err
}
return utilRes.Resp(c, utilRes.Response{
Success: true,
Messages: utilRes.Messages{"Articles successfully retrieved"},
Data: articlesData,
})
}
// Save Articles
// @Summary Create Articles
// @Description API for create Articles

View File

@ -68,6 +68,7 @@ func ArticlesResponseMapper(
ShareCount: articlesReq.ShareCount,
ViewCount: articlesReq.ViewCount,
CommentCount: articlesReq.CommentCount,
OldId: articlesReq.OldId,
StatusId: articlesReq.StatusId,
IsBanner: articlesReq.IsBanner,
IsPublish: articlesReq.IsPublish,

View File

@ -24,6 +24,7 @@ type ArticlesRepository interface {
GetAllPublishSchedule() (articless []*entity.Articles, err error)
FindOne(id uint) (articles *entity.Articles, err error)
FindByFilename(thumbnailName string) (articleReturn *entity.Articles, err error)
FindByOldId(oldId uint) (articles *entity.Articles, err error)
Create(articles *entity.Articles) (articleReturn *entity.Articles, err error)
Update(id uint, articles *entity.Articles) (err error)
UpdateSkipNull(id uint, articles *entity.Articles) (err error)
@ -125,7 +126,6 @@ func (_i *articlesRepository) FindOne(id uint) (articles *entity.Articles, err e
}
func (_i *articlesRepository) FindByFilename(thumbnailName string) (articles *entity.Articles, err error) {
if err := _i.DB.DB.Where("thumbnail_name = ?", thumbnailName).First(&articles).Error; err != nil {
return nil, err
}
@ -133,6 +133,14 @@ func (_i *articlesRepository) FindByFilename(thumbnailName string) (articles *en
return articles, nil
}
func (_i *articlesRepository) FindByOldId(oldId uint) (articles *entity.Articles, err error) {
if err := _i.DB.DB.Where("old_id = ?", oldId).First(&articles).Error; err != nil {
return nil, err
}
return articles, nil
}
func (_i *articlesRepository) Create(articles *entity.Articles) (articleReturn *entity.Articles, err error) {
result := _i.DB.DB.Create(articles)
return articles, result.Error

View File

@ -24,6 +24,7 @@ type ArticlesResponse struct {
ViewCount *int `json:"viewCount"`
CommentCount *int `json:"commentCount"`
AiArticleId *int `json:"aiArticleId"`
OldId *uint `json:"oldId"`
StatusId *int `json:"statusId"`
IsBanner *bool `json:"isBanner"`
IsPublish *bool `json:"isPublish"`

View File

@ -49,6 +49,7 @@ type articlesService struct {
type ArticlesService interface {
All(req request.ArticlesQueryRequest) (articles []*response.ArticlesResponse, paging paginator.Pagination, err error)
Show(id uint) (articles *response.ArticlesResponse, err error)
ShowByOldId(oldId uint) (articles *response.ArticlesResponse, err error)
Save(req request.ArticlesCreateRequest, authToken string) (articles *entity.Articles, err error)
SaveThumbnail(c *fiber.Ctx) (err error)
Update(id uint, req request.ArticlesUpdateRequest) (err error)
@ -130,6 +131,17 @@ func (_i *articlesService) Show(id uint) (articles *response.ArticlesResponse, e
return mapper.ArticlesResponseMapper(_i.Log, host, result, _i.ArticleCategoriesRepo, _i.ArticleCategoryDetailsRepo, _i.ArticleFilesRepo, _i.UsersRepo), nil
}
func (_i *articlesService) ShowByOldId(oldId uint) (articles *response.ArticlesResponse, err error) {
result, err := _i.Repo.FindByOldId(oldId)
if err != nil {
return nil, err
}
host := _i.Cfg.App.Domain
return mapper.ArticlesResponseMapper(_i.Log, host, result, _i.ArticleCategoriesRepo, _i.ArticleCategoryDetailsRepo, _i.ArticleFilesRepo, _i.UsersRepo), nil
}
func (_i *articlesService) Save(req request.ArticlesCreateRequest, authToken string) (articles *entity.Articles, err error) {
_i.Log.Info().Interface("data", req).Msg("")
newReq := req.ToEntity()

View File

@ -3588,6 +3588,55 @@ const docTemplate = `{
}
}
},
"/articles/old-id/{id}": {
"get": {
"security": [
{
"Bearer": []
}
],
"description": "API for getting one Articles",
"tags": [
"Articles"
],
"summary": "Get one Articles",
"parameters": [
{
"type": "integer",
"description": "Articles Old ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.BadRequestError"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/response.UnauthorizedError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.InternalServerError"
}
}
}
}
},
"/articles/publish-scheduling": {
"post": {
"security": [

View File

@ -3577,6 +3577,55 @@
}
}
},
"/articles/old-id/{id}": {
"get": {
"security": [
{
"Bearer": []
}
],
"description": "API for getting one Articles",
"tags": [
"Articles"
],
"summary": "Get one Articles",
"parameters": [
{
"type": "integer",
"description": "Articles Old ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.Response"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.BadRequestError"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/response.UnauthorizedError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.InternalServerError"
}
}
}
}
},
"/articles/publish-scheduling": {
"post": {
"security": [

View File

@ -3327,6 +3327,37 @@ paths:
summary: Update Banner Articles
tags:
- Articles
/articles/old-id/{id}:
get:
description: API for getting one Articles
parameters:
- description: Articles Old ID
in: path
name: id
required: true
type: integer
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.Response'
"400":
description: Bad Request
schema:
$ref: '#/definitions/response.BadRequestError'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/response.UnauthorizedError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.InternalServerError'
security:
- Bearer: []
summary: Get one Articles
tags:
- Articles
/articles/publish-scheduling:
post:
description: API for Publish Schedule of Article