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"`
|
||||
Position *int `json:"position" 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"`
|
||||
IsPublish *bool `json:"is_publish" gorm:"type:bool;default:false"`
|
||||
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) {
|
||||
router.Get("/", articleCategoriesController.All)
|
||||
router.Get("/:id", articleCategoriesController.Show)
|
||||
router.Get("/old/:id", articleCategoriesController.ShowByOldId)
|
||||
router.Post("/", articleCategoriesController.Save)
|
||||
router.Put("/:id", articleCategoriesController.Update)
|
||||
router.Post("/thumbnail/:id", articleCategoriesController.SaveThumbnail)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ type articleCategoriesController struct {
|
|||
type ArticleCategoriesController 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
|
||||
|
|
@ -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
|
||||
// @Summary Create ArticleCategories
|
||||
// @Description API for create ArticleCategories
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ type articleCategoriesRepository struct {
|
|||
type ArticleCategoriesRepository interface {
|
||||
GetAll(req request.ArticleCategoriesQueryRequest) (articleCategoriess []*entity.ArticleCategories, paging paginator.Pagination, 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)
|
||||
Update(id uint, articleCategories *entity.ArticleCategories) (err error)
|
||||
Delete(id uint) (err error)
|
||||
|
|
@ -87,6 +88,14 @@ func (_i *articleCategoriesRepository) FindOne(id uint) (articleCategories *enti
|
|||
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) {
|
||||
result := _i.DB.DB.Create(articleCategories)
|
||||
return articleCategories, result.Error
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ type ArticleCategoriesCreateRequest struct {
|
|||
StatusId int `json:"statusId" validate:"required"`
|
||||
Tags *string `json:"tags"`
|
||||
ParentId *int `json:"parentId"`
|
||||
OldCategoryId *uint `json:"oldCategoryId"`
|
||||
}
|
||||
|
||||
func (req ArticleCategoriesCreateRequest) ToEntity() *entity.ArticleCategories {
|
||||
|
|
@ -34,6 +35,7 @@ func (req ArticleCategoriesCreateRequest) ToEntity() *entity.ArticleCategories {
|
|||
Description: req.Description,
|
||||
Tags: req.Tags,
|
||||
ParentId: req.ParentId,
|
||||
OldCategoryId: req.OldCategoryId,
|
||||
StatusId: req.StatusId,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ type articleCategoriesService struct {
|
|||
type ArticleCategoriesService interface {
|
||||
All(req request.ArticleCategoriesQueryRequest) (articleCategories []*response.ArticleCategoriesResponse, paging paginator.Pagination, 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)
|
||||
SaveThumbnail(c *fiber.Ctx) (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
|
||||
}
|
||||
|
||||
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) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
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}": {
|
||||
"get": {
|
||||
"security": [
|
||||
|
|
@ -7263,6 +7312,9 @@ const docTemplate = `{
|
|||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"oldCategoryId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"parentId": {
|
||||
"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}": {
|
||||
"get": {
|
||||
"security": [
|
||||
|
|
@ -7252,6 +7301,9 @@
|
|||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"oldCategoryId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"parentId": {
|
||||
"type": "integer"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ definitions:
|
|||
properties:
|
||||
description:
|
||||
type: string
|
||||
oldCategoryId:
|
||||
type: integer
|
||||
parentId:
|
||||
type: integer
|
||||
statusId:
|
||||
|
|
@ -1178,6 +1180,37 @@ paths:
|
|||
summary: update ArticleCategories
|
||||
tags:
|
||||
- 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}:
|
||||
post:
|
||||
description: API for Upload ArticleCategories Thumbnail
|
||||
|
|
|
|||
Loading…
Reference in New Issue