feat: update csrf header on all api, add subscription api, fixing update repo in all service
This commit is contained in:
parent
a8a9441dfc
commit
b04079a554
|
|
@ -0,0 +1,11 @@
|
|||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type Subscription struct {
|
||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||
Email string `json:"email" gorm:"type:varchar"`
|
||||
IsActive bool `json:"is_active" gorm:"type:bool;default:true"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||
}
|
||||
|
|
@ -108,6 +108,7 @@ func Models() []interface{} {
|
|||
entity.MasterApprovalStatuses{},
|
||||
entity.Provinces{},
|
||||
entity.OneTimePasswords{},
|
||||
entity.Subscription{},
|
||||
entity.UserLevels{},
|
||||
entity.UserRoles{},
|
||||
entity.UserRoleAccesses{},
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ func (_i *activityLogsController) Show(c *fiber.Ctx) error {
|
|||
// @Description API for create ActivityLogs
|
||||
// @Tags ActivityLogs
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.ActivityLogsCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -142,6 +143,7 @@ func (_i *activityLogsController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update ActivityLogs
|
||||
// @Tags ActivityLogs
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.ActivityLogsUpdateRequest true "Required payload"
|
||||
// @Param id path int true "ActivityLogs ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -176,6 +178,7 @@ func (_i *activityLogsController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for delete ActivityLogs
|
||||
// @Tags ActivityLogs
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "ActivityLogs ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ func (_i *advertisementController) Show(c *fiber.Ctx) error {
|
|||
// @Description API for create Advertisement
|
||||
// @Tags Advertisement
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.AdvertisementCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -141,6 +142,7 @@ func (_i *advertisementController) Save(c *fiber.Ctx) error {
|
|||
// @Tags Advertisement
|
||||
// @Security Bearer
|
||||
// @Produce json
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param file formData file true "Upload file" multiple false
|
||||
// @Param id path int true "Advertisement ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -170,6 +172,7 @@ func (_i *advertisementController) Upload(c *fiber.Ctx) error {
|
|||
// @Description API for update Advertisement
|
||||
// @Tags Advertisement
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.AdvertisementUpdateRequest true "Required payload"
|
||||
// @Param id path int true "Advertisement ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -204,6 +207,7 @@ func (_i *advertisementController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for Update Publish Advertisement
|
||||
// @Tags Advertisement
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param id path int true "Advertisement ID"
|
||||
// @Param isPublish query bool true "Advertisement Publish Status"
|
||||
|
|
@ -239,6 +243,7 @@ func (_i *advertisementController) UpdatePublish(c *fiber.Ctx) error {
|
|||
// @Description API for delete Advertisement
|
||||
// @Tags Advertisement
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "Advertisement ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/advertisement/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -21,7 +22,7 @@ type AdvertisementRepository interface {
|
|||
FindOne(id uint) (advertisement *entity.Advertisement, err error)
|
||||
FindByFilename(contentFilename string) (advertisement *entity.Advertisement, err error)
|
||||
Create(advertisement *entity.Advertisement) (advertisementReturn *entity.Advertisement, err error)
|
||||
Update(id uint, advertisement map[string]interface{}) (err error)
|
||||
Update(id uint, advertisement *entity.Advertisement) (err error)
|
||||
Delete(id uint) (err error)
|
||||
}
|
||||
|
||||
|
|
@ -103,10 +104,14 @@ func (_i *advertisementRepository) Create(advertisement *entity.Advertisement) (
|
|||
return advertisement, result.Error
|
||||
}
|
||||
|
||||
func (_i *advertisementRepository) Update(id uint, advertisement map[string]interface{}) (err error) {
|
||||
func (_i *advertisementRepository) Update(id uint, advertisement *entity.Advertisement) (err error) {
|
||||
advertisementMap, err := utilSvc.StructToMap(advertisement)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.DB.DB.Model(&entity.Advertisement{}).
|
||||
Where(&entity.Advertisement{ID: id}).
|
||||
Updates(advertisement).Error
|
||||
Updates(advertisementMap).Error
|
||||
}
|
||||
|
||||
func (_i *advertisementRepository) Delete(id uint) error {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import (
|
|||
config "go-humas-be/config/config"
|
||||
minioStorage "go-humas-be/config/config"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
|
|
@ -155,11 +154,7 @@ func (_i *advertisementService) Upload(c *fiber.Ctx, id uint) (err error) {
|
|||
result.ContentFileName = &newFilename
|
||||
result.ContentFilePath = &objectName
|
||||
|
||||
resultMaps, err := utilSvc.StructToMap(result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = _i.Repo.Update(id, resultMaps)
|
||||
err = _i.Repo.Update(id, result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -177,11 +172,7 @@ func (_i *advertisementService) Upload(c *fiber.Ctx, id uint) (err error) {
|
|||
|
||||
func (_i *advertisementService) Update(id uint, req request.AdvertisementUpdateRequest) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
resultMaps, err := utilSvc.StructToMap(req.ToEntity())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.Repo.Update(id, resultMaps)
|
||||
return _i.Repo.Update(id, req.ToEntity())
|
||||
}
|
||||
|
||||
func (_i *advertisementService) UpdatePublish(id uint, isPublish bool) (err error) {
|
||||
|
|
@ -203,11 +194,7 @@ func (_i *advertisementService) UpdatePublish(id uint, isPublish bool) (err erro
|
|||
Format(time.RFC3339)).Str("Service:Resource", "UpdatePublish").
|
||||
Interface("result", result).Msg("")
|
||||
|
||||
resultMaps, err := utilSvc.StructToMap(result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.Repo.Update(id, resultMaps)
|
||||
return _i.Repo.Update(id, result)
|
||||
}
|
||||
|
||||
func (_i *advertisementService) Delete(id uint) error {
|
||||
|
|
@ -215,14 +202,8 @@ func (_i *advertisementService) Delete(id uint) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result.IsActive = false
|
||||
|
||||
resultMaps, err := utilSvc.StructToMap(result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.Repo.Update(id, resultMaps)
|
||||
return _i.Repo.Update(id, result)
|
||||
}
|
||||
|
||||
func (_i *advertisementService) Viewer(c *fiber.Ctx) (err error) {
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@ func (_i *articleApprovalsController) Show(c *fiber.Ctx) error {
|
|||
// @Description API for create ArticleApprovals
|
||||
// @Tags ArticleApprovals
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.ArticleApprovalsCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -138,6 +139,7 @@ func (_i *articleApprovalsController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update ArticleApprovals
|
||||
// @Tags ArticleApprovals
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.ArticleApprovalsUpdateRequest true "Required payload"
|
||||
// @Param id path int true "ArticleApprovals ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -172,6 +174,7 @@ func (_i *articleApprovalsController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for delete ArticleApprovals
|
||||
// @Tags ArticleApprovals
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "ArticleApprovals ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/article_approvals/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -89,9 +90,13 @@ func (_i *articleApprovalsRepository) Create(articleApprovals *entity.ArticleApp
|
|||
}
|
||||
|
||||
func (_i *articleApprovalsRepository) Update(id uint, articleApprovals *entity.ArticleApprovals) (err error) {
|
||||
articleApprovalsMap, err := utilSvc.StructToMap(articleApprovals)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.DB.DB.Model(&entity.ArticleApprovals{}).
|
||||
Where(&entity.ArticleApprovals{ID: id}).
|
||||
Updates(articleApprovals).Error
|
||||
Updates(articleApprovalsMap).Error
|
||||
}
|
||||
|
||||
func (_i *articleApprovalsRepository) Delete(id uint) error {
|
||||
|
|
|
|||
|
|
@ -166,6 +166,7 @@ func (_i *articleCategoriesController) ShowBySlug(c *fiber.Ctx) error {
|
|||
// @Description API for create ArticleCategories
|
||||
// @Tags Article Categories
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.ArticleCategoriesCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -198,6 +199,7 @@ func (_i *articleCategoriesController) Save(c *fiber.Ctx) error {
|
|||
// @Tags Article Categories
|
||||
// @Security Bearer
|
||||
// @Produce json
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param files formData file true "Upload thumbnail"
|
||||
// @Param id path int true "ArticleCategories ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -222,6 +224,7 @@ func (_i *articleCategoriesController) SaveThumbnail(c *fiber.Ctx) error {
|
|||
// @Description API for update ArticleCategories
|
||||
// @Tags Article Categories
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.ArticleCategoriesUpdateRequest true "Required payload"
|
||||
// @Param id path int true "ArticleCategories ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -256,6 +259,7 @@ func (_i *articleCategoriesController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for delete ArticleCategories
|
||||
// @Tags Article Categories
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "ArticleCategories ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/article_categories/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -119,9 +120,13 @@ func (_i *articleCategoriesRepository) Create(articleCategories *entity.ArticleC
|
|||
}
|
||||
|
||||
func (_i *articleCategoriesRepository) Update(id uint, articleCategories *entity.ArticleCategories) (err error) {
|
||||
articleCategoriesMap, err := utilSvc.StructToMap(articleCategories)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.DB.DB.Model(&entity.ArticleCategories{}).
|
||||
Where(&entity.ArticleCategories{ID: id}).
|
||||
Updates(articleCategories).Error
|
||||
Updates(articleCategoriesMap).Error
|
||||
}
|
||||
|
||||
func (_i *articleCategoriesRepository) Delete(id uint) error {
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ func (_i *articleCategoryDetailsController) Show(c *fiber.Ctx) error {
|
|||
// @Description API for create ArticleCategoryDetails
|
||||
// @Tags Untags
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Body request.ArticleCategoryDetailsCreateRequest
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 401 {object} response.Response
|
||||
|
|
@ -123,6 +124,7 @@ func (_i *articleCategoryDetailsController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update ArticleCategoryDetails
|
||||
// @Tags Untags
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Body request.ArticleCategoryDetailsUpdateRequest
|
||||
// @Param id path int true "ArticleCategoryDetails ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -157,6 +159,7 @@ func (_i *articleCategoryDetailsController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for delete ArticleCategoryDetails
|
||||
// @Tags Untags
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "ArticleCategoryDetails ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 401 {object} response.Response
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@ func (_i *articleCommentsController) Show(c *fiber.Ctx) error {
|
|||
// @Description API for create ArticleComments
|
||||
// @Tags ArticleComments
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.ArticleCommentsCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -138,6 +139,7 @@ func (_i *articleCommentsController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update ArticleComments
|
||||
// @Tags ArticleComments
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.ArticleCommentsUpdateRequest true "Required payload"
|
||||
// @Param id path int true "ArticleComments ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -172,6 +174,7 @@ func (_i *articleCommentsController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for delete ArticleComments
|
||||
// @Tags ArticleComments
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "ArticleComments ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -200,6 +203,7 @@ func (_i *articleCommentsController) Delete(c *fiber.Ctx) error {
|
|||
// @Description API for Approval ArticleComments
|
||||
// @Tags ArticleComments
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.ArticleCommentsApprovalRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/article_comments/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -91,9 +92,13 @@ func (_i *articleCommentsRepository) Create(articleComments *entity.ArticleComme
|
|||
}
|
||||
|
||||
func (_i *articleCommentsRepository) Update(id uint, articleComments *entity.ArticleComments) (err error) {
|
||||
articleCommentsMap, err := utilSvc.StructToMap(articleComments)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.DB.DB.Model(&entity.ArticleComments{}).
|
||||
Where(&entity.ArticleComments{ID: id}).
|
||||
Updates(articleComments).Error
|
||||
Updates(articleCommentsMap).Error
|
||||
}
|
||||
|
||||
func (_i *articleCommentsRepository) Delete(id uint) error {
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ func (_i *articleFilesController) Show(c *fiber.Ctx) error {
|
|||
// @Tags Article Files
|
||||
// @Security Bearer
|
||||
// @Produce json
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param files formData file true "Upload file" multiple true
|
||||
// @Param articleId path int true "Article ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -135,6 +136,7 @@ func (_i *articleFilesController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update ArticleFiles
|
||||
// @Tags Article Files
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.ArticleFilesUpdateRequest true "Required payload"
|
||||
// @Param id path int true "ArticleFiles ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -169,6 +171,7 @@ func (_i *articleFilesController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for delete ArticleFiles
|
||||
// @Tags Article Files
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "ArticleFiles ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/article_files/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -103,9 +104,13 @@ func (_i *articleFilesRepository) Create(articleFiles *entity.ArticleFiles) (err
|
|||
}
|
||||
|
||||
func (_i *articleFilesRepository) Update(id uint, articleFiles *entity.ArticleFiles) (err error) {
|
||||
articleFilesMap, err := utilSvc.StructToMap(articleFiles)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.DB.DB.Model(&entity.ArticleFiles{}).
|
||||
Where(&entity.ArticleFiles{ID: id}).
|
||||
Updates(articleFiles).Error
|
||||
Updates(articleFilesMap).Error
|
||||
}
|
||||
|
||||
func (_i *articleFilesRepository) Delete(id uint) error {
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ func (_i *articleNulisAIController) Show(c *fiber.Ctx) error {
|
|||
// @Description API for create ArticleNulisAI
|
||||
// @Tags ArticleNulisAI
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.ArticleNulisAICreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -143,6 +144,7 @@ func (_i *articleNulisAIController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update ArticleNulisAI
|
||||
// @Tags ArticleNulisAI
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.ArticleNulisAIUpdateRequest true "Required payload"
|
||||
// @Param id path int true "ArticleNulisAI ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -177,6 +179,7 @@ func (_i *articleNulisAIController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for publish ArticleNulisAI
|
||||
// @Tags ArticleNulisAI
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.ArticleNulisAIUpdateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -206,6 +209,7 @@ func (_i *articleNulisAIController) Publish(c *fiber.Ctx) error {
|
|||
// @Description API for delete ArticleNulisAI
|
||||
// @Tags ArticleNulisAI
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "ArticleNulisAI ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ func (_i *articlesController) Show(c *fiber.Ctx) error {
|
|||
// @Description API for create Articles
|
||||
// @Tags Articles
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.ArticlesCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -148,6 +149,7 @@ func (_i *articlesController) Save(c *fiber.Ctx) error {
|
|||
// @Tags Articles
|
||||
// @Security Bearer
|
||||
// @Produce json
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param files formData file true "Upload thumbnail"
|
||||
// @Param id path int true "Articles ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -172,6 +174,7 @@ func (_i *articlesController) SaveThumbnail(c *fiber.Ctx) error {
|
|||
// @Description API for update Articles
|
||||
// @Tags Articles
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.ArticlesUpdateRequest true "Required payload"
|
||||
// @Param id path int true "Articles ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -206,6 +209,7 @@ func (_i *articlesController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for Update Banner Articles
|
||||
// @Tags Articles
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "Articles ID"
|
||||
// @Param isBanner query bool true "Articles Banner Status"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -240,6 +244,7 @@ func (_i *articlesController) UpdateBanner(c *fiber.Ctx) error {
|
|||
// @Description API for delete Articles
|
||||
// @Tags Articles
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "Articles ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -371,6 +376,7 @@ func (_i *articlesController) ArticleMonthlyStats(c *fiber.Ctx) error {
|
|||
// @Description API for Publish Schedule of Article
|
||||
// @Tags Articles
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param id query int false "article id"
|
||||
// @Param date query string false "publish date"
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"go-humas-be/app/module/articles/request"
|
||||
"go-humas-be/app/module/articles/response"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -138,9 +139,13 @@ func (_i *articlesRepository) Create(articles *entity.Articles) (articleReturn *
|
|||
}
|
||||
|
||||
func (_i *articlesRepository) Update(id uint, articles *entity.Articles) (err error) {
|
||||
articlesMap, err := utilSvc.StructToMap(articles)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.DB.DB.Model(&entity.Articles{}).
|
||||
Where(&entity.Articles{ID: id}).
|
||||
Save(articles).Error
|
||||
Updates(articlesMap).Error
|
||||
}
|
||||
|
||||
func (_i *articlesRepository) UpdateSkipNull(id uint, articles *entity.Articles) (err error) {
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ func (_i *customStaticPagesController) ShowBySlug(c *fiber.Ctx) error {
|
|||
// @Description API for create CustomStaticPages
|
||||
// @Tags CustomStaticPages
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.CustomStaticPagesCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -163,6 +164,7 @@ func (_i *customStaticPagesController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update CustomStaticPages
|
||||
// @Tags CustomStaticPages
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.CustomStaticPagesUpdateRequest true "Required payload"
|
||||
// @Param id path int true "CustomStaticPages ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -197,6 +199,7 @@ func (_i *customStaticPagesController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for delete CustomStaticPages
|
||||
// @Tags CustomStaticPages
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "CustomStaticPages ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/custom_static_pages/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -96,9 +97,13 @@ func (_i *customStaticPagesRepository) Create(customStaticPages *entity.CustomSt
|
|||
}
|
||||
|
||||
func (_i *customStaticPagesRepository) Update(id uint, customStaticPages *entity.CustomStaticPages) (err error) {
|
||||
customStaticPagesMap, err := utilSvc.StructToMap(customStaticPages)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.DB.DB.Model(&entity.CustomStaticPages{}).
|
||||
Where(&entity.CustomStaticPages{ID: id}).
|
||||
Updates(customStaticPages).Error
|
||||
Updates(customStaticPagesMap).Error
|
||||
}
|
||||
|
||||
func (_i *customStaticPagesRepository) Delete(id uint) error {
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ func (_i *feedbacksController) Show(c *fiber.Ctx) error {
|
|||
// @Description API for create Feedbacks
|
||||
// @Tags Feedbacks
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.FeedbacksCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -137,6 +138,7 @@ func (_i *feedbacksController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update Feedbacks
|
||||
// @Tags Feedbacks
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.FeedbacksUpdateRequest true "Required payload"
|
||||
// @Param id path int true "Feedbacks ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -171,6 +173,7 @@ func (_i *feedbacksController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for delete Feedbacks
|
||||
// @Tags Feedbacks
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "Feedbacks ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"go-humas-be/app/module/feedbacks/request"
|
||||
"go-humas-be/app/module/feedbacks/response"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -94,9 +95,13 @@ func (_i *feedbacksRepository) Create(feedbacks *entity.Feedbacks) (feedbacksRet
|
|||
}
|
||||
|
||||
func (_i *feedbacksRepository) Update(id uint, feedbacks *entity.Feedbacks) (err error) {
|
||||
feedbacksMap, err := utilSvc.StructToMap(feedbacks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.DB.DB.Model(&entity.Feedbacks{}).
|
||||
Where(&entity.Feedbacks{ID: id}).
|
||||
Updates(feedbacks).Error
|
||||
Updates(feedbacksMap).Error
|
||||
}
|
||||
|
||||
func (_i *feedbacksRepository) Delete(id uint) error {
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ func (_i *magazineFilesController) Show(c *fiber.Ctx) error {
|
|||
// @Description API for create MagazineFiles
|
||||
// @Tags Magazine Files
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param files formData file true "Upload file" multiple true
|
||||
// @Param title formData string true "Magazine file title"
|
||||
// @Param description formData string true "Magazine file description"
|
||||
|
|
@ -134,8 +135,9 @@ func (_i *magazineFilesController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update MagazineFiles
|
||||
// @Tags Magazine Files
|
||||
// @Security Bearer
|
||||
// @Body request.MagazineFilesUpdateRequest
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "MagazineFiles ID"
|
||||
// @Body request.MagazineFilesUpdateRequest
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
|
|
@ -167,6 +169,7 @@ func (_i *magazineFilesController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for delete MagazineFiles
|
||||
// @Tags Magazine Files
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "MagazineFiles ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/magazine_files/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -106,9 +107,13 @@ func (_i *magazineFilesRepository) Create(magazineFiles *entity.MagazineFiles) (
|
|||
}
|
||||
|
||||
func (_i *magazineFilesRepository) Update(id uint, magazineFiles *entity.MagazineFiles) (err error) {
|
||||
magazineFilesMap, err := utilSvc.StructToMap(magazineFiles)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.DB.DB.Model(&entity.MagazineFiles{}).
|
||||
Where(&entity.MagazineFiles{ID: id}).
|
||||
Updates(magazineFiles).Error
|
||||
Updates(magazineFilesMap).Error
|
||||
}
|
||||
|
||||
func (_i *magazineFilesRepository) Delete(id uint) error {
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ func (_i *magazinesController) Show(c *fiber.Ctx) error {
|
|||
// @Description API for create Magazines
|
||||
// @Tags Magazines
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.MagazinesCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -135,6 +136,7 @@ func (_i *magazinesController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update Magazines
|
||||
// @Tags Magazines
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "Magazines ID"
|
||||
// @Param payload body request.MagazinesUpdateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -169,8 +171,9 @@ func (_i *magazinesController) Update(c *fiber.Ctx) error {
|
|||
// @Tags Magazines
|
||||
// @Security Bearer
|
||||
// @Produce json
|
||||
// @Param files formData file true "Upload thumbnail"
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "Magazine ID"
|
||||
// @Param files formData file true "Upload thumbnail"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
|
|
@ -208,6 +211,7 @@ func (_i *magazinesController) Viewer(c *fiber.Ctx) error {
|
|||
// @Description API for delete Magazines
|
||||
// @Tags Magazines
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "Magazines ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/magazines/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -99,9 +100,13 @@ func (_i *magazinesRepository) Create(magazines *entity.Magazines) (magazineRetu
|
|||
}
|
||||
|
||||
func (_i *magazinesRepository) Update(id uint, magazines *entity.Magazines) (err error) {
|
||||
magazinesMap, err := utilSvc.StructToMap(magazines)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.DB.DB.Model(&entity.Magazines{}).
|
||||
Where(&entity.Magazines{ID: id}).
|
||||
Updates(magazines).Error
|
||||
Updates(magazinesMap).Error
|
||||
}
|
||||
|
||||
func (_i *magazinesRepository) Delete(id uint) error {
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ func (_i *masterMenusController) Show(c *fiber.Ctx) error {
|
|||
// @Description API for create MasterMenus
|
||||
// @Tags MasterMenus
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.MasterMenusCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -132,6 +133,7 @@ func (_i *masterMenusController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update MasterMenus
|
||||
// @Tags MasterMenus
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Body request.MasterMenusUpdateRequest
|
||||
// @Param id path int true "MasterMenus ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -167,6 +169,7 @@ func (_i *masterMenusController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for delete MasterMenus
|
||||
// @Tags MasterMenus
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "MasterMenus ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ func (_i *masterModulesController) Show(c *fiber.Ctx) error {
|
|||
// @Description API for create MasterModules
|
||||
// @Tags MasterModules
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.MasterModulesCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -130,6 +131,7 @@ func (_i *masterModulesController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update MasterModules
|
||||
// @Tags MasterModules
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "MasterModules ID"
|
||||
// @Param payload body request.MasterModulesUpdateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -164,6 +166,7 @@ func (_i *masterModulesController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for delete MasterModules
|
||||
// @Tags MasterModules
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "MasterModules ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/subscription/service"
|
||||
)
|
||||
|
||||
type Controller struct {
|
||||
Subscription SubscriptionController
|
||||
}
|
||||
|
||||
func NewController(SubscriptionService service.SubscriptionService, log zerolog.Logger) *Controller {
|
||||
return &Controller{
|
||||
Subscription: NewSubscriptionController(SubscriptionService, log),
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,192 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/subscription/request"
|
||||
"go-humas-be/app/module/subscription/service"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilRes "go-humas-be/utils/response"
|
||||
utilVal "go-humas-be/utils/validator"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type subscriptionController struct {
|
||||
subscriptionService service.SubscriptionService
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
type SubscriptionController interface {
|
||||
All(c *fiber.Ctx) error
|
||||
Show(c *fiber.Ctx) error
|
||||
Save(c *fiber.Ctx) error
|
||||
Update(c *fiber.Ctx) error
|
||||
Delete(c *fiber.Ctx) error
|
||||
}
|
||||
|
||||
func NewSubscriptionController(subscriptionService service.SubscriptionService, log zerolog.Logger) SubscriptionController {
|
||||
return &subscriptionController{
|
||||
subscriptionService: subscriptionService,
|
||||
Log: log,
|
||||
}
|
||||
}
|
||||
|
||||
// All get all Subscription
|
||||
// @Summary Get all Subscription
|
||||
// @Description API for getting all Subscription
|
||||
// @Tags Subscription
|
||||
// @Security Bearer
|
||||
// @Param req query request.SubscriptionQueryRequest false "query parameters"
|
||||
// @Param req query paginator.Pagination false "pagination parameters"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /subscription [get]
|
||||
func (_i *subscriptionController) All(c *fiber.Ctx) error {
|
||||
paginate, err := paginator.Paginate(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
reqContext := request.SubscriptionQueryRequestContext{
|
||||
Email: c.Query("email"),
|
||||
}
|
||||
req := reqContext.ToParamRequest()
|
||||
req.Pagination = paginate
|
||||
|
||||
subscriptionData, paging, err := _i.subscriptionService.All(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"Subscription list successfully retrieved"},
|
||||
Data: subscriptionData,
|
||||
Meta: paging,
|
||||
})
|
||||
}
|
||||
|
||||
// Show get one Subscription
|
||||
// @Summary Get one Subscription
|
||||
// @Description API for getting one Subscription
|
||||
// @Tags Subscription
|
||||
// @Security Bearer
|
||||
// @Param id path int true "Subscription ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /subscription/{id} [get]
|
||||
func (_i *subscriptionController) Show(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
subscriptionData, err := _i.subscriptionService.Show(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"Subscription successfully retrieved"},
|
||||
Data: subscriptionData,
|
||||
})
|
||||
}
|
||||
|
||||
// Save create Subscription
|
||||
// @Summary Create Subscription
|
||||
// @Description API for create Subscription
|
||||
// @Tags Subscription
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.SubscriptionCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /subscription [post]
|
||||
func (_i *subscriptionController) Save(c *fiber.Ctx) error {
|
||||
req := new(request.SubscriptionCreateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dataResult, err := _i.subscriptionService.Save(*req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"Subscription successfully created"},
|
||||
Data: dataResult,
|
||||
})
|
||||
}
|
||||
|
||||
// Update update Subscription
|
||||
// @Summary update Subscription
|
||||
// @Description API for update Subscription
|
||||
// @Tags Subscription
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.SubscriptionUpdateRequest true "Required payload"
|
||||
// @Param id path int true "Subscription ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /subscription/{id} [put]
|
||||
func (_i *subscriptionController) Update(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := new(request.SubscriptionUpdateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.subscriptionService.Update(uint(id), *req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"Subscription successfully updated"},
|
||||
})
|
||||
}
|
||||
|
||||
// Delete delete Subscription
|
||||
// @Summary delete Subscription
|
||||
// @Description API for delete Subscription
|
||||
// @Tags Subscription
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "Subscription ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /subscription/{id} [delete]
|
||||
func (_i *subscriptionController) Delete(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.subscriptionService.Delete(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"Subscription successfully deleted"},
|
||||
})
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
res "go-humas-be/app/module/subscription/response"
|
||||
)
|
||||
|
||||
func SubscriptionResponseMapper(subscriptionReq *entity.Subscription) (subscriptionRes *res.SubscriptionResponse) {
|
||||
if subscriptionReq != nil {
|
||||
subscriptionRes = &res.SubscriptionResponse{
|
||||
ID: subscriptionReq.ID,
|
||||
Email: subscriptionReq.Email,
|
||||
IsActive: subscriptionReq.IsActive,
|
||||
CreatedAt: subscriptionReq.CreatedAt,
|
||||
UpdatedAt: subscriptionReq.UpdatedAt,
|
||||
}
|
||||
}
|
||||
return subscriptionRes
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/subscription/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type subscriptionRepository struct {
|
||||
DB *database.Database
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// SubscriptionRepository define interface of ISubscriptionRepository
|
||||
type SubscriptionRepository interface {
|
||||
GetAll(req request.SubscriptionQueryRequest) (subscriptions []*entity.Subscription, paging paginator.Pagination, err error)
|
||||
FindOne(id uint) (subscription *entity.Subscription, err error)
|
||||
Create(subscription *entity.Subscription) (subscriptionReturn *entity.Subscription, err error)
|
||||
Update(id uint, subscription *entity.Subscription) (err error)
|
||||
Delete(id uint) (err error)
|
||||
}
|
||||
|
||||
func NewSubscriptionRepository(db *database.Database, logger zerolog.Logger) SubscriptionRepository {
|
||||
return &subscriptionRepository{
|
||||
DB: db,
|
||||
Log: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// implement interface of ISubscriptionRepository
|
||||
func (_i *subscriptionRepository) GetAll(req request.SubscriptionQueryRequest) (subscriptions []*entity.Subscription, paging paginator.Pagination, err error) {
|
||||
var count int64
|
||||
|
||||
query := _i.DB.DB.Model(&entity.Subscription{})
|
||||
query = query.Where("is_active = ?", true)
|
||||
|
||||
if req.Email != nil && *req.Email != "" {
|
||||
email := strings.ToLower(*req.Email)
|
||||
query = query.Where("LOWER(email) LIKE ?", "%"+strings.ToLower(email)+"%")
|
||||
}
|
||||
query.Count(&count)
|
||||
|
||||
if req.Pagination.SortBy != "" {
|
||||
direction := "ASC"
|
||||
if req.Pagination.Sort == "desc" {
|
||||
direction = "DESC"
|
||||
}
|
||||
query.Order(fmt.Sprintf("%s %s", req.Pagination.SortBy, direction))
|
||||
}
|
||||
|
||||
req.Pagination.Count = count
|
||||
req.Pagination = paginator.Paging(req.Pagination)
|
||||
|
||||
err = query.Offset(req.Pagination.Offset).Limit(req.Pagination.Limit).Find(&subscriptions).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
paging = *req.Pagination
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *subscriptionRepository) FindOne(id uint) (subscription *entity.Subscription, err error) {
|
||||
if err := _i.DB.DB.First(&subscription, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return subscription, nil
|
||||
}
|
||||
|
||||
func (_i *subscriptionRepository) Create(subscription *entity.Subscription) (subscriptionReturn *entity.Subscription, err error) {
|
||||
result := _i.DB.DB.Create(subscription)
|
||||
return subscription, result.Error
|
||||
}
|
||||
|
||||
func (_i *subscriptionRepository) Update(id uint, subscription *entity.Subscription) (err error) {
|
||||
return _i.DB.DB.Model(&entity.Subscription{}).
|
||||
Where(&entity.Subscription{ID: id}).
|
||||
Updates(subscription).Error
|
||||
}
|
||||
|
||||
func (_i *subscriptionRepository) Delete(id uint) error {
|
||||
return _i.DB.DB.Delete(&entity.Subscription{}, id).Error
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/utils/paginator"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SubscriptionGeneric interface {
|
||||
ToEntity()
|
||||
}
|
||||
|
||||
type SubscriptionQueryRequest struct {
|
||||
Email *string `json:"email"`
|
||||
Pagination *paginator.Pagination `json:"pagination"`
|
||||
}
|
||||
|
||||
type SubscriptionCreateRequest struct {
|
||||
Email string `json:"email" validate:"required,email"`
|
||||
}
|
||||
|
||||
func (req SubscriptionCreateRequest) ToEntity() *entity.Subscription {
|
||||
return &entity.Subscription{
|
||||
Email: req.Email,
|
||||
}
|
||||
}
|
||||
|
||||
type SubscriptionUpdateRequest struct {
|
||||
ID uint `json:"id" validate:"required"`
|
||||
Email string `json:"email" validate:"required,email"`
|
||||
}
|
||||
|
||||
func (req SubscriptionUpdateRequest) ToEntity() *entity.Subscription {
|
||||
return &entity.Subscription{
|
||||
ID: req.ID,
|
||||
Email: req.Email,
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
type SubscriptionQueryRequestContext struct {
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
func (req SubscriptionQueryRequestContext) ToParamRequest() SubscriptionQueryRequest {
|
||||
var request SubscriptionQueryRequest
|
||||
|
||||
if email := req.Email; email != "" {
|
||||
request.Email = &email
|
||||
}
|
||||
|
||||
return request
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package response
|
||||
|
||||
import "time"
|
||||
|
||||
type SubscriptionResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Email string `json:"email"`
|
||||
IsActive bool `json:"isActive"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/subscription/mapper"
|
||||
"go-humas-be/app/module/subscription/repository"
|
||||
"go-humas-be/app/module/subscription/request"
|
||||
"go-humas-be/app/module/subscription/response"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
"go-humas-be/utils/paginator"
|
||||
)
|
||||
|
||||
// SubscriptionService
|
||||
type subscriptionService struct {
|
||||
Repo repository.SubscriptionRepository
|
||||
UsersRepo usersRepository.UsersRepository
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// SubscriptionService define interface of ISubscriptionService
|
||||
type SubscriptionService interface {
|
||||
All(req request.SubscriptionQueryRequest) (subscription []*response.SubscriptionResponse, paging paginator.Pagination, err error)
|
||||
Show(id uint) (subscription *response.SubscriptionResponse, err error)
|
||||
Save(req request.SubscriptionCreateRequest) (subscription *entity.Subscription, err error)
|
||||
Update(id uint, req request.SubscriptionUpdateRequest) (err error)
|
||||
Delete(id uint) error
|
||||
}
|
||||
|
||||
// NewSubscriptionService init SubscriptionService
|
||||
func NewSubscriptionService(repo repository.SubscriptionRepository, log zerolog.Logger, usersRepo usersRepository.UsersRepository) SubscriptionService {
|
||||
|
||||
return &subscriptionService{
|
||||
Repo: repo,
|
||||
Log: log,
|
||||
UsersRepo: usersRepo,
|
||||
}
|
||||
}
|
||||
|
||||
// All implement interface of SubscriptionService
|
||||
func (_i *subscriptionService) All(req request.SubscriptionQueryRequest) (subscriptions []*response.SubscriptionResponse, paging paginator.Pagination, err error) {
|
||||
results, paging, err := _i.Repo.GetAll(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
subscriptions = append(subscriptions, mapper.SubscriptionResponseMapper(result))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *subscriptionService) Show(id uint) (subscription *response.SubscriptionResponse, err error) {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mapper.SubscriptionResponseMapper(result), nil
|
||||
}
|
||||
|
||||
func (_i *subscriptionService) Save(req request.SubscriptionCreateRequest) (subscription *entity.Subscription, err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
newReq := req.ToEntity()
|
||||
return _i.Repo.Create(newReq)
|
||||
}
|
||||
|
||||
func (_i *subscriptionService) Update(id uint, req request.SubscriptionUpdateRequest) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
return _i.Repo.Update(id, req.ToEntity())
|
||||
}
|
||||
|
||||
func (_i *subscriptionService) Delete(id uint) error {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result.IsActive = true
|
||||
return _i.Repo.Update(id, result)
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package subscription
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go-humas-be/app/module/subscription/controller"
|
||||
"go-humas-be/app/module/subscription/repository"
|
||||
"go-humas-be/app/module/subscription/service"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
// struct of SubscriptionRouter
|
||||
type SubscriptionRouter struct {
|
||||
App fiber.Router
|
||||
Controller *controller.Controller
|
||||
}
|
||||
|
||||
// register bulky of Subscription module
|
||||
var NewSubscriptionModule = fx.Options(
|
||||
// register repository of Subscription module
|
||||
fx.Provide(repository.NewSubscriptionRepository),
|
||||
|
||||
// register service of Subscription module
|
||||
fx.Provide(service.NewSubscriptionService),
|
||||
|
||||
// register controller of Subscription module
|
||||
fx.Provide(controller.NewController),
|
||||
|
||||
// register router of Subscription module
|
||||
fx.Provide(NewSubscriptionRouter),
|
||||
)
|
||||
|
||||
// init SubscriptionRouter
|
||||
func NewSubscriptionRouter(fiber *fiber.App, controller *controller.Controller) *SubscriptionRouter {
|
||||
return &SubscriptionRouter{
|
||||
App: fiber,
|
||||
Controller: controller,
|
||||
}
|
||||
}
|
||||
|
||||
// register routes of Subscription module
|
||||
func (_i *SubscriptionRouter) RegisterSubscriptionRoutes() {
|
||||
// define controllers
|
||||
subscriptionController := _i.Controller.Subscription
|
||||
|
||||
// define routes
|
||||
_i.App.Route("/subscription", func(router fiber.Router) {
|
||||
router.Get("/", subscriptionController.All)
|
||||
router.Get("/:id", subscriptionController.Show)
|
||||
router.Post("/", subscriptionController.Save)
|
||||
router.Put("/:id", subscriptionController.Update)
|
||||
router.Delete("/:id", subscriptionController.Delete)
|
||||
})
|
||||
}
|
||||
|
|
@ -128,6 +128,7 @@ func (_i *userLevelsController) ShowByAlias(c *fiber.Ctx) error {
|
|||
// @Description API for create UserLevels
|
||||
// @Tags UserLevels
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.UserLevelsCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -157,6 +158,7 @@ func (_i *userLevelsController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update UserLevels
|
||||
// @Tags UserLevels
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.UserLevelsUpdateRequest true "Required payload"
|
||||
// @Param id path int true "UserLevels ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -191,6 +193,7 @@ func (_i *userLevelsController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for delete UserLevels
|
||||
// @Tags UserLevels
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "UserLevels ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 401 {object} response.Response
|
||||
|
|
@ -220,6 +223,7 @@ func (_i *userLevelsController) Delete(c *fiber.Ctx) error {
|
|||
// @Description API for Enable Approval of Article
|
||||
// @Tags UserLevels
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.UserLevelsApprovalRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/user_levels/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -94,9 +95,13 @@ func (_i *userLevelsRepository) Create(userLevels *entity.UserLevels) (userLevel
|
|||
}
|
||||
|
||||
func (_i *userLevelsRepository) Update(id uint, userLevels *entity.UserLevels) (err error) {
|
||||
userLevelsMap, err := utilSvc.StructToMap(userLevels)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.DB.DB.Model(&entity.UserLevels{}).
|
||||
Where(&entity.UserLevels{ID: id}).
|
||||
Updates(userLevels).Error
|
||||
Updates(userLevelsMap).Error
|
||||
}
|
||||
|
||||
func (_i *userLevelsRepository) Delete(id uint) error {
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ func (_i *userRoleAccessesController) Show(c *fiber.Ctx) error {
|
|||
// @Description API for create UserRoleAccesses
|
||||
// @Tags UserRoleAccesses
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.UserRoleAccessesCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -128,6 +129,7 @@ func (_i *userRoleAccessesController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update UserRoleAccesses
|
||||
// @Tags UserRoleAccesses
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.UserRoleAccessesUpdateRequest true "Required payload"
|
||||
// @Param id path int true "UserRoleAccesses ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -163,6 +165,7 @@ func (_i *userRoleAccessesController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for delete UserRoleAccesses
|
||||
// @Tags UserRoleAccesses
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "UserRoleAccesses ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ func (_i *userRolesController) Show(c *fiber.Ctx) error {
|
|||
// @Description API for create UserRoles
|
||||
// @Tags UserRoles
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.UserRolesCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -137,6 +138,7 @@ func (_i *userRolesController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update UserRoles
|
||||
// @Tags UserRoles
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.UserRolesUpdateRequest true "Required payload"
|
||||
// @Param id path int true "UserRoles ID"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -171,6 +173,7 @@ func (_i *userRolesController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for delete UserRoles
|
||||
// @Tags UserRoles
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "UserRoles ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/user_roles/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -90,9 +91,13 @@ func (_i *userRolesRepository) Create(userRoles *entity.UserRoles) (userRolesRet
|
|||
}
|
||||
|
||||
func (_i *userRolesRepository) Update(id uint, userRoles *entity.UserRoles) (err error) {
|
||||
userRolesMap, err := utilSvc.StructToMap(userRoles)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.DB.DB.Model(&entity.UserRoles{}).
|
||||
Where(&entity.UserRoles{ID: id}).
|
||||
Updates(userRoles).Error
|
||||
Updates(userRolesMap).Error
|
||||
}
|
||||
|
||||
func (_i *userRolesRepository) Delete(id uint) error {
|
||||
|
|
|
|||
|
|
@ -174,6 +174,7 @@ func (_i *usersController) ShowInfo(c *fiber.Ctx) error {
|
|||
// @Description API for create Users
|
||||
// @Tags Users
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.UsersCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -206,8 +207,9 @@ func (_i *usersController) Save(c *fiber.Ctx) error {
|
|||
// @Description API for update Users
|
||||
// @Tags Users
|
||||
// @Security Bearer
|
||||
// @Param payload body request.UsersUpdateRequest true "Required payload"
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "Users ID"
|
||||
// @Param payload body request.UsersUpdateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
|
|
@ -240,6 +242,7 @@ func (_i *usersController) Update(c *fiber.Ctx) error {
|
|||
// @Description API for Login Users
|
||||
// @Tags Users
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.UserLogin true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -273,6 +276,7 @@ func (_i *usersController) Login(c *fiber.Ctx) error {
|
|||
// @Description API for ParetoLogin Users
|
||||
// @Tags Users
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.UserLogin true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -306,6 +310,7 @@ func (_i *usersController) ParetoLogin(c *fiber.Ctx) error {
|
|||
// @Description API for delete Users
|
||||
// @Tags Users
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param id path int true "Users ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -334,6 +339,7 @@ func (_i *usersController) Delete(c *fiber.Ctx) error {
|
|||
// @Description API for SavePassword Users
|
||||
// @Tags Users
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.UserSavePassword true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
|
|
@ -365,6 +371,7 @@ func (_i *usersController) SavePassword(c *fiber.Ctx) error {
|
|||
// @Description API for ResetPassword Users
|
||||
// @Tags Users
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.UserResetPassword true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -393,6 +400,7 @@ func (_i *usersController) ResetPassword(c *fiber.Ctx) error {
|
|||
// @Description API for ForgotPassword Users
|
||||
// @Tags Users
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.UserForgotPassword true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -421,6 +429,7 @@ func (_i *usersController) ForgotPassword(c *fiber.Ctx) error {
|
|||
// @Description API for OtpRequest Users
|
||||
// @Tags Users
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.UserOtpRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -449,6 +458,7 @@ func (_i *usersController) OtpRequest(c *fiber.Ctx) error {
|
|||
// @Description API for OtpValidation Users
|
||||
// @Tags Users
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.UserOtpValidation true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -477,6 +487,7 @@ func (_i *usersController) OtpValidation(c *fiber.Ctx) error {
|
|||
// @Description API for Email Validation Users
|
||||
// @Tags Users
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.UserEmailValidationRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -505,6 +516,7 @@ func (_i *usersController) EmailValidation(c *fiber.Ctx) error {
|
|||
// @Description API for Setup Email Users
|
||||
// @Tags Users
|
||||
// @Security Bearer
|
||||
// @Param X-Csrf-Token header string true "Insert the X-Csrf-Token"
|
||||
// @Param payload body request.UserEmailValidationRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database"
|
||||
|
|
@ -137,10 +138,14 @@ func (_i *usersRepository) Create(users *users.Users) (userReturn *users.Users,
|
|||
return users, result.Error
|
||||
}
|
||||
|
||||
func (_i *usersRepository) Update(id uint, usersReturn *users.Users) (err error) {
|
||||
func (_i *usersRepository) Update(id uint, userReturn *users.Users) (err error) {
|
||||
userReturnMap, err := StructToMap(userReturn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return _i.DB.DB.Model(&users.Users{}).
|
||||
Where(&users.Users{ID: id}).
|
||||
Updates(usersReturn).Error
|
||||
Updates(userReturnMap).Error
|
||||
}
|
||||
|
||||
func (_i *usersRepository) Delete(id uint) error {
|
||||
|
|
@ -189,3 +194,18 @@ func (_i *usersRepository) FindOtpByIdentity(identity string, code string) (otp
|
|||
|
||||
return otp, nil
|
||||
}
|
||||
|
||||
func StructToMap(obj interface{}) (map[string]interface{}, error) {
|
||||
var result map[string]interface{}
|
||||
jsonData, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(jsonData, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
"go-humas-be/app/module/master_menus"
|
||||
"go-humas-be/app/module/master_modules"
|
||||
"go-humas-be/app/module/provinces"
|
||||
"go-humas-be/app/module/subscription"
|
||||
"go-humas-be/app/module/user_levels"
|
||||
"go-humas-be/app/module/user_role_accesses"
|
||||
"go-humas-be/app/module/user_roles"
|
||||
|
|
@ -51,6 +52,7 @@ type Router struct {
|
|||
MasterMenusRouter *master_menus.MasterMenusRouter
|
||||
MasterModulesRouter *master_modules.MasterModulesRouter
|
||||
ProvincesRouter *provinces.ProvincesRouter
|
||||
SubscriptionRouter *subscription.SubscriptionRouter
|
||||
UserLevelsRouter *user_levels.UserLevelsRouter
|
||||
UserRoleAccessesRouter *user_role_accesses.UserRoleAccessesRouter
|
||||
UserRolesRouter *user_roles.UserRolesRouter
|
||||
|
|
@ -79,6 +81,7 @@ func NewRouter(
|
|||
masterMenuRouter *master_menus.MasterMenusRouter,
|
||||
masterModuleRouter *master_modules.MasterModulesRouter,
|
||||
provincesRouter *provinces.ProvincesRouter,
|
||||
subscriptionRouter *subscription.SubscriptionRouter,
|
||||
userLevelsRouter *user_levels.UserLevelsRouter,
|
||||
userRoleAccessesRouter *user_role_accesses.UserRoleAccessesRouter,
|
||||
userRolesRouter *user_roles.UserRolesRouter,
|
||||
|
|
@ -105,6 +108,7 @@ func NewRouter(
|
|||
MasterMenusRouter: masterMenuRouter,
|
||||
MasterModulesRouter: masterModuleRouter,
|
||||
ProvincesRouter: provincesRouter,
|
||||
SubscriptionRouter: subscriptionRouter,
|
||||
UserLevelsRouter: userLevelsRouter,
|
||||
UserRoleAccessesRouter: userRoleAccessesRouter,
|
||||
UserRolesRouter: userRolesRouter,
|
||||
|
|
@ -141,6 +145,7 @@ func (r *Router) Register() {
|
|||
r.MasterMenusRouter.RegisterMasterMenusRoutes()
|
||||
r.MasterModulesRouter.RegisterMasterModulesRoutes()
|
||||
r.ProvincesRouter.RegisterProvincesRoutes()
|
||||
r.SubscriptionRouter.RegisterSubscriptionRoutes()
|
||||
r.UserLevelsRouter.RegisterUserLevelsRoutes()
|
||||
r.UserRoleAccessesRouter.RegisterUserRoleAccessesRoutes()
|
||||
r.UsersRouter.RegisterUsersRoutes()
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
2
main.go
2
main.go
|
|
@ -22,6 +22,7 @@ import (
|
|||
"go-humas-be/app/module/master_menus"
|
||||
"go-humas-be/app/module/master_modules"
|
||||
"go-humas-be/app/module/provinces"
|
||||
"go-humas-be/app/module/subscription"
|
||||
"go-humas-be/app/module/user_levels"
|
||||
"go-humas-be/app/module/user_role_accesses"
|
||||
"go-humas-be/app/module/user_role_level_details"
|
||||
|
|
@ -77,6 +78,7 @@ func main() {
|
|||
master_menus.NewMasterMenusModule,
|
||||
master_modules.NewMasterModulesModule,
|
||||
provinces.NewProvincesModule,
|
||||
subscription.NewSubscriptionModule,
|
||||
user_levels.NewUserLevelsModule,
|
||||
user_roles.NewUserRolesModule,
|
||||
user_role_accesses.NewUserRoleAccessesModule,
|
||||
|
|
|
|||
Loading…
Reference in New Issue