feat: update articles
This commit is contained in:
parent
72c7abc3f8
commit
22be1c04c6
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
|
|
@ -45,6 +45,7 @@ func (_i *ArticlesRouter) RegisterArticlesRoutes() {
|
||||||
// define routes
|
// define routes
|
||||||
_i.App.Route("/articles", func(router fiber.Router) {
|
_i.App.Route("/articles", func(router fiber.Router) {
|
||||||
router.Get("/", articlesController.All)
|
router.Get("/", articlesController.All)
|
||||||
|
router.Get("/old-id/:id", articlesController.ShowByOldId)
|
||||||
router.Get("/:id", articlesController.Show)
|
router.Get("/:id", articlesController.Show)
|
||||||
router.Post("/", articlesController.Save)
|
router.Post("/", articlesController.Save)
|
||||||
router.Put("/:id", articlesController.Update)
|
router.Put("/:id", articlesController.Update)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ type articlesController struct {
|
||||||
type ArticlesController interface {
|
type ArticlesController 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
|
||||||
|
|
@ -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
|
// Save Articles
|
||||||
// @Summary Create Articles
|
// @Summary Create Articles
|
||||||
// @Description API for create Articles
|
// @Description API for create Articles
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ func ArticlesResponseMapper(
|
||||||
ShareCount: articlesReq.ShareCount,
|
ShareCount: articlesReq.ShareCount,
|
||||||
ViewCount: articlesReq.ViewCount,
|
ViewCount: articlesReq.ViewCount,
|
||||||
CommentCount: articlesReq.CommentCount,
|
CommentCount: articlesReq.CommentCount,
|
||||||
|
OldId: articlesReq.OldId,
|
||||||
StatusId: articlesReq.StatusId,
|
StatusId: articlesReq.StatusId,
|
||||||
IsBanner: articlesReq.IsBanner,
|
IsBanner: articlesReq.IsBanner,
|
||||||
IsPublish: articlesReq.IsPublish,
|
IsPublish: articlesReq.IsPublish,
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ type ArticlesRepository interface {
|
||||||
GetAllPublishSchedule() (articless []*entity.Articles, err error)
|
GetAllPublishSchedule() (articless []*entity.Articles, err error)
|
||||||
FindOne(id uint) (articles *entity.Articles, err error)
|
FindOne(id uint) (articles *entity.Articles, err error)
|
||||||
FindByFilename(thumbnailName string) (articleReturn *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)
|
Create(articles *entity.Articles) (articleReturn *entity.Articles, err error)
|
||||||
Update(id uint, articles *entity.Articles) (err error)
|
Update(id uint, articles *entity.Articles) (err error)
|
||||||
UpdateSkipNull(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) {
|
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 {
|
if err := _i.DB.DB.Where("thumbnail_name = ?", thumbnailName).First(&articles).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -133,6 +133,14 @@ func (_i *articlesRepository) FindByFilename(thumbnailName string) (articles *en
|
||||||
return articles, nil
|
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) {
|
func (_i *articlesRepository) Create(articles *entity.Articles) (articleReturn *entity.Articles, err error) {
|
||||||
result := _i.DB.DB.Create(articles)
|
result := _i.DB.DB.Create(articles)
|
||||||
return articles, result.Error
|
return articles, result.Error
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ type ArticlesResponse struct {
|
||||||
ViewCount *int `json:"viewCount"`
|
ViewCount *int `json:"viewCount"`
|
||||||
CommentCount *int `json:"commentCount"`
|
CommentCount *int `json:"commentCount"`
|
||||||
AiArticleId *int `json:"aiArticleId"`
|
AiArticleId *int `json:"aiArticleId"`
|
||||||
|
OldId *uint `json:"oldId"`
|
||||||
StatusId *int `json:"statusId"`
|
StatusId *int `json:"statusId"`
|
||||||
IsBanner *bool `json:"isBanner"`
|
IsBanner *bool `json:"isBanner"`
|
||||||
IsPublish *bool `json:"isPublish"`
|
IsPublish *bool `json:"isPublish"`
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ type articlesService struct {
|
||||||
type ArticlesService interface {
|
type ArticlesService interface {
|
||||||
All(req request.ArticlesQueryRequest) (articles []*response.ArticlesResponse, paging paginator.Pagination, err error)
|
All(req request.ArticlesQueryRequest) (articles []*response.ArticlesResponse, paging paginator.Pagination, err error)
|
||||||
Show(id uint) (articles *response.ArticlesResponse, 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)
|
Save(req request.ArticlesCreateRequest, authToken string) (articles *entity.Articles, err error)
|
||||||
SaveThumbnail(c *fiber.Ctx) (err error)
|
SaveThumbnail(c *fiber.Ctx) (err error)
|
||||||
Update(id uint, req request.ArticlesUpdateRequest) (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
|
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) {
|
func (_i *articlesService) Save(req request.ArticlesCreateRequest, authToken string) (articles *entity.Articles, err error) {
|
||||||
_i.Log.Info().Interface("data", req).Msg("")
|
_i.Log.Info().Interface("data", req).Msg("")
|
||||||
newReq := req.ToEntity()
|
newReq := req.ToEntity()
|
||||||
|
|
|
||||||
|
|
@ -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": {
|
"/articles/publish-scheduling": {
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
"security": [
|
||||||
|
|
|
||||||
|
|
@ -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": {
|
"/articles/publish-scheduling": {
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
"security": [
|
||||||
|
|
|
||||||
|
|
@ -3327,6 +3327,37 @@ paths:
|
||||||
summary: Update Banner Articles
|
summary: Update Banner Articles
|
||||||
tags:
|
tags:
|
||||||
- Articles
|
- 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:
|
/articles/publish-scheduling:
|
||||||
post:
|
post:
|
||||||
description: API for Publish Schedule of Article
|
description: API for Publish Schedule of Article
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue