feat: update user levels and advertisement
This commit is contained in:
parent
f97f8ab34d
commit
b55f806f6b
|
|
@ -5,7 +5,7 @@ import (
|
|||
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 {
|
||||
advertisementRes = &res.AdvertisementResponse{
|
||||
ID: advertisementReq.ID,
|
||||
|
|
@ -18,6 +18,10 @@ func AdvertisementResponseMapper(advertisementReq *entity.Advertisement) (advert
|
|||
CreatedAt: advertisementReq.CreatedAt,
|
||||
UpdatedAt: advertisementReq.UpdatedAt,
|
||||
}
|
||||
|
||||
if advertisementReq.ContentFilePath != nil {
|
||||
advertisementRes.ContentFileUrl = host + "/advertisement/viewer/" + *advertisementReq.ContentFileName
|
||||
}
|
||||
}
|
||||
return advertisementRes
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@ package response
|
|||
import "time"
|
||||
|
||||
type AdvertisementResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
RedirectLink string `json:"redirectLink"`
|
||||
Placement string `json:"placement"`
|
||||
StatusId int `json:"statusId"`
|
||||
IsActive bool `json:"isActive"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
RedirectLink string `json:"redirectLink"`
|
||||
ContentFileUrl string `json:"contentFileUrl"`
|
||||
Placement string `json:"placement"`
|
||||
StatusId int `json:"statusId"`
|
||||
IsActive bool `json:"isActive"`
|
||||
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/response"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
config "go-humas-be/config/config"
|
||||
minioStorage "go-humas-be/config/config"
|
||||
"go-humas-be/utils/paginator"
|
||||
"io"
|
||||
|
|
@ -29,6 +30,7 @@ type advertisementService struct {
|
|||
Repo repository.AdvertisementRepository
|
||||
UsersRepo usersRepository.UsersRepository
|
||||
Log zerolog.Logger
|
||||
Cfg *config.Config
|
||||
MinioStorage *minioStorage.MinioStorage
|
||||
}
|
||||
|
||||
|
|
@ -45,13 +47,14 @@ type AdvertisementService interface {
|
|||
}
|
||||
|
||||
// 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{
|
||||
Repo: repo,
|
||||
UsersRepo: usersRepo,
|
||||
MinioStorage: minioStorage,
|
||||
Log: log,
|
||||
Cfg: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -62,8 +65,9 @@ func (_i *advertisementService) All(req request.AdvertisementQueryRequest) (adve
|
|||
return
|
||||
}
|
||||
|
||||
host := _i.Cfg.App.Domain
|
||||
for _, result := range results {
|
||||
advertisements = append(advertisements, mapper.AdvertisementResponseMapper(result))
|
||||
advertisements = append(advertisements, mapper.AdvertisementResponseMapper(result, host))
|
||||
}
|
||||
|
||||
return
|
||||
|
|
@ -75,7 +79,8 @@ func (_i *advertisementService) Show(id uint) (advertisement *response.Advertise
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ type UserLevelsController interface {
|
|||
Save(c *fiber.Ctx) error
|
||||
Update(c *fiber.Ctx) error
|
||||
Delete(c *fiber.Ctx) error
|
||||
EnableApproval(c *fiber.Ctx) error
|
||||
}
|
||||
|
||||
func NewUserLevelsController(userLevelsService service.UserLevelsService) UserLevelsController {
|
||||
|
|
@ -212,3 +213,37 @@ func (_i *userLevelsController) Delete(c *fiber.Ctx) error {
|
|||
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)
|
||||
Update(id uint, req request.UserLevelsUpdateRequest) (err error)
|
||||
Delete(id uint) error
|
||||
EnableApproval(id uint, isApprovalActive bool) (err error)
|
||||
}
|
||||
|
||||
// NewUserLevelsService init UserLevelsService
|
||||
|
|
@ -96,3 +97,14 @@ func (_i *userLevelsService) Delete(id uint) error {
|
|||
result.IsActive = &isActive
|
||||
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.Put("/:id", userLevelsController.Update)
|
||||
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": {
|
||||
"post": {
|
||||
"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": {
|
||||
"post": {
|
||||
"security": [
|
||||
|
|
|
|||
|
|
@ -3100,6 +3100,45 @@ paths:
|
|||
summary: Update Banner Articles
|
||||
tags:
|
||||
- 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:
|
||||
post:
|
||||
description: API for Publish Schedule of Article
|
||||
|
|
|
|||
Loading…
Reference in New Issue