feat: update user levels and advertisement
This commit is contained in:
parent
d0991a57ad
commit
ee92534a58
|
|
@ -5,7 +5,7 @@ import (
|
||||||
res "go-humas-be/app/module/advertisement/response"
|
res "go-humas-be/app/module/advertisement/response"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AdvertisementResponseMapper(advertisementReq *entity.Advertisement) (advertisementRes *res.AdvertisementResponse) {
|
func AdvertisementResponseMapper(advertisementReq *entity.Advertisement, host string) (advertisementRes *res.AdvertisementResponse) {
|
||||||
if advertisementReq != nil {
|
if advertisementReq != nil {
|
||||||
advertisementRes = &res.AdvertisementResponse{
|
advertisementRes = &res.AdvertisementResponse{
|
||||||
ID: advertisementReq.ID,
|
ID: advertisementReq.ID,
|
||||||
|
|
@ -18,6 +18,10 @@ func AdvertisementResponseMapper(advertisementReq *entity.Advertisement) (advert
|
||||||
CreatedAt: advertisementReq.CreatedAt,
|
CreatedAt: advertisementReq.CreatedAt,
|
||||||
UpdatedAt: advertisementReq.UpdatedAt,
|
UpdatedAt: advertisementReq.UpdatedAt,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if advertisementReq.ContentFilePath != nil {
|
||||||
|
advertisementRes.ContentFileUrl = host + "/advertisement/viewer/" + *advertisementReq.ContentFileName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return advertisementRes
|
return advertisementRes
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,14 @@ package response
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type AdvertisementResponse struct {
|
type AdvertisementResponse struct {
|
||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
RedirectLink string `json:"redirectLink"`
|
RedirectLink string `json:"redirectLink"`
|
||||||
Placement string `json:"placement"`
|
ContentFileUrl string `json:"contentFileUrl"`
|
||||||
StatusId int `json:"statusId"`
|
Placement string `json:"placement"`
|
||||||
IsActive bool `json:"isActive"`
|
StatusId int `json:"statusId"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
IsActive bool `json:"isActive"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"go-humas-be/app/module/advertisement/request"
|
"go-humas-be/app/module/advertisement/request"
|
||||||
"go-humas-be/app/module/advertisement/response"
|
"go-humas-be/app/module/advertisement/response"
|
||||||
usersRepository "go-humas-be/app/module/users/repository"
|
usersRepository "go-humas-be/app/module/users/repository"
|
||||||
|
config "go-humas-be/config/config"
|
||||||
minioStorage "go-humas-be/config/config"
|
minioStorage "go-humas-be/config/config"
|
||||||
"go-humas-be/utils/paginator"
|
"go-humas-be/utils/paginator"
|
||||||
"io"
|
"io"
|
||||||
|
|
@ -29,6 +30,7 @@ type advertisementService struct {
|
||||||
Repo repository.AdvertisementRepository
|
Repo repository.AdvertisementRepository
|
||||||
UsersRepo usersRepository.UsersRepository
|
UsersRepo usersRepository.UsersRepository
|
||||||
Log zerolog.Logger
|
Log zerolog.Logger
|
||||||
|
Cfg *config.Config
|
||||||
MinioStorage *minioStorage.MinioStorage
|
MinioStorage *minioStorage.MinioStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,13 +47,14 @@ type AdvertisementService interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAdvertisementService init AdvertisementService
|
// NewAdvertisementService init AdvertisementService
|
||||||
func NewAdvertisementService(repo repository.AdvertisementRepository, minioStorage *minioStorage.MinioStorage, usersRepo usersRepository.UsersRepository, log zerolog.Logger) AdvertisementService {
|
func NewAdvertisementService(repo repository.AdvertisementRepository, minioStorage *minioStorage.MinioStorage, usersRepo usersRepository.UsersRepository, log zerolog.Logger, cfg *config.Config) AdvertisementService {
|
||||||
|
|
||||||
return &advertisementService{
|
return &advertisementService{
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
UsersRepo: usersRepo,
|
UsersRepo: usersRepo,
|
||||||
MinioStorage: minioStorage,
|
MinioStorage: minioStorage,
|
||||||
Log: log,
|
Log: log,
|
||||||
|
Cfg: cfg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,8 +65,9 @@ func (_i *advertisementService) All(req request.AdvertisementQueryRequest) (adve
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
host := _i.Cfg.App.Domain
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
advertisements = append(advertisements, mapper.AdvertisementResponseMapper(result))
|
advertisements = append(advertisements, mapper.AdvertisementResponseMapper(result, host))
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
@ -75,7 +79,8 @@ func (_i *advertisementService) Show(id uint) (advertisement *response.Advertise
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapper.AdvertisementResponseMapper(result), nil
|
host := _i.Cfg.App.Domain
|
||||||
|
return mapper.AdvertisementResponseMapper(result, host), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *advertisementService) Save(req request.AdvertisementCreateRequest) (advertisement *entity.Advertisement, err error) {
|
func (_i *advertisementService) Save(req request.AdvertisementCreateRequest) (advertisement *entity.Advertisement, err error) {
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ type UserLevelsController interface {
|
||||||
Save(c *fiber.Ctx) error
|
Save(c *fiber.Ctx) error
|
||||||
Update(c *fiber.Ctx) error
|
Update(c *fiber.Ctx) error
|
||||||
Delete(c *fiber.Ctx) error
|
Delete(c *fiber.Ctx) error
|
||||||
|
EnableApproval(c *fiber.Ctx) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUserLevelsController(userLevelsService service.UserLevelsService) UserLevelsController {
|
func NewUserLevelsController(userLevelsService service.UserLevelsService) UserLevelsController {
|
||||||
|
|
@ -212,3 +213,37 @@ func (_i *userLevelsController) Delete(c *fiber.Ctx) error {
|
||||||
Messages: utilRes.Messages{"UserLevels successfully deleted"},
|
Messages: utilRes.Messages{"UserLevels successfully deleted"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EnableApproval Articles
|
||||||
|
// @Summary EnableApproval Articles
|
||||||
|
// @Description API for Enable Approval of Article
|
||||||
|
// @Tags UserLevels
|
||||||
|
// @Security Bearer
|
||||||
|
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||||
|
// @Param id query int false "user level id"
|
||||||
|
// @Param isApprovalActive query string false "approval status"
|
||||||
|
// @Success 200 {object} response.Response
|
||||||
|
// @Failure 400 {object} response.BadRequestError
|
||||||
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
|
// @Failure 500 {object} response.InternalServerError
|
||||||
|
// @Router /articles/enable-approval [post]
|
||||||
|
func (_i *userLevelsController) EnableApproval(c *fiber.Ctx) error {
|
||||||
|
id, err := strconv.ParseUint(c.Query("id"), 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
isApprovalActive, err := strconv.ParseBool(c.Query("isPublish"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = _i.userLevelsService.EnableApproval(uint(id), isApprovalActive)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return utilRes.Resp(c, utilRes.Response{
|
||||||
|
Success: true,
|
||||||
|
Messages: utilRes.Messages{"isApprovalActive of UserLevels successfully saved"},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ type UserLevelsService interface {
|
||||||
Save(req request.UserLevelsCreateRequest) (userLevels *entity.UserLevels, err error)
|
Save(req request.UserLevelsCreateRequest) (userLevels *entity.UserLevels, err error)
|
||||||
Update(id uint, req request.UserLevelsUpdateRequest) (err error)
|
Update(id uint, req request.UserLevelsUpdateRequest) (err error)
|
||||||
Delete(id uint) error
|
Delete(id uint) error
|
||||||
|
EnableApproval(id uint, isApprovalActive bool) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUserLevelsService init UserLevelsService
|
// NewUserLevelsService init UserLevelsService
|
||||||
|
|
@ -96,3 +97,14 @@ func (_i *userLevelsService) Delete(id uint) error {
|
||||||
result.IsActive = &isActive
|
result.IsActive = &isActive
|
||||||
return _i.Repo.Update(id, result)
|
return _i.Repo.Update(id, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (_i *userLevelsService) EnableApproval(id uint, isApprovalActive bool) (err error) {
|
||||||
|
result, err := _i.Repo.FindOne(id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*result.IsApprovalActive = isApprovalActive
|
||||||
|
|
||||||
|
return _i.Repo.Update(id, result)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,5 +50,6 @@ func (_i *UserLevelsRouter) RegisterUserLevelsRoutes() {
|
||||||
router.Post("/", userLevelsController.Save)
|
router.Post("/", userLevelsController.Save)
|
||||||
router.Put("/:id", userLevelsController.Update)
|
router.Put("/:id", userLevelsController.Update)
|
||||||
router.Delete("/:id", userLevelsController.Delete)
|
router.Delete("/:id", userLevelsController.Delete)
|
||||||
|
router.Put("/approval/:id", userLevelsController.EnableApproval)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3319,6 +3319,67 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/articles/enable-approval": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "API for Enable Approval of Article",
|
||||||
|
"tags": [
|
||||||
|
"UserLevels"
|
||||||
|
],
|
||||||
|
"summary": "EnableApproval Articles",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"default": "Bearer \u003cAdd access token here\u003e",
|
||||||
|
"description": "Insert your access token",
|
||||||
|
"name": "Authorization",
|
||||||
|
"in": "header"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "user level id",
|
||||||
|
"name": "id",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "approval status",
|
||||||
|
"name": "isApprovalActive",
|
||||||
|
"in": "query"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.BadRequestError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.UnauthorizedError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.InternalServerError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/articles/publish-scheduling": {
|
"/articles/publish-scheduling": {
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
"security": [
|
||||||
|
|
|
||||||
|
|
@ -3308,6 +3308,67 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/articles/enable-approval": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "API for Enable Approval of Article",
|
||||||
|
"tags": [
|
||||||
|
"UserLevels"
|
||||||
|
],
|
||||||
|
"summary": "EnableApproval Articles",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"default": "Bearer \u003cAdd access token here\u003e",
|
||||||
|
"description": "Insert your access token",
|
||||||
|
"name": "Authorization",
|
||||||
|
"in": "header"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "user level id",
|
||||||
|
"name": "id",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "approval status",
|
||||||
|
"name": "isApprovalActive",
|
||||||
|
"in": "query"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.BadRequestError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.UnauthorizedError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.InternalServerError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/articles/publish-scheduling": {
|
"/articles/publish-scheduling": {
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
"security": [
|
||||||
|
|
|
||||||
|
|
@ -3100,6 +3100,45 @@ paths:
|
||||||
summary: Update Banner Articles
|
summary: Update Banner Articles
|
||||||
tags:
|
tags:
|
||||||
- Articles
|
- Articles
|
||||||
|
/articles/enable-approval:
|
||||||
|
post:
|
||||||
|
description: API for Enable Approval of Article
|
||||||
|
parameters:
|
||||||
|
- default: Bearer <Add access token here>
|
||||||
|
description: Insert your access token
|
||||||
|
in: header
|
||||||
|
name: Authorization
|
||||||
|
type: string
|
||||||
|
- description: user level id
|
||||||
|
in: query
|
||||||
|
name: id
|
||||||
|
type: integer
|
||||||
|
- description: approval status
|
||||||
|
in: query
|
||||||
|
name: isApprovalActive
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.BadRequestError'
|
||||||
|
"401":
|
||||||
|
description: Unauthorized
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.UnauthorizedError'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.InternalServerError'
|
||||||
|
security:
|
||||||
|
- Bearer: []
|
||||||
|
summary: EnableApproval Articles
|
||||||
|
tags:
|
||||||
|
- UserLevels
|
||||||
/articles/publish-scheduling:
|
/articles/publish-scheduling:
|
||||||
post:
|
post:
|
||||||
description: API for Publish Schedule of Article
|
description: API for Publish Schedule of Article
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue