feat: update article categories
This commit is contained in:
parent
4596710872
commit
461e79a481
|
|
@ -11,6 +11,7 @@ type ArticleCategories struct {
|
||||||
Tags *string `json:"tags" gorm:"type:varchar"`
|
Tags *string `json:"tags" gorm:"type:varchar"`
|
||||||
Position *int `json:"position" gorm:"type:int4"`
|
Position *int `json:"position" gorm:"type:int4"`
|
||||||
CreatedById *uint `json:"created_by_id" gorm:"type:int4"`
|
CreatedById *uint `json:"created_by_id" gorm:"type:int4"`
|
||||||
|
OldCategoryId *uint `json:"old_category_id" gorm:"type:int4"`
|
||||||
StatusId int `json:"status_id" gorm:"type:int4;default:1"`
|
StatusId int `json:"status_id" gorm:"type:int4;default:1"`
|
||||||
IsPublish *bool `json:"is_publish" gorm:"type:bool;default:false"`
|
IsPublish *bool `json:"is_publish" gorm:"type:bool;default:false"`
|
||||||
PublishedAt *time.Time `json:"published_at" gorm:"type:timestamp"`
|
PublishedAt *time.Time `json:"published_at" gorm:"type:timestamp"`
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ func (_i *ArticleCategoriesRouter) RegisterArticleCategoriesRoutes() {
|
||||||
_i.App.Route("/article-categories", func(router fiber.Router) {
|
_i.App.Route("/article-categories", func(router fiber.Router) {
|
||||||
router.Get("/", articleCategoriesController.All)
|
router.Get("/", articleCategoriesController.All)
|
||||||
router.Get("/:id", articleCategoriesController.Show)
|
router.Get("/:id", articleCategoriesController.Show)
|
||||||
|
router.Get("/old/:id", articleCategoriesController.ShowByOldId)
|
||||||
router.Post("/", articleCategoriesController.Save)
|
router.Post("/", articleCategoriesController.Save)
|
||||||
router.Put("/:id", articleCategoriesController.Update)
|
router.Put("/:id", articleCategoriesController.Update)
|
||||||
router.Post("/thumbnail/:id", articleCategoriesController.SaveThumbnail)
|
router.Post("/thumbnail/:id", articleCategoriesController.SaveThumbnail)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ type articleCategoriesController struct {
|
||||||
type ArticleCategoriesController interface {
|
type ArticleCategoriesController interface {
|
||||||
All(c *fiber.Ctx) error
|
All(c *fiber.Ctx) error
|
||||||
Show(c *fiber.Ctx) error
|
Show(c *fiber.Ctx) error
|
||||||
|
ShowByOldId(c *fiber.Ctx) error
|
||||||
Save(c *fiber.Ctx) error
|
Save(c *fiber.Ctx) error
|
||||||
SaveThumbnail(c *fiber.Ctx) error
|
SaveThumbnail(c *fiber.Ctx) error
|
||||||
Update(c *fiber.Ctx) error
|
Update(c *fiber.Ctx) error
|
||||||
|
|
@ -101,6 +102,35 @@ func (_i *articleCategoriesController) Show(c *fiber.Ctx) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ShowByOldId ArticleCategories
|
||||||
|
// @Summary Get one ArticleCategories
|
||||||
|
// @Description API for getting one ArticleCategories
|
||||||
|
// @Tags Article Categories
|
||||||
|
// @Security Bearer
|
||||||
|
// @Param id path int true "ArticleCategories Old ID"
|
||||||
|
// @Success 200 {object} response.Response
|
||||||
|
// @Failure 400 {object} response.BadRequestError
|
||||||
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
|
// @Failure 500 {object} response.InternalServerError
|
||||||
|
// @Router /article-categories/old/{id} [get]
|
||||||
|
func (_i *articleCategoriesController) ShowByOldId(c *fiber.Ctx) error {
|
||||||
|
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
articleCategoriesData, err := _i.articleCategoriesService.ShowByOldId(uint(id))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return utilRes.Resp(c, utilRes.Response{
|
||||||
|
Success: true,
|
||||||
|
Messages: utilRes.Messages{"ArticleCategories successfully retrieved"},
|
||||||
|
Data: articleCategoriesData,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Save ArticleCategories
|
// Save ArticleCategories
|
||||||
// @Summary Create ArticleCategories
|
// @Summary Create ArticleCategories
|
||||||
// @Description API for create ArticleCategories
|
// @Description API for create ArticleCategories
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ type articleCategoriesRepository struct {
|
||||||
type ArticleCategoriesRepository interface {
|
type ArticleCategoriesRepository interface {
|
||||||
GetAll(req request.ArticleCategoriesQueryRequest) (articleCategoriess []*entity.ArticleCategories, paging paginator.Pagination, err error)
|
GetAll(req request.ArticleCategoriesQueryRequest) (articleCategoriess []*entity.ArticleCategories, paging paginator.Pagination, err error)
|
||||||
FindOne(id uint) (articleCategories *entity.ArticleCategories, err error)
|
FindOne(id uint) (articleCategories *entity.ArticleCategories, err error)
|
||||||
|
FindOneByOldId(id uint) (articleCategories *entity.ArticleCategories, err error)
|
||||||
Create(articleCategories *entity.ArticleCategories) (articleCategoriesReturn *entity.ArticleCategories, err error)
|
Create(articleCategories *entity.ArticleCategories) (articleCategoriesReturn *entity.ArticleCategories, err error)
|
||||||
Update(id uint, articleCategories *entity.ArticleCategories) (err error)
|
Update(id uint, articleCategories *entity.ArticleCategories) (err error)
|
||||||
Delete(id uint) (err error)
|
Delete(id uint) (err error)
|
||||||
|
|
@ -87,6 +88,14 @@ func (_i *articleCategoriesRepository) FindOne(id uint) (articleCategories *enti
|
||||||
return articleCategories, nil
|
return articleCategories, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (_i *articleCategoriesRepository) FindOneByOldId(id uint) (articleCategories *entity.ArticleCategories, err error) {
|
||||||
|
if err := _i.DB.DB.Where("old_category_id = ?", id).First(&articleCategories).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return articleCategories, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (_i *articleCategoriesRepository) Create(articleCategories *entity.ArticleCategories) (articleCategoriesReturn *entity.ArticleCategories, err error) {
|
func (_i *articleCategoriesRepository) Create(articleCategories *entity.ArticleCategories) (articleCategoriesReturn *entity.ArticleCategories, err error) {
|
||||||
result := _i.DB.DB.Create(articleCategories)
|
result := _i.DB.DB.Create(articleCategories)
|
||||||
return articleCategories, result.Error
|
return articleCategories, result.Error
|
||||||
|
|
|
||||||
|
|
@ -21,20 +21,22 @@ type ArticleCategoriesQueryRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArticleCategoriesCreateRequest struct {
|
type ArticleCategoriesCreateRequest struct {
|
||||||
Title string `json:"title" validate:"required"`
|
Title string `json:"title" validate:"required"`
|
||||||
Description string `json:"description" validate:"required"`
|
Description string `json:"description" validate:"required"`
|
||||||
StatusId int `json:"statusId" validate:"required"`
|
StatusId int `json:"statusId" validate:"required"`
|
||||||
Tags *string `json:"tags"`
|
Tags *string `json:"tags"`
|
||||||
ParentId *int `json:"parentId"`
|
ParentId *int `json:"parentId"`
|
||||||
|
OldCategoryId *uint `json:"oldCategoryId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (req ArticleCategoriesCreateRequest) ToEntity() *entity.ArticleCategories {
|
func (req ArticleCategoriesCreateRequest) ToEntity() *entity.ArticleCategories {
|
||||||
return &entity.ArticleCategories{
|
return &entity.ArticleCategories{
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Tags: req.Tags,
|
Tags: req.Tags,
|
||||||
ParentId: req.ParentId,
|
ParentId: req.ParentId,
|
||||||
StatusId: req.StatusId,
|
OldCategoryId: req.OldCategoryId,
|
||||||
|
StatusId: req.StatusId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ type articleCategoriesService struct {
|
||||||
type ArticleCategoriesService interface {
|
type ArticleCategoriesService interface {
|
||||||
All(req request.ArticleCategoriesQueryRequest) (articleCategories []*response.ArticleCategoriesResponse, paging paginator.Pagination, err error)
|
All(req request.ArticleCategoriesQueryRequest) (articleCategories []*response.ArticleCategoriesResponse, paging paginator.Pagination, err error)
|
||||||
Show(id uint) (articleCategories *response.ArticleCategoriesResponse, err error)
|
Show(id uint) (articleCategories *response.ArticleCategoriesResponse, err error)
|
||||||
|
ShowByOldId(id uint) (articleCategories *response.ArticleCategoriesResponse, err error)
|
||||||
Save(req request.ArticleCategoriesCreateRequest, authToken string) (articleCategories *entity.ArticleCategories, err error)
|
Save(req request.ArticleCategoriesCreateRequest, authToken string) (articleCategories *entity.ArticleCategories, err error)
|
||||||
SaveThumbnail(c *fiber.Ctx) (err error)
|
SaveThumbnail(c *fiber.Ctx) (err error)
|
||||||
Update(id uint, req request.ArticleCategoriesUpdateRequest) (err error)
|
Update(id uint, req request.ArticleCategoriesUpdateRequest) (err error)
|
||||||
|
|
@ -82,6 +83,15 @@ func (_i *articleCategoriesService) Show(id uint) (articleCategories *response.A
|
||||||
return mapper.ArticleCategoriesResponseMapper(result, host), nil
|
return mapper.ArticleCategoriesResponseMapper(result, host), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (_i *articleCategoriesService) ShowByOldId(id uint) (articleCategories *response.ArticleCategoriesResponse, err error) {
|
||||||
|
result, err := _i.Repo.FindOneByOldId(id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
host := _i.Cfg.App.Domain
|
||||||
|
return mapper.ArticleCategoriesResponseMapper(result, host), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (_i *articleCategoriesService) Save(req request.ArticleCategoriesCreateRequest, authToken string) (articleCategories *entity.ArticleCategories, err error) {
|
func (_i *articleCategoriesService) Save(req request.ArticleCategoriesCreateRequest, authToken string) (articleCategories *entity.ArticleCategories, err error) {
|
||||||
_i.Log.Info().Interface("data", req).Msg("")
|
_i.Log.Info().Interface("data", req).Msg("")
|
||||||
newReq := req.ToEntity()
|
newReq := req.ToEntity()
|
||||||
|
|
|
||||||
|
|
@ -489,6 +489,55 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/article-categories/old/{id}": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "API for getting one ArticleCategories",
|
||||||
|
"tags": [
|
||||||
|
"Article Categories"
|
||||||
|
],
|
||||||
|
"summary": "Get one ArticleCategories",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "ArticleCategories 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/article-categories/thumbnail/viewer/{id}": {
|
"/article-categories/thumbnail/viewer/{id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
|
|
@ -7263,6 +7312,9 @@ const docTemplate = `{
|
||||||
"description": {
|
"description": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"oldCategoryId": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"parentId": {
|
"parentId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -478,6 +478,55 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/article-categories/old/{id}": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "API for getting one ArticleCategories",
|
||||||
|
"tags": [
|
||||||
|
"Article Categories"
|
||||||
|
],
|
||||||
|
"summary": "Get one ArticleCategories",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "ArticleCategories 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/article-categories/thumbnail/viewer/{id}": {
|
"/article-categories/thumbnail/viewer/{id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
|
|
@ -7252,6 +7301,9 @@
|
||||||
"description": {
|
"description": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"oldCategoryId": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"parentId": {
|
"parentId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,8 @@ definitions:
|
||||||
properties:
|
properties:
|
||||||
description:
|
description:
|
||||||
type: string
|
type: string
|
||||||
|
oldCategoryId:
|
||||||
|
type: integer
|
||||||
parentId:
|
parentId:
|
||||||
type: integer
|
type: integer
|
||||||
statusId:
|
statusId:
|
||||||
|
|
@ -1178,6 +1180,37 @@ paths:
|
||||||
summary: update ArticleCategories
|
summary: update ArticleCategories
|
||||||
tags:
|
tags:
|
||||||
- Article Categories
|
- Article Categories
|
||||||
|
/article-categories/old/{id}:
|
||||||
|
get:
|
||||||
|
description: API for getting one ArticleCategories
|
||||||
|
parameters:
|
||||||
|
- description: ArticleCategories 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 ArticleCategories
|
||||||
|
tags:
|
||||||
|
- Article Categories
|
||||||
/article-categories/thumbnail/{id}:
|
/article-categories/thumbnail/{id}:
|
||||||
post:
|
post:
|
||||||
description: API for Upload ArticleCategories Thumbnail
|
description: API for Upload ArticleCategories Thumbnail
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue