feat: update article, article category
This commit is contained in:
parent
cd825462f9
commit
555cfd6864
|
|
@ -1,12 +0,0 @@
|
||||||
package entity
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
type ArticleCategoryDetails struct {
|
|
||||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
|
||||||
ArticleId uint `json:"article_id" gorm:"type:int4"`
|
|
||||||
CategoryId int `json:"category_id" gorm:"type:int4"`
|
|
||||||
IsActive bool `json:"is_active" gorm:"type:bool"`
|
|
||||||
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
|
||||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package article_category_details
|
||||||
|
|
||||||
|
import (
|
||||||
|
entity "go-humas-be/app/database/entity"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ArticleCategoryDetails struct {
|
||||||
|
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||||
|
ArticleId uint `json:"article_id" gorm:"type:int4"`
|
||||||
|
CategoryId int `json:"category_id" gorm:"type:int4"`
|
||||||
|
Category *entity.ArticleCategories `json:"category" gorm:"foreignKey:CategoryId;references:ID"`
|
||||||
|
IsActive bool `json:"is_active" gorm:"type:bool"`
|
||||||
|
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ package database
|
||||||
import (
|
import (
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity"
|
||||||
|
"go-humas-be/app/database/entity/article_category_details"
|
||||||
"go-humas-be/config/config"
|
"go-humas-be/config/config"
|
||||||
"gorm.io/driver/postgres"
|
"gorm.io/driver/postgres"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
@ -69,7 +70,7 @@ func Models() []interface{} {
|
||||||
return []interface{}{
|
return []interface{}{
|
||||||
entity.Articles{},
|
entity.Articles{},
|
||||||
entity.ArticleCategories{},
|
entity.ArticleCategories{},
|
||||||
entity.ArticleCategoryDetails{},
|
article_category_details.ArticleCategoryDetails{},
|
||||||
entity.ArticleFiles{},
|
entity.ArticleFiles{},
|
||||||
entity.ArticleNulisAI{},
|
entity.ArticleNulisAI{},
|
||||||
entity.Cities{},
|
entity.Cities{},
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
package mapper
|
package mapper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity/article_category_details"
|
||||||
res "go-humas-be/app/module/article_category_details/response"
|
res "go-humas-be/app/module/article_category_details/response"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ArticleCategoryDetailsResponseMapper(articleCategoryDetailsReq *entity.ArticleCategoryDetails) (articleCategoryDetailsRes *res.ArticleCategoryDetailsResponse) {
|
func ArticleCategoryDetailsResponseMapper(articleCategoryDetailsReq *article_category_details.ArticleCategoryDetails) (articleCategoryDetailsRes *res.ArticleCategoryDetailsResponse) {
|
||||||
if articleCategoryDetailsReq != nil {
|
if articleCategoryDetailsReq != nil {
|
||||||
|
|
||||||
articleCategoryDetailsRes = &res.ArticleCategoryDetailsResponse{
|
articleCategoryDetailsRes = &res.ArticleCategoryDetailsResponse{
|
||||||
ID: articleCategoryDetailsReq.ID,
|
ID: articleCategoryDetailsReq.ID,
|
||||||
ArticleId: articleCategoryDetailsReq.ArticleId,
|
ArticleId: articleCategoryDetailsReq.ArticleId,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go-humas-be/app/database"
|
"go-humas-be/app/database"
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity/article_category_details"
|
||||||
"go-humas-be/app/module/article_category_details/request"
|
"go-humas-be/app/module/article_category_details/request"
|
||||||
"go-humas-be/utils/paginator"
|
"go-humas-be/utils/paginator"
|
||||||
)
|
)
|
||||||
|
|
@ -13,10 +13,11 @@ type articleCategoryDetailsRepository struct {
|
||||||
|
|
||||||
// ArticleCategoryDetailsRepository define interface of IArticleCategoryDetailsRepository
|
// ArticleCategoryDetailsRepository define interface of IArticleCategoryDetailsRepository
|
||||||
type ArticleCategoryDetailsRepository interface {
|
type ArticleCategoryDetailsRepository interface {
|
||||||
GetAll(req request.ArticleCategoryDetailsQueryRequest) (articleCategoryDetailss []*entity.ArticleCategoryDetails, paging paginator.Pagination, err error)
|
GetAll(req request.ArticleCategoryDetailsQueryRequest) (articleCategoryDetailss []*article_category_details.ArticleCategoryDetails, paging paginator.Pagination, err error)
|
||||||
FindOne(id uint) (articleCategoryDetails *entity.ArticleCategoryDetails, err error)
|
FindOne(id uint) (articleCategoryDetails *article_category_details.ArticleCategoryDetails, err error)
|
||||||
Create(articleCategoryDetails *entity.ArticleCategoryDetails) (err error)
|
FindByArticleId(articleId uint) (articleCategoryDetailss []*article_category_details.ArticleCategoryDetails, err error)
|
||||||
Update(id uint, articleCategoryDetails *entity.ArticleCategoryDetails) (err error)
|
Create(articleCategoryDetails *article_category_details.ArticleCategoryDetails) (err error)
|
||||||
|
Update(id uint, articleCategoryDetails *article_category_details.ArticleCategoryDetails) (err error)
|
||||||
Delete(id uint) (err error)
|
Delete(id uint) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,10 +28,10 @@ func NewArticleCategoryDetailsRepository(db *database.Database) ArticleCategoryD
|
||||||
}
|
}
|
||||||
|
|
||||||
// implement interface of IArticleCategoryDetailsRepository
|
// implement interface of IArticleCategoryDetailsRepository
|
||||||
func (_i *articleCategoryDetailsRepository) GetAll(req request.ArticleCategoryDetailsQueryRequest) (articleCategoryDetailss []*entity.ArticleCategoryDetails, paging paginator.Pagination, err error) {
|
func (_i *articleCategoryDetailsRepository) GetAll(req request.ArticleCategoryDetailsQueryRequest) (articleCategoryDetailss []*article_category_details.ArticleCategoryDetails, paging paginator.Pagination, err error) {
|
||||||
var count int64
|
var count int64
|
||||||
|
|
||||||
query := _i.DB.DB.Model(&entity.ArticleCategoryDetails{})
|
query := _i.DB.DB.Model(&article_category_details.ArticleCategoryDetails{})
|
||||||
query.Count(&count)
|
query.Count(&count)
|
||||||
|
|
||||||
req.Pagination.Count = count
|
req.Pagination.Count = count
|
||||||
|
|
@ -46,7 +47,7 @@ func (_i *articleCategoryDetailsRepository) GetAll(req request.ArticleCategoryDe
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *articleCategoryDetailsRepository) FindOne(id uint) (articleCategoryDetails *entity.ArticleCategoryDetails, err error) {
|
func (_i *articleCategoryDetailsRepository) FindOne(id uint) (articleCategoryDetails *article_category_details.ArticleCategoryDetails, err error) {
|
||||||
if err := _i.DB.DB.First(&articleCategoryDetails, id).Error; err != nil {
|
if err := _i.DB.DB.First(&articleCategoryDetails, id).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -54,16 +55,24 @@ func (_i *articleCategoryDetailsRepository) FindOne(id uint) (articleCategoryDet
|
||||||
return articleCategoryDetails, nil
|
return articleCategoryDetails, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *articleCategoryDetailsRepository) Create(articleCategoryDetails *entity.ArticleCategoryDetails) (err error) {
|
func (_i *articleCategoryDetailsRepository) FindByArticleId(articleId uint) (articleCategoryDetailss []*article_category_details.ArticleCategoryDetails, err error) {
|
||||||
|
if err := _i.DB.DB.Where("article_id = ?", articleId).Preload("Category").Find(&articleCategoryDetailss).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return articleCategoryDetailss, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_i *articleCategoryDetailsRepository) Create(articleCategoryDetails *article_category_details.ArticleCategoryDetails) (err error) {
|
||||||
return _i.DB.DB.Create(articleCategoryDetails).Error
|
return _i.DB.DB.Create(articleCategoryDetails).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *articleCategoryDetailsRepository) Update(id uint, articleCategoryDetails *entity.ArticleCategoryDetails) (err error) {
|
func (_i *articleCategoryDetailsRepository) Update(id uint, articleCategoryDetails *article_category_details.ArticleCategoryDetails) (err error) {
|
||||||
return _i.DB.DB.Model(&entity.ArticleCategoryDetails{}).
|
return _i.DB.DB.Model(&article_category_details.ArticleCategoryDetails{}).
|
||||||
Where(&entity.ArticleCategoryDetails{ID: id}).
|
Where(&article_category_details.ArticleCategoryDetails{ID: id}).
|
||||||
Updates(articleCategoryDetails).Error
|
Updates(articleCategoryDetails).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *articleCategoryDetailsRepository) Delete(id uint) error {
|
func (_i *articleCategoryDetailsRepository) Delete(id uint) error {
|
||||||
return _i.DB.DB.Delete(&entity.ArticleCategoryDetails{}, id).Error
|
return _i.DB.DB.Delete(&article_category_details.ArticleCategoryDetails{}, id).Error
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package request
|
package request
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity/article_category_details"
|
||||||
"go-humas-be/utils/paginator"
|
"go-humas-be/utils/paginator"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
@ -23,8 +23,8 @@ type ArticleCategoryDetailsCreateRequest struct {
|
||||||
IsActive bool `json:"is_active" validate:"required"`
|
IsActive bool `json:"is_active" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (req ArticleCategoryDetailsCreateRequest) ToEntity() *entity.ArticleCategoryDetails {
|
func (req ArticleCategoryDetailsCreateRequest) ToEntity() *article_category_details.ArticleCategoryDetails {
|
||||||
return &entity.ArticleCategoryDetails{
|
return &article_category_details.ArticleCategoryDetails{
|
||||||
ArticleId: req.ArticleId,
|
ArticleId: req.ArticleId,
|
||||||
CategoryId: req.CategoryId,
|
CategoryId: req.CategoryId,
|
||||||
IsActive: req.IsActive,
|
IsActive: req.IsActive,
|
||||||
|
|
@ -40,8 +40,8 @@ type ArticleCategoryDetailsUpdateRequest struct {
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (req ArticleCategoryDetailsUpdateRequest) ToEntity() *entity.ArticleCategoryDetails {
|
func (req ArticleCategoryDetailsUpdateRequest) ToEntity() *article_category_details.ArticleCategoryDetails {
|
||||||
return &entity.ArticleCategoryDetails{
|
return &article_category_details.ArticleCategoryDetails{
|
||||||
ID: req.ID,
|
ID: req.ID,
|
||||||
ArticleId: req.ArticleId,
|
ArticleId: req.ArticleId,
|
||||||
CategoryId: req.CategoryId,
|
CategoryId: req.CategoryId,
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,6 @@ func (_i *articleNulisAIService) Publish(req request.ArticleNulisAICreateRequest
|
||||||
articleReq := articles.ArticlesCreateRequest{
|
articleReq := articles.ArticlesCreateRequest{
|
||||||
Title: newReq.Title,
|
Title: newReq.Title,
|
||||||
Slug: utilSvc.MakeSlug(req.Title),
|
Slug: utilSvc.MakeSlug(req.Title),
|
||||||
CategoryId: newReq.CategoryId,
|
|
||||||
Tags: newReq.Tags,
|
Tags: newReq.Tags,
|
||||||
TypeId: 1,
|
TypeId: 1,
|
||||||
Description: newReq.Description,
|
Description: newReq.Description,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,10 @@ package mapper
|
||||||
import (
|
import (
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity"
|
||||||
|
articleCategoriesMapper "go-humas-be/app/module/article_categories/mapper"
|
||||||
articleCategoriesRepository "go-humas-be/app/module/article_categories/repository"
|
articleCategoriesRepository "go-humas-be/app/module/article_categories/repository"
|
||||||
|
articleCategoriesResponse "go-humas-be/app/module/article_categories/response"
|
||||||
|
articleCategoryDetailsRepository "go-humas-be/app/module/article_category_details/repository"
|
||||||
articleFilesMapper "go-humas-be/app/module/article_files/mapper"
|
articleFilesMapper "go-humas-be/app/module/article_files/mapper"
|
||||||
articleFilesRepository "go-humas-be/app/module/article_files/repository"
|
articleFilesRepository "go-humas-be/app/module/article_files/repository"
|
||||||
articleFilesResponse "go-humas-be/app/module/article_files/response"
|
articleFilesResponse "go-humas-be/app/module/article_files/response"
|
||||||
|
|
@ -16,6 +19,7 @@ func ArticlesResponseMapper(
|
||||||
host string,
|
host string,
|
||||||
articlesReq *entity.Articles,
|
articlesReq *entity.Articles,
|
||||||
articleCategoriesRepo articleCategoriesRepository.ArticleCategoriesRepository,
|
articleCategoriesRepo articleCategoriesRepository.ArticleCategoriesRepository,
|
||||||
|
articleCategoryDetailsRepo articleCategoryDetailsRepository.ArticleCategoryDetailsRepository,
|
||||||
articleFilesRepo articleFilesRepository.ArticleFilesRepository,
|
articleFilesRepo articleFilesRepository.ArticleFilesRepository,
|
||||||
usersRepo usersRepository.UsersRepository,
|
usersRepo usersRepository.UsersRepository,
|
||||||
) (articlesRes *res.ArticlesResponse) {
|
) (articlesRes *res.ArticlesResponse) {
|
||||||
|
|
@ -29,11 +33,13 @@ func ArticlesResponseMapper(
|
||||||
}
|
}
|
||||||
|
|
||||||
categoryName := ""
|
categoryName := ""
|
||||||
if articlesReq.CategoryId != 0 {
|
articleCategories, _ := articleCategoryDetailsRepo.FindByArticleId(articlesReq.ID)
|
||||||
findCategory, _ := articleCategoriesRepo.FindOne(uint(articlesReq.CategoryId))
|
var articleCategoriesArr []*articleCategoriesResponse.ArticleCategoriesResponse
|
||||||
if findCategory != nil {
|
if articleCategories != nil && len(articleCategories) > 0 {
|
||||||
categoryName = findCategory.Title
|
for _, result := range articleCategories {
|
||||||
|
articleCategoriesArr = append(articleCategoriesArr, articleCategoriesMapper.ArticleCategoriesResponseMapper(result.Category, ""))
|
||||||
}
|
}
|
||||||
|
log.Info().Interface("articleCategoriesArr", articleCategoriesArr).Msg("")
|
||||||
}
|
}
|
||||||
|
|
||||||
articleFiles, _ := articleFilesRepo.FindByArticle(articlesReq.ID)
|
articleFiles, _ := articleFilesRepo.FindByArticle(articlesReq.ID)
|
||||||
|
|
@ -68,6 +74,7 @@ func ArticlesResponseMapper(
|
||||||
CreatedAt: articlesReq.CreatedAt,
|
CreatedAt: articlesReq.CreatedAt,
|
||||||
UpdatedAt: articlesReq.UpdatedAt,
|
UpdatedAt: articlesReq.UpdatedAt,
|
||||||
ArticleFiles: articleFilesArr,
|
ArticleFiles: articleFilesArr,
|
||||||
|
ArticleCategories: articleCategoriesArr,
|
||||||
}
|
}
|
||||||
|
|
||||||
if articlesReq.ThumbnailName != nil {
|
if articlesReq.ThumbnailName != nil {
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ type ArticlesCreateRequest struct {
|
||||||
Slug string `json:"slug" validate:"required"`
|
Slug string `json:"slug" validate:"required"`
|
||||||
Description string `json:"description" validate:"required"`
|
Description string `json:"description" validate:"required"`
|
||||||
HtmlDescription string `json:"htmlDescription" validate:"required"`
|
HtmlDescription string `json:"htmlDescription" validate:"required"`
|
||||||
CategoryId int `json:"categoryId" validate:"required"`
|
|
||||||
CategoryIds string `json:"categoryIds" validate:"required"`
|
CategoryIds string `json:"categoryIds" validate:"required"`
|
||||||
TypeId int `json:"typeId" validate:"required"`
|
TypeId int `json:"typeId" validate:"required"`
|
||||||
Tags string `json:"tags" validate:"required"`
|
Tags string `json:"tags" validate:"required"`
|
||||||
|
|
@ -43,7 +42,6 @@ func (req ArticlesCreateRequest) ToEntity() *entity.Articles {
|
||||||
HtmlDescription: req.HtmlDescription,
|
HtmlDescription: req.HtmlDescription,
|
||||||
TypeId: req.TypeId,
|
TypeId: req.TypeId,
|
||||||
Tags: req.Tags,
|
Tags: req.Tags,
|
||||||
CategoryId: req.CategoryId,
|
|
||||||
OldId: req.OldId,
|
OldId: req.OldId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +51,7 @@ type ArticlesUpdateRequest struct {
|
||||||
Slug string `json:"slug" validate:"required"`
|
Slug string `json:"slug" validate:"required"`
|
||||||
Description string `json:"description" validate:"required"`
|
Description string `json:"description" validate:"required"`
|
||||||
HtmlDescription string `json:"htmlDescription" validate:"required"`
|
HtmlDescription string `json:"htmlDescription" validate:"required"`
|
||||||
CategoryId int `json:"categoryId" validate:"required"`
|
CategoryIds string `json:"categoryIds" validate:"required"`
|
||||||
TypeId int `json:"typeId" validate:"required"`
|
TypeId int `json:"typeId" validate:"required"`
|
||||||
Tags string `json:"tags" validate:"required"`
|
Tags string `json:"tags" validate:"required"`
|
||||||
CreatedById *uint `json:"createdById"`
|
CreatedById *uint `json:"createdById"`
|
||||||
|
|
@ -67,7 +65,6 @@ func (req ArticlesUpdateRequest) ToEntity() *entity.Articles {
|
||||||
Slug: req.Slug,
|
Slug: req.Slug,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
HtmlDescription: req.HtmlDescription,
|
HtmlDescription: req.HtmlDescription,
|
||||||
CategoryId: req.CategoryId,
|
|
||||||
TypeId: req.TypeId,
|
TypeId: req.TypeId,
|
||||||
Tags: req.Tags,
|
Tags: req.Tags,
|
||||||
StatusId: req.StatusId,
|
StatusId: req.StatusId,
|
||||||
|
|
@ -79,7 +76,6 @@ func (req ArticlesUpdateRequest) ToEntity() *entity.Articles {
|
||||||
Slug: req.Slug,
|
Slug: req.Slug,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
HtmlDescription: req.HtmlDescription,
|
HtmlDescription: req.HtmlDescription,
|
||||||
CategoryId: req.CategoryId,
|
|
||||||
TypeId: req.TypeId,
|
TypeId: req.TypeId,
|
||||||
Tags: req.Tags,
|
Tags: req.Tags,
|
||||||
StatusId: req.StatusId,
|
StatusId: req.StatusId,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package response
|
package response
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
articleCategoriesResponse "go-humas-be/app/module/article_categories/response"
|
||||||
articleFilesResponse "go-humas-be/app/module/article_files/response"
|
articleFilesResponse "go-humas-be/app/module/article_files/response"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
@ -30,4 +31,5 @@ type ArticlesResponse struct {
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
|
||||||
ArticleFiles []*articleFilesResponse.ArticleFilesResponse `json:"files"`
|
ArticleFiles []*articleFilesResponse.ArticleFilesResponse `json:"files"`
|
||||||
|
ArticleCategories []*articleCategoriesResponse.ArticleCategoriesResponse `json:"categories"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ func (_i *articlesService) All(req request.ArticlesQueryRequest) (articless []*r
|
||||||
port := _i.Cfg.App.ExternalPort
|
port := _i.Cfg.App.ExternalPort
|
||||||
|
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
articleRes := mapper.ArticlesResponseMapper(_i.Log, host+port, result, _i.ArticleCategoriesRepo, _i.ArticleFilesRepo, _i.UsersRepo)
|
articleRes := mapper.ArticlesResponseMapper(_i.Log, host+port, result, _i.ArticleCategoriesRepo, _i.ArticleCategoryDetailsRepo, _i.ArticleFilesRepo, _i.UsersRepo)
|
||||||
articless = append(articless, articleRes)
|
articless = append(articless, articleRes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ func (_i *articlesService) Show(id uint) (articles *response.ArticlesResponse, e
|
||||||
host := _i.Cfg.App.Domain
|
host := _i.Cfg.App.Domain
|
||||||
port := _i.Cfg.App.ExternalPort
|
port := _i.Cfg.App.ExternalPort
|
||||||
|
|
||||||
return mapper.ArticlesResponseMapper(_i.Log, host+port, result, _i.ArticleCategoriesRepo, _i.ArticleFilesRepo, _i.UsersRepo), nil
|
return mapper.ArticlesResponseMapper(_i.Log, host+port, 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) {
|
||||||
|
|
@ -128,20 +128,28 @@ func (_i *articlesService) Save(req request.ArticlesCreateRequest, authToken str
|
||||||
categoryIds = strings.Split(req.CategoryIds, ",")
|
categoryIds = strings.Split(req.CategoryIds, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
for categoryId := range categoryIds {
|
_i.Log.Info().Interface("categoryIds", categoryIds).Msg("")
|
||||||
findCategory, err := _i.ArticleCategoriesRepo.FindOne(uint(categoryId))
|
|
||||||
|
for _, categoryId := range categoryIds {
|
||||||
|
categoryIdInt, _ := strconv.Atoi(categoryId)
|
||||||
|
|
||||||
|
_i.Log.Info().Interface("categoryIdUint", uint(categoryIdInt)).Msg("")
|
||||||
|
|
||||||
|
findCategory, err := _i.ArticleCategoriesRepo.FindOne(uint(categoryIdInt))
|
||||||
|
|
||||||
|
_i.Log.Info().Interface("findCategory", findCategory).Msg("")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if findCategory != nil {
|
if findCategory == nil {
|
||||||
return nil, errors.New("category not found")
|
return nil, errors.New("category not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
categoryReq := articleCategoryDetailsReq.ArticleCategoryDetailsCreateRequest{
|
categoryReq := articleCategoryDetailsReq.ArticleCategoryDetailsCreateRequest{
|
||||||
ArticleId: saveArticleRepo.ID,
|
ArticleId: saveArticleRepo.ID,
|
||||||
CategoryId: categoryId,
|
CategoryId: categoryIdInt,
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
}
|
}
|
||||||
newCategoryReq := categoryReq.ToEntity()
|
newCategoryReq := categoryReq.ToEntity()
|
||||||
|
|
|
||||||
|
|
@ -6307,7 +6307,6 @@ const docTemplate = `{
|
||||||
"request.ArticlesCreateRequest": {
|
"request.ArticlesCreateRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"categoryId",
|
|
||||||
"categoryIds",
|
"categoryIds",
|
||||||
"description",
|
"description",
|
||||||
"htmlDescription",
|
"htmlDescription",
|
||||||
|
|
@ -6317,9 +6316,6 @@ const docTemplate = `{
|
||||||
"typeId"
|
"typeId"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"categoryId": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"categoryIds": {
|
"categoryIds": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|
@ -6349,7 +6345,7 @@ const docTemplate = `{
|
||||||
"request.ArticlesUpdateRequest": {
|
"request.ArticlesUpdateRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"categoryId",
|
"categoryIds",
|
||||||
"description",
|
"description",
|
||||||
"htmlDescription",
|
"htmlDescription",
|
||||||
"slug",
|
"slug",
|
||||||
|
|
@ -6358,8 +6354,8 @@ const docTemplate = `{
|
||||||
"typeId"
|
"typeId"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"categoryId": {
|
"categoryIds": {
|
||||||
"type": "integer"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"createdById": {
|
"createdById": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
|
|
|
||||||
|
|
@ -6296,7 +6296,6 @@
|
||||||
"request.ArticlesCreateRequest": {
|
"request.ArticlesCreateRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"categoryId",
|
|
||||||
"categoryIds",
|
"categoryIds",
|
||||||
"description",
|
"description",
|
||||||
"htmlDescription",
|
"htmlDescription",
|
||||||
|
|
@ -6306,9 +6305,6 @@
|
||||||
"typeId"
|
"typeId"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"categoryId": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"categoryIds": {
|
"categoryIds": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|
@ -6338,7 +6334,7 @@
|
||||||
"request.ArticlesUpdateRequest": {
|
"request.ArticlesUpdateRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"categoryId",
|
"categoryIds",
|
||||||
"description",
|
"description",
|
||||||
"htmlDescription",
|
"htmlDescription",
|
||||||
"slug",
|
"slug",
|
||||||
|
|
@ -6347,8 +6343,8 @@
|
||||||
"typeId"
|
"typeId"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"categoryId": {
|
"categoryIds": {
|
||||||
"type": "integer"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"createdById": {
|
"createdById": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
|
|
|
||||||
|
|
@ -157,8 +157,6 @@ definitions:
|
||||||
type: object
|
type: object
|
||||||
request.ArticlesCreateRequest:
|
request.ArticlesCreateRequest:
|
||||||
properties:
|
properties:
|
||||||
categoryId:
|
|
||||||
type: integer
|
|
||||||
categoryIds:
|
categoryIds:
|
||||||
type: string
|
type: string
|
||||||
description:
|
description:
|
||||||
|
|
@ -176,7 +174,6 @@ definitions:
|
||||||
typeId:
|
typeId:
|
||||||
type: integer
|
type: integer
|
||||||
required:
|
required:
|
||||||
- categoryId
|
|
||||||
- categoryIds
|
- categoryIds
|
||||||
- description
|
- description
|
||||||
- htmlDescription
|
- htmlDescription
|
||||||
|
|
@ -187,8 +184,8 @@ definitions:
|
||||||
type: object
|
type: object
|
||||||
request.ArticlesUpdateRequest:
|
request.ArticlesUpdateRequest:
|
||||||
properties:
|
properties:
|
||||||
categoryId:
|
categoryIds:
|
||||||
type: integer
|
type: string
|
||||||
createdById:
|
createdById:
|
||||||
type: integer
|
type: integer
|
||||||
description:
|
description:
|
||||||
|
|
@ -206,7 +203,7 @@ definitions:
|
||||||
typeId:
|
typeId:
|
||||||
type: integer
|
type: integer
|
||||||
required:
|
required:
|
||||||
- categoryId
|
- categoryIds
|
||||||
- description
|
- description
|
||||||
- htmlDescription
|
- htmlDescription
|
||||||
- slug
|
- slug
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue