feat: update refactoring ppid to humas
This commit is contained in:
parent
649a4946da
commit
e130e39dde
|
|
@ -19,7 +19,6 @@ build-2:
|
|||
command: [ "--insecure-registry=103.82.242.92:8900" ]
|
||||
script:
|
||||
- docker login -u $DEPLOY_USERNAME -p $DEPLOY_TOKEN 103.82.242.92:8900
|
||||
# - docker build -t registry.gitlab.com/hanifsalafi/web-humas-be:dev .
|
||||
- docker-compose build
|
||||
- docker tag registry.gitlab.com/hanifsalafi/web-humas-be:dev 103.82.242.92:8900/humas/web-humas-be:dev
|
||||
- docker push 103.82.242.92:8900/humas/web-humas-be:dev
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
|
|
@ -1 +0,0 @@
|
|||
go-humas-be
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/../go-humas-be/.idea/go-humas-be.iml" filepath="$PROJECT_DIR$/../go-humas-be/.idea/go-humas-be.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/go-humas-be.iml" filepath="$PROJECT_DIR$/.idea/go-humas-be.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type PpidDataApprovalHistories struct {
|
||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||
Message string `json:"message" gorm:"type:varchar"`
|
||||
ApprovalStatusId int `json:"approval_status_id" gorm:"type:int4"`
|
||||
PpidDataId uint `json:"ppid_data_id" gorm:"type:int4"`
|
||||
ApprovalBy uint `json:"approval_by" gorm:"type:int4"`
|
||||
ApprovalAtLevel int `json:"approval_at_level" gorm:"type:int4"`
|
||||
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()"`
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type PpidDataCategories struct {
|
||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||
Title string `json:"title" gorm:"type:varchar"`
|
||||
Description string `json:"description" gorm:"type:varchar"`
|
||||
Slug string `json:"slug" gorm:"type:varchar"`
|
||||
ParentId *uint `json:"parent_id" gorm:"type:int4"`
|
||||
CreatedById *uint `json:"created_by_id" gorm:"type:int4"`
|
||||
LevelGroupId *uint `json:"level_group_id" gorm:"type:int4"`
|
||||
GroupBy *string `json:"group_by" gorm:"type:int4"`
|
||||
Position *int `json:"position" gorm:"type:int4"`
|
||||
ThumbnailPath *string `json:"thumbnail_path" gorm:"type:varchar"`
|
||||
ThumbnailUrl *string `json:"thumbnail_url" 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()"`
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type PpidDataFiles struct {
|
||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||
PpidDataId int `json:"ppid_data_id" gorm:"type:int4"`
|
||||
Title *string `json:"title" gorm:"type:varchar"`
|
||||
Type *string `json:"type" gorm:"type:varchar"`
|
||||
FileType *string `json:"file_type" gorm:"type:varchar"`
|
||||
FileName *string `json:"file_name" gorm:"type:varchar"`
|
||||
FilePath *string `json:"file_path" gorm:"type:varchar"`
|
||||
FileUrl *string `json:"file_url" gorm:"type:varchar"`
|
||||
Size *string `json:"size" gorm:"type:varchar"`
|
||||
Position *int `json:"position" gorm:"type:int4"`
|
||||
DownloadCount *int `json:"download_count" gorm:"type:int4;default:0"`
|
||||
CreatedById *int `json:"created_by_id" gorm:"type:int4"`
|
||||
StatusId *int `json:"status_id" gorm:"type:int4"`
|
||||
IsPublish *bool `json:"is_publish" gorm:"type:bool;default:false"`
|
||||
PublishedAt *time.Time `json:"published_at" gorm:"type:timestamp"`
|
||||
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()"`
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type PpidDatas struct {
|
||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||
Title string `json:"title" gorm:"type:varchar"`
|
||||
Description string `json:"description" gorm:"type:varchar"`
|
||||
Slug string `json:"slug" gorm:"type:varchar"`
|
||||
CategoryId uint `json:"category_id" gorm:"index"`
|
||||
Category PpidDataCategories `json:"category" gorm:"foreignKey:CategoryId;references:ID"`
|
||||
CreatedById *uint `json:"created_by_id" gorm:"index"`
|
||||
CreatedBy Users `json:"created_by" gorm:"foreignKey:CreatedById;references:ID"`
|
||||
LevelGroupId *uint `json:"level_group_id" gorm:"index"`
|
||||
LevelGroup UserLevels `json:"level_group" gorm:"foreignKey:LevelGroupId;references:ID"`
|
||||
Group *string `json:"group" gorm:"type:varchar"`
|
||||
Position *int `json:"position" gorm:"type:int4"`
|
||||
NeedApprovalFromUserRole *string `json:"need_approval_from_user_role" gorm:"type:varchar"`
|
||||
NeedApprovalFromUserLevel *string `json:"need_approval_from_user_level" gorm:"type:varchar"`
|
||||
BackApprovalToUserRole *string `json:"back_approval_to_user_role" gorm:"type:varchar"`
|
||||
BackApprovalToUserLevel *string `json:"back_approval_to_user_level" gorm:"type:varchar"`
|
||||
IsPublish *bool `json:"is_publish" gorm:"type:bool;default:false"`
|
||||
PublishLevel *int `json:"publish_level" gorm:"type:int4"`
|
||||
PublishedAt *time.Time `json:"published_at" gorm:"type:timestamp"`
|
||||
ApprovalStatusId int `json:"approval_status_id" gorm:"type:int4"`
|
||||
StatusId int `json:"status_id" gorm:"type:int4"`
|
||||
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()"`
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type RequestForInformationItems struct {
|
||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||
RequestForInformationId int `json:"request_for_information_id" gorm:"type:int4"`
|
||||
RequestedInfo string `json:"requested_info" gorm:"type:varchar"`
|
||||
DetailedInfo string `json:"detailed_info" gorm:"type:varchar"`
|
||||
Reason string `json:"reason" gorm:"type:varchar"`
|
||||
StatusId int `json:"status_id" gorm:"type:int4"`
|
||||
IsActive *bool `json:"is_active" gorm:"type:bool"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type RequestForInformationObjection struct {
|
||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||
RequestForInformationItemId uint `json:"request_for_information_item_id" gorm:"type:int4"`
|
||||
DocumentName string `json:"document_name" gorm:"type:varchar"`
|
||||
MainReason string `json:"main_reason" gorm:"type:varchar"`
|
||||
SecondaryReason string `json:"secondary_reason" gorm:"type:varchar"`
|
||||
CreatedById uint `json:"created_by_id" gorm:"type:int4"`
|
||||
StatusId int `json:"status_id" gorm:"type:int4"`
|
||||
IsActive *bool `json:"is_active" gorm:"type:bool"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type RequestForInformationObjectionReplies struct {
|
||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||
RequestForInformationObjectionId int `json:"request_for_information_objection_id" gorm:"type:int4"`
|
||||
Response string `json:"response" gorm:"type:varchar"`
|
||||
StatusId int `json:"status_id" gorm:"type:int4"`
|
||||
CreatedById *uint `json:"created_by_id" gorm:"type:int4"`
|
||||
IsActive *bool `json:"is_active" gorm:"type:bool"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type RequestForInformationReplies struct {
|
||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||
RequestForInformationItemId int `json:"request_for_information_item_id" gorm:"type:int4"`
|
||||
FileUrl string `json:"file_url" gorm:"type:varchar"`
|
||||
Response string `json:"response" gorm:"type:varchar"`
|
||||
StatusId int `json:"status_id" gorm:"type:int4"`
|
||||
CreatedById *uint `json:"created_by_id" gorm:"type:int4"`
|
||||
IsActive *bool `json:"is_active" gorm:"type:bool"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type RequestForInformations struct {
|
||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||
TicketNumber string `json:"ticket_number" gorm:"type:varchar"`
|
||||
HowToGetInfo string `json:"how_to_get_info" gorm:"type:varchar"`
|
||||
HowToGetFiles string `json:"how_to_get_files" gorm:"type:varchar"`
|
||||
NextAction string `json:"next_action" gorm:"type:varchar"`
|
||||
StatusId int `json:"status_id" gorm:"type:int4"`
|
||||
CreatedById *uint `json:"created_by_id" gorm:"type:int4"`
|
||||
IsActive *bool `json:"is_active" gorm:"type:bool"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||
}
|
||||
|
|
@ -79,16 +79,7 @@ func Models() []interface{} {
|
|||
entity.MasterModules{},
|
||||
entity.MasterStatuses{},
|
||||
entity.MasterApprovalStatuses{},
|
||||
entity.PpidDatas{},
|
||||
entity.PpidDataFiles{},
|
||||
entity.PpidDataApprovalHistories{},
|
||||
entity.PpidDataCategories{},
|
||||
entity.Provinces{},
|
||||
entity.RequestForInformations{},
|
||||
entity.RequestForInformationItems{},
|
||||
entity.RequestForInformationReplies{},
|
||||
entity.RequestForInformationObjection{},
|
||||
entity.RequestForInformationObjectionReplies{},
|
||||
entity.UserLevels{},
|
||||
entity.UserRoles{},
|
||||
entity.UserRoleAccesses{},
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ func (_i *articleCategoriesController) Save(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
// SaveThumbnail PpidDataCategories
|
||||
// SaveThumbnail ArticleCategories
|
||||
// @Summary Upload ArticleCategories Thumbnail
|
||||
// @Description API for Upload ArticleCategories Thumbnail
|
||||
// @Tags Article Categories
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
package controller
|
||||
|
||||
import "go-humas-be/app/module/ppid_data_approval_histories/service"
|
||||
|
||||
type Controller struct {
|
||||
PpidDataApprovalHistories PpidDataApprovalHistoriesController
|
||||
}
|
||||
|
||||
func NewController(PpidDataApprovalHistoriesService service.PpidDataApprovalHistoriesService) *Controller {
|
||||
return &Controller{
|
||||
PpidDataApprovalHistories: NewPpidDataApprovalHistoriesController(PpidDataApprovalHistoriesService),
|
||||
}
|
||||
}
|
||||
|
|
@ -1,169 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go-humas-be/app/module/ppid_data_approval_histories/request"
|
||||
"go-humas-be/app/module/ppid_data_approval_histories/service"
|
||||
"strconv"
|
||||
|
||||
utilRes "go-humas-be/utils/response"
|
||||
utilVal "go-humas-be/utils/validator"
|
||||
)
|
||||
|
||||
type ppidDataApprovalHistoriesController struct {
|
||||
ppidDataApprovalHistoriesService service.PpidDataApprovalHistoriesService
|
||||
}
|
||||
|
||||
type PpidDataApprovalHistoriesController interface {
|
||||
All(c *fiber.Ctx) error
|
||||
Show(c *fiber.Ctx) error
|
||||
ShowByPpidData(c *fiber.Ctx) error
|
||||
Save(c *fiber.Ctx) error
|
||||
Delete(c *fiber.Ctx) error
|
||||
}
|
||||
|
||||
func NewPpidDataApprovalHistoriesController(ppidDataApprovalHistoriesService service.PpidDataApprovalHistoriesService) PpidDataApprovalHistoriesController {
|
||||
return &ppidDataApprovalHistoriesController{
|
||||
ppidDataApprovalHistoriesService: ppidDataApprovalHistoriesService,
|
||||
}
|
||||
}
|
||||
|
||||
// All PpidDataApprovalHistories
|
||||
// @Summary Get all PpidDataApprovalHistories
|
||||
// @Description API for getting all PpidDataApprovalHistories
|
||||
// @Tags Task
|
||||
// @Security Bearer
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-approval-histories [get]
|
||||
func (_i *ppidDataApprovalHistoriesController) All(c *fiber.Ctx) error {
|
||||
ppidDataApprovalHistoriesData, err := _i.ppidDataApprovalHistoriesService.All()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataApprovalHistories list successfully retrieved"},
|
||||
Data: ppidDataApprovalHistoriesData,
|
||||
})
|
||||
}
|
||||
|
||||
// Show PpidDataApprovalHistories
|
||||
// @Summary Get one PpidDataApprovalHistories
|
||||
// @Description API for getting one PpidDataApprovalHistories
|
||||
// @Tags Task
|
||||
// @Security Bearer
|
||||
// @Param id path int true "PpidDataApprovalHistories ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-approval-histories/{id} [get]
|
||||
func (_i *ppidDataApprovalHistoriesController) Show(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ppidDataApprovalHistoriesData, err := _i.ppidDataApprovalHistoriesService.Show(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataApprovalHistories successfully retrieved"},
|
||||
Data: ppidDataApprovalHistoriesData,
|
||||
})
|
||||
}
|
||||
|
||||
// ShowByPpidData PpidDataApprovalHistories
|
||||
// @Summary Get one PpidDataApprovalHistories
|
||||
// @Description API for getting one PpidDataApprovalHistories
|
||||
// @Tags Task
|
||||
// @Security Bearer
|
||||
// @Param ppidDataId path int true "PpidData ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-approval-histories/ppid-data/:ppidDataId [get]
|
||||
func (_i *ppidDataApprovalHistoriesController) ShowByPpidData(c *fiber.Ctx) error {
|
||||
ppidDataId, err := strconv.Atoi(c.Params("ppidDataId"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ppidDataApprovalHistoriesData, err := _i.ppidDataApprovalHistoriesService.ShowByPpidData(uint(ppidDataId))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataApprovalHistories successfully retrieved"},
|
||||
Data: ppidDataApprovalHistoriesData,
|
||||
})
|
||||
}
|
||||
|
||||
// Save create PpidDataApprovalHistories
|
||||
// @Summary Create PpidDataApprovalHistories
|
||||
// @Description API for create PpidDataApprovalHistories
|
||||
// @Tags Task
|
||||
// @Security Bearer
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Body request.PpidDataApprovalHistoriesCreateRequest
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 401 {object} response.Response
|
||||
// @Failure 404 {object} response.Response
|
||||
// @Failure 422 {object} response.Response
|
||||
// @Failure 500 {object} response.Response
|
||||
// @Router /ppid-data-approval-histories [post]
|
||||
func (_i *ppidDataApprovalHistoriesController) Save(c *fiber.Ctx) error {
|
||||
req := new(request.PpidDataApprovalHistoriesCreateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
authToken := c.Get("Authorization")
|
||||
|
||||
err := _i.ppidDataApprovalHistoriesService.Save(*req, authToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Messages: utilRes.Messages{"PpidDataApprovalHistories successfully created"},
|
||||
})
|
||||
}
|
||||
|
||||
// Delete delete PpidDataApprovalHistories
|
||||
// @Summary delete PpidDataApprovalHistories
|
||||
// @Description API for delete PpidDataApprovalHistories
|
||||
// @Tags Task
|
||||
// @Security Bearer
|
||||
// @Param id path int true "PpidDataApprovalHistories ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 401 {object} response.Response
|
||||
// @Failure 404 {object} response.Response
|
||||
// @Failure 422 {object} response.Response
|
||||
// @Failure 500 {object} response.Response
|
||||
// @Router /ppid-data-approval-histories/{id} [delete]
|
||||
func (_i *ppidDataApprovalHistoriesController) Delete(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.ppidDataApprovalHistoriesService.Delete(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Messages: utilRes.Messages{"PpidDataApprovalHistories successfully deleted"},
|
||||
})
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
res "go-humas-be/app/module/ppid_data_approval_histories/response"
|
||||
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
)
|
||||
|
||||
func PpidDataApprovalHistoriesResponseMapper(ppidDataApprovalHistoriesReq *entity.PpidDataApprovalHistories, usersRepo usersRepository.UsersRepository) (ppidDataApprovalHistoriesRes *res.PpidDataApprovalHistoriesResponse) {
|
||||
if ppidDataApprovalHistoriesReq != nil {
|
||||
findUser, _ := usersRepo.FindOne(ppidDataApprovalHistoriesReq.ApprovalBy)
|
||||
createdByName := ""
|
||||
if findUser != nil {
|
||||
createdByName = findUser.Fullname
|
||||
}
|
||||
|
||||
ppidDataApprovalHistoriesRes = &res.PpidDataApprovalHistoriesResponse{
|
||||
ID: ppidDataApprovalHistoriesReq.ID,
|
||||
Message: ppidDataApprovalHistoriesReq.Message,
|
||||
ApprovalStatusId: ppidDataApprovalHistoriesReq.ApprovalStatusId,
|
||||
PpidDataId: ppidDataApprovalHistoriesReq.PpidDataId,
|
||||
ApprovalById: ppidDataApprovalHistoriesReq.ApprovalBy,
|
||||
ApprovalByName: createdByName,
|
||||
ApprovalAtLevel: ppidDataApprovalHistoriesReq.ApprovalAtLevel,
|
||||
IsActive: ppidDataApprovalHistoriesReq.IsActive,
|
||||
CreatedAt: ppidDataApprovalHistoriesReq.CreatedAt,
|
||||
UpdatedAt: ppidDataApprovalHistoriesReq.UpdatedAt,
|
||||
}
|
||||
}
|
||||
return ppidDataApprovalHistoriesRes
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
package ppid_data_approval_histories
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go-humas-be/app/module/ppid_data_approval_histories/controller"
|
||||
"go-humas-be/app/module/ppid_data_approval_histories/repository"
|
||||
"go-humas-be/app/module/ppid_data_approval_histories/service"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
// struct of PpidDataApprovalHistoriesRouter
|
||||
type PpidDataApprovalHistoriesRouter struct {
|
||||
App fiber.Router
|
||||
Controller *controller.Controller
|
||||
}
|
||||
|
||||
// register bulky of PpidDataApprovalHistories module
|
||||
var NewPpidDataApprovalHistoriesModule = fx.Options(
|
||||
// register repository of PpidDataApprovalHistories module
|
||||
fx.Provide(repository.NewPpidDataApprovalHistoriesRepository),
|
||||
|
||||
// register service of PpidDataApprovalHistories module
|
||||
fx.Provide(service.NewPpidDataApprovalHistoriesService),
|
||||
|
||||
// register controller of PpidDataApprovalHistories module
|
||||
fx.Provide(controller.NewController),
|
||||
|
||||
// register router of PpidDataApprovalHistories module
|
||||
fx.Provide(NewPpidDataApprovalHistoriesRouter),
|
||||
)
|
||||
|
||||
// init PpidDataApprovalHistoriesRouter
|
||||
func NewPpidDataApprovalHistoriesRouter(fiber *fiber.App, controller *controller.Controller) *PpidDataApprovalHistoriesRouter {
|
||||
return &PpidDataApprovalHistoriesRouter{
|
||||
App: fiber,
|
||||
Controller: controller,
|
||||
}
|
||||
}
|
||||
|
||||
// register routes of PpidDataApprovalHistories module
|
||||
func (_i *PpidDataApprovalHistoriesRouter) RegisterPpidDataApprovalHistoriesRoutes() {
|
||||
// define controllers
|
||||
ppidDataApprovalHistoriesController := _i.Controller.PpidDataApprovalHistories
|
||||
|
||||
// define routes
|
||||
_i.App.Route("/ppid-data-approval-histories", func(router fiber.Router) {
|
||||
router.Get("/", ppidDataApprovalHistoriesController.All)
|
||||
router.Get("/:id", ppidDataApprovalHistoriesController.Show)
|
||||
router.Get("/ppid-data/:ppidDataId", ppidDataApprovalHistoriesController.ShowByPpidData)
|
||||
router.Post("/", ppidDataApprovalHistoriesController.Save)
|
||||
router.Delete("/:id", ppidDataApprovalHistoriesController.Delete)
|
||||
})
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database"
|
||||
"go-humas-be/app/database/entity"
|
||||
)
|
||||
|
||||
type ppidDataApprovalHistoriesRepository struct {
|
||||
DB *database.Database
|
||||
}
|
||||
|
||||
// PpidDataApprovalHistoriesRepository define interface of IPpidDataApprovalHistoriesRepository
|
||||
type PpidDataApprovalHistoriesRepository interface {
|
||||
GetAll() (ppidDataApprovalHistories []*entity.PpidDataApprovalHistories, err error)
|
||||
FindOne(id uint) (ppidDataApprovalHistories *entity.PpidDataApprovalHistories, err error)
|
||||
FindByPpidData(ppidDataId uint) (ppidDataApprovalHistories []*entity.PpidDataApprovalHistories, err error)
|
||||
Create(ppidDataApprovalHistories *entity.PpidDataApprovalHistories) (err error)
|
||||
Update(id uint, ppidDataApprovalHistories *entity.PpidDataApprovalHistories) (err error)
|
||||
Delete(id uint) (err error)
|
||||
}
|
||||
|
||||
func NewPpidDataApprovalHistoriesRepository(db *database.Database) PpidDataApprovalHistoriesRepository {
|
||||
return &ppidDataApprovalHistoriesRepository{
|
||||
DB: db,
|
||||
}
|
||||
}
|
||||
|
||||
// implement interface of IPpidDataApprovalHistoriesRepository
|
||||
func (_i *ppidDataApprovalHistoriesRepository) GetAll() (ppidDataApprovalHistories []*entity.PpidDataApprovalHistories, err error) {
|
||||
if err := _i.DB.DB.Find(&ppidDataApprovalHistories).
|
||||
Where(&entity.PpidDataApprovalHistories{IsActive: true}).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ppidDataApprovalHistories, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataApprovalHistoriesRepository) FindOne(id uint) (ppidDataApprovalHistories *entity.PpidDataApprovalHistories, err error) {
|
||||
if err := _i.DB.DB.First(&ppidDataApprovalHistories, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ppidDataApprovalHistories, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataApprovalHistoriesRepository) FindByPpidData(ppidDataId uint) (ppidDataApprovalHistories []*entity.PpidDataApprovalHistories, err error) {
|
||||
if err := _i.DB.DB.Find(&ppidDataApprovalHistories).
|
||||
Where(&entity.PpidDataApprovalHistories{PpidDataId: ppidDataId, IsActive: true}).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ppidDataApprovalHistories, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataApprovalHistoriesRepository) Create(ppidDataApprovalHistories *entity.PpidDataApprovalHistories) (err error) {
|
||||
return _i.DB.DB.Create(ppidDataApprovalHistories).Error
|
||||
}
|
||||
|
||||
func (_i *ppidDataApprovalHistoriesRepository) Update(id uint, ppidDataApprovalHistories *entity.PpidDataApprovalHistories) (err error) {
|
||||
return _i.DB.DB.Model(&entity.PpidDataApprovalHistories{}).
|
||||
Where(&entity.PpidDataApprovalHistories{ID: id}).
|
||||
Updates(ppidDataApprovalHistories).Error
|
||||
}
|
||||
|
||||
func (_i *ppidDataApprovalHistoriesRepository) Delete(id uint) error {
|
||||
return _i.DB.DB.Delete(&entity.PpidDataApprovalHistories{}, id).Error
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
)
|
||||
|
||||
type PpidDataApprovalHistoriesGeneric interface {
|
||||
ToEntity()
|
||||
}
|
||||
|
||||
type PpidDataApprovalHistoriesCreateRequest struct {
|
||||
PpidDataId uint `json:"ppidDataId" validate:"required"`
|
||||
Message string `json:"message" validate:"required"`
|
||||
ApprovalStatusId int `json:"approvalStatusId" validate:"required"`
|
||||
ApprovalAtLevel *int `json:"approvalAtLevel"`
|
||||
}
|
||||
|
||||
func (req PpidDataApprovalHistoriesCreateRequest) ToEntity() *entity.PpidDataApprovalHistories {
|
||||
return &entity.PpidDataApprovalHistories{
|
||||
PpidDataId: req.PpidDataId,
|
||||
Message: req.Message,
|
||||
ApprovalStatusId: req.ApprovalStatusId,
|
||||
ApprovalAtLevel: *req.ApprovalAtLevel,
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package response
|
||||
|
||||
import "time"
|
||||
|
||||
type PpidDataApprovalHistoriesResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Message string `json:"message"`
|
||||
ApprovalStatusId int `json:"approval_status_id"`
|
||||
PpidDataId uint `json:"ppid_data_id"`
|
||||
ApprovalById uint `json:"approval_by_id"`
|
||||
ApprovalByName string `json:"approval_by_name"`
|
||||
ApprovalAtLevel int `json:"approval_at_level"`
|
||||
IsActive bool `json:"is_active"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/ppid_data_approval_histories/mapper"
|
||||
"go-humas-be/app/module/ppid_data_approval_histories/repository"
|
||||
"go-humas-be/app/module/ppid_data_approval_histories/request"
|
||||
"go-humas-be/app/module/ppid_data_approval_histories/response"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
)
|
||||
|
||||
// PpidDataApprovalHistoriesService
|
||||
type ppidDataApprovalHistoriesService struct {
|
||||
Repo repository.PpidDataApprovalHistoriesRepository
|
||||
UsersRepo usersRepository.UsersRepository
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// PpidDataApprovalHistoriesService define interface of IPpidDataApprovalHistoriesService
|
||||
type PpidDataApprovalHistoriesService interface {
|
||||
All() (ppidDataApprovalHistories []*response.PpidDataApprovalHistoriesResponse, err error)
|
||||
Show(id uint) (ppidDataApprovalHistories *response.PpidDataApprovalHistoriesResponse, err error)
|
||||
ShowByPpidData(ppidDataId uint) (ppidDataApprovalHistories []*response.PpidDataApprovalHistoriesResponse, err error)
|
||||
Save(req request.PpidDataApprovalHistoriesCreateRequest, authToken string) (err error)
|
||||
Delete(id uint) error
|
||||
}
|
||||
|
||||
// NewPpidDataApprovalHistoriesService init PpidDataApprovalHistoriesService
|
||||
func NewPpidDataApprovalHistoriesService(repo repository.PpidDataApprovalHistoriesRepository, usersRepo usersRepository.UsersRepository, log zerolog.Logger) PpidDataApprovalHistoriesService {
|
||||
|
||||
return &ppidDataApprovalHistoriesService{
|
||||
Repo: repo,
|
||||
UsersRepo: usersRepo,
|
||||
Log: log,
|
||||
}
|
||||
}
|
||||
|
||||
// All implement interface of PpidDataApprovalHistoriesService
|
||||
func (_i *ppidDataApprovalHistoriesService) All() (ppidDataApprovalHistories []*response.PpidDataApprovalHistoriesResponse, err error) {
|
||||
results, err := _i.Repo.GetAll()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
ppidDataApprovalHistories = append(ppidDataApprovalHistories, mapper.PpidDataApprovalHistoriesResponseMapper(result, _i.UsersRepo))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *ppidDataApprovalHistoriesService) Show(id uint) (ppidDataApprovalHistories *response.PpidDataApprovalHistoriesResponse, err error) {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mapper.PpidDataApprovalHistoriesResponseMapper(result, _i.UsersRepo), nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataApprovalHistoriesService) ShowByPpidData(ppidDataId uint) (ppidDataApprovalHistories []*response.PpidDataApprovalHistoriesResponse, err error) {
|
||||
results, err := _i.Repo.FindByPpidData(ppidDataId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
ppidDataApprovalHistories = append(ppidDataApprovalHistories, mapper.PpidDataApprovalHistoriesResponseMapper(result, _i.UsersRepo))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *ppidDataApprovalHistoriesService) Save(req request.PpidDataApprovalHistoriesCreateRequest, authToken string) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
newReq := req.ToEntity()
|
||||
|
||||
createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||
newReq.ApprovalBy = createdBy.ID
|
||||
|
||||
return _i.Repo.Create(newReq)
|
||||
}
|
||||
|
||||
func (_i *ppidDataApprovalHistoriesService) Delete(id uint) error {
|
||||
return _i.Repo.Delete(id)
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/ppid_data_categories/service"
|
||||
)
|
||||
|
||||
type Controller struct {
|
||||
PpidDataCategories PpidDataCategoriesController
|
||||
}
|
||||
|
||||
func NewController(PpidDataCategoriesService service.PpidDataCategoriesService, log zerolog.Logger) *Controller {
|
||||
return &Controller{
|
||||
PpidDataCategories: NewPpidDataCategoriesController(PpidDataCategoriesService, log),
|
||||
}
|
||||
}
|
||||
|
|
@ -1,321 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/ppid_data_categories/request"
|
||||
"go-humas-be/app/module/ppid_data_categories/response"
|
||||
"go-humas-be/app/module/ppid_data_categories/service"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
utilRes "go-humas-be/utils/response"
|
||||
utilVal "go-humas-be/utils/validator"
|
||||
)
|
||||
|
||||
type ppidDataCategoriesController struct {
|
||||
ppidDataCategoriesService service.PpidDataCategoriesService
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
type PpidDataCategoriesController interface {
|
||||
All(c *fiber.Ctx) error
|
||||
Show(c *fiber.Ctx) error
|
||||
ShowBySlug(c *fiber.Ctx) error
|
||||
Save(c *fiber.Ctx) error
|
||||
SaveThumbnail(c *fiber.Ctx) error
|
||||
Update(c *fiber.Ctx) error
|
||||
UpdatePosition(c *fiber.Ctx) error
|
||||
Delete(c *fiber.Ctx) error
|
||||
Viewer(c *fiber.Ctx) error
|
||||
}
|
||||
|
||||
func NewPpidDataCategoriesController(ppidDataCategoriesService service.PpidDataCategoriesService, log zerolog.Logger) PpidDataCategoriesController {
|
||||
return &ppidDataCategoriesController{
|
||||
ppidDataCategoriesService: ppidDataCategoriesService,
|
||||
Log: log,
|
||||
}
|
||||
}
|
||||
|
||||
// All PpidDataCategories
|
||||
// @Summary Get all PpidDataCategories
|
||||
// @Description API for getting all PpidDataCategories
|
||||
// @Tags PPID Categories
|
||||
// @Security Bearer
|
||||
// @Param Authorization header string false "Insert your access token" default (Bearer <Add access token here>)
|
||||
// @Param req query request.PpidDataCategoriesQueryRequest 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 /ppid-data-categories [get]
|
||||
func (_i *ppidDataCategoriesController) All(c *fiber.Ctx) error {
|
||||
paginate, err := paginator.Paginate(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
reqContext := request.PpidDataCategoriesQueryRequestContext{
|
||||
Title: c.Query("title"),
|
||||
Description: c.Query("description"),
|
||||
ParentId: c.Query("parentId"),
|
||||
IsOnlyTop: c.Query("isOnlyTop"),
|
||||
Group: c.Query("group"),
|
||||
LevelGroup: c.Query("levelGroup"),
|
||||
IsPpidDataIncluded: c.Query("isPpidDataIncluded"),
|
||||
}
|
||||
req := reqContext.ToParamRequest()
|
||||
|
||||
authToken := c.Get("Authorization")
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:All", "ppidDataCategoriesController").
|
||||
Interface("authToken", authToken).Msg("")
|
||||
|
||||
req.Pagination = paginate
|
||||
var ppidDataCategoriesData []*response.PpidDataCategoriesResponse
|
||||
var ppidDataCategoriesWithPpidDataResponse []*response.PpidDataCategoriesWithPpidDataResponse
|
||||
var paging paginator.Pagination
|
||||
|
||||
isPpidDataIncluded := req.IsPpidDataIncluded
|
||||
if isPpidDataIncluded != nil && *isPpidDataIncluded == true {
|
||||
ppidDataCategoriesWithPpidDataResponse, paging, err = _i.ppidDataCategoriesService.AllInPpidData(req, authToken)
|
||||
} else {
|
||||
ppidDataCategoriesData, paging, err = _i.ppidDataCategoriesService.All(req)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var dataResponse any
|
||||
if ppidDataCategoriesData != nil {
|
||||
dataResponse = ppidDataCategoriesData
|
||||
} else {
|
||||
dataResponse = ppidDataCategoriesWithPpidDataResponse
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataCategories list successfully retrieved"},
|
||||
Data: dataResponse,
|
||||
Meta: paging,
|
||||
})
|
||||
}
|
||||
|
||||
// Show PpidDataCategories
|
||||
// @Summary Get one PpidDataCategories
|
||||
// @Description API for getting one PpidDataCategories
|
||||
// @Tags PPID Categories
|
||||
// @Security Bearer
|
||||
// @Param id path int true "PpidDataCategories ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-categories/{id} [get]
|
||||
func (_i *ppidDataCategoriesController) Show(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ppidDataCategoriesData, err := _i.ppidDataCategoriesService.Show(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataCategories successfully retrieved"},
|
||||
Data: ppidDataCategoriesData,
|
||||
})
|
||||
}
|
||||
|
||||
// ShowBySlug PpidDataCategories
|
||||
// @Summary Get one PpidDataCategories
|
||||
// @Description API for getting one PpidDataCategories
|
||||
// @Tags PPID Categories
|
||||
// @Security Bearer
|
||||
// @Param slug path string true "PpidDataCategories Slug"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-categories/slug/{slug} [get]
|
||||
func (_i *ppidDataCategoriesController) ShowBySlug(c *fiber.Ctx) error {
|
||||
slug := c.Params("slug")
|
||||
|
||||
ppidDataCategoriesData, err := _i.ppidDataCategoriesService.ShowBySlug(slug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataCategories successfully retrieved"},
|
||||
Data: ppidDataCategoriesData,
|
||||
})
|
||||
}
|
||||
|
||||
// Save PpidDataCategories
|
||||
// @Summary Create PpidDataCategories
|
||||
// @Description API for create PpidDataCategories
|
||||
// @Tags PPID Categories
|
||||
// @Security Bearer
|
||||
// @Param Authorization header string true "Insert your access token" default (Bearer <Add access token here>)
|
||||
// @Param payload body request.PpidDataCategoriesCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-categories [post]
|
||||
func (_i *ppidDataCategoriesController) Save(c *fiber.Ctx) error {
|
||||
req := new(request.PpidDataCategoriesCreateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
authToken := c.Get("Authorization")
|
||||
err := _i.ppidDataCategoriesService.Save(*req, authToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataCategories successfully created"},
|
||||
})
|
||||
}
|
||||
|
||||
// SaveThumbnail PpidDataCategories
|
||||
// @Summary Upload PpidDataCategories Thumbnail
|
||||
// @Description API for Upload PpidDataCategories Thumbnail
|
||||
// @Tags PPID Categories
|
||||
// @Security Bearer
|
||||
// @Produce json
|
||||
// @Param files formData file true "Upload thumbnail"
|
||||
// @Param id path int true "Ppid Data Category ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-categories/thumbnail/{id} [post]
|
||||
func (_i *ppidDataCategoriesController) SaveThumbnail(c *fiber.Ctx) error {
|
||||
err := _i.ppidDataCategoriesService.SaveThumbnail(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"Thumbnail of PpidDataFiles successfully created"},
|
||||
})
|
||||
}
|
||||
|
||||
// Update PpidDataCategories
|
||||
// @Summary Update PpidDataCategories
|
||||
// @Description API for update PpidDataCategories
|
||||
// @Tags PPID Categories
|
||||
// @Security Bearer
|
||||
// @Param payload body request.PpidDataCategoriesUpdateRequest true "Required payload"
|
||||
// @Param id path int true "PpidDataCategories ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-categories/{id} [put]
|
||||
func (_i *ppidDataCategoriesController) Update(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := new(request.PpidDataCategoriesUpdateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.ppidDataCategoriesService.Update(uint(id), *req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataCategories successfully updated"},
|
||||
})
|
||||
}
|
||||
|
||||
// UpdatePosition PpidDataCategories
|
||||
// @Summary UpdatePosition PpidDataCategories
|
||||
// @Description API for Update Position PpidDataCategories
|
||||
// @Tags PPID Categories
|
||||
// @Security Bearer
|
||||
// @Param payload body request.PpidDataCategoriesUpdatePositionPayload true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-categories/position [post]
|
||||
func (_i *ppidDataCategoriesController) UpdatePosition(c *fiber.Ctx) error {
|
||||
req := new(request.PpidDataCategoriesUpdatePositionPayload)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := _i.ppidDataCategoriesService.UpdatePosition(req.Positions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataCategories successfully updated"},
|
||||
})
|
||||
}
|
||||
|
||||
// Delete PpidDataCategories
|
||||
// @Summary Delete PpidDataCategories
|
||||
// @Description API for delete PpidDataCategories
|
||||
// @Tags PPID Categories
|
||||
// @Security Bearer
|
||||
// @Param id path int true "PpidDataCategories ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-categories/{id} [delete]
|
||||
func (_i *ppidDataCategoriesController) Delete(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.ppidDataCategoriesService.Delete(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataCategories successfully deleted"},
|
||||
})
|
||||
}
|
||||
|
||||
// Viewer PpidDataCategories
|
||||
// @Summary Viewer PpidDataCategories
|
||||
// @Description API for View Thumbnail of PpidDataCategories
|
||||
// @Tags PPID Categories
|
||||
// @Security Bearer
|
||||
// @Param id path string true "PPID Categories ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-categories/thumbnail/viewer/{id} [get]
|
||||
func (_i *ppidDataCategoriesController) Viewer(c *fiber.Ctx) error {
|
||||
return _i.ppidDataCategoriesService.Viewer(c)
|
||||
}
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/ppid_data_categories/repository"
|
||||
res "go-humas-be/app/module/ppid_data_categories/response"
|
||||
ppidDataFilesRepository "go-humas-be/app/module/ppid_data_files/repository"
|
||||
"go-humas-be/app/module/ppid_datas/mapper"
|
||||
ppidDatasRepository "go-humas-be/app/module/ppid_datas/repository"
|
||||
"go-humas-be/app/module/ppid_datas/request"
|
||||
"go-humas-be/app/module/ppid_datas/response"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
"go-humas-be/utils/paginator"
|
||||
)
|
||||
|
||||
func PpidDataCategoriesResponseMapper(ppidDataCategoriesReq *entity.PpidDataCategories, childPpidDataCategoriesReq []*entity.PpidDataCategories) (ppidDataCategoriesRes *res.PpidDataCategoriesResponse) {
|
||||
if ppidDataCategoriesReq != nil {
|
||||
var childPpidDataCategoriesRes []*res.PpidDataCategoriesResponse
|
||||
if childPpidDataCategoriesReq != nil && len(childPpidDataCategoriesReq) > 0 {
|
||||
for _, item := range childPpidDataCategoriesReq {
|
||||
childPpidDataCategoriesRes = append(childPpidDataCategoriesRes, PpidDataCategoriesResponseMapper(item, nil))
|
||||
}
|
||||
}
|
||||
|
||||
ppidDataCategoriesRes = &res.PpidDataCategoriesResponse{
|
||||
ID: ppidDataCategoriesReq.ID,
|
||||
Title: ppidDataCategoriesReq.Title,
|
||||
Description: ppidDataCategoriesReq.Description,
|
||||
Slug: ppidDataCategoriesReq.Slug,
|
||||
ParentId: ppidDataCategoriesReq.ParentId,
|
||||
Position: ppidDataCategoriesReq.Position,
|
||||
LevelGroupId: ppidDataCategoriesReq.LevelGroupId,
|
||||
GroupBy: ppidDataCategoriesReq.GroupBy,
|
||||
ThumbnailUrl: ppidDataCategoriesReq.ThumbnailUrl,
|
||||
IsActive: ppidDataCategoriesReq.IsActive,
|
||||
CreatedAt: ppidDataCategoriesReq.CreatedAt,
|
||||
UpdatedAt: ppidDataCategoriesReq.UpdatedAt,
|
||||
|
||||
Children: childPpidDataCategoriesRes,
|
||||
}
|
||||
}
|
||||
return ppidDataCategoriesRes
|
||||
}
|
||||
|
||||
func PpidDataCategoriesWithPpidDataResponseMapper(
|
||||
log zerolog.Logger,
|
||||
ppidDataCategoriesReq *entity.PpidDataCategories,
|
||||
ppidDataCategoriesRepo repository.PpidDataCategoriesRepository,
|
||||
ppidDatasRepo ppidDatasRepository.PpidDatasRepository,
|
||||
ppidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository,
|
||||
usersRepo usersRepository.UsersRepository,
|
||||
) (ppidDataCategoriesRes *res.PpidDataCategoriesWithPpidDataResponse) {
|
||||
if ppidDataCategoriesReq != nil {
|
||||
pagination := paginator.Pagination{
|
||||
Limit: -1,
|
||||
}
|
||||
|
||||
ppidDatasReq := request.PpidDatasQueryRequest{
|
||||
CategoryId: &ppidDataCategoriesReq.ID,
|
||||
Pagination: &pagination,
|
||||
}
|
||||
|
||||
ppidDatas, _, _ := ppidDatasRepo.GetAll(ppidDatasReq)
|
||||
|
||||
var ppidDatasArr []*response.PpidDatasResponse
|
||||
if len(ppidDatas) > 0 {
|
||||
for _, result := range ppidDatas {
|
||||
ppidDatasArr = append(ppidDatasArr, mapper.PpidDatasResponseMapper(log, ppidDataCategoriesRepo, ppidDataFilesRepo, usersRepo, result))
|
||||
}
|
||||
}
|
||||
|
||||
ppidDataCategoriesRes = &res.PpidDataCategoriesWithPpidDataResponse{
|
||||
ID: ppidDataCategoriesReq.ID,
|
||||
Title: ppidDataCategoriesReq.Title,
|
||||
Description: ppidDataCategoriesReq.Description,
|
||||
Slug: ppidDataCategoriesReq.Slug,
|
||||
ParentId: ppidDataCategoriesReq.ParentId,
|
||||
Position: ppidDataCategoriesReq.Position,
|
||||
LevelGroupId: ppidDataCategoriesReq.LevelGroupId,
|
||||
GroupBy: ppidDataCategoriesReq.GroupBy,
|
||||
ThumbnailUrl: ppidDataCategoriesReq.ThumbnailUrl,
|
||||
IsActive: ppidDataCategoriesReq.IsActive,
|
||||
CreatedAt: ppidDataCategoriesReq.CreatedAt,
|
||||
UpdatedAt: ppidDataCategoriesReq.UpdatedAt,
|
||||
|
||||
PpidDatas: ppidDatasArr,
|
||||
}
|
||||
}
|
||||
return ppidDataCategoriesRes
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
package ppid_data_categories
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go-humas-be/app/module/ppid_data_categories/controller"
|
||||
"go-humas-be/app/module/ppid_data_categories/repository"
|
||||
"go-humas-be/app/module/ppid_data_categories/service"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
// struct of PpidDataCategoriesRouter
|
||||
type PpidDataCategoriesRouter struct {
|
||||
App fiber.Router
|
||||
Controller *controller.Controller
|
||||
}
|
||||
|
||||
// register bulky of PpidDataCategories module
|
||||
var NewPpidDataCategoriesModule = fx.Options(
|
||||
// register repository of PpidDataCategories module
|
||||
fx.Provide(repository.NewPpidDataCategoriesRepository),
|
||||
|
||||
// register service of PpidDataCategories module
|
||||
fx.Provide(service.NewPpidDataCategoriesService),
|
||||
|
||||
// register controller of PpidDataCategories module
|
||||
fx.Provide(controller.NewController),
|
||||
|
||||
// register router of PpidDataCategories module
|
||||
fx.Provide(NewPpidDataCategoriesRouter),
|
||||
)
|
||||
|
||||
// init PpidDataCategoriesRouter
|
||||
func NewPpidDataCategoriesRouter(fiber *fiber.App, controller *controller.Controller) *PpidDataCategoriesRouter {
|
||||
return &PpidDataCategoriesRouter{
|
||||
App: fiber,
|
||||
Controller: controller,
|
||||
}
|
||||
}
|
||||
|
||||
// register routes of PpidDataCategories module
|
||||
func (_i *PpidDataCategoriesRouter) RegisterPpidDataCategoriesRoutes() {
|
||||
// define controllers
|
||||
ppidDataCategoriesController := _i.Controller.PpidDataCategories
|
||||
|
||||
// define routes
|
||||
_i.App.Route("/ppid-data-categories", func(router fiber.Router) {
|
||||
router.Get("/", ppidDataCategoriesController.All)
|
||||
router.Get("/:id", ppidDataCategoriesController.Show)
|
||||
router.Get("/slug/:slug", ppidDataCategoriesController.ShowBySlug)
|
||||
router.Post("/", ppidDataCategoriesController.Save)
|
||||
router.Put("/:id", ppidDataCategoriesController.Update)
|
||||
router.Post("/position", ppidDataCategoriesController.UpdatePosition)
|
||||
router.Post("/thumbnail/:id", ppidDataCategoriesController.SaveThumbnail)
|
||||
router.Get("/thumbnail/viewer/:id", ppidDataCategoriesController.Viewer)
|
||||
router.Delete("/:id", ppidDataCategoriesController.Delete)
|
||||
})
|
||||
}
|
||||
|
|
@ -1,185 +0,0 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/ppid_data_categories/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ppidDataCategoriesRepository struct {
|
||||
DB *database.Database
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// PpidDataCategoriesRepository define interface of IPpidDataCategoriesRepository
|
||||
type PpidDataCategoriesRepository interface {
|
||||
GetAll(req request.PpidDataCategoriesQueryRequest) (ppidDataCategoriess []*entity.PpidDataCategories, paging paginator.Pagination, err error)
|
||||
GetAllNonPage(req request.PpidDataCategoriesQueryRequest) (ppidDataCategoriess []*entity.PpidDataCategories, paging paginator.Pagination, err error)
|
||||
FindOne(id uint) (ppidDataCategories *entity.PpidDataCategories, err error)
|
||||
FindOneBySlug(slug string) (ppidDataCategories *entity.PpidDataCategories, err error)
|
||||
FindOneLastPosition() (ppidDataCategories *entity.PpidDataCategories, err error)
|
||||
Create(ppidDataCategories *entity.PpidDataCategories) (err error)
|
||||
Update(id uint, ppidDataCategories *entity.PpidDataCategories) (err error)
|
||||
UpdateAll(ppidDataCategories []*entity.PpidDataCategories) (err error)
|
||||
Delete(id uint) (err error)
|
||||
}
|
||||
|
||||
func NewPpidDataCategoriesRepository(db *database.Database, logger zerolog.Logger) PpidDataCategoriesRepository {
|
||||
return &ppidDataCategoriesRepository{
|
||||
DB: db,
|
||||
Log: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// implement interface of IPpidDataCategoriesRepository
|
||||
func (_i *ppidDataCategoriesRepository) GetAll(req request.PpidDataCategoriesQueryRequest) (ppidDataCategoriess []*entity.PpidDataCategories, paging paginator.Pagination, err error) {
|
||||
var count int64
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:GetAlls", "Interface:ppidDataCategoriesRepository").
|
||||
Interface("req", req).Msg("")
|
||||
|
||||
query := _i.DB.DB.Model(&entity.PpidDataCategories{})
|
||||
query = query.Where("is_active = ?", true)
|
||||
|
||||
if req.Title != nil && *req.Title != "" {
|
||||
title := strings.ToLower(*req.Title)
|
||||
query = query.Where("LOWER(title) LIKE ?", "%"+strings.ToLower(title)+"%")
|
||||
}
|
||||
if req.Description != nil && *req.Description != "" {
|
||||
description := strings.ToLower(*req.Description)
|
||||
query = query.Where("LOWER(description) LIKE ?", "%"+strings.ToLower(description)+"%")
|
||||
}
|
||||
if req.ParentId != nil {
|
||||
query = query.Where("parent_id = ?", req.ParentId)
|
||||
}
|
||||
if req.Group != nil {
|
||||
query = query.Where("group_by = ?", req.Group)
|
||||
}
|
||||
if req.LevelGroupId != nil {
|
||||
query = query.Where("level_group_id = ?", req.LevelGroupId)
|
||||
}
|
||||
if req.IsOnlyTop != nil {
|
||||
if *req.IsOnlyTop == true {
|
||||
query = query.Where("parent_id IS NULL")
|
||||
}
|
||||
}
|
||||
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(&ppidDataCategoriess).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
paging = *req.Pagination
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// implement interface of IPpidDataCategoriesRepository
|
||||
func (_i *ppidDataCategoriesRepository) GetAllNonPage(req request.PpidDataCategoriesQueryRequest) (ppidDataCategoriess []*entity.PpidDataCategories, paging paginator.Pagination, err error) {
|
||||
var count int64
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:GetAll", "Interface:ppidDataCategoriesRepository").
|
||||
Interface("req", req).Msg("")
|
||||
|
||||
query := _i.DB.DB.Model(&entity.PpidDataCategories{})
|
||||
query = query.Where("is_active = ?", true)
|
||||
|
||||
if req.Title != nil && *req.Title != "" {
|
||||
title := strings.ToLower(*req.Title)
|
||||
query = query.Where("LOWER(title) LIKE ?", "%"+strings.ToLower(title)+"%")
|
||||
}
|
||||
if req.Description != nil && *req.Description != "" {
|
||||
description := strings.ToLower(*req.Description)
|
||||
query = query.Where("LOWER(description) LIKE ?", "%"+strings.ToLower(description)+"%")
|
||||
}
|
||||
if req.ParentId != nil {
|
||||
query = query.Where("parent_id = ?", req.ParentId)
|
||||
}
|
||||
if req.IsOnlyTop != nil {
|
||||
if *req.IsOnlyTop == true {
|
||||
query = query.Where("parent_id IS NULL")
|
||||
}
|
||||
}
|
||||
query.Count(&count)
|
||||
|
||||
err = query.Find(&ppidDataCategoriess).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesRepository) FindOne(id uint) (ppidDataCategories *entity.PpidDataCategories, err error) {
|
||||
if err := _i.DB.DB.First(&ppidDataCategories, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ppidDataCategories, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesRepository) FindOneBySlug(slug string) (ppidDataCategories *entity.PpidDataCategories, err error) {
|
||||
if err := _i.DB.DB.Where("slug = ?", slug).First(&ppidDataCategories).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:FindOneBySlug", "Interface:FindOneBySlug").
|
||||
Interface("ppidDataCategories", ppidDataCategories).Msg("")
|
||||
|
||||
return ppidDataCategories, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesRepository) FindOneLastPosition() (ppidDataCategories *entity.PpidDataCategories, err error) {
|
||||
if err := _i.DB.DB.Where("position IS NOT NULL").Last(&ppidDataCategories).
|
||||
Order(fmt.Sprintf("%s %s", "position", "DESC")).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ppidDataCategories, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesRepository) Create(ppidDataCategories *entity.PpidDataCategories) (err error) {
|
||||
return _i.DB.DB.Create(ppidDataCategories).Error
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesRepository) Update(id uint, ppidDataCategories *entity.PpidDataCategories) (err error) {
|
||||
return _i.DB.DB.Model(&entity.PpidDataCategories{}).
|
||||
Where(&entity.PpidDataCategories{ID: id}).
|
||||
Updates(ppidDataCategories).Error
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesRepository) UpdateAll(ppidDataCategories []*entity.PpidDataCategories) (err error) {
|
||||
for _, req := range ppidDataCategories {
|
||||
err := _i.DB.DB.Model(&entity.PpidDataCategories{}).
|
||||
Where(&entity.PpidDataCategories{ID: req.ID}).
|
||||
Updates(req).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesRepository) Delete(id uint) error {
|
||||
return _i.DB.DB.Delete(&entity.PpidDataCategories{}, id).Error
|
||||
}
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PpidDataCategoriesGeneric interface {
|
||||
ToEntity()
|
||||
}
|
||||
|
||||
type PpidDataCategoriesQueryRequest struct {
|
||||
Title *string `json:"title"`
|
||||
Description *string `json:"description"`
|
||||
IsOnlyTop *bool `json:"isOnlyTop"`
|
||||
IsPpidDataIncluded *bool `json:"isPpidDataIncluded"`
|
||||
ParentId *uint `json:"parentId"`
|
||||
Group *string `json:"group"`
|
||||
LevelGroup *string `json:"levelGroup"`
|
||||
LevelGroupId *uint `json:"levelGroupId"`
|
||||
Pagination *paginator.Pagination `json:"pagination"`
|
||||
}
|
||||
|
||||
type PpidDataCategoriesCreateRequest struct {
|
||||
Title string `json:"title" validate:"required"`
|
||||
Description string `json:"description" validate:"required"`
|
||||
Slug string `json:"slug" validate:"required"`
|
||||
ParentId *uint `json:"parentId"`
|
||||
}
|
||||
|
||||
func (req PpidDataCategoriesCreateRequest) ToEntity() *entity.PpidDataCategories {
|
||||
return &entity.PpidDataCategories{
|
||||
Title: req.Title,
|
||||
Description: req.Description,
|
||||
Slug: req.Slug,
|
||||
ParentId: req.ParentId,
|
||||
}
|
||||
}
|
||||
|
||||
type PpidDataCategoriesUpdateRequest struct {
|
||||
ID uint `json:"id" validate:"required"`
|
||||
Title string `json:"title" validate:"required"`
|
||||
Description string `json:"description" validate:"required"`
|
||||
Slug string `json:"slug" validate:"required"`
|
||||
ParentId *uint `json:"parentId"`
|
||||
}
|
||||
|
||||
func (req PpidDataCategoriesUpdateRequest) ToEntity() *entity.PpidDataCategories {
|
||||
return &entity.PpidDataCategories{
|
||||
ID: req.ID,
|
||||
Title: req.Title,
|
||||
Description: req.Description,
|
||||
Slug: req.Slug,
|
||||
ParentId: req.ParentId,
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
type PpidDataCategoriesUpdatePositionPayload struct {
|
||||
Positions []PpidDataCategoriesUpdatePositionRequest `json:"positions"`
|
||||
}
|
||||
|
||||
type PpidDataCategoriesUpdatePositionRequest struct {
|
||||
ID uint `json:"id" validate:"required"`
|
||||
Position int `json:"position" validate:"required"`
|
||||
}
|
||||
|
||||
func (req PpidDataCategoriesUpdatePositionRequest) ToEntity() *entity.PpidDataCategories {
|
||||
return &entity.PpidDataCategories{
|
||||
ID: req.ID,
|
||||
Position: &req.Position,
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
type PpidDataCategoriesQueryRequestContext struct {
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
IsOnlyTop string `json:"isOnlyTop"`
|
||||
IsPpidDataIncluded string `json:"isPpidDataIncluded"`
|
||||
Group string `json:"group"`
|
||||
LevelGroup string `json:"levelGroup"`
|
||||
LevelGroupId string `json:"levelGroupId"`
|
||||
ParentId string `json:"parentId"`
|
||||
}
|
||||
|
||||
func (req PpidDataCategoriesQueryRequestContext) ToParamRequest() PpidDataCategoriesQueryRequest {
|
||||
var request PpidDataCategoriesQueryRequest
|
||||
|
||||
if title := req.Title; title != "" {
|
||||
request.Title = &title
|
||||
}
|
||||
if description := req.Description; description != "" {
|
||||
request.Description = &description
|
||||
}
|
||||
if parentIdStr := req.ParentId; parentIdStr != "" {
|
||||
parentId, err := strconv.ParseUint(parentIdStr, 10, 0)
|
||||
parentIdUint := uint(parentId)
|
||||
if err == nil {
|
||||
request.ParentId = &parentIdUint
|
||||
}
|
||||
}
|
||||
if isOnlyTopStr := req.IsOnlyTop; isOnlyTopStr != "" {
|
||||
isOnlyTop, err := strconv.ParseBool(isOnlyTopStr)
|
||||
if err == nil {
|
||||
request.IsOnlyTop = &isOnlyTop
|
||||
}
|
||||
}
|
||||
if group := req.Group; group != "" {
|
||||
request.Group = &group
|
||||
}
|
||||
if levelGroup := req.LevelGroup; levelGroup != "" {
|
||||
request.LevelGroup = &levelGroup
|
||||
}
|
||||
if levelGroupIdStr := req.LevelGroupId; levelGroupIdStr != "" {
|
||||
levelGroupId, err := strconv.ParseUint(levelGroupIdStr, 10, 0)
|
||||
levelGroupIdUint := uint(levelGroupId)
|
||||
if err == nil {
|
||||
request.LevelGroupId = &levelGroupIdUint
|
||||
}
|
||||
}
|
||||
if isPpidDataIncludedStr := req.IsPpidDataIncluded; isPpidDataIncludedStr != "" {
|
||||
isPpidDataIncluded, err := strconv.ParseBool(isPpidDataIncludedStr)
|
||||
if err == nil {
|
||||
request.IsPpidDataIncluded = &isPpidDataIncluded
|
||||
}
|
||||
}
|
||||
|
||||
return request
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
package response
|
||||
|
||||
import (
|
||||
"go-humas-be/app/module/ppid_datas/response"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PpidDataCategoriesResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Slug string `json:"slug"`
|
||||
ParentId *uint `json:"parentId"`
|
||||
Position *int `json:"position"`
|
||||
LevelGroupId *uint `json:"levelGroupId"`
|
||||
GroupBy *string `json:"groupBy"`
|
||||
ThumbnailUrl *string `json:"thumbnailUrl"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
|
||||
Children []*PpidDataCategoriesResponse `json:"children"`
|
||||
}
|
||||
|
||||
type PpidDataCategoriesWithPpidDataResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Slug string `json:"slug"`
|
||||
ParentId *uint `json:"parentId"`
|
||||
Position *int `json:"position"`
|
||||
LevelGroupId *uint `json:"levelGroupId"`
|
||||
GroupBy *string `json:"groupBy"`
|
||||
ThumbnailUrl *string `json:"thumbnailUrl"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
|
||||
PpidDatas []*response.PpidDatasResponse `json:"ppidDatas"`
|
||||
}
|
||||
|
|
@ -1,369 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/ppid_data_categories/mapper"
|
||||
"go-humas-be/app/module/ppid_data_categories/repository"
|
||||
"go-humas-be/app/module/ppid_data_categories/request"
|
||||
"go-humas-be/app/module/ppid_data_categories/response"
|
||||
ppidDataFilesRepository "go-humas-be/app/module/ppid_data_files/repository"
|
||||
ppidDatasRepository "go-humas-be/app/module/ppid_datas/repository"
|
||||
userLevelsRepository "go-humas-be/app/module/user_levels/repository"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
config "go-humas-be/config/config"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"mime"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// PpidDataCategoriesService
|
||||
type ppidDataCategoriesService struct {
|
||||
Repo repository.PpidDataCategoriesRepository
|
||||
PpidDatasRepo ppidDatasRepository.PpidDatasRepository
|
||||
PpidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository
|
||||
UsersRepo usersRepository.UsersRepository
|
||||
UserLevelsRepo userLevelsRepository.UserLevelsRepository
|
||||
MinioStorage *config.MinioStorage
|
||||
Log zerolog.Logger
|
||||
Cfg *config.Config
|
||||
}
|
||||
|
||||
// PpidDataCategoriesService define interface of IPpidDataCategoriesService
|
||||
type PpidDataCategoriesService interface {
|
||||
All(req request.PpidDataCategoriesQueryRequest) (ppidDataCategories []*response.PpidDataCategoriesResponse, paging paginator.Pagination, err error)
|
||||
AllInPpidData(req request.PpidDataCategoriesQueryRequest, authToken string) (ppidDataCategories []*response.PpidDataCategoriesWithPpidDataResponse, paging paginator.Pagination, err error)
|
||||
Show(id uint) (ppidDataCategories *response.PpidDataCategoriesResponse, err error)
|
||||
ShowBySlug(slug string) (ppidDataCategories *response.PpidDataCategoriesResponse, err error)
|
||||
Save(req request.PpidDataCategoriesCreateRequest, authToken string) (err error)
|
||||
SaveThumbnail(c *fiber.Ctx) (err error)
|
||||
Update(id uint, req request.PpidDataCategoriesUpdateRequest) (err error)
|
||||
UpdatePosition(req []request.PpidDataCategoriesUpdatePositionRequest) (err error)
|
||||
Delete(id uint) error
|
||||
Viewer(c *fiber.Ctx) error
|
||||
}
|
||||
|
||||
// NewPpidDataCategoriesService init PpidDataCategoriesService
|
||||
func NewPpidDataCategoriesService(
|
||||
repo repository.PpidDataCategoriesRepository,
|
||||
ppidDatasRepo ppidDatasRepository.PpidDatasRepository,
|
||||
ppidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository,
|
||||
usersRepo usersRepository.UsersRepository,
|
||||
userLevelsRepo userLevelsRepository.UserLevelsRepository,
|
||||
minioStorage *config.MinioStorage,
|
||||
log zerolog.Logger,
|
||||
cfg *config.Config,
|
||||
) PpidDataCategoriesService {
|
||||
|
||||
return &ppidDataCategoriesService{
|
||||
Repo: repo,
|
||||
PpidDatasRepo: ppidDatasRepo,
|
||||
PpidDataFilesRepo: ppidDataFilesRepo,
|
||||
UsersRepo: usersRepo,
|
||||
UserLevelsRepo: userLevelsRepo,
|
||||
MinioStorage: minioStorage,
|
||||
Log: log,
|
||||
Cfg: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
// All implement interface of PpidDataCategoriesService
|
||||
func (_i *ppidDataCategoriesService) All(req request.PpidDataCategoriesQueryRequest) (ppidDataCategories []*response.PpidDataCategoriesResponse, paging paginator.Pagination, err error) {
|
||||
results, paging, err := _i.Repo.GetAll(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
req := request.PpidDataCategoriesQueryRequest{
|
||||
ParentId: &result.ID,
|
||||
}
|
||||
subResult, _, _ := _i.Repo.GetAllNonPage(req)
|
||||
ppidDataCategories = append(ppidDataCategories, mapper.PpidDataCategoriesResponseMapper(result, subResult))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesService) AllInPpidData(req request.PpidDataCategoriesQueryRequest, authToken string) (ppidDataCategories []*response.PpidDataCategoriesWithPpidDataResponse, paging paginator.Pagination, err error) {
|
||||
|
||||
if req.LevelGroup != nil {
|
||||
findLevel, err := _i.UserLevelsRepo.FindOneByAlias(*req.LevelGroup)
|
||||
if err != nil {
|
||||
return ppidDataCategories, paging, err
|
||||
}
|
||||
if findLevel != nil {
|
||||
req.LevelGroupId = &findLevel.ID
|
||||
}
|
||||
} else {
|
||||
createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||
if createdBy != nil {
|
||||
req.LevelGroupId = &createdBy.UserLevelId
|
||||
} else {
|
||||
mabesGroup := "mabes"
|
||||
req.Group = &mabesGroup
|
||||
}
|
||||
}
|
||||
results, paging, err := _i.Repo.GetAll(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
ppidDataCategories = append(ppidDataCategories, mapper.PpidDataCategoriesWithPpidDataResponseMapper(_i.Log, result, _i.Repo, _i.PpidDatasRepo, _i.PpidDataFilesRepo, _i.UsersRepo))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesService) Show(id uint) (ppidDataCategories *response.PpidDataCategoriesResponse, err error) {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req := request.PpidDataCategoriesQueryRequest{
|
||||
ParentId: &result.ID,
|
||||
}
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:Show", "Interface:ppidDataCategoriesService").
|
||||
Interface("req", req).Msg("")
|
||||
|
||||
subResult, _, _ := _i.Repo.GetAllNonPage(req)
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:Show", "Interface:ppidDataCategoriesService").
|
||||
Interface("res", subResult).Msg("")
|
||||
|
||||
return mapper.PpidDataCategoriesResponseMapper(result, subResult), nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesService) ShowBySlug(slug string) (ppidDataCategories *response.PpidDataCategoriesResponse, err error) {
|
||||
result, err := _i.Repo.FindOneBySlug(slug)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req := request.PpidDataCategoriesQueryRequest{
|
||||
ParentId: &result.ID,
|
||||
Pagination: &paginator.Pagination{
|
||||
Limit: 20,
|
||||
},
|
||||
}
|
||||
subResult, _, _ := _i.Repo.GetAll(req)
|
||||
|
||||
return mapper.PpidDataCategoriesResponseMapper(result, subResult), nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesService) Save(req request.PpidDataCategoriesCreateRequest, authToken string) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
|
||||
lastPpidData, _ := _i.Repo.FindOneLastPosition()
|
||||
lastPosition := lastPpidData.Position
|
||||
*lastPosition += 1
|
||||
|
||||
newReq := req.ToEntity()
|
||||
newReq.Position = lastPosition
|
||||
|
||||
createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||
if createdBy != nil {
|
||||
newReq.CreatedById = &createdBy.ID
|
||||
newReq.LevelGroupId = &createdBy.UserLevelId
|
||||
|
||||
userLevels, err := _i.UserLevelsRepo.FindOne(uint(createdBy.UserLevelId))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if userLevels != nil {
|
||||
newReq.GroupBy = userLevels.Group
|
||||
}
|
||||
}
|
||||
|
||||
return _i.Repo.Create(newReq)
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesService) SaveThumbnail(c *fiber.Ctx) (err error) {
|
||||
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
host := _i.Cfg.App.Domain
|
||||
port := _i.Cfg.App.ExternalPort
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:SaveThumbnail", "Categories:SaveThumbnail").
|
||||
Interface("id", id).Msg("")
|
||||
|
||||
bucketName := _i.MinioStorage.Cfg.ObjectStorage.MinioStorage.BucketName
|
||||
|
||||
form, err := c.MultipartForm()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
files := form.File["files"]
|
||||
|
||||
// Create minio connection.
|
||||
minioClient, err := _i.MinioStorage.ConnectMinio()
|
||||
if err != nil {
|
||||
// Return status 500 and minio connection error.
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": true,
|
||||
"msg": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
// Iterasi semua file yang diunggah
|
||||
for _, file := range files {
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:Resource", "Uploader:: loop1").
|
||||
Interface("data", file).Msg("")
|
||||
|
||||
src, err := file.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
filename := filepath.Base(file.Filename)
|
||||
filename = strings.ReplaceAll(filename, " ", "")
|
||||
filenameWithoutExt := filepath.Clean(filename[:len(filename)-len(filepath.Ext(filename))])
|
||||
extension := filepath.Ext(file.Filename)[1:]
|
||||
|
||||
rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
randUniqueId := rand.Intn(1000000)
|
||||
|
||||
newFilenameWithoutExt := filenameWithoutExt + "_" + strconv.Itoa(randUniqueId)
|
||||
newFilename := newFilenameWithoutExt + "." + extension
|
||||
objectName := "ppid/category/thumbnail/" + newFilename
|
||||
|
||||
findCategory, err := _i.Repo.FindOne(uint(id))
|
||||
|
||||
thumbnailUrl := host + port + "/ppid-data-categories/thumbnail/viewer/" + strconv.Itoa(int(id))
|
||||
|
||||
findCategory.ThumbnailPath = &objectName
|
||||
findCategory.ThumbnailUrl = &thumbnailUrl
|
||||
|
||||
err = _i.Repo.Update(uint(id), findCategory)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Upload file ke MinIO
|
||||
_, err = minioClient.PutObject(context.Background(), bucketName, objectName, src, file.Size, minio.PutObjectOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:Resource", "User:All").
|
||||
Interface("data", "Successfully uploaded").Msg("")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesService) Update(id uint, req request.PpidDataCategoriesUpdateRequest) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
return _i.Repo.Update(id, req.ToEntity())
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesService) UpdatePosition(req []request.PpidDataCategoriesUpdatePositionRequest) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
|
||||
var entityReq []*entity.PpidDataCategories
|
||||
for _, reqItem := range req {
|
||||
entityReq = append(entityReq, reqItem.ToEntity())
|
||||
}
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:UpdatePosition", "ppidDataCategoriesController").
|
||||
Interface("entityReq", entityReq).Msg("")
|
||||
|
||||
return _i.Repo.UpdateAll(entityReq)
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesService) Delete(id uint) error {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
isActive := false
|
||||
result.IsActive = &isActive
|
||||
return _i.Repo.Update(id, result)
|
||||
}
|
||||
|
||||
func (_i *ppidDataCategoriesService) Viewer(c *fiber.Ctx) (err error) {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
result, err := _i.Repo.FindOne(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if result.ThumbnailPath == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
bucketName := _i.MinioStorage.Cfg.ObjectStorage.MinioStorage.BucketName
|
||||
objectName := result.ThumbnailPath
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:Resource", "Article:Uploads").
|
||||
Interface("data", objectName).Msg("")
|
||||
|
||||
// Create minio connection.
|
||||
minioClient, err := _i.MinioStorage.ConnectMinio()
|
||||
if err != nil {
|
||||
// Return status 500 and minio connection error.
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": true,
|
||||
"msg": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
fileContent, err := minioClient.GetObject(ctx, bucketName, *objectName, minio.GetObjectOptions{})
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer fileContent.Close()
|
||||
|
||||
contentType := mime.TypeByExtension("." + getFileExtension(*objectName))
|
||||
if contentType == "" {
|
||||
contentType = "application/octet-stream"
|
||||
}
|
||||
|
||||
c.Set("Content-Type", contentType)
|
||||
|
||||
if _, err := io.Copy(c.Response().BodyWriter(), fileContent); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func getFileExtension(filename string) string {
|
||||
// split file name
|
||||
parts := strings.Split(filename, ".")
|
||||
|
||||
// jika tidak ada ekstensi, kembalikan string kosong
|
||||
if len(parts) == 1 || (len(parts) == 2 && parts[0] == "") {
|
||||
return ""
|
||||
}
|
||||
|
||||
// ambil ekstensi terakhir
|
||||
return parts[len(parts)-1]
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/ppid_data_files/service"
|
||||
)
|
||||
|
||||
type Controller struct {
|
||||
PpidDataFiles PpidDataFilesController
|
||||
}
|
||||
|
||||
func NewController(PpidDataFilesService service.PpidDataFilesService, log zerolog.Logger) *Controller {
|
||||
return &Controller{
|
||||
PpidDataFiles: NewPpidDataFilesController(PpidDataFilesService, log),
|
||||
}
|
||||
}
|
||||
|
|
@ -1,241 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/ppid_data_files/request"
|
||||
"go-humas-be/app/module/ppid_data_files/service"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilRes "go-humas-be/utils/response"
|
||||
utilVal "go-humas-be/utils/validator"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ppidDataFilesController struct {
|
||||
ppidDataFilesService service.PpidDataFilesService
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
type PpidDataFilesController interface {
|
||||
All(c *fiber.Ctx) error
|
||||
Show(c *fiber.Ctx) error
|
||||
Save(c *fiber.Ctx) error
|
||||
Update(c *fiber.Ctx) error
|
||||
UpdatePosition(c *fiber.Ctx) error
|
||||
Delete(c *fiber.Ctx) error
|
||||
Viewer(c *fiber.Ctx) error
|
||||
}
|
||||
|
||||
func NewPpidDataFilesController(ppidDataFilesService service.PpidDataFilesService, log zerolog.Logger) PpidDataFilesController {
|
||||
return &ppidDataFilesController{
|
||||
ppidDataFilesService: ppidDataFilesService,
|
||||
Log: log,
|
||||
}
|
||||
}
|
||||
|
||||
// All PpidDataFiles
|
||||
// @Summary Get all PpidDataFiles
|
||||
// @Description API for getting all PpidDataFiles
|
||||
// @Tags PPID Files
|
||||
// @Security Bearer
|
||||
// @Param req query request.PpidDataFilesQueryRequest 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 /ppid-data-files [get]
|
||||
func (_i *ppidDataFilesController) All(c *fiber.Ctx) error {
|
||||
paginate, err := paginator.Paginate(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
reqContext := request.PpidDataFilesQueryRequestContext{
|
||||
Title: c.Query("title"),
|
||||
PpidDataId: c.Query("ppidDataId"),
|
||||
Description: c.Query("description"),
|
||||
Unit: c.Query("unit"),
|
||||
FileType: c.Query("fileType"),
|
||||
StatusId: c.Query("statusId"),
|
||||
IsPublish: c.Query("isPublish"),
|
||||
}
|
||||
req := reqContext.ToParamRequest()
|
||||
req.Pagination = paginate
|
||||
|
||||
ppidDataFilesData, paging, err := _i.ppidDataFilesService.All(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataFiles list successfully retrieved"},
|
||||
Data: ppidDataFilesData,
|
||||
Meta: paging,
|
||||
})
|
||||
}
|
||||
|
||||
// Show PpidDataFiles
|
||||
// @Summary Get one PpidDataFiles
|
||||
// @Description API for getting one PpidDataFiles
|
||||
// @Tags PPID Files
|
||||
// @Security Bearer
|
||||
// @Param id path int true "PpidDataFiles ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-files/{id} [get]
|
||||
func (_i *ppidDataFilesController) Show(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ppidDataFilesData, err := _i.ppidDataFilesService.Show(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataFiles successfully retrieved"},
|
||||
Data: ppidDataFilesData,
|
||||
})
|
||||
}
|
||||
|
||||
// Save PpidDataFiles
|
||||
// @Summary Create PpidDataFiles
|
||||
// @Description API for create PpidDataFiles
|
||||
// @Tags PPID Files
|
||||
// @Security Bearer
|
||||
// @Produce json
|
||||
// @Param titles formData string false "Titles"
|
||||
// @Param types formData string false "Types"
|
||||
// @Param positions formData string false "Positions"
|
||||
// @Param urls formData string false "Upload Url"
|
||||
// @Param files formData file false "Upload File"
|
||||
// @Param ppidDataId path int true "Ppid Data ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-files/{ppidDataId} [post]
|
||||
func (_i *ppidDataFilesController) Save(c *fiber.Ctx) error {
|
||||
err := _i.ppidDataFilesService.Save(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataFiles successfully created"},
|
||||
})
|
||||
}
|
||||
|
||||
// Update PpidDataFiles
|
||||
// @Summary update PpidDataFiles
|
||||
// @Description API for update PpidDataFiles
|
||||
// @Tags PPID Files
|
||||
// @Security Bearer
|
||||
// @Param payload body request.PpidDataFilesUpdateRequest true "Required payload"
|
||||
// @Param id path int true "Ppid Data ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-files/{id} [put]
|
||||
func (_i *ppidDataFilesController) Update(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := new(request.PpidDataFilesUpdateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.ppidDataFilesService.Update(uint(id), *req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataFiles successfully updated"},
|
||||
})
|
||||
}
|
||||
|
||||
// UpdatePosition PpidDataFiles
|
||||
// @Summary updatePosition PpidDataFiles
|
||||
// @Description API for PpidDataFiles
|
||||
// @Tags PPID Files
|
||||
// @Security Bearer
|
||||
// @Param payload body request.PpidDataFilesUpdatePositionPayload true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-files/update/position [post]
|
||||
func (_i *ppidDataFilesController) UpdatePosition(c *fiber.Ctx) error {
|
||||
req := new(request.PpidDataFilesUpdatePositionPayload)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := _i.ppidDataFilesService.UpdatePosition(req.Positions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataFiles successfully updated"},
|
||||
})
|
||||
}
|
||||
|
||||
// Delete PpidDataFiles
|
||||
// @Summary delete PpidDataFiles
|
||||
// @Description API for delete PpidDataFiles
|
||||
// @Tags PPID Files
|
||||
// @Security Bearer
|
||||
// @Param id path int true "PpidDataFiles ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-files/{id} [delete]
|
||||
func (_i *ppidDataFilesController) Delete(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.ppidDataFilesService.Delete(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataFiles successfully deleted"},
|
||||
})
|
||||
}
|
||||
|
||||
// Viewer PpidDataFiles
|
||||
// @Summary Create PpidDataFiles
|
||||
// @Description API for create PpidDataFiles
|
||||
// @Tags PPID Files
|
||||
// @Security Bearer
|
||||
// @Param filename path string true "Ppid Data Filename"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-files/viewer/{filename} [get]
|
||||
func (_i *ppidDataFilesController) Viewer(c *fiber.Ctx) error {
|
||||
filename := c.Params("filename")
|
||||
return _i.ppidDataFilesService.Viewer(c, filename)
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
res "go-humas-be/app/module/ppid_data_files/response"
|
||||
)
|
||||
|
||||
func PpidDataFilesResponseMapper(ppidDataFilesReq *entity.PpidDataFiles) (ppidDataFilesRes *res.PpidDataFilesResponse) {
|
||||
if ppidDataFilesReq != nil {
|
||||
ppidDataFilesRes = &res.PpidDataFilesResponse{
|
||||
ID: ppidDataFilesReq.ID,
|
||||
Title: ppidDataFilesReq.Title,
|
||||
Type: ppidDataFilesReq.Type,
|
||||
PpidDataId: ppidDataFilesReq.PpidDataId,
|
||||
FileName: ppidDataFilesReq.FileName,
|
||||
FileUrl: ppidDataFilesReq.FileUrl,
|
||||
FileType: ppidDataFilesReq.FileType,
|
||||
DownloadCount: ppidDataFilesReq.DownloadCount,
|
||||
Position: ppidDataFilesReq.Position,
|
||||
CreatedById: ppidDataFilesReq.CreatedById,
|
||||
StatusId: ppidDataFilesReq.StatusId,
|
||||
IsPublish: ppidDataFilesReq.IsPublish,
|
||||
PublishedAt: ppidDataFilesReq.PublishedAt,
|
||||
IsActive: ppidDataFilesReq.IsActive,
|
||||
CreatedAt: ppidDataFilesReq.CreatedAt,
|
||||
UpdatedAt: ppidDataFilesReq.UpdatedAt,
|
||||
}
|
||||
}
|
||||
return ppidDataFilesRes
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
package ppid_data_files
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go-humas-be/app/module/ppid_data_files/controller"
|
||||
"go-humas-be/app/module/ppid_data_files/repository"
|
||||
"go-humas-be/app/module/ppid_data_files/service"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
// struct of PpidDataFilesRouter
|
||||
type PpidDataFilesRouter struct {
|
||||
App fiber.Router
|
||||
Controller *controller.Controller
|
||||
}
|
||||
|
||||
// register bulky of PpidDataFiles module
|
||||
var NewPpidDataFilesModule = fx.Options(
|
||||
// register repository of PpidDataFiles module
|
||||
fx.Provide(repository.NewPpidDataFilesRepository),
|
||||
|
||||
// register service of PpidDataFiles module
|
||||
fx.Provide(service.NewPpidDataFilesService),
|
||||
|
||||
// register controller of PpidDataFiles module
|
||||
fx.Provide(controller.NewController),
|
||||
|
||||
// register router of PpidDataFiles module
|
||||
fx.Provide(NewPpidDataFilesRouter),
|
||||
)
|
||||
|
||||
// init PpidDataFilesRouter
|
||||
func NewPpidDataFilesRouter(fiber *fiber.App, controller *controller.Controller) *PpidDataFilesRouter {
|
||||
return &PpidDataFilesRouter{
|
||||
App: fiber,
|
||||
Controller: controller,
|
||||
}
|
||||
}
|
||||
|
||||
// register routes of PpidDataFiles module
|
||||
func (_i *PpidDataFilesRouter) RegisterPpidDataFilesRoutes() {
|
||||
// define controllers
|
||||
ppidDataFilesController := _i.Controller.PpidDataFiles
|
||||
|
||||
// define routes
|
||||
_i.App.Route("/ppid-data-files", func(router fiber.Router) {
|
||||
router.Get("/", ppidDataFilesController.All)
|
||||
router.Get("/:id", ppidDataFilesController.Show)
|
||||
router.Post("/:ppidDataId", ppidDataFilesController.Save)
|
||||
router.Put("/:id", ppidDataFilesController.Update)
|
||||
router.Post("/update/position", ppidDataFilesController.UpdatePosition)
|
||||
router.Delete("/:id", ppidDataFilesController.Delete)
|
||||
router.Get("/viewer/:filename", ppidDataFilesController.Viewer)
|
||||
})
|
||||
}
|
||||
|
|
@ -1,154 +0,0 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/ppid_data_files/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ppidDataFilesRepository struct {
|
||||
DB *database.Database
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// PpidDataFilesRepository define interface of IPpidDataFilesRepository
|
||||
type PpidDataFilesRepository interface {
|
||||
GetAll(req request.PpidDataFilesQueryRequest) (ppidDataFiless []*entity.PpidDataFiles, paging paginator.Pagination, err error)
|
||||
FindOne(id uint) (ppidDataFiles *entity.PpidDataFiles, err error)
|
||||
FindByFilename(filename string) (ppidDataFiles *entity.PpidDataFiles, err error)
|
||||
FindByPpidData(ppidDataId uint) (ppidDataFiles []*entity.PpidDataFiles, err error)
|
||||
FindOneLastPosition() (ppidDataFiles *entity.PpidDataFiles, err error)
|
||||
Create(ppidDataFiles *entity.PpidDataFiles) (err error)
|
||||
Update(id uint, ppidDataFiles *entity.PpidDataFiles) (err error)
|
||||
UpdateAll(ppidDataFiles []*entity.PpidDataFiles) (err error)
|
||||
Delete(id uint) (err error)
|
||||
}
|
||||
|
||||
func NewPpidDataFilesRepository(db *database.Database, logger zerolog.Logger) PpidDataFilesRepository {
|
||||
return &ppidDataFilesRepository{
|
||||
DB: db,
|
||||
Log: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// implement interface of IPpidDataFilesRepository
|
||||
func (_i *ppidDataFilesRepository) GetAll(req request.PpidDataFilesQueryRequest) (ppidDataFiless []*entity.PpidDataFiles, paging paginator.Pagination, err error) {
|
||||
var count int64
|
||||
|
||||
query := _i.DB.DB.Model(&entity.PpidDataFiles{})
|
||||
query = query.Where("is_active = ?", true)
|
||||
|
||||
if req.Title != nil && *req.Title != "" {
|
||||
title := strings.ToLower(*req.Title)
|
||||
query = query.Where("LOWER(title) LIKE ?", "%"+strings.ToLower(title)+"%")
|
||||
}
|
||||
if req.Description != nil && *req.Description != "" {
|
||||
description := strings.ToLower(*req.Description)
|
||||
query = query.Where("LOWER(description) LIKE ?", "%"+strings.ToLower(description)+"%")
|
||||
}
|
||||
if req.Unit != nil && *req.Unit != "" {
|
||||
unit := strings.ToLower(*req.Unit)
|
||||
query = query.Where("LOWER(unit) LIKE ?", "%"+strings.ToLower(unit)+"%")
|
||||
}
|
||||
if req.FileType != nil && *req.FileType != "" {
|
||||
query = query.Where("file_type = ?", req.FileType)
|
||||
}
|
||||
if req.PpidDataId != nil {
|
||||
query = query.Where("ppid_data_id = ?", req.PpidDataId)
|
||||
}
|
||||
if req.IsPublish != nil {
|
||||
query = query.Where("is_publish = ?", req.IsPublish)
|
||||
}
|
||||
if req.StatusId != nil {
|
||||
query = query.Where("status_id = ?", req.StatusId)
|
||||
}
|
||||
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)
|
||||
|
||||
if req.Pagination.Limit == -1 {
|
||||
query.Limit(req.Pagination.Limit)
|
||||
}
|
||||
|
||||
err = query.Offset(req.Pagination.Offset).Limit(req.Pagination.Limit).Find(&ppidDataFiless).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
paging = *req.Pagination
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesRepository) FindOne(id uint) (ppidDataFiles *entity.PpidDataFiles, err error) {
|
||||
if err := _i.DB.DB.First(&ppidDataFiles, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ppidDataFiles, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesRepository) FindByFilename(filename string) (ppidDataFiles *entity.PpidDataFiles, err error) {
|
||||
|
||||
if err := _i.DB.DB.Where("file_name = ?", filename).First(&ppidDataFiles).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ppidDataFiles, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesRepository) FindByPpidData(ppidDataId uint) (ppidDataFiles []*entity.PpidDataFiles, err error) {
|
||||
if err := _i.DB.DB.Where("ppid_data_id = ?", ppidDataId).Find(&ppidDataFiles).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ppidDataFiles, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesRepository) FindOneLastPosition() (ppidDataFiles *entity.PpidDataFiles, err error) {
|
||||
if err := _i.DB.DB.Where("position IS NOT NULL").Last(&ppidDataFiles).
|
||||
Order(fmt.Sprintf("%s %s", "position", "DESC")).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ppidDataFiles, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesRepository) Create(ppidDataFiles *entity.PpidDataFiles) (err error) {
|
||||
return _i.DB.DB.Create(ppidDataFiles).Error
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesRepository) Update(id uint, ppidDataFiles *entity.PpidDataFiles) (err error) {
|
||||
return _i.DB.DB.Model(&entity.PpidDataFiles{}).
|
||||
Where(&entity.PpidDataFiles{ID: id}).
|
||||
Updates(ppidDataFiles).Error
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesRepository) UpdateAll(ppidDataFiles []*entity.PpidDataFiles) (err error) {
|
||||
for _, req := range ppidDataFiles {
|
||||
err := _i.DB.DB.Model(&entity.PpidDataFiles{}).
|
||||
Where(&entity.PpidDataFiles{ID: req.ID}).
|
||||
Updates(req).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesRepository) Delete(id uint) error {
|
||||
return _i.DB.DB.Delete(&entity.PpidDataFiles{}, id).Error
|
||||
}
|
||||
|
|
@ -1,152 +0,0 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PpidDataFilesGeneric interface {
|
||||
ToEntity()
|
||||
}
|
||||
|
||||
type PpidDataFilesQueryRequest struct {
|
||||
Title *string `json:"title"`
|
||||
PpidDataId *int `json:"ppidDataId"`
|
||||
Description *string `json:"description"`
|
||||
Unit *string `json:"unit"`
|
||||
FileType *string `json:"fileType"`
|
||||
Position *int `json:"position"`
|
||||
StatusId *int `json:"statusId"`
|
||||
IsPublish *bool `json:"isPublish"`
|
||||
Pagination *paginator.Pagination `json:"pagination"`
|
||||
}
|
||||
|
||||
type PpidDataFilesCreateRequest struct {
|
||||
PpidDataId int `json:"ppidDataId" validate:"required"`
|
||||
Title *string `json:"title"`
|
||||
Type *string `json:"type"`
|
||||
Position *int `json:"position"`
|
||||
FileType *string `json:"fileType"`
|
||||
FileName *string `json:"fileName"`
|
||||
FilePath *string `json:"filePath"`
|
||||
FileUrl *string `json:"fileUrl"`
|
||||
Size *string `json:"size"`
|
||||
CreatedById *int `json:"createdById"`
|
||||
StatusId *int `json:"statusId"`
|
||||
}
|
||||
|
||||
func (req PpidDataFilesCreateRequest) ToEntity() *entity.PpidDataFiles {
|
||||
return &entity.PpidDataFiles{
|
||||
Title: req.Title,
|
||||
Type: req.Type,
|
||||
Position: req.Position,
|
||||
PpidDataId: req.PpidDataId,
|
||||
FileType: req.FileType,
|
||||
FileName: req.FileName,
|
||||
FilePath: req.FilePath,
|
||||
FileUrl: req.FileUrl,
|
||||
Size: req.Size,
|
||||
CreatedById: req.CreatedById,
|
||||
StatusId: req.StatusId,
|
||||
}
|
||||
}
|
||||
|
||||
type PpidDataFilesUpdateRequest struct {
|
||||
ID uint `json:"id" validate:"required"`
|
||||
PpidDataId int `json:"ppidDataId" validate:"required"`
|
||||
Title *string `json:"title"`
|
||||
FileType *string `json:"fileType"`
|
||||
FilePath *string `json:"filePath"`
|
||||
CreatedById *int `json:"createdById"`
|
||||
StatusId *int `json:"statusId"`
|
||||
IsPublish *bool `json:"isPublish"`
|
||||
PublishedAt *time.Time `json:"publishedAt"`
|
||||
}
|
||||
|
||||
func (req PpidDataFilesUpdateRequest) ToEntity() *entity.PpidDataFiles {
|
||||
return &entity.PpidDataFiles{
|
||||
ID: req.ID,
|
||||
Title: req.Title,
|
||||
PpidDataId: req.PpidDataId,
|
||||
FileType: req.FileType,
|
||||
FilePath: req.FilePath,
|
||||
CreatedById: req.CreatedById,
|
||||
StatusId: req.StatusId,
|
||||
IsPublish: req.IsPublish,
|
||||
PublishedAt: req.PublishedAt,
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
type PpidDataFilesUpdatePositionPayload struct {
|
||||
Positions []PpidDataFilesUpdatePositionRequest `json:"positions"`
|
||||
}
|
||||
|
||||
type PpidDataFilesUpdatePositionRequest struct {
|
||||
ID uint `json:"id" validate:"required"`
|
||||
Position int `json:"position" validate:"required"`
|
||||
}
|
||||
|
||||
func (req PpidDataFilesUpdatePositionRequest) ToEntity() *entity.PpidDataFiles {
|
||||
return &entity.PpidDataFiles{
|
||||
ID: req.ID,
|
||||
Position: &req.Position,
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
type PpidDataFilesQueryRequestContext struct {
|
||||
Title string `json:"title"`
|
||||
PpidDataId string `json:"ppidDataId"`
|
||||
Description string `json:"description"`
|
||||
Unit string `json:"unit"`
|
||||
FileType string `json:"fileType"`
|
||||
Position string `json:"position"`
|
||||
StatusId string `json:"statusId"`
|
||||
IsPublish string `json:"isPublish"`
|
||||
}
|
||||
|
||||
func (req PpidDataFilesQueryRequestContext) ToParamRequest() PpidDataFilesQueryRequest {
|
||||
var request PpidDataFilesQueryRequest
|
||||
|
||||
if title := req.Title; title != "" {
|
||||
request.Title = &title
|
||||
}
|
||||
if ppidDataIdStr := req.PpidDataId; ppidDataIdStr != "" {
|
||||
ppidDataId, err := strconv.Atoi(ppidDataIdStr)
|
||||
if err == nil {
|
||||
request.PpidDataId = &ppidDataId
|
||||
}
|
||||
}
|
||||
if description := req.Description; description != "" {
|
||||
request.Title = &description
|
||||
}
|
||||
if unit := req.Unit; unit != "" {
|
||||
request.Unit = &unit
|
||||
}
|
||||
if fileType := req.FileType; fileType != "" {
|
||||
request.FileType = &fileType
|
||||
}
|
||||
if positionStr := req.Position; positionStr != "" {
|
||||
position, err := strconv.Atoi(positionStr)
|
||||
if err == nil {
|
||||
request.Position = &position
|
||||
}
|
||||
}
|
||||
if statusIdStr := req.StatusId; statusIdStr != "" {
|
||||
statusId, err := strconv.Atoi(statusIdStr)
|
||||
if err == nil {
|
||||
request.StatusId = &statusId
|
||||
}
|
||||
}
|
||||
if isPublishStr := req.IsPublish; isPublishStr != "" {
|
||||
isPublish, err := strconv.ParseBool(isPublishStr)
|
||||
if err == nil {
|
||||
request.IsPublish = &isPublish
|
||||
}
|
||||
}
|
||||
|
||||
return request
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
package response
|
||||
|
||||
import "time"
|
||||
|
||||
type PpidDataFilesResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Title *string `json:"title"`
|
||||
Type *string `json:"type"`
|
||||
PpidDataId int `json:"ppidDataId"`
|
||||
FileName *string `json:"fileName"`
|
||||
FileType *string `json:"fileType"`
|
||||
FileUrl *string `json:"fileUrl"`
|
||||
DownloadCount *int `json:"downloadCount"`
|
||||
CreatedById *int `json:"createdById"`
|
||||
Position *int `json:"position"`
|
||||
StatusId *int `json:"statusId"`
|
||||
IsPublish *bool `json:"isPublish"`
|
||||
PublishedAt *time.Time `json:"publishedAt"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
|
@ -1,327 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/ppid_data_files/mapper"
|
||||
"go-humas-be/app/module/ppid_data_files/repository"
|
||||
"go-humas-be/app/module/ppid_data_files/request"
|
||||
"go-humas-be/app/module/ppid_data_files/response"
|
||||
config "go-humas-be/config/config"
|
||||
"go-humas-be/utils/paginator"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"mime"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// PpidDataFilesService
|
||||
type ppidDataFilesService struct {
|
||||
Repo repository.PpidDataFilesRepository
|
||||
Log zerolog.Logger
|
||||
MinioStorage *config.MinioStorage
|
||||
Cfg *config.Config
|
||||
}
|
||||
|
||||
// PpidDataFilesService define interface of IPpidDataFilesService
|
||||
type PpidDataFilesService interface {
|
||||
All(req request.PpidDataFilesQueryRequest) (ppidDataFiles []*response.PpidDataFilesResponse, paging paginator.Pagination, err error)
|
||||
Show(id uint) (ppidDataFiles *response.PpidDataFilesResponse, err error)
|
||||
Save(c *fiber.Ctx) error
|
||||
Update(id uint, req request.PpidDataFilesUpdateRequest) (err error)
|
||||
UpdatePosition(req []request.PpidDataFilesUpdatePositionRequest) (err error)
|
||||
Delete(id uint) error
|
||||
Viewer(c *fiber.Ctx, filename string) error
|
||||
}
|
||||
|
||||
// NewPpidDataFilesService init PpidDataFilesService
|
||||
func NewPpidDataFilesService(repo repository.PpidDataFilesRepository, log zerolog.Logger, minioStorage *config.MinioStorage, cfg *config.Config) PpidDataFilesService {
|
||||
|
||||
return &ppidDataFilesService{
|
||||
Repo: repo,
|
||||
Log: log,
|
||||
MinioStorage: minioStorage,
|
||||
Cfg: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
// All implement interface of PpidDataFilesService
|
||||
func (_i *ppidDataFilesService) All(req request.PpidDataFilesQueryRequest) (ppidDataFiless []*response.PpidDataFilesResponse, paging paginator.Pagination, err error) {
|
||||
results, paging, err := _i.Repo.GetAll(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
ppidDataFiless = append(ppidDataFiless, mapper.PpidDataFilesResponseMapper(result))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesService) Show(id uint) (ppidDataFiles *response.PpidDataFilesResponse, err error) {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mapper.PpidDataFilesResponseMapper(result), nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesService) Save(c *fiber.Ctx) (err error) {
|
||||
|
||||
id, err := strconv.ParseUint(c.Params("ppidDataId"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
host := _i.Cfg.App.Domain
|
||||
port := _i.Cfg.App.ExternalPort
|
||||
|
||||
form, err := c.MultipartForm()
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service", "Save").
|
||||
Interface("form", form).Msg("")
|
||||
|
||||
titlesString := form.Value["titles"]
|
||||
titles := strings.Split(titlesString[0], ",")
|
||||
typesString := form.Value["types"]
|
||||
types := strings.Split(typesString[0], ",")
|
||||
positionsString := form.Value["positions"]
|
||||
positions := strings.Split(positionsString[0], ",")
|
||||
var urls []string
|
||||
urlsString := form.Value["urls"]
|
||||
if urlsString != nil {
|
||||
urls = strings.Split(urlsString[0], ",")
|
||||
}
|
||||
files := form.File["files"]
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service", "Save").
|
||||
Interface("titlesString", titlesString).Msg("")
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service", "Save").
|
||||
Interface("typesString", typesString).Msg("")
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service", "Save").
|
||||
Interface("positionsString", positionsString).Msg("")
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service", "Save").
|
||||
Interface("urlsString", urlsString).Msg("")
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service", "Save").
|
||||
Interface("urls", urls).Msg("")
|
||||
|
||||
fileCounter := 0
|
||||
urlCounter := 0
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service", "Save").
|
||||
Interface("form", files).Msg("")
|
||||
|
||||
for index, fileType := range types {
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service", "Save").
|
||||
Interface("types", fileType).Msg("")
|
||||
|
||||
position := &positions[index]
|
||||
positionInt64, err := strconv.ParseInt(*position, 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
positionInt := int(positionInt64)
|
||||
statusId := 1
|
||||
title := titles[index]
|
||||
req := request.PpidDataFilesCreateRequest{
|
||||
Title: &title,
|
||||
PpidDataId: int(id),
|
||||
Type: &fileType,
|
||||
Position: &positionInt,
|
||||
StatusId: &statusId,
|
||||
}
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service", "Save").
|
||||
Interface("request", req).Msg("")
|
||||
|
||||
if fileType == "url" {
|
||||
url := urls[urlCounter]
|
||||
//filename := path.Base(url)
|
||||
//filenameWithoutExt := filepath.Clean(filename[:len(filename)-len(filepath.Ext(filename))])
|
||||
//extension := filepath.Ext(filename)[1:]
|
||||
//title := strings.ReplaceAll(filenameWithoutExt, "-", " ")
|
||||
|
||||
//req.Title = &title
|
||||
//req.FileType = &extension
|
||||
req.FileName = &title
|
||||
req.FileUrl = &url
|
||||
|
||||
urlCounter += 1
|
||||
} else {
|
||||
bucketName := _i.MinioStorage.Cfg.ObjectStorage.MinioStorage.BucketName
|
||||
|
||||
// Create minio connection.
|
||||
minioClient, err := _i.MinioStorage.ConnectMinio()
|
||||
if err != nil {
|
||||
// Return status 500 and minio connection error.
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": true,
|
||||
"msg": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
// Iterasi semua file yang diunggah
|
||||
file := files[fileCounter]
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:Resource", "Uploader:: loop1").
|
||||
Interface("data", file).Msg("")
|
||||
|
||||
src, err := file.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
filename := filepath.Base(file.Filename)
|
||||
filename = strings.ReplaceAll(filename, " ", "")
|
||||
filenameWithoutExt := filepath.Clean(filename[:len(filename)-len(filepath.Ext(filename))])
|
||||
extension := filepath.Ext(file.Filename)[1:]
|
||||
|
||||
rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
randUniqueId := rand.Intn(1000000)
|
||||
|
||||
newFilenameWithoutExt := filenameWithoutExt + "_" + strconv.Itoa(randUniqueId)
|
||||
newFilename := newFilenameWithoutExt + "." + extension
|
||||
objectName := "ppid/upload/" + newFilename
|
||||
|
||||
size := strconv.FormatInt(file.Size, 10)
|
||||
viewerPath := "/ppid-data-files/viewer/"
|
||||
fileUrl := host + port + viewerPath + newFilename
|
||||
|
||||
//req.Title = &newFilenameWithoutExt
|
||||
req.FileType = &extension
|
||||
req.FileName = &newFilename
|
||||
req.FilePath = &objectName
|
||||
req.FileUrl = &fileUrl
|
||||
req.Size = &size
|
||||
|
||||
// Upload file to MinIO
|
||||
_, err = minioClient.PutObject(context.Background(), bucketName, objectName, src, file.Size, minio.PutObjectOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileCounter += 1
|
||||
}
|
||||
|
||||
err = _i.Repo.Create(req.ToEntity())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:Resource", "User:All").
|
||||
Interface("data", "Successfully uploaded").Msg("")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesService) Update(id uint, req request.PpidDataFilesUpdateRequest) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
return _i.Repo.Update(id, req.ToEntity())
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesService) UpdatePosition(req []request.PpidDataFilesUpdatePositionRequest) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
|
||||
var entityReq []*entity.PpidDataFiles
|
||||
for _, reqItem := range req {
|
||||
entityReq = append(entityReq, reqItem.ToEntity())
|
||||
}
|
||||
|
||||
return _i.Repo.UpdateAll(entityReq)
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesService) Delete(id uint) error {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
isActive := false
|
||||
result.IsActive = &isActive
|
||||
return _i.Repo.Update(id, result)
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesService) Viewer(c *fiber.Ctx, filename string) (err error) {
|
||||
result, err := _i.Repo.FindByFilename(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if result.FilePath == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
bucketName := _i.MinioStorage.Cfg.ObjectStorage.MinioStorage.BucketName
|
||||
objectName := result.FilePath
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:Resource", "Article:Uploads").
|
||||
Interface("data", objectName).Msg("")
|
||||
|
||||
// Create minio connection.
|
||||
minioClient, err := _i.MinioStorage.ConnectMinio()
|
||||
if err != nil {
|
||||
// Return status 500 and minio connection error.
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": true,
|
||||
"msg": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
fileContent, err := minioClient.GetObject(ctx, bucketName, *objectName, minio.GetObjectOptions{})
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer fileContent.Close()
|
||||
|
||||
// Tentukan Content-Type berdasarkan ekstensi file
|
||||
contentType := mime.TypeByExtension("." + getFileExtension(*objectName))
|
||||
if contentType == "" {
|
||||
contentType = "application/octet-stream" // fallback jika tidak ada tipe MIME yang cocok
|
||||
}
|
||||
|
||||
c.Set("Content-Type", contentType)
|
||||
|
||||
if _, err := io.Copy(c.Response().BodyWriter(), fileContent); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func getFileExtension(filename string) string {
|
||||
// split file name
|
||||
parts := strings.Split(filename, ".")
|
||||
|
||||
// jika tidak ada ekstensi, kembalikan string kosong
|
||||
if len(parts) == 1 || (len(parts) == 2 && parts[0] == "") {
|
||||
return ""
|
||||
}
|
||||
|
||||
// ambil ekstensi terakhir
|
||||
return parts[len(parts)-1]
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
package controller
|
||||
|
||||
import "go-humas-be/app/module/ppid_datas/service"
|
||||
|
||||
type Controller struct {
|
||||
PpidDatas PpidDatasController
|
||||
}
|
||||
|
||||
func NewController(PpidDatasService service.PpidDatasService) *Controller {
|
||||
return &Controller{
|
||||
PpidDatas: NewPpidDatasController(PpidDatasService),
|
||||
}
|
||||
}
|
||||
|
|
@ -1,262 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/ppid_datas/request"
|
||||
"go-humas-be/app/module/ppid_datas/service"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strconv"
|
||||
|
||||
requestPpidApproval "go-humas-be/app/module/ppid_data_approval_histories/request"
|
||||
utilRes "go-humas-be/utils/response"
|
||||
utilVal "go-humas-be/utils/validator"
|
||||
)
|
||||
|
||||
type ppidDatasController struct {
|
||||
ppidDatasService service.PpidDatasService
|
||||
log zerolog.Logger
|
||||
}
|
||||
|
||||
type PpidDatasController interface {
|
||||
All(c *fiber.Ctx) error
|
||||
Show(c *fiber.Ctx) error
|
||||
Save(c *fiber.Ctx) error
|
||||
Update(c *fiber.Ctx) error
|
||||
UpdatePosition(c *fiber.Ctx) error
|
||||
UpdateApprovalStatus(c *fiber.Ctx) error
|
||||
Delete(c *fiber.Ctx) error
|
||||
}
|
||||
|
||||
func NewPpidDatasController(ppidDatasService service.PpidDatasService) PpidDatasController {
|
||||
return &ppidDatasController{
|
||||
ppidDatasService: ppidDatasService,
|
||||
}
|
||||
}
|
||||
|
||||
// All PpidDatas
|
||||
// @Summary Get all PpidDatas
|
||||
// @Description API for getting all PpidDatas
|
||||
// @Tags PPID Data
|
||||
// @Security Bearer
|
||||
// @Param Authorization header string false "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param req query request.PpidDatasQueryRequest 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 /ppid-datas [get]
|
||||
func (_i *ppidDatasController) All(c *fiber.Ctx) error {
|
||||
paginate, err := paginator.Paginate(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
authToken := c.Get("Authorization")
|
||||
|
||||
reqContext := request.PpidDatasQueryRequestContext{
|
||||
Title: c.Query("title"),
|
||||
Description: c.Query("description"),
|
||||
CategoryId: c.Query("categoryId"),
|
||||
UserId: c.Query("userId"),
|
||||
UserRoleId: c.Query("userRoleId"),
|
||||
UserLevelId: c.Query("userLevelId"),
|
||||
Group: c.Query("group"),
|
||||
LevelGroupId: c.Query("levelGroupId"),
|
||||
StatusId: c.Query("statusId"),
|
||||
IsPublish: c.Query("isPublish"),
|
||||
}
|
||||
|
||||
req := reqContext.ToParamRequest()
|
||||
req.Pagination = paginate
|
||||
|
||||
ppidDatasData, paging, err := _i.ppidDatasService.All(req, &authToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDatas list successfully retrieved"},
|
||||
Data: ppidDatasData,
|
||||
Meta: paging,
|
||||
})
|
||||
}
|
||||
|
||||
// Show PpidDatas
|
||||
// @Summary Get one PpidDatas
|
||||
// @Description API for getting one PpidDatas
|
||||
// @Tags PPID Data
|
||||
// @Security Bearer
|
||||
// @Param id path string true "PpidDatas [ ID / Slug ]"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-datas/{id} [get]
|
||||
func (_i *ppidDatasController) Show(c *fiber.Ctx) error {
|
||||
id := c.Params("id")
|
||||
ppidDatasData, err := _i.ppidDatasService.Show(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDatas successfully retrieved"},
|
||||
Data: ppidDatasData,
|
||||
})
|
||||
}
|
||||
|
||||
// Save PpidDatas
|
||||
// @Summary Create PpidDatas
|
||||
// @Description API for create PpidDatas
|
||||
// @Tags PPID Data
|
||||
// @Security Bearer
|
||||
// @Param Authorization header string true "Insert your access token" default (Bearer <Add access token here>)
|
||||
// @Param payload body request.PpidDatasCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-datas [post]
|
||||
func (_i *ppidDatasController) Save(c *fiber.Ctx) error {
|
||||
req := new(request.PpidDatasCreateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
authToken := c.Get("Authorization")
|
||||
dataResult, err := _i.ppidDatasService.Save(*req, authToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDatas successfully created"},
|
||||
Data: dataResult,
|
||||
})
|
||||
}
|
||||
|
||||
// Update PpidDatas
|
||||
// @Summary update PpidDatas
|
||||
// @Description API for update PpidDatas
|
||||
// @Tags PPID Data
|
||||
// @Security Bearer
|
||||
// @Param payload body request.PpidDatasCreateRequest true "Required payload"
|
||||
// @Param id path int true "PpidDatas ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-datas/{id} [put]
|
||||
func (_i *ppidDatasController) Update(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := new(request.PpidDatasUpdateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.ppidDatasService.Update(uint(id), *req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDatas successfully updated"},
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateApprovalStatus PpidDatas
|
||||
// @Summary UpdateApprovalStatus PpidDatas
|
||||
// @Description API for UpdateApprovalStatus PpidDatas
|
||||
// @Tags PPID Data
|
||||
// @Security Bearer
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body requestPpidApproval.PpidDataApprovalHistoriesCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-datas/approval [post]
|
||||
func (_i *ppidDatasController) UpdateApprovalStatus(c *fiber.Ctx) error {
|
||||
req := new(requestPpidApproval.PpidDataApprovalHistoriesCreateRequest)
|
||||
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
authToken := c.Get("Authorization")
|
||||
err := _i.ppidDatasService.UpdateApprovalStatus(*req, authToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDatas successfully updated"},
|
||||
})
|
||||
}
|
||||
|
||||
// UpdatePosition PpidDatas
|
||||
// @Summary UpdatePosition PpidDatas
|
||||
// @Description API for Update Position PpidDatas
|
||||
// @Tags PPID Data
|
||||
// @Security Bearer
|
||||
// @Param payload body request.PpidDatasUpdatePositionPayload true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-datas/position [post]
|
||||
func (_i *ppidDatasController) UpdatePosition(c *fiber.Ctx) error {
|
||||
req := new(request.PpidDatasUpdatePositionPayload)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := _i.ppidDatasService.UpdatePosition(req.Positions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDataCategories successfully updated"},
|
||||
})
|
||||
}
|
||||
|
||||
// Delete PpidDatas
|
||||
// @Summary delete PpidDatas
|
||||
// @Description API for delete PpidDatas
|
||||
// @Tags PPID Data
|
||||
// @Security Bearer
|
||||
// @Param id path int true "PpidDatas ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-datas/{id} [delete]
|
||||
func (_i *ppidDatasController) Delete(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.ppidDatasService.Delete(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDatas successfully deleted"},
|
||||
})
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database/entity"
|
||||
ppidDataCategoriesRepository "go-humas-be/app/module/ppid_data_categories/repository"
|
||||
ppidDataFilesMapper "go-humas-be/app/module/ppid_data_files/mapper"
|
||||
ppidDataFilesRepository "go-humas-be/app/module/ppid_data_files/repository"
|
||||
ppidDataFilesResponse "go-humas-be/app/module/ppid_data_files/response"
|
||||
res "go-humas-be/app/module/ppid_datas/response"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
"time"
|
||||
)
|
||||
|
||||
func PpidDatasResponseMapper(
|
||||
log zerolog.Logger,
|
||||
ppidDataCategoriesRepo ppidDataCategoriesRepository.PpidDataCategoriesRepository,
|
||||
ppidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository,
|
||||
usersRepo usersRepository.UsersRepository,
|
||||
ppidDatasReq *entity.PpidDatas,
|
||||
) (ppidDatasRes *res.PpidDatasResponse) {
|
||||
if ppidDatasReq == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
//log.Info().Str("timestamp", time.Now().
|
||||
// Format(time.RFC3339)).Str("Service:PpidDatasResponseMapper", "PpidData:Category").
|
||||
// Interface("Category", ppidDatasReq.Category).Msg("")
|
||||
|
||||
log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:PpidDatasResponseMapper", "PpidData:Category").
|
||||
Interface("CreatedBy", ppidDatasReq.CreatedBy).Msg("")
|
||||
|
||||
categoryName := ""
|
||||
if ppidDatasReq.Category.ID != 0 {
|
||||
categoryName = ppidDatasReq.Category.Title
|
||||
}
|
||||
|
||||
findUser, err := usersRepo.FindOne(*ppidDatasReq.CreatedById)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Error fetching user")
|
||||
return nil
|
||||
}
|
||||
createdByName := ""
|
||||
if findUser != nil {
|
||||
createdByName = findUser.Fullname
|
||||
}
|
||||
|
||||
ppidDataFiles, err := ppidDataFilesRepo.FindByPpidData(ppidDatasReq.ID)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Error fetching files")
|
||||
return nil
|
||||
}
|
||||
|
||||
var ppidDataFilesArr []*ppidDataFilesResponse.PpidDataFilesResponse
|
||||
if len(ppidDataFiles) > 0 {
|
||||
for _, result := range ppidDataFiles {
|
||||
ppidDataFilesArr = append(ppidDataFilesArr, ppidDataFilesMapper.PpidDataFilesResponseMapper(result))
|
||||
}
|
||||
}
|
||||
|
||||
ppidDatasRes = &res.PpidDatasResponse{
|
||||
ID: ppidDatasReq.ID,
|
||||
Title: ppidDatasReq.Title,
|
||||
Description: ppidDatasReq.Description,
|
||||
Slug: ppidDatasReq.Slug,
|
||||
CategoryId: ppidDatasReq.CategoryId,
|
||||
CategoryName: &categoryName,
|
||||
CreatedById: ppidDatasReq.CreatedById,
|
||||
CreatedByName: &createdByName,
|
||||
Position: ppidDatasReq.Position,
|
||||
StatusId: ppidDatasReq.StatusId,
|
||||
IsPublish: ppidDatasReq.IsPublish,
|
||||
PublishedAt: ppidDatasReq.PublishedAt,
|
||||
IsActive: ppidDatasReq.IsActive,
|
||||
CreatedAt: ppidDatasReq.CreatedAt,
|
||||
UpdatedAt: ppidDatasReq.UpdatedAt,
|
||||
|
||||
PpidDataFiles: ppidDataFilesArr,
|
||||
}
|
||||
|
||||
return ppidDatasRes
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
package ppid_datas
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go-humas-be/app/module/ppid_datas/controller"
|
||||
"go-humas-be/app/module/ppid_datas/repository"
|
||||
"go-humas-be/app/module/ppid_datas/service"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
// struct of PpidDatasRouter
|
||||
type PpidDatasRouter struct {
|
||||
App fiber.Router
|
||||
Controller *controller.Controller
|
||||
}
|
||||
|
||||
// register bulky of PpidDatas module
|
||||
var NewPpidDatasModule = fx.Options(
|
||||
// register repository of PpidDatas module
|
||||
fx.Provide(repository.NewPpidDatasRepository),
|
||||
|
||||
// register service of PpidDatas module
|
||||
fx.Provide(service.NewPpidDatasService),
|
||||
|
||||
// register controller of PpidDatas module
|
||||
fx.Provide(controller.NewController),
|
||||
|
||||
// register router of PpidDatas module
|
||||
fx.Provide(NewPpidDatasRouter),
|
||||
)
|
||||
|
||||
// init PpidDatasRouter
|
||||
func NewPpidDatasRouter(fiber *fiber.App, controller *controller.Controller) *PpidDatasRouter {
|
||||
return &PpidDatasRouter{
|
||||
App: fiber,
|
||||
Controller: controller,
|
||||
}
|
||||
}
|
||||
|
||||
// register routes of PpidDatas module
|
||||
func (_i *PpidDatasRouter) RegisterPpidDatasRoutes() {
|
||||
// define controllers
|
||||
ppidDatasController := _i.Controller.PpidDatas
|
||||
|
||||
// define routes
|
||||
_i.App.Route("/ppid-datas", func(router fiber.Router) {
|
||||
router.Get("/", ppidDatasController.All)
|
||||
router.Get("/:id", ppidDatasController.Show)
|
||||
router.Post("/", ppidDatasController.Save)
|
||||
router.Put("/:id", ppidDatasController.Update)
|
||||
router.Post("/position", ppidDatasController.UpdatePosition)
|
||||
router.Post("/approval", ppidDatasController.UpdateApprovalStatus)
|
||||
router.Delete("/:id", ppidDatasController.Delete)
|
||||
})
|
||||
}
|
||||
|
|
@ -1,165 +0,0 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/ppid_datas/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ppidDatasRepository struct {
|
||||
DB *database.Database
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// PpidDatasRepository define interface of IPpidDatasRepository
|
||||
type PpidDatasRepository interface {
|
||||
GetAll(req request.PpidDatasQueryRequest) (ppidDatass []*entity.PpidDatas, paging paginator.Pagination, err error)
|
||||
FindOne(id uint) (ppidDatas *entity.PpidDatas, err error)
|
||||
FindOneUsingSlug(slug string) (ppidDatas *entity.PpidDatas, err error)
|
||||
FindOneLastPosition() (ppidDatas *entity.PpidDatas, err error)
|
||||
Create(ppidDatas *entity.PpidDatas) (ppidDataReturn *entity.PpidDatas, err error)
|
||||
Update(id uint, ppidDatas *entity.PpidDatas) (err error)
|
||||
UpdateAll(ppidDatas []*entity.PpidDatas) (err error)
|
||||
Delete(id uint) (err error)
|
||||
}
|
||||
|
||||
func NewPpidDatasRepository(db *database.Database, logger zerolog.Logger) PpidDatasRepository {
|
||||
return &ppidDatasRepository{
|
||||
DB: db,
|
||||
Log: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// implement interface of IPpidDatasRepository
|
||||
func (_i *ppidDatasRepository) GetAll(req request.PpidDatasQueryRequest) (ppidDatass []*entity.PpidDatas, paging paginator.Pagination, err error) {
|
||||
var count int64
|
||||
|
||||
query := _i.DB.DB.Model(&entity.PpidDatas{}).Preload("CreatedBy").Preload("Category").Preload("LevelGroup")
|
||||
query = query.Where("is_active = ?", true)
|
||||
|
||||
if req.Title != nil && *req.Title != "" {
|
||||
title := strings.ToLower(*req.Title)
|
||||
query = query.Where("LOWER(title) LIKE ?", "%"+strings.ToLower(title)+"%")
|
||||
}
|
||||
if req.Description != nil && *req.Description != "" {
|
||||
description := strings.ToLower(*req.Description)
|
||||
query = query.Where("LOWER(description) LIKE ?", "%"+strings.ToLower(description)+"%")
|
||||
}
|
||||
if req.CategoryId != nil {
|
||||
query = query.Where("category_id = ?", req.CategoryId)
|
||||
}
|
||||
if req.LevelGroupId != nil {
|
||||
query = query.Where("level_group_id = ?", req.LevelGroupId)
|
||||
}
|
||||
if req.LevelGroupId != nil {
|
||||
query = query.Where("level_group_id = ?", req.LevelGroupId)
|
||||
}
|
||||
if req.IsPublish != nil {
|
||||
query = query.Where("is_publish = ?", req.IsPublish)
|
||||
}
|
||||
if req.StatusId != nil {
|
||||
query = query.Where("status_id = ?", req.StatusId)
|
||||
}
|
||||
if req.UserId != nil {
|
||||
userRoleIdStr := strconv.Itoa(int(*req.UserRoleId))
|
||||
userLevelIdStr := strconv.Itoa(int(*req.UserLevelId))
|
||||
query = query.
|
||||
Where("created_by_id = ?", req.UserId).
|
||||
Or("need_approval_from_user_role LIKE ?", ":"+userRoleIdStr+":").
|
||||
Or("need_approval_from_user_level LIKE ?", userLevelIdStr).
|
||||
Or("back_approval_to_user_role = ?", userRoleIdStr).
|
||||
Or("back_approval_to_user_level = ?", userLevelIdStr)
|
||||
}
|
||||
query.Count(&count)
|
||||
|
||||
//_i.Log.Info().Str("timestamp", time.Now().
|
||||
// Format(time.RFC3339)).Str("ppidDatasRepository:GetAll", "PpidData:CreatedBy").
|
||||
// Interface("Query", query.ToSQL).Msg("")
|
||||
|
||||
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)
|
||||
|
||||
if req.Pagination.Limit != -1 {
|
||||
query.Limit(req.Pagination.Limit)
|
||||
}
|
||||
|
||||
err = query.Offset(req.Pagination.Offset).Find(&ppidDatass).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
paging = *req.Pagination
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *ppidDatasRepository) FindOne(id uint) (ppidDatas *entity.PpidDatas, err error) {
|
||||
if err := _i.DB.DB.First(&ppidDatas, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ppidDatas, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDatasRepository) FindOneUsingSlug(slug string) (ppidDatas *entity.PpidDatas, err error) {
|
||||
if err := _i.DB.DB.Where("slug = ?", slug).First(&ppidDatas).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ppidDatas, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDatasRepository) FindOneLastPosition() (ppidDatas *entity.PpidDatas, err error) {
|
||||
if err := _i.DB.DB.Where("position IS NOT NULL").Last(&ppidDatas).
|
||||
Order(fmt.Sprintf("%s %s", "position", "DESC")).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ppidDatas, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDatasRepository) Create(ppidDatas *entity.PpidDatas) (ppidDataReturn *entity.PpidDatas, err error) {
|
||||
result := _i.DB.DB.Create(ppidDatas)
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:Create", "PpidData:Create").
|
||||
Interface("result", ppidDatas).Msg("")
|
||||
|
||||
return ppidDatas, result.Error
|
||||
}
|
||||
|
||||
func (_i *ppidDatasRepository) Update(id uint, ppidDatas *entity.PpidDatas) (err error) {
|
||||
return _i.DB.DB.Model(&entity.PpidDatas{}).
|
||||
Where(&entity.PpidDatas{ID: id}).
|
||||
Updates(ppidDatas).Error
|
||||
}
|
||||
|
||||
func (_i *ppidDatasRepository) UpdateAll(ppidDatas []*entity.PpidDatas) (err error) {
|
||||
for _, req := range ppidDatas {
|
||||
err := _i.DB.DB.Model(&entity.PpidDatas{}).
|
||||
Where(&entity.PpidDatas{ID: req.ID}).
|
||||
Updates(req).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_i *ppidDatasRepository) Delete(id uint) error {
|
||||
return _i.DB.DB.Delete(&entity.PpidDatas{}, id).Error
|
||||
}
|
||||
|
|
@ -1,179 +0,0 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PpidDatasGeneric interface {
|
||||
ToEntity()
|
||||
}
|
||||
|
||||
type PpidDatasQueryRequest struct {
|
||||
Title *string `json:"title"`
|
||||
Description *string `json:"description"`
|
||||
CategoryId *uint `json:"categoryId"`
|
||||
LevelGroupId *int `json:"levelGroupId"`
|
||||
Group *string `json:"group"`
|
||||
UserId *uint `json:"userId"`
|
||||
UserRoleId *uint `json:"userRoleId"`
|
||||
UserLevelId *uint `json:"userLevelId"`
|
||||
StatusId *int `json:"statusId"`
|
||||
IsPublish *bool `json:"isPublish"`
|
||||
Pagination *paginator.Pagination `json:"pagination"`
|
||||
}
|
||||
|
||||
type PpidDatasCreateRequest struct {
|
||||
Title string `json:"title" validate:"required"`
|
||||
Description string `json:"description" validate:"required"`
|
||||
Slug string `json:"slug" validate:"required"`
|
||||
CategoryId uint `json:"categoryId" validate:"required"`
|
||||
StatusId int `json:"statusId" validate:"required"`
|
||||
LevelGroupId *uint `json:"levelGroupId"`
|
||||
Group *string `json:"group"`
|
||||
}
|
||||
|
||||
func (req PpidDatasCreateRequest) ToEntity() *entity.PpidDatas {
|
||||
return &entity.PpidDatas{
|
||||
Title: req.Title,
|
||||
Description: req.Description,
|
||||
Slug: req.Slug,
|
||||
CategoryId: req.CategoryId,
|
||||
StatusId: req.StatusId,
|
||||
LevelGroupId: req.LevelGroupId,
|
||||
Group: req.Group,
|
||||
}
|
||||
}
|
||||
|
||||
type PpidDatasUpdateRequest struct {
|
||||
ID uint `json:"id" validate:"required"`
|
||||
Title string `json:"title" validate:"required"`
|
||||
Description string `json:"description" validate:"required"`
|
||||
Slug string `json:"slug" validate:"required"`
|
||||
CategoryId uint `json:"categoryId" validate:"required"`
|
||||
StatusId int `json:"statusId" validate:"required"`
|
||||
NeedApprovalFromUserRole *string `json:"needApprovalFrom"`
|
||||
NeedApprovalFromUserLevel *string `json:"needApprovalFromUserLevel"`
|
||||
BackApprovalToUserRole *string `json:"backApprovalToUserRole"`
|
||||
BackApprovalToUserLevel *string `json:"backApprovalToUserLevel"`
|
||||
IsPublish *bool `json:"isPublish"`
|
||||
PublishLevel *int `json:"publishLevel"`
|
||||
PublishedAt *time.Time `json:"publishedAt"`
|
||||
LevelGroupId *uint `json:"levelGroupId"`
|
||||
Group *string `json:"group"`
|
||||
}
|
||||
|
||||
func (req PpidDatasUpdateRequest) ToEntity() *entity.PpidDatas {
|
||||
return &entity.PpidDatas{
|
||||
ID: req.ID,
|
||||
Title: req.Title,
|
||||
Description: req.Description,
|
||||
Slug: req.Slug,
|
||||
CategoryId: req.CategoryId,
|
||||
StatusId: req.StatusId,
|
||||
NeedApprovalFromUserRole: req.NeedApprovalFromUserRole,
|
||||
NeedApprovalFromUserLevel: req.NeedApprovalFromUserLevel,
|
||||
BackApprovalToUserRole: req.BackApprovalToUserRole,
|
||||
BackApprovalToUserLevel: req.BackApprovalToUserLevel,
|
||||
IsPublish: req.IsPublish,
|
||||
PublishedAt: req.PublishedAt,
|
||||
LevelGroupId: req.LevelGroupId,
|
||||
Group: req.Group,
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
type PpidDatasUpdatePositionPayload struct {
|
||||
Positions []PpidDatasUpdatePositionRequest `json:"positions"`
|
||||
}
|
||||
|
||||
type PpidDatasUpdatePositionRequest struct {
|
||||
ID uint `json:"id" validate:"required"`
|
||||
Position int `json:"position" validate:"required"`
|
||||
}
|
||||
|
||||
func (req PpidDatasUpdatePositionRequest) ToEntity() *entity.PpidDatas {
|
||||
return &entity.PpidDatas{
|
||||
ID: req.ID,
|
||||
Position: &req.Position,
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
type PpidDatasQueryRequestContext struct {
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
CategoryId string `json:"categoryId"`
|
||||
LevelGroupId string `json:"levelGroupId"`
|
||||
Group string `json:"group"`
|
||||
CreatedById string `json:"createdById"`
|
||||
UserId string `json:"userId"`
|
||||
UserRoleId string `json:"userRoleId"`
|
||||
UserLevelId string `json:"userLevelId"`
|
||||
StatusId string `json:"statusId"`
|
||||
IsPublish string `json:"isPublish"`
|
||||
}
|
||||
|
||||
func (req PpidDatasQueryRequestContext) ToParamRequest() PpidDatasQueryRequest {
|
||||
var request PpidDatasQueryRequest
|
||||
|
||||
if title := req.Title; title != "" {
|
||||
request.Title = &title
|
||||
}
|
||||
if description := req.Description; description != "" {
|
||||
request.Description = &description
|
||||
}
|
||||
if levelGroupIdStr := req.LevelGroupId; levelGroupIdStr != "" {
|
||||
levelGroupId, err := strconv.Atoi(levelGroupIdStr)
|
||||
if err == nil {
|
||||
request.LevelGroupId = &levelGroupId
|
||||
}
|
||||
}
|
||||
if group := req.Group; group != "" {
|
||||
request.Group = &group
|
||||
}
|
||||
if categoryIdStr := req.CategoryId; categoryIdStr != "" {
|
||||
categoryId, err := strconv.Atoi(categoryIdStr)
|
||||
if err == nil {
|
||||
categoryIdUint := uint(categoryId)
|
||||
request.CategoryId = &categoryIdUint
|
||||
}
|
||||
}
|
||||
if isPublishStr := req.IsPublish; isPublishStr != "" {
|
||||
isPublish, err := strconv.ParseBool(isPublishStr)
|
||||
if err == nil {
|
||||
request.IsPublish = &isPublish
|
||||
}
|
||||
}
|
||||
if statusIdStr := req.StatusId; statusIdStr != "" {
|
||||
statusId, err := strconv.Atoi(statusIdStr)
|
||||
if err == nil {
|
||||
request.StatusId = &statusId
|
||||
}
|
||||
}
|
||||
if userIdStr := req.UserId; userIdStr != "" {
|
||||
userId, err := strconv.Atoi(userIdStr)
|
||||
if err == nil {
|
||||
userIdUint := uint(userId)
|
||||
request.UserId = &userIdUint
|
||||
}
|
||||
}
|
||||
if userRoleIdStr := req.UserRoleId; userRoleIdStr != "" {
|
||||
userRoleId, err := strconv.Atoi(userRoleIdStr)
|
||||
if err == nil {
|
||||
userRoleIdUint := uint(userRoleId)
|
||||
request.UserRoleId = &userRoleIdUint
|
||||
}
|
||||
}
|
||||
if userLevelIdStr := req.UserLevelId; userLevelIdStr != "" {
|
||||
userLevelId, err := strconv.Atoi(userLevelIdStr)
|
||||
if err == nil {
|
||||
userLevelIdUint := uint(userLevelId)
|
||||
request.UserLevelId = &userLevelIdUint
|
||||
}
|
||||
}
|
||||
|
||||
return request
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
package response
|
||||
|
||||
import (
|
||||
ppidDataFilesResponse "go-humas-be/app/module/ppid_data_files/response"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PpidDatasResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Slug string `json:"slug"`
|
||||
CategoryId uint `json:"categoryId"`
|
||||
CategoryName *string `json:"categoryName"`
|
||||
CreatedById *uint `json:"createdById"`
|
||||
CreatedByName *string `json:"createdByName"`
|
||||
StatusId int `json:"statusId"`
|
||||
StatusName int `json:"statusName"`
|
||||
IsPublish *bool `json:"isPublish"`
|
||||
Position *int `json:"position"`
|
||||
PublishedAt *time.Time `json:"publishedAt"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
|
||||
PpidDataFiles []*ppidDataFilesResponse.PpidDataFilesResponse `json:"files"`
|
||||
}
|
||||
|
|
@ -1,234 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database/entity"
|
||||
requestPpidApproval "go-humas-be/app/module/ppid_data_approval_histories/request"
|
||||
ppidDataCategoriesRepository "go-humas-be/app/module/ppid_data_categories/repository"
|
||||
ppidDataFilesRepository "go-humas-be/app/module/ppid_data_files/repository"
|
||||
"go-humas-be/app/module/ppid_datas/mapper"
|
||||
"go-humas-be/app/module/ppid_datas/repository"
|
||||
"go-humas-be/app/module/ppid_datas/request"
|
||||
"go-humas-be/app/module/ppid_datas/response"
|
||||
userLevelsRepository "go-humas-be/app/module/user_levels/repository"
|
||||
userRoleLevelDetailsRepository "go-humas-be/app/module/user_role_level_details/repository"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// PpidDatasService
|
||||
type ppidDatasService struct {
|
||||
Repo repository.PpidDatasRepository
|
||||
PpidDataCategoriesRepo ppidDataCategoriesRepository.PpidDataCategoriesRepository
|
||||
PpidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository
|
||||
UsersRepo usersRepository.UsersRepository
|
||||
UserLevelsRepo userLevelsRepository.UserLevelsRepository
|
||||
userRoleLevelDetailsRepo userRoleLevelDetailsRepository.UserRoleLevelDetailsRepository
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// PpidDatasService define interface of IPpidDatasService
|
||||
type PpidDatasService interface {
|
||||
All(req request.PpidDatasQueryRequest, authToken *string) (ppidDatas []*response.PpidDatasResponse, paging paginator.Pagination, err error)
|
||||
Show(id string) (ppidDatas *response.PpidDatasResponse, err error)
|
||||
Save(req request.PpidDatasCreateRequest, authToken string) (ppidDatas *entity.PpidDatas, err error)
|
||||
Update(id uint, req request.PpidDatasUpdateRequest) (err error)
|
||||
UpdateApprovalStatus(req requestPpidApproval.PpidDataApprovalHistoriesCreateRequest, authToken string) (err error)
|
||||
UpdatePosition(req []request.PpidDatasUpdatePositionRequest) (err error)
|
||||
Delete(id uint) error
|
||||
}
|
||||
|
||||
// NewPpidDatasService init PpidDatasService
|
||||
func NewPpidDatasService(
|
||||
repo repository.PpidDatasRepository,
|
||||
ppidDataCategoriesRepo ppidDataCategoriesRepository.PpidDataCategoriesRepository,
|
||||
ppidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository,
|
||||
usersRepo usersRepository.UsersRepository,
|
||||
userLevelsRepo userLevelsRepository.UserLevelsRepository,
|
||||
userRoleLevelDetailsRepo userRoleLevelDetailsRepository.UserRoleLevelDetailsRepository,
|
||||
log zerolog.Logger,
|
||||
) PpidDatasService {
|
||||
|
||||
return &ppidDatasService{
|
||||
Repo: repo,
|
||||
PpidDataCategoriesRepo: ppidDataCategoriesRepo,
|
||||
PpidDataFilesRepo: ppidDataFilesRepo,
|
||||
UsersRepo: usersRepo,
|
||||
UserLevelsRepo: userLevelsRepo,
|
||||
userRoleLevelDetailsRepo: userRoleLevelDetailsRepo,
|
||||
Log: log,
|
||||
}
|
||||
}
|
||||
|
||||
// All implement interface of PpidDatasService
|
||||
func (_i *ppidDatasService) All(req request.PpidDatasQueryRequest, authToken *string) (ppidDatass []*response.PpidDatasResponse, paging paginator.Pagination, err error) {
|
||||
|
||||
var user *entity.Users
|
||||
if authToken != nil && *authToken != "" {
|
||||
user = utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, *authToken)
|
||||
req.UserId = &user.ID
|
||||
req.UserRoleId = &user.UserRoleId
|
||||
req.UserLevelId = &user.UserLevelId
|
||||
}
|
||||
results, paging, err := _i.Repo.GetAll(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
ppidDatass = append(ppidDatass, mapper.PpidDatasResponseMapper(_i.Log, _i.PpidDataCategoriesRepo, _i.PpidDataFilesRepo, _i.UsersRepo, result))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *ppidDatasService) Show(id string) (ppidDatas *response.PpidDatasResponse, err error) {
|
||||
|
||||
var result *entity.PpidDatas
|
||||
|
||||
if utilSvc.IsNumeric(id) {
|
||||
idInt, _ := strconv.Atoi(id)
|
||||
result, err = _i.Repo.FindOne(uint(idInt))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
result, err = _i.Repo.FindOneUsingSlug(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return mapper.PpidDatasResponseMapper(_i.Log, _i.PpidDataCategoriesRepo, _i.PpidDataFilesRepo, _i.UsersRepo, result), nil
|
||||
}
|
||||
|
||||
func (_i *ppidDatasService) Save(req request.PpidDatasCreateRequest, authToken string) (ppidDatas *entity.PpidDatas, err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
newReq := req.ToEntity()
|
||||
|
||||
createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||
newReq.CreatedById = &createdBy.ID
|
||||
newReq.LevelGroupId = &createdBy.UserLevelId
|
||||
|
||||
userLevels, err := _i.UserLevelsRepo.FindOne(uint(createdBy.UserLevelId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newReq.Group = userLevels.Group
|
||||
|
||||
lastPpidData, _ := _i.Repo.FindOneLastPosition()
|
||||
lastPosition := lastPpidData.Position
|
||||
*lastPosition += 1
|
||||
newReq.Position = lastPosition
|
||||
|
||||
return _i.Repo.Create(newReq)
|
||||
}
|
||||
|
||||
func (_i *ppidDatasService) Update(id uint, req request.PpidDatasUpdateRequest) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
return _i.Repo.Update(id, req.ToEntity())
|
||||
}
|
||||
|
||||
func (_i *ppidDatasService) UpdatePosition(req []request.PpidDatasUpdatePositionRequest) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
|
||||
var entityReq []*entity.PpidDatas
|
||||
for _, reqItem := range req {
|
||||
entityReq = append(entityReq, reqItem.ToEntity())
|
||||
}
|
||||
|
||||
return _i.Repo.UpdateAll(entityReq)
|
||||
}
|
||||
|
||||
func (_i *ppidDatasService) UpdateApprovalStatus(req requestPpidApproval.PpidDataApprovalHistoriesCreateRequest, authToken string) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
ppidData, err := _i.Repo.FindOne(req.PpidDataId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if req.ApprovalStatusId == 1 {
|
||||
ppidData.NeedApprovalFromUserRole = nil
|
||||
ppidData.NeedApprovalFromUserLevel = nil
|
||||
ppidData.BackApprovalToUserRole = nil
|
||||
ppidData.BackApprovalToUserLevel = nil
|
||||
}
|
||||
|
||||
approvalBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||
if approvalBy != nil {
|
||||
approvalByUserLevel, _ := _i.UserLevelsRepo.FindOne(uint(approvalBy.UserLevelId))
|
||||
approvalByParentLevel, _ := _i.UserLevelsRepo.FindOne(uint(approvalByUserLevel.ParentLevelId))
|
||||
|
||||
_i.Log.Info().Interface("== findUserLevel ==", approvalByUserLevel).Msg("")
|
||||
_i.Log.Info().Interface("== findUserParentLevel ==", approvalByParentLevel).Msg("")
|
||||
if approvalByUserLevel != nil {
|
||||
ppidData.ApprovalStatusId = req.ApprovalStatusId
|
||||
if req.ApprovalStatusId == 1 {
|
||||
if approvalByUserLevel.LevelNumber == 1 {
|
||||
isPublish := true
|
||||
publishLevel := 1
|
||||
timeNow := time.Now()
|
||||
ppidData.IsPublish = &isPublish
|
||||
ppidData.PublishLevel = &publishLevel
|
||||
ppidData.PublishedAt = &timeNow
|
||||
ppidData.ApprovalStatusId = req.ApprovalStatusId
|
||||
ppidData.NeedApprovalFromUserRole = nil
|
||||
ppidData.NeedApprovalFromUserLevel = nil
|
||||
} else if approvalByUserLevel.LevelNumber > 1 {
|
||||
isPublish := true
|
||||
publishLevel := 2
|
||||
timeNow := time.Now()
|
||||
ppidData.IsPublish = &isPublish
|
||||
ppidData.PublishLevel = &publishLevel
|
||||
ppidData.PublishedAt = &timeNow
|
||||
|
||||
needApprovalFromUserLevel := strconv.FormatUint(uint64(approvalByParentLevel.ID), 10)
|
||||
ppidData.NeedApprovalFromUserLevel = &needApprovalFromUserLevel
|
||||
|
||||
findUserRoles, _ := _i.userRoleLevelDetailsRepo.FindByUserLevels(approvalByParentLevel.ID)
|
||||
var needApprovalFromUserRole []string
|
||||
for _, role := range findUserRoles {
|
||||
roleId := strconv.FormatUint(uint64(role.UserRoleId), 10)
|
||||
needApprovalFromUserRole = append(needApprovalFromUserRole, roleId)
|
||||
}
|
||||
needApprovalFromUserRoleStr := strings.Join(needApprovalFromUserRole, ":")
|
||||
*ppidData.NeedApprovalFromUserRole = ":" + needApprovalFromUserRoleStr + ":"
|
||||
}
|
||||
} else if req.ApprovalStatusId == 2 {
|
||||
createdBy, _ := _i.UsersRepo.FindOne(*ppidData.CreatedById)
|
||||
if createdBy != nil {
|
||||
backApprovalFromUserRole := strconv.FormatUint(uint64(createdBy.UserRoleId), 10)
|
||||
ppidData.BackApprovalToUserRole = &backApprovalFromUserRole
|
||||
|
||||
needApprovalFromUserLevel := strconv.FormatUint(uint64(createdBy.UserLevelId), 10)
|
||||
ppidData.BackApprovalToUserLevel = &needApprovalFromUserLevel
|
||||
}
|
||||
} else {
|
||||
isPublish := false
|
||||
ppidData.IsPublish = &isPublish
|
||||
ppidData.PublishLevel = nil
|
||||
ppidData.PublishedAt = nil
|
||||
ppidData.ApprovalStatusId = req.ApprovalStatusId
|
||||
ppidData.NeedApprovalFromUserRole = nil
|
||||
ppidData.NeedApprovalFromUserLevel = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _i.Repo.Update(req.PpidDataId, ppidData)
|
||||
}
|
||||
|
||||
func (_i *ppidDatasService) Delete(id uint) error {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
isActive := false
|
||||
result.IsActive = &isActive
|
||||
return _i.Repo.Update(id, result)
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/request_for_information_items/service"
|
||||
)
|
||||
|
||||
type Controller struct {
|
||||
RequestForInformationItems RequestForInformationItemsController
|
||||
}
|
||||
|
||||
func NewController(RequestForInformationItemsService service.RequestForInformationItemsService, log zerolog.Logger) *Controller {
|
||||
return &Controller{
|
||||
RequestForInformationItems: NewRequestForInformationItemsController(RequestForInformationItemsService, log),
|
||||
}
|
||||
}
|
||||
|
|
@ -1,194 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/request_for_information_items/request"
|
||||
"go-humas-be/app/module/request_for_information_items/service"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilRes "go-humas-be/utils/response"
|
||||
utilVal "go-humas-be/utils/validator"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type requestForInformationItemsController struct {
|
||||
requestForInformationItemsService service.RequestForInformationItemsService
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
type RequestForInformationItemsController 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 NewRequestForInformationItemsController(requestForInformationItemsService service.RequestForInformationItemsService, log zerolog.Logger) RequestForInformationItemsController {
|
||||
return &requestForInformationItemsController{
|
||||
requestForInformationItemsService: requestForInformationItemsService,
|
||||
Log: log,
|
||||
}
|
||||
}
|
||||
|
||||
// All get all RequestForInformationItems
|
||||
// @Summary Get all RequestForInformationItems
|
||||
// @Description API for getting all RequestForInformationItems
|
||||
// @Tags RequestForInformationItems
|
||||
// @Security Bearer
|
||||
// @Param req query request.RequestForInformationItemsQueryRequest 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 /request-for-information-items [get]
|
||||
func (_i *requestForInformationItemsController) All(c *fiber.Ctx) error {
|
||||
paginate, err := paginator.Paginate(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
reqContext := request.RequestForInformationItemsQueryRequestContext{
|
||||
RequestForInformationId: c.Query("requestForInformationId"),
|
||||
RequestedInfo: c.Query("requestedInfo"),
|
||||
DetailedInfo: c.Query("detailedInfo"),
|
||||
Reason: c.Query("reason"),
|
||||
StatusId: c.Query("statusId"),
|
||||
}
|
||||
req := reqContext.ToParamRequest()
|
||||
req.Pagination = paginate
|
||||
|
||||
requestForInformationItemsData, paging, err := _i.requestForInformationItemsService.All(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationItems list successfully retrieved"},
|
||||
Data: requestForInformationItemsData,
|
||||
Meta: paging,
|
||||
})
|
||||
}
|
||||
|
||||
// Show get one RequestForInformationItems
|
||||
// @Summary Get one RequestForInformationItems
|
||||
// @Description API for getting one RequestForInformationItems
|
||||
// @Tags RequestForInformationItems
|
||||
// @Security Bearer
|
||||
// @Param id path int true "RequestForInformationItems ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-items/{id} [get]
|
||||
func (_i *requestForInformationItemsController) Show(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
requestForInformationItemsData, err := _i.requestForInformationItemsService.Show(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationItems successfully retrieved"},
|
||||
Data: requestForInformationItemsData,
|
||||
})
|
||||
}
|
||||
|
||||
// Save create RequestForInformationItems
|
||||
// @Summary Create RequestForInformationItems
|
||||
// @Description API for create RequestForInformationItems
|
||||
// @Tags RequestForInformationItems
|
||||
// @Security Bearer
|
||||
// @Param payload body request.RequestForInformationItemsCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-items [post]
|
||||
func (_i *requestForInformationItemsController) Save(c *fiber.Ctx) error {
|
||||
req := new(request.RequestForInformationItemsCreateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
authToken := c.Get("Authorization")
|
||||
dataResult, err := _i.requestForInformationItemsService.Save(*req, authToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationItems successfully created"},
|
||||
Data: dataResult,
|
||||
})
|
||||
}
|
||||
|
||||
// Update update RequestForInformationItems
|
||||
// @Summary update RequestForInformationItems
|
||||
// @Description API for update RequestForInformationItems
|
||||
// @Tags RequestForInformationItems
|
||||
// @Security Bearer
|
||||
// @Param payload body request.RequestForInformationItemsUpdateRequest true "Required payload"
|
||||
// @Param id path int true "RequestForInformationItems ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-items/{id} [put]
|
||||
func (_i *requestForInformationItemsController) Update(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := new(request.RequestForInformationItemsUpdateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.requestForInformationItemsService.Update(uint(id), *req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationItems successfully updated"},
|
||||
})
|
||||
}
|
||||
|
||||
// Delete delete RequestForInformationItems
|
||||
// @Summary delete RequestForInformationItems
|
||||
// @Description API for delete RequestForInformationItems
|
||||
// @Tags RequestForInformationItems
|
||||
// @Security Bearer
|
||||
// @Param id path int true "RequestForInformationItems ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-items/{id} [delete]
|
||||
func (_i *requestForInformationItemsController) Delete(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.requestForInformationItemsService.Delete(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationItems successfully deleted"},
|
||||
})
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
res "go-humas-be/app/module/request_for_information_items/response"
|
||||
)
|
||||
|
||||
func RequestForInformationItemsResponseMapper(requestForInformationItemsReq *entity.RequestForInformationItems) (requestForInformationItemsRes *res.RequestForInformationItemsResponse) {
|
||||
if requestForInformationItemsReq != nil {
|
||||
requestForInformationItemsRes = &res.RequestForInformationItemsResponse{
|
||||
ID: requestForInformationItemsReq.ID,
|
||||
RequestForInformationId: requestForInformationItemsReq.RequestForInformationId,
|
||||
RequestedInfo: requestForInformationItemsReq.RequestedInfo,
|
||||
DetailedInfo: requestForInformationItemsReq.DetailedInfo,
|
||||
Reason: requestForInformationItemsReq.Reason,
|
||||
StatusId: requestForInformationItemsReq.StatusId,
|
||||
IsActive: requestForInformationItemsReq.IsActive,
|
||||
CreatedAt: requestForInformationItemsReq.CreatedAt,
|
||||
UpdatedAt: requestForInformationItemsReq.UpdatedAt,
|
||||
}
|
||||
}
|
||||
return requestForInformationItemsRes
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/request_for_information_items/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type requestForInformationItemsRepository struct {
|
||||
DB *database.Database
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// RequestForInformationItemsRepository define interface of IRequestForInformationItemsRepository
|
||||
type RequestForInformationItemsRepository interface {
|
||||
GetAll(req request.RequestForInformationItemsQueryRequest) (requestForInformationItemss []*entity.RequestForInformationItems, paging paginator.Pagination, err error)
|
||||
FindOne(id uint) (requestForInformationItems *entity.RequestForInformationItems, err error)
|
||||
Create(requestForInformationItems *entity.RequestForInformationItems) (requestForInformationItemsReturn *entity.RequestForInformationItems, err error)
|
||||
Update(id uint, requestForInformationItems *entity.RequestForInformationItems) (err error)
|
||||
Delete(id uint) (err error)
|
||||
}
|
||||
|
||||
func NewRequestForInformationItemsRepository(db *database.Database, logger zerolog.Logger) RequestForInformationItemsRepository {
|
||||
return &requestForInformationItemsRepository{
|
||||
DB: db,
|
||||
Log: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// implement interface of IRequestForInformationItemsRepository
|
||||
func (_i *requestForInformationItemsRepository) GetAll(req request.RequestForInformationItemsQueryRequest) (requestForInformationItemss []*entity.RequestForInformationItems, paging paginator.Pagination, err error) {
|
||||
var count int64
|
||||
|
||||
query := _i.DB.DB.Model(&entity.RequestForInformationItems{})
|
||||
query = query.Where("is_active = ?", true)
|
||||
|
||||
if req.RequestForInformationId != nil {
|
||||
query = query.Where("request_for_information_id = ?", req.RequestForInformationId)
|
||||
}
|
||||
if req.RequestedInfo != nil && *req.RequestedInfo != "" {
|
||||
requestedInfo := strings.ToLower(*req.RequestedInfo)
|
||||
query = query.Where("LOWER(requested_info) LIKE ?", "%"+strings.ToLower(requestedInfo)+"%")
|
||||
}
|
||||
if req.DetailedInfo != nil && *req.DetailedInfo != "" {
|
||||
detailedInfo := strings.ToLower(*req.DetailedInfo)
|
||||
query = query.Where("LOWER(detailed_info) LIKE ?", "%"+strings.ToLower(detailedInfo)+"%")
|
||||
}
|
||||
if req.Reason != nil && *req.Reason != "" {
|
||||
reason := strings.ToLower(*req.Reason)
|
||||
query = query.Where("LOWER(reason) LIKE ?", "%"+strings.ToLower(reason)+"%")
|
||||
}
|
||||
if req.StatusId != nil {
|
||||
query = query.Where("status_id = ?", req.StatusId)
|
||||
}
|
||||
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(&requestForInformationItemss).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
paging = *req.Pagination
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *requestForInformationItemsRepository) FindOne(id uint) (requestForInformationItems *entity.RequestForInformationItems, err error) {
|
||||
if err := _i.DB.DB.First(&requestForInformationItems, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return requestForInformationItems, nil
|
||||
}
|
||||
|
||||
func (_i *requestForInformationItemsRepository) Create(requestForInformationItems *entity.RequestForInformationItems) (requestForInformationItemsReturn *entity.RequestForInformationItems, err error) {
|
||||
result := _i.DB.DB.Create(requestForInformationItems)
|
||||
return requestForInformationItems, result.Error
|
||||
}
|
||||
|
||||
func (_i *requestForInformationItemsRepository) Update(id uint, requestForInformationItems *entity.RequestForInformationItems) (err error) {
|
||||
return _i.DB.DB.Model(&entity.RequestForInformationItems{}).
|
||||
Where(&entity.RequestForInformationItems{ID: id}).
|
||||
Updates(requestForInformationItems).Error
|
||||
}
|
||||
|
||||
func (_i *requestForInformationItemsRepository) Delete(id uint) error {
|
||||
return _i.DB.DB.Delete(&entity.RequestForInformationItems{}, id).Error
|
||||
}
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RequestForInformationItemsGeneric interface {
|
||||
ToEntity()
|
||||
}
|
||||
|
||||
type RequestForInformationItemsQueryRequest struct {
|
||||
RequestForInformationId *int `json:"requestForInformationId"`
|
||||
RequestedInfo *string `json:"requestedInfo"`
|
||||
DetailedInfo *string `json:"detailedInfo"`
|
||||
Reason *string `json:"reason"`
|
||||
StatusId *int `json:"statusId"`
|
||||
Pagination *paginator.Pagination `json:"pagination"`
|
||||
}
|
||||
|
||||
type RequestForInformationItemsCreateRequest struct {
|
||||
RequestForInformationId int `json:"requestForInformationId" validate:"required"`
|
||||
RequestedInfo string `json:"requestedInfo" validate:"required"`
|
||||
DetailedInfo string `json:"detailedInfo" validate:"required"`
|
||||
Reason string `json:"reason" validate:"required"`
|
||||
StatusId int `json:"statusId" validate:"required"`
|
||||
}
|
||||
|
||||
func (req RequestForInformationItemsCreateRequest) ToEntity() *entity.RequestForInformationItems {
|
||||
return &entity.RequestForInformationItems{
|
||||
RequestForInformationId: req.RequestForInformationId,
|
||||
RequestedInfo: req.RequestedInfo,
|
||||
DetailedInfo: req.DetailedInfo,
|
||||
Reason: req.Reason,
|
||||
StatusId: req.StatusId,
|
||||
IsActive: func() *bool { b := true; return &b }(),
|
||||
}
|
||||
}
|
||||
|
||||
type RequestForInformationItemsUpdateRequest struct {
|
||||
ID uint `json:"id" validate:"required"`
|
||||
RequestForInformationId int `json:"requestForInformationId" validate:"required"`
|
||||
RequestedInfo string `json:"requestedInfo" validate:"required"`
|
||||
DetailedInfo string `json:"detailedInfo" validate:"required"`
|
||||
Reason string `json:"reason" validate:"required"`
|
||||
StatusId int `json:"statusId" validate:"required"`
|
||||
}
|
||||
|
||||
func (req RequestForInformationItemsUpdateRequest) ToEntity() *entity.RequestForInformationItems {
|
||||
return &entity.RequestForInformationItems{
|
||||
ID: req.ID,
|
||||
RequestForInformationId: req.RequestForInformationId,
|
||||
RequestedInfo: req.RequestedInfo,
|
||||
DetailedInfo: req.DetailedInfo,
|
||||
Reason: req.Reason,
|
||||
StatusId: req.StatusId,
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
type RequestForInformationItemsQueryRequestContext struct {
|
||||
RequestForInformationId string `json:"requestForInformationId"`
|
||||
RequestedInfo string `json:"requestedInfo"`
|
||||
DetailedInfo string `json:"detailedInfo"`
|
||||
Reason string `json:"reason"`
|
||||
StatusId string `json:"statusId"`
|
||||
}
|
||||
|
||||
func (req RequestForInformationItemsQueryRequestContext) ToParamRequest() RequestForInformationItemsQueryRequest {
|
||||
var request RequestForInformationItemsQueryRequest
|
||||
|
||||
if requestForInformationIdStr := req.RequestForInformationId; requestForInformationIdStr != "" {
|
||||
requestForInformationId, err := strconv.Atoi(requestForInformationIdStr)
|
||||
if err == nil {
|
||||
request.RequestForInformationId = &requestForInformationId
|
||||
}
|
||||
}
|
||||
if requestedInfo := req.RequestedInfo; requestedInfo != "" {
|
||||
request.RequestedInfo = &requestedInfo
|
||||
}
|
||||
if detailedInfo := req.DetailedInfo; detailedInfo != "" {
|
||||
request.DetailedInfo = &detailedInfo
|
||||
}
|
||||
if reason := req.Reason; reason != "" {
|
||||
request.Reason = &reason
|
||||
}
|
||||
if statusIdStr := req.StatusId; statusIdStr != "" {
|
||||
statusId, err := strconv.Atoi(statusIdStr)
|
||||
if err == nil {
|
||||
request.StatusId = &statusId
|
||||
}
|
||||
}
|
||||
|
||||
return request
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
package request_for_information_items
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go-humas-be/app/module/request_for_information_items/controller"
|
||||
"go-humas-be/app/module/request_for_information_items/repository"
|
||||
"go-humas-be/app/module/request_for_information_items/service"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
// struct of RequestForInformationItemsRouter
|
||||
type RequestForInformationItemsRouter struct {
|
||||
App fiber.Router
|
||||
Controller *controller.Controller
|
||||
}
|
||||
|
||||
// register bulky of RequestForInformationItems module
|
||||
var NewRequestForInformationItemsModule = fx.Options(
|
||||
// register repository of RequestForInformationItems module
|
||||
fx.Provide(repository.NewRequestForInformationItemsRepository),
|
||||
|
||||
// register service of RequestForInformationItems module
|
||||
fx.Provide(service.NewRequestForInformationItemsService),
|
||||
|
||||
// register controller of RequestForInformationItems module
|
||||
fx.Provide(controller.NewController),
|
||||
|
||||
// register router of RequestForInformationItems module
|
||||
fx.Provide(NewRequestForInformationItemsRouter),
|
||||
)
|
||||
|
||||
// init RequestForInformationItemsRouter
|
||||
func NewRequestForInformationItemsRouter(fiber *fiber.App, controller *controller.Controller) *RequestForInformationItemsRouter {
|
||||
return &RequestForInformationItemsRouter{
|
||||
App: fiber,
|
||||
Controller: controller,
|
||||
}
|
||||
}
|
||||
|
||||
// register routes of RequestForInformationItems module
|
||||
func (_i *RequestForInformationItemsRouter) RegisterRequestForInformationItemsRoutes() {
|
||||
// define controllers
|
||||
requestForInformationItemsController := _i.Controller.RequestForInformationItems
|
||||
|
||||
// define routes
|
||||
_i.App.Route("/request-for-information-items", func(router fiber.Router) {
|
||||
router.Get("/", requestForInformationItemsController.All)
|
||||
router.Get("/:id", requestForInformationItemsController.Show)
|
||||
router.Post("/", requestForInformationItemsController.Save)
|
||||
router.Put("/:id", requestForInformationItemsController.Update)
|
||||
router.Delete("/:id", requestForInformationItemsController.Delete)
|
||||
})
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package response
|
||||
|
||||
import "time"
|
||||
|
||||
type RequestForInformationItemsResponse struct {
|
||||
ID uint `json:"id"`
|
||||
RequestForInformationId int `json:"requestForInformationId"`
|
||||
RequestedInfo string `json:"requestedInfo"`
|
||||
DetailedInfo string `json:"detailedInfo"`
|
||||
Reason string `json:"reason"`
|
||||
StatusId int `json:"statusId"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/request_for_information_items/mapper"
|
||||
"go-humas-be/app/module/request_for_information_items/repository"
|
||||
"go-humas-be/app/module/request_for_information_items/request"
|
||||
"go-humas-be/app/module/request_for_information_items/response"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
"go-humas-be/utils/paginator"
|
||||
)
|
||||
|
||||
// RequestForInformationItemsService
|
||||
type requestForInformationItemsService struct {
|
||||
Repo repository.RequestForInformationItemsRepository
|
||||
UsersRepo usersRepository.UsersRepository
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// RequestForInformationItemsService define interface of IRequestForInformationItemsService
|
||||
type RequestForInformationItemsService interface {
|
||||
All(req request.RequestForInformationItemsQueryRequest) (requestForInformationItems []*response.RequestForInformationItemsResponse, paging paginator.Pagination, err error)
|
||||
Show(id uint) (requestForInformationItems *response.RequestForInformationItemsResponse, err error)
|
||||
Save(req request.RequestForInformationItemsCreateRequest, authToken string) (requestForInformationItems *entity.RequestForInformationItems, err error)
|
||||
Update(id uint, req request.RequestForInformationItemsUpdateRequest) (err error)
|
||||
Delete(id uint) error
|
||||
}
|
||||
|
||||
// NewRequestForInformationItemsService init RequestForInformationItemsService
|
||||
func NewRequestForInformationItemsService(repo repository.RequestForInformationItemsRepository, log zerolog.Logger, usersRepo usersRepository.UsersRepository) RequestForInformationItemsService {
|
||||
|
||||
return &requestForInformationItemsService{
|
||||
Repo: repo,
|
||||
Log: log,
|
||||
UsersRepo: usersRepo,
|
||||
}
|
||||
}
|
||||
|
||||
// All implement interface of RequestForInformationItemsService
|
||||
func (_i *requestForInformationItemsService) All(req request.RequestForInformationItemsQueryRequest) (requestForInformationItemss []*response.RequestForInformationItemsResponse, paging paginator.Pagination, err error) {
|
||||
results, paging, err := _i.Repo.GetAll(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
requestForInformationItemss = append(requestForInformationItemss, mapper.RequestForInformationItemsResponseMapper(result))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *requestForInformationItemsService) Show(id uint) (requestForInformationItems *response.RequestForInformationItemsResponse, err error) {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mapper.RequestForInformationItemsResponseMapper(result), nil
|
||||
}
|
||||
|
||||
func (_i *requestForInformationItemsService) Save(req request.RequestForInformationItemsCreateRequest, authToken string) (requestForInformationItems *entity.RequestForInformationItems, err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
|
||||
newReq := req.ToEntity()
|
||||
|
||||
return _i.Repo.Create(newReq)
|
||||
}
|
||||
|
||||
func (_i *requestForInformationItemsService) Update(id uint, req request.RequestForInformationItemsUpdateRequest) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
return _i.Repo.Update(id, req.ToEntity())
|
||||
}
|
||||
|
||||
func (_i *requestForInformationItemsService) Delete(id uint) error {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
isActive := false
|
||||
result.IsActive = &isActive
|
||||
return _i.Repo.Update(id, result)
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/request_for_information_objection/service"
|
||||
)
|
||||
|
||||
type Controller struct {
|
||||
RequestForInformationObjection RequestForInformationObjectionController
|
||||
}
|
||||
|
||||
func NewController(RequestForInformationObjectionService service.RequestForInformationObjectionService, log zerolog.Logger) *Controller {
|
||||
return &Controller{
|
||||
RequestForInformationObjection: NewRequestForInformationObjectionController(RequestForInformationObjectionService, log),
|
||||
}
|
||||
}
|
||||
|
|
@ -1,198 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/request_for_information_objection/request"
|
||||
"go-humas-be/app/module/request_for_information_objection/service"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strconv"
|
||||
|
||||
utilRes "go-humas-be/utils/response"
|
||||
utilVal "go-humas-be/utils/validator"
|
||||
)
|
||||
|
||||
type requestForInformationObjectionController struct {
|
||||
requestForInformationObjectionService service.RequestForInformationObjectionService
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
type RequestForInformationObjectionController 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 NewRequestForInformationObjectionController(requestForInformationObjectionService service.RequestForInformationObjectionService, log zerolog.Logger) RequestForInformationObjectionController {
|
||||
return &requestForInformationObjectionController{
|
||||
requestForInformationObjectionService: requestForInformationObjectionService,
|
||||
Log: log,
|
||||
}
|
||||
}
|
||||
|
||||
// All get all RequestForInformationObjection
|
||||
// @Summary Get all RequestForInformationObjection
|
||||
// @Description API for getting all RequestForInformationObjection
|
||||
// @Tags RequestForInformationObjection
|
||||
// @Security Bearer
|
||||
// @Param req query request.RequestForInformationObjectionQueryRequest 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 /request-for-information-objection [get]
|
||||
func (_i *requestForInformationObjectionController) All(c *fiber.Ctx) error {
|
||||
paginate, err := paginator.Paginate(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
reqContext := request.RequestForInformationObjectionQueryRequestContext{
|
||||
RequestForInformationItemId: c.Query("requestForInformationItemId"),
|
||||
DocumentName: c.Query("documentName"),
|
||||
MainReason: c.Query("mainReason"),
|
||||
SecondaryReason: c.Query("secondaryReason"),
|
||||
CreatedById: c.Query("createdById"),
|
||||
StatusId: c.Query("statusId"),
|
||||
}
|
||||
req := reqContext.ToParamRequest()
|
||||
req.Pagination = paginate
|
||||
|
||||
requestForInformationObjectionData, paging, err := _i.requestForInformationObjectionService.All(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationObjection list successfully retrieved"},
|
||||
Data: requestForInformationObjectionData,
|
||||
Meta: paging,
|
||||
})
|
||||
}
|
||||
|
||||
// Show get one RequestForInformationObjection
|
||||
// @Summary Get one RequestForInformationObjection
|
||||
// @Description API for getting one RequestForInformationObjection
|
||||
// @Tags RequestForInformationObjection
|
||||
// @Security Bearer
|
||||
// @Param id path int true "RequestForInformationObjection ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-objection/{id} [get]
|
||||
func (_i *requestForInformationObjectionController) Show(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
requestForInformationObjectionData, err := _i.requestForInformationObjectionService.Show(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationObjection successfully retrieved"},
|
||||
Data: requestForInformationObjectionData,
|
||||
})
|
||||
}
|
||||
|
||||
// Save create RequestForInformationObjection
|
||||
// @Summary Create RequestForInformationObjection
|
||||
// @Description API for create RequestForInformationObjection
|
||||
// @Tags RequestForInformationObjection
|
||||
// @Security Bearer
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.RequestForInformationObjectionCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-objection [post]
|
||||
func (_i *requestForInformationObjectionController) Save(c *fiber.Ctx) error {
|
||||
req := new(request.RequestForInformationObjectionCreateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
authToken := c.Get("Authorization")
|
||||
dataResult, err := _i.requestForInformationObjectionService.Save(*req, authToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationObjection successfully created"},
|
||||
Data: dataResult,
|
||||
})
|
||||
}
|
||||
|
||||
// Update update RequestForInformationObjection
|
||||
// @Summary update RequestForInformationObjection
|
||||
// @Description API for update RequestForInformationObjection
|
||||
// @Tags RequestForInformationObjection
|
||||
// @Security Bearer
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.RequestForInformationObjectionUpdateRequest true "Required payload"
|
||||
// @Param id path int true "RequestForInformationObjection ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-objection/{id} [put]
|
||||
func (_i *requestForInformationObjectionController) Update(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := new(request.RequestForInformationObjectionUpdateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.requestForInformationObjectionService.Update(uint(id), *req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationObjection successfully updated"},
|
||||
})
|
||||
}
|
||||
|
||||
// Delete delete RequestForInformationObjection
|
||||
// @Summary delete RequestForInformationObjection
|
||||
// @Description API for delete RequestForInformationObjection
|
||||
// @Tags RequestForInformationObjection
|
||||
// @Security Bearer
|
||||
// @Param id path int true "RequestForInformationObjection ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-objection/{id} [delete]
|
||||
func (_i *requestForInformationObjectionController) Delete(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.requestForInformationObjectionService.Delete(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationObjection successfully deleted"},
|
||||
})
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
res "go-humas-be/app/module/request_for_information_objection/response"
|
||||
)
|
||||
|
||||
func RequestForInformationObjectionResponseMapper(requestForInformationObjectionReq *entity.RequestForInformationObjection) (requestForInformationObjectionRes *res.RequestForInformationObjectionResponse) {
|
||||
if requestForInformationObjectionReq != nil {
|
||||
requestForInformationObjectionRes = &res.RequestForInformationObjectionResponse{
|
||||
ID: requestForInformationObjectionReq.ID,
|
||||
RequestForInformationItemId: requestForInformationObjectionReq.RequestForInformationItemId,
|
||||
DocumentName: requestForInformationObjectionReq.DocumentName,
|
||||
MainReason: requestForInformationObjectionReq.MainReason,
|
||||
SecondaryReason: requestForInformationObjectionReq.SecondaryReason,
|
||||
CreatedById: requestForInformationObjectionReq.CreatedById,
|
||||
StatusId: requestForInformationObjectionReq.StatusId,
|
||||
IsActive: requestForInformationObjectionReq.IsActive,
|
||||
CreatedAt: requestForInformationObjectionReq.CreatedAt,
|
||||
UpdatedAt: requestForInformationObjectionReq.UpdatedAt,
|
||||
}
|
||||
}
|
||||
return requestForInformationObjectionRes
|
||||
}
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/request_for_information_objection/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type requestForInformationObjectionRepository struct {
|
||||
DB *database.Database
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// RequestForInformationObjectionRepository define interface of IRequestForInformationObjectionRepository
|
||||
type RequestForInformationObjectionRepository interface {
|
||||
GetAll(req request.RequestForInformationObjectionQueryRequest) (requestForInformationObjections []*entity.RequestForInformationObjection, paging paginator.Pagination, err error)
|
||||
FindOne(id uint) (requestForInformationObjection *entity.RequestForInformationObjection, err error)
|
||||
Create(requestForInformationObjection *entity.RequestForInformationObjection) (requestForInformationObjectionReturn *entity.RequestForInformationObjection, err error)
|
||||
Update(id uint, requestForInformationObjection *entity.RequestForInformationObjection) (err error)
|
||||
Delete(id uint) (err error)
|
||||
}
|
||||
|
||||
func NewRequestForInformationObjectionRepository(db *database.Database, logger zerolog.Logger) RequestForInformationObjectionRepository {
|
||||
return &requestForInformationObjectionRepository{
|
||||
DB: db,
|
||||
Log: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// implement interface of IRequestForInformationObjectionRepository
|
||||
func (_i *requestForInformationObjectionRepository) GetAll(req request.RequestForInformationObjectionQueryRequest) (requestForInformationObjections []*entity.RequestForInformationObjection, paging paginator.Pagination, err error) {
|
||||
var count int64
|
||||
|
||||
query := _i.DB.DB.Model(&entity.RequestForInformationObjection{})
|
||||
query = query.Where("is_active = ?", true)
|
||||
|
||||
if req.RequestForInformationItemId != nil {
|
||||
query = query.Where("request_for_information_item_id = ?", req.RequestForInformationItemId)
|
||||
}
|
||||
if req.DocumentName != nil && *req.DocumentName != "" {
|
||||
documentName := strings.ToLower(*req.DocumentName)
|
||||
query = query.Where("LOWER(document_name) LIKE ?", "%"+strings.ToLower(documentName)+"%")
|
||||
}
|
||||
if req.MainReason != nil && *req.MainReason != "" {
|
||||
mainReason := strings.ToLower(*req.MainReason)
|
||||
query = query.Where("LOWER(main_reason) LIKE ?", "%"+strings.ToLower(mainReason)+"%")
|
||||
}
|
||||
if req.SecondaryReason != nil && *req.SecondaryReason != "" {
|
||||
secondaryReason := strings.ToLower(*req.SecondaryReason)
|
||||
query = query.Where("LOWER(secondary_reason) LIKE ?", "%"+strings.ToLower(secondaryReason)+"%")
|
||||
}
|
||||
if req.CreatedById != nil {
|
||||
query = query.Where("created_by_id = ?", req.CreatedById)
|
||||
}
|
||||
if req.StatusId != nil {
|
||||
query = query.Where("status_id = ?", req.StatusId)
|
||||
}
|
||||
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(&requestForInformationObjections).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
paging = *req.Pagination
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionRepository) FindOne(id uint) (requestForInformationObjection *entity.RequestForInformationObjection, err error) {
|
||||
if err := _i.DB.DB.First(&requestForInformationObjection, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return requestForInformationObjection, nil
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionRepository) Create(requestForInformationObjection *entity.RequestForInformationObjection) (requestForInformationObjectionReturn *entity.RequestForInformationObjection, err error) {
|
||||
result := _i.DB.DB.Create(requestForInformationObjection)
|
||||
return requestForInformationObjection, result.Error
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionRepository) Update(id uint, requestForInformationObjection *entity.RequestForInformationObjection) (err error) {
|
||||
return _i.DB.DB.Model(&entity.RequestForInformationObjection{}).
|
||||
Where(&entity.RequestForInformationObjection{ID: id}).
|
||||
Updates(requestForInformationObjection).Error
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionRepository) Delete(id uint) error {
|
||||
return _i.DB.DB.Delete(&entity.RequestForInformationObjection{}, id).Error
|
||||
}
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RequestForInformationObjectionGeneric interface {
|
||||
ToEntity()
|
||||
}
|
||||
|
||||
type RequestForInformationObjectionQueryRequest struct {
|
||||
RequestForInformationItemId *uint `json:"requestForInformationItemId"`
|
||||
DocumentName *string `json:"documentName"`
|
||||
MainReason *string `json:"mainReason"`
|
||||
SecondaryReason *string `json:"secondaryReason"`
|
||||
CreatedById *int `json:"createdById"`
|
||||
StatusId *int `json:"statusId"`
|
||||
Pagination *paginator.Pagination `json:"pagination"`
|
||||
}
|
||||
|
||||
type RequestForInformationObjectionCreateRequest struct {
|
||||
RequestForInformationItemId uint `json:"requestForInformationItemId" validate:"required"`
|
||||
DocumentName string `json:"documentName" validate:"required"`
|
||||
MainReason string `json:"mainReason" validate:"required"`
|
||||
SecondaryReason string `json:"secondaryReason" validate:"required"`
|
||||
StatusId int `json:"statusId" validate:"required"`
|
||||
}
|
||||
|
||||
func (req RequestForInformationObjectionCreateRequest) ToEntity() *entity.RequestForInformationObjection {
|
||||
return &entity.RequestForInformationObjection{
|
||||
RequestForInformationItemId: req.RequestForInformationItemId,
|
||||
DocumentName: req.DocumentName,
|
||||
MainReason: req.MainReason,
|
||||
SecondaryReason: req.SecondaryReason,
|
||||
StatusId: req.StatusId,
|
||||
IsActive: func() *bool { b := true; return &b }(),
|
||||
}
|
||||
}
|
||||
|
||||
type RequestForInformationObjectionUpdateRequest struct {
|
||||
ID uint `json:"id" validate:"required"`
|
||||
RequestForInformationItemId uint `json:"requestForInformationItemId" validate:"required"`
|
||||
DocumentName string `json:"documentName" validate:"required"`
|
||||
MainReason string `json:"mainReason" validate:"required"`
|
||||
SecondaryReason string `json:"secondaryReason" validate:"required"`
|
||||
StatusId int `json:"statusId" validate:"required"`
|
||||
}
|
||||
|
||||
func (req RequestForInformationObjectionUpdateRequest) ToEntity() *entity.RequestForInformationObjection {
|
||||
return &entity.RequestForInformationObjection{
|
||||
ID: req.ID,
|
||||
RequestForInformationItemId: req.RequestForInformationItemId,
|
||||
DocumentName: req.DocumentName,
|
||||
MainReason: req.MainReason,
|
||||
SecondaryReason: req.SecondaryReason,
|
||||
StatusId: req.StatusId,
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
type RequestForInformationObjectionQueryRequestContext struct {
|
||||
RequestForInformationItemId string `json:"requestForInformationItemId"`
|
||||
DocumentName string `json:"documentName"`
|
||||
MainReason string `json:"mainReason"`
|
||||
SecondaryReason string `json:"secondaryReason"`
|
||||
CreatedById string `json:"createdById"`
|
||||
StatusId string `json:"statusId"`
|
||||
}
|
||||
|
||||
func (req RequestForInformationObjectionQueryRequestContext) ToParamRequest() RequestForInformationObjectionQueryRequest {
|
||||
var request RequestForInformationObjectionQueryRequest
|
||||
|
||||
if requestForInformationIdStr := req.RequestForInformationItemId; requestForInformationIdStr != "" {
|
||||
requestForInformationId, err := strconv.Atoi(requestForInformationIdStr)
|
||||
if err == nil {
|
||||
requestForInformationIdUint := uint(requestForInformationId)
|
||||
request.RequestForInformationItemId = &requestForInformationIdUint
|
||||
}
|
||||
}
|
||||
if documentName := req.DocumentName; documentName != "" {
|
||||
request.DocumentName = &documentName
|
||||
}
|
||||
if mainReason := req.MainReason; mainReason != "" {
|
||||
request.MainReason = &mainReason
|
||||
}
|
||||
if secondaryReason := req.SecondaryReason; secondaryReason != "" {
|
||||
request.SecondaryReason = &secondaryReason
|
||||
}
|
||||
if createdByIdStr := req.CreatedById; createdByIdStr != "" {
|
||||
createdById, err := strconv.Atoi(createdByIdStr)
|
||||
if err == nil {
|
||||
request.CreatedById = &createdById
|
||||
}
|
||||
}
|
||||
if statusIdStr := req.StatusId; statusIdStr != "" {
|
||||
statusId, err := strconv.Atoi(statusIdStr)
|
||||
if err == nil {
|
||||
request.StatusId = &statusId
|
||||
}
|
||||
}
|
||||
|
||||
return request
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
package request_for_information_objection
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go-humas-be/app/module/request_for_information_objection/controller"
|
||||
"go-humas-be/app/module/request_for_information_objection/repository"
|
||||
"go-humas-be/app/module/request_for_information_objection/service"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
// struct of RequestForInformationObjectionRouter
|
||||
type RequestForInformationObjectionRouter struct {
|
||||
App fiber.Router
|
||||
Controller *controller.Controller
|
||||
}
|
||||
|
||||
// register bulky of RequestForInformationObjection module
|
||||
var NewRequestForInformationObjectionModule = fx.Options(
|
||||
// register repository of RequestForInformationObjection module
|
||||
fx.Provide(repository.NewRequestForInformationObjectionRepository),
|
||||
|
||||
// register service of RequestForInformationObjection module
|
||||
fx.Provide(service.NewRequestForInformationObjectionService),
|
||||
|
||||
// register controller of RequestForInformationObjection module
|
||||
fx.Provide(controller.NewController),
|
||||
|
||||
// register router of RequestForInformationObjection module
|
||||
fx.Provide(NewRequestForInformationObjectionRouter),
|
||||
)
|
||||
|
||||
// init RequestForInformationObjectionRouter
|
||||
func NewRequestForInformationObjectionRouter(fiber *fiber.App, controller *controller.Controller) *RequestForInformationObjectionRouter {
|
||||
return &RequestForInformationObjectionRouter{
|
||||
App: fiber,
|
||||
Controller: controller,
|
||||
}
|
||||
}
|
||||
|
||||
// register routes of RequestForInformationObjection module
|
||||
func (_i *RequestForInformationObjectionRouter) RegisterRequestForInformationObjectionRoutes() {
|
||||
// define controllers
|
||||
requestForInformationObjectionController := _i.Controller.RequestForInformationObjection
|
||||
|
||||
// define routes
|
||||
_i.App.Route("/request-for-information-objection", func(router fiber.Router) {
|
||||
router.Get("/", requestForInformationObjectionController.All)
|
||||
router.Get("/:id", requestForInformationObjectionController.Show)
|
||||
router.Post("/", requestForInformationObjectionController.Save)
|
||||
router.Put("/:id", requestForInformationObjectionController.Update)
|
||||
router.Delete("/:id", requestForInformationObjectionController.Delete)
|
||||
})
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package response
|
||||
|
||||
import "time"
|
||||
|
||||
type RequestForInformationObjectionResponse struct {
|
||||
ID uint `json:"id"`
|
||||
RequestForInformationItemId uint `json:"requestForInformationItemId"`
|
||||
DocumentName string `json:"documentName"`
|
||||
MainReason string `json:"mainReason"`
|
||||
SecondaryReason string `json:"secondaryReason"`
|
||||
CreatedById uint `json:"createdById"`
|
||||
StatusId int `json:"statusId"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/request_for_information_objection/mapper"
|
||||
"go-humas-be/app/module/request_for_information_objection/repository"
|
||||
"go-humas-be/app/module/request_for_information_objection/request"
|
||||
"go-humas-be/app/module/request_for_information_objection/response"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
"go-humas-be/utils/paginator"
|
||||
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
)
|
||||
|
||||
// RequestForInformationObjectionService
|
||||
type requestForInformationObjectionService struct {
|
||||
Repo repository.RequestForInformationObjectionRepository
|
||||
UsersRepo usersRepository.UsersRepository
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// RequestForInformationObjectionService define interface of IRequestForInformationObjectionService
|
||||
type RequestForInformationObjectionService interface {
|
||||
All(req request.RequestForInformationObjectionQueryRequest) (requestForInformationObjection []*response.RequestForInformationObjectionResponse, paging paginator.Pagination, err error)
|
||||
Show(id uint) (requestForInformationObjection *response.RequestForInformationObjectionResponse, err error)
|
||||
Save(req request.RequestForInformationObjectionCreateRequest, authToken string) (requestForInformationObjection *entity.RequestForInformationObjection, err error)
|
||||
Update(id uint, req request.RequestForInformationObjectionUpdateRequest) (err error)
|
||||
Delete(id uint) error
|
||||
}
|
||||
|
||||
// NewRequestForInformationObjectionService init RequestForInformationObjectionService
|
||||
func NewRequestForInformationObjectionService(repo repository.RequestForInformationObjectionRepository, log zerolog.Logger, usersRepo usersRepository.UsersRepository) RequestForInformationObjectionService {
|
||||
|
||||
return &requestForInformationObjectionService{
|
||||
Repo: repo,
|
||||
Log: log,
|
||||
UsersRepo: usersRepo,
|
||||
}
|
||||
}
|
||||
|
||||
// All implement interface of RequestForInformationObjectionService
|
||||
func (_i *requestForInformationObjectionService) All(req request.RequestForInformationObjectionQueryRequest) (requestForInformationObjections []*response.RequestForInformationObjectionResponse, paging paginator.Pagination, err error) {
|
||||
results, paging, err := _i.Repo.GetAll(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
requestForInformationObjections = append(requestForInformationObjections, mapper.RequestForInformationObjectionResponseMapper(result))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionService) Show(id uint) (requestForInformationObjection *response.RequestForInformationObjectionResponse, err error) {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mapper.RequestForInformationObjectionResponseMapper(result), nil
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionService) Save(req request.RequestForInformationObjectionCreateRequest, authToken string) (requestForInformationObjection *entity.RequestForInformationObjection, err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
|
||||
newReq := req.ToEntity()
|
||||
|
||||
createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||
newReq.CreatedById = createdBy.ID
|
||||
|
||||
return _i.Repo.Create(newReq)
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionService) Update(id uint, req request.RequestForInformationObjectionUpdateRequest) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
return _i.Repo.Update(id, req.ToEntity())
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionService) Delete(id uint) error {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
isActive := false
|
||||
result.IsActive = &isActive
|
||||
return _i.Repo.Update(id, result)
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/request_for_information_objection_replies/service"
|
||||
)
|
||||
|
||||
type Controller struct {
|
||||
RequestForInformationObjectionReplies RequestForInformationObjectionRepliesController
|
||||
}
|
||||
|
||||
func NewController(RequestForInformationObjectionRepliesService service.RequestForInformationObjectionRepliesService, log zerolog.Logger) *Controller {
|
||||
return &Controller{
|
||||
RequestForInformationObjectionReplies: NewRequestForInformationObjectionRepliesController(RequestForInformationObjectionRepliesService, log),
|
||||
}
|
||||
}
|
||||
|
|
@ -1,193 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/request_for_information_objection_replies/request"
|
||||
"go-humas-be/app/module/request_for_information_objection_replies/service"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilRes "go-humas-be/utils/response"
|
||||
utilVal "go-humas-be/utils/validator"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type requestForInformationObjectionRepliesController struct {
|
||||
requestForInformationObjectionRepliesService service.RequestForInformationObjectionRepliesService
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
type RequestForInformationObjectionRepliesController 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 NewRequestForInformationObjectionRepliesController(requestForInformationObjectionRepliesService service.RequestForInformationObjectionRepliesService, log zerolog.Logger) RequestForInformationObjectionRepliesController {
|
||||
return &requestForInformationObjectionRepliesController{
|
||||
requestForInformationObjectionRepliesService: requestForInformationObjectionRepliesService,
|
||||
Log: log,
|
||||
}
|
||||
}
|
||||
|
||||
// All get all RequestForInformationObjectionReplies
|
||||
// @Summary Get all RequestForInformationObjectionReplies
|
||||
// @Description API for getting all RequestForInformationObjectionReplies
|
||||
// @Tags RequestForInformationObjectionReplies
|
||||
// @Security Bearer
|
||||
// @Param req query request.RequestForInformationObjectionRepliesQueryRequest 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 /request-for-information-objection-replies [get]
|
||||
func (_i *requestForInformationObjectionRepliesController) All(c *fiber.Ctx) error {
|
||||
paginate, err := paginator.Paginate(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
reqContext := request.RequestForInformationObjectionRepliesQueryRequestContext{
|
||||
RequestForInformationObjectionId: c.Query("requestForInformationObjectionId"),
|
||||
Response: c.Query("response"),
|
||||
StatusId: c.Query("statusId"),
|
||||
}
|
||||
req := reqContext.ToParamRequest()
|
||||
req.Pagination = paginate
|
||||
|
||||
requestForInformationObjectionRepliesData, paging, err := _i.requestForInformationObjectionRepliesService.All(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationObjectionReplies list successfully retrieved"},
|
||||
Data: requestForInformationObjectionRepliesData,
|
||||
Meta: paging,
|
||||
})
|
||||
}
|
||||
|
||||
// Show get one RequestForInformationObjectionReplies
|
||||
// @Summary Get one RequestForInformationObjectionReplies
|
||||
// @Description API for getting one RequestForInformationObjectionReplies
|
||||
// @Tags RequestForInformationObjectionReplies
|
||||
// @Security Bearer
|
||||
// @Param id path int true "RequestForInformationObjectionReplies ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-objection-replies/{id} [get]
|
||||
func (_i *requestForInformationObjectionRepliesController) Show(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
requestForInformationObjectionRepliesData, err := _i.requestForInformationObjectionRepliesService.Show(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationObjectionReplies successfully retrieved"},
|
||||
Data: requestForInformationObjectionRepliesData,
|
||||
})
|
||||
}
|
||||
|
||||
// Save create RequestForInformationObjectionReplies
|
||||
// @Summary Create RequestForInformationObjectionReplies
|
||||
// @Description API for create RequestForInformationObjectionReplies
|
||||
// @Tags RequestForInformationObjectionReplies
|
||||
// @Security Bearer
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.RequestForInformationObjectionRepliesCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-objection-replies [post]
|
||||
func (_i *requestForInformationObjectionRepliesController) Save(c *fiber.Ctx) error {
|
||||
req := new(request.RequestForInformationObjectionRepliesCreateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
authToken := c.Get("Authorization")
|
||||
dataResult, err := _i.requestForInformationObjectionRepliesService.Save(*req, authToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationObjectionReplies successfully created"},
|
||||
Data: dataResult,
|
||||
})
|
||||
}
|
||||
|
||||
// Update update RequestForInformationObjectionReplies
|
||||
// @Summary update RequestForInformationObjectionReplies
|
||||
// @Description API for update RequestForInformationObjectionReplies
|
||||
// @Tags RequestForInformationObjectionReplies
|
||||
// @Security Bearer
|
||||
// @Param payload body request.RequestForInformationObjectionRepliesUpdateRequest true "Required payload"
|
||||
// @Param id path int true "RequestForInformationObjectionReplies ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-objection-replies/{id} [put]
|
||||
func (_i *requestForInformationObjectionRepliesController) Update(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := new(request.RequestForInformationObjectionRepliesUpdateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.requestForInformationObjectionRepliesService.Update(uint(id), *req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationObjectionReplies successfully updated"},
|
||||
})
|
||||
}
|
||||
|
||||
// Delete delete RequestForInformationObjectionReplies
|
||||
// @Summary delete RequestForInformationObjectionReplies
|
||||
// @Description API for delete RequestForInformationObjectionReplies
|
||||
// @Tags RequestForInformationObjectionReplies
|
||||
// @Security Bearer
|
||||
// @Param id path int true "RequestForInformationObjectionReplies ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-objection-replies/{id} [delete]
|
||||
func (_i *requestForInformationObjectionRepliesController) Delete(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.requestForInformationObjectionRepliesService.Delete(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationObjectionReplies successfully deleted"},
|
||||
})
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
res "go-humas-be/app/module/request_for_information_objection_replies/response"
|
||||
)
|
||||
|
||||
func RequestForInformationObjectionRepliesResponseMapper(requestForInformationObjectionRepliesReq *entity.RequestForInformationObjectionReplies) (requestForInformationObjectionRepliesRes *res.RequestForInformationObjectionRepliesResponse) {
|
||||
if requestForInformationObjectionRepliesReq != nil {
|
||||
requestForInformationObjectionRepliesRes = &res.RequestForInformationObjectionRepliesResponse{
|
||||
ID: requestForInformationObjectionRepliesReq.ID,
|
||||
RequestForInformationObjectionId: requestForInformationObjectionRepliesReq.RequestForInformationObjectionId,
|
||||
Response: requestForInformationObjectionRepliesReq.Response,
|
||||
StatusId: requestForInformationObjectionRepliesReq.StatusId,
|
||||
CreatedById: requestForInformationObjectionRepliesReq.CreatedById,
|
||||
IsActive: requestForInformationObjectionRepliesReq.IsActive,
|
||||
CreatedAt: requestForInformationObjectionRepliesReq.CreatedAt,
|
||||
UpdatedAt: requestForInformationObjectionRepliesReq.UpdatedAt,
|
||||
}
|
||||
}
|
||||
return requestForInformationObjectionRepliesRes
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/request_for_information_objection_replies/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type requestForInformationObjectionRepliesRepository struct {
|
||||
DB *database.Database
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// RequestForInformationObjectionRepliesRepository define interface of IRequestForInformationObjectionRepliesRepository
|
||||
type RequestForInformationObjectionRepliesRepository interface {
|
||||
GetAll(req request.RequestForInformationObjectionRepliesQueryRequest) (requestForInformationObjectionRepliess []*entity.RequestForInformationObjectionReplies, paging paginator.Pagination, err error)
|
||||
FindOne(id uint) (requestForInformationObjectionReplies *entity.RequestForInformationObjectionReplies, err error)
|
||||
Create(requestForInformationObjectionReplies *entity.RequestForInformationObjectionReplies) (requestForInformationObjectionRepliesReturn *entity.RequestForInformationObjectionReplies, err error)
|
||||
Update(id uint, requestForInformationObjectionReplies *entity.RequestForInformationObjectionReplies) (err error)
|
||||
Delete(id uint) (err error)
|
||||
}
|
||||
|
||||
func NewRequestForInformationObjectionRepliesRepository(db *database.Database, logger zerolog.Logger) RequestForInformationObjectionRepliesRepository {
|
||||
return &requestForInformationObjectionRepliesRepository{
|
||||
DB: db,
|
||||
Log: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// implement interface of IRequestForInformationObjectionRepliesRepository
|
||||
func (_i *requestForInformationObjectionRepliesRepository) GetAll(req request.RequestForInformationObjectionRepliesQueryRequest) (requestForInformationObjectionRepliess []*entity.RequestForInformationObjectionReplies, paging paginator.Pagination, err error) {
|
||||
var count int64
|
||||
|
||||
query := _i.DB.DB.Model(&entity.RequestForInformationObjectionReplies{})
|
||||
query = query.Where("is_active = ?", true)
|
||||
|
||||
if req.RequestForInformationObjectionId != nil {
|
||||
query = query.Where("request_for_information_objection_id = ?", req.RequestForInformationObjectionId)
|
||||
}
|
||||
if req.Response != nil && *req.Response != "" {
|
||||
response := strings.ToLower(*req.Response)
|
||||
query = query.Where("LOWER(response) LIKE ?", "%"+strings.ToLower(response)+"%")
|
||||
}
|
||||
if req.StatusId != nil {
|
||||
query = query.Where("status_id = ?", req.StatusId)
|
||||
}
|
||||
if req.CreatedById != nil {
|
||||
query = query.Where("created_by_id = ?", req.CreatedById)
|
||||
}
|
||||
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(&requestForInformationObjectionRepliess).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
paging = *req.Pagination
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionRepliesRepository) FindOne(id uint) (requestForInformationObjectionReplies *entity.RequestForInformationObjectionReplies, err error) {
|
||||
if err := _i.DB.DB.First(&requestForInformationObjectionReplies, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return requestForInformationObjectionReplies, nil
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionRepliesRepository) Create(requestForInformationObjectionReplies *entity.RequestForInformationObjectionReplies) (requestForInformationObjectionRepliesReturn *entity.RequestForInformationObjectionReplies, err error) {
|
||||
result := _i.DB.DB.Create(requestForInformationObjectionReplies)
|
||||
return requestForInformationObjectionReplies, result.Error
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionRepliesRepository) Update(id uint, requestForInformationObjectionReplies *entity.RequestForInformationObjectionReplies) (err error) {
|
||||
return _i.DB.DB.Model(&entity.RequestForInformationObjectionReplies{}).
|
||||
Where(&entity.RequestForInformationObjectionReplies{ID: id}).
|
||||
Updates(requestForInformationObjectionReplies).Error
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionRepliesRepository) Delete(id uint) error {
|
||||
return _i.DB.DB.Delete(&entity.RequestForInformationObjectionReplies{}, id).Error
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RequestForInformationObjectionRepliesGeneric interface {
|
||||
ToEntity()
|
||||
}
|
||||
|
||||
type RequestForInformationObjectionRepliesQueryRequest struct {
|
||||
RequestForInformationObjectionId *int `json:"requestForInformationObjectionId"`
|
||||
Response *string `json:"response"`
|
||||
StatusId *int `json:"statusId"`
|
||||
CreatedById *int `json:"createdById"`
|
||||
Pagination *paginator.Pagination `json:"pagination"`
|
||||
}
|
||||
|
||||
type RequestForInformationObjectionRepliesCreateRequest struct {
|
||||
RequestForInformationObjectionId int `json:"requestForInformationObjectionId" validate:"required"`
|
||||
Response string `json:"response" validate:"required"`
|
||||
StatusId int `json:"statusId" validate:"required"`
|
||||
CreatedById int `json:"createdById" validate:"required"`
|
||||
}
|
||||
|
||||
func (req RequestForInformationObjectionRepliesCreateRequest) ToEntity() *entity.RequestForInformationObjectionReplies {
|
||||
return &entity.RequestForInformationObjectionReplies{
|
||||
RequestForInformationObjectionId: req.RequestForInformationObjectionId,
|
||||
Response: req.Response,
|
||||
StatusId: req.StatusId,
|
||||
IsActive: func() *bool { b := true; return &b }(),
|
||||
}
|
||||
}
|
||||
|
||||
type RequestForInformationObjectionRepliesUpdateRequest struct {
|
||||
ID uint `json:"id" validate:"required"`
|
||||
RequestForInformationObjectionId int `json:"requestForInformationObjectionId" validate:"required"`
|
||||
Response string `json:"response" validate:"required"`
|
||||
StatusId int `json:"statusId" validate:"required"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (req RequestForInformationObjectionRepliesUpdateRequest) ToEntity() *entity.RequestForInformationObjectionReplies {
|
||||
return &entity.RequestForInformationObjectionReplies{
|
||||
ID: req.ID,
|
||||
RequestForInformationObjectionId: req.RequestForInformationObjectionId,
|
||||
Response: req.Response,
|
||||
StatusId: req.StatusId,
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
type RequestForInformationObjectionRepliesQueryRequestContext struct {
|
||||
RequestForInformationObjectionId string `json:"requestForInformationObjectionId"`
|
||||
Response string `json:"response"`
|
||||
StatusId string `json:"statusId"`
|
||||
CreatedById string `json:"createdById"`
|
||||
}
|
||||
|
||||
func (req RequestForInformationObjectionRepliesQueryRequestContext) ToParamRequest() RequestForInformationObjectionRepliesQueryRequest {
|
||||
var request RequestForInformationObjectionRepliesQueryRequest
|
||||
|
||||
if requestForInformationObjectionIdStr := req.RequestForInformationObjectionId; requestForInformationObjectionIdStr != "" {
|
||||
requestForInformationObjectionId, err := strconv.Atoi(requestForInformationObjectionIdStr)
|
||||
if err == nil {
|
||||
request.RequestForInformationObjectionId = &requestForInformationObjectionId
|
||||
}
|
||||
}
|
||||
if response := req.Response; response != "" {
|
||||
request.Response = &response
|
||||
}
|
||||
if statusIdStr := req.StatusId; statusIdStr != "" {
|
||||
statusId, err := strconv.Atoi(statusIdStr)
|
||||
if err == nil {
|
||||
request.StatusId = &statusId
|
||||
}
|
||||
}
|
||||
if createdByIdStr := req.CreatedById; createdByIdStr != "" {
|
||||
createdById, err := strconv.Atoi(createdByIdStr)
|
||||
if err == nil {
|
||||
request.CreatedById = &createdById
|
||||
}
|
||||
}
|
||||
|
||||
return request
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
package request_for_information_objection_replies
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go-humas-be/app/module/request_for_information_objection_replies/controller"
|
||||
"go-humas-be/app/module/request_for_information_objection_replies/repository"
|
||||
"go-humas-be/app/module/request_for_information_objection_replies/service"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
// struct of RequestForInformationObjectionRepliesRouter
|
||||
type RequestForInformationObjectionRepliesRouter struct {
|
||||
App fiber.Router
|
||||
Controller *controller.Controller
|
||||
}
|
||||
|
||||
// register bulky of RequestForInformationObjectionReplies module
|
||||
var NewRequestForInformationObjectionRepliesModule = fx.Options(
|
||||
// register repository of RequestForInformationObjectionReplies module
|
||||
fx.Provide(repository.NewRequestForInformationObjectionRepliesRepository),
|
||||
|
||||
// register service of RequestForInformationObjectionReplies module
|
||||
fx.Provide(service.NewRequestForInformationObjectionRepliesService),
|
||||
|
||||
// register controller of RequestForInformationObjectionReplies module
|
||||
fx.Provide(controller.NewController),
|
||||
|
||||
// register router of RequestForInformationObjectionReplies module
|
||||
fx.Provide(NewRequestForInformationObjectionRepliesRouter),
|
||||
)
|
||||
|
||||
// init RequestForInformationObjectionRepliesRouter
|
||||
func NewRequestForInformationObjectionRepliesRouter(fiber *fiber.App, controller *controller.Controller) *RequestForInformationObjectionRepliesRouter {
|
||||
return &RequestForInformationObjectionRepliesRouter{
|
||||
App: fiber,
|
||||
Controller: controller,
|
||||
}
|
||||
}
|
||||
|
||||
// register routes of RequestForInformationObjectionReplies module
|
||||
func (_i *RequestForInformationObjectionRepliesRouter) RegisterRequestForInformationObjectionRepliesRoutes() {
|
||||
// define controllers
|
||||
requestForInformationObjectionRepliesController := _i.Controller.RequestForInformationObjectionReplies
|
||||
|
||||
// define routes
|
||||
_i.App.Route("/request-for-information-objection-replies", func(router fiber.Router) {
|
||||
router.Get("/", requestForInformationObjectionRepliesController.All)
|
||||
router.Get("/:id", requestForInformationObjectionRepliesController.Show)
|
||||
router.Post("/", requestForInformationObjectionRepliesController.Save)
|
||||
router.Put("/:id", requestForInformationObjectionRepliesController.Update)
|
||||
router.Delete("/:id", requestForInformationObjectionRepliesController.Delete)
|
||||
})
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
package response
|
||||
|
||||
import "time"
|
||||
|
||||
type RequestForInformationObjectionRepliesResponse struct {
|
||||
ID uint `json:"id"`
|
||||
RequestForInformationObjectionId int `json:"requestForInformationObjectionId"`
|
||||
Response string `json:"response"`
|
||||
StatusId int `json:"statusId"`
|
||||
CreatedById *uint `json:"createdById"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/request_for_information_objection_replies/mapper"
|
||||
"go-humas-be/app/module/request_for_information_objection_replies/repository"
|
||||
"go-humas-be/app/module/request_for_information_objection_replies/request"
|
||||
"go-humas-be/app/module/request_for_information_objection_replies/response"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
"go-humas-be/utils/paginator"
|
||||
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
)
|
||||
|
||||
// RequestForInformationObjectionRepliesService
|
||||
type requestForInformationObjectionRepliesService struct {
|
||||
Repo repository.RequestForInformationObjectionRepliesRepository
|
||||
UsersRepo usersRepository.UsersRepository
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// RequestForInformationObjectionRepliesService define interface of IRequestForInformationObjectionRepliesService
|
||||
type RequestForInformationObjectionRepliesService interface {
|
||||
All(req request.RequestForInformationObjectionRepliesQueryRequest) (requestForInformationObjectionReplies []*response.RequestForInformationObjectionRepliesResponse, paging paginator.Pagination, err error)
|
||||
Show(id uint) (requestForInformationObjectionReplies *response.RequestForInformationObjectionRepliesResponse, err error)
|
||||
Save(req request.RequestForInformationObjectionRepliesCreateRequest, authToken string) (requestForInformationObjectionReplies *entity.RequestForInformationObjectionReplies, err error)
|
||||
Update(id uint, req request.RequestForInformationObjectionRepliesUpdateRequest) (err error)
|
||||
Delete(id uint) error
|
||||
}
|
||||
|
||||
// NewRequestForInformationObjectionRepliesService init RequestForInformationObjectionRepliesService
|
||||
func NewRequestForInformationObjectionRepliesService(repo repository.RequestForInformationObjectionRepliesRepository, log zerolog.Logger, usersRepo usersRepository.UsersRepository) RequestForInformationObjectionRepliesService {
|
||||
|
||||
return &requestForInformationObjectionRepliesService{
|
||||
Repo: repo,
|
||||
Log: log,
|
||||
UsersRepo: usersRepo,
|
||||
}
|
||||
}
|
||||
|
||||
// All implement interface of RequestForInformationObjectionRepliesService
|
||||
func (_i *requestForInformationObjectionRepliesService) All(req request.RequestForInformationObjectionRepliesQueryRequest) (requestForInformationObjectionRepliess []*response.RequestForInformationObjectionRepliesResponse, paging paginator.Pagination, err error) {
|
||||
results, paging, err := _i.Repo.GetAll(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
requestForInformationObjectionRepliess = append(requestForInformationObjectionRepliess, mapper.RequestForInformationObjectionRepliesResponseMapper(result))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionRepliesService) Show(id uint) (requestForInformationObjectionReplies *response.RequestForInformationObjectionRepliesResponse, err error) {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mapper.RequestForInformationObjectionRepliesResponseMapper(result), nil
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionRepliesService) Save(req request.RequestForInformationObjectionRepliesCreateRequest, authToken string) (requestForInformationObjectionReplies *entity.RequestForInformationObjectionReplies, err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
|
||||
newReq := req.ToEntity()
|
||||
|
||||
createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||
newReq.CreatedById = &createdBy.ID
|
||||
|
||||
return _i.Repo.Create(newReq)
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionRepliesService) Update(id uint, req request.RequestForInformationObjectionRepliesUpdateRequest) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
return _i.Repo.Update(id, req.ToEntity())
|
||||
}
|
||||
|
||||
func (_i *requestForInformationObjectionRepliesService) Delete(id uint) error {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
isActive := false
|
||||
result.IsActive = &isActive
|
||||
return _i.Repo.Update(id, result)
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/request_for_information_replies/service"
|
||||
)
|
||||
|
||||
type Controller struct {
|
||||
RequestForInformationReplies RequestForInformationRepliesController
|
||||
}
|
||||
|
||||
func NewController(RequestForInformationRepliesService service.RequestForInformationRepliesService, log zerolog.Logger) *Controller {
|
||||
return &Controller{
|
||||
RequestForInformationReplies: NewRequestForInformationRepliesController(RequestForInformationRepliesService, log),
|
||||
}
|
||||
}
|
||||
|
|
@ -1,195 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/request_for_information_replies/request"
|
||||
"go-humas-be/app/module/request_for_information_replies/service"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilRes "go-humas-be/utils/response"
|
||||
utilVal "go-humas-be/utils/validator"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type requestForInformationRepliesController struct {
|
||||
requestForInformationRepliesService service.RequestForInformationRepliesService
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
type RequestForInformationRepliesController 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 NewRequestForInformationRepliesController(requestForInformationRepliesService service.RequestForInformationRepliesService, log zerolog.Logger) RequestForInformationRepliesController {
|
||||
return &requestForInformationRepliesController{
|
||||
requestForInformationRepliesService: requestForInformationRepliesService,
|
||||
Log: log,
|
||||
}
|
||||
}
|
||||
|
||||
// All get all RequestForInformationReplies
|
||||
// @Summary Get all RequestForInformationReplies
|
||||
// @Description API for getting all RequestForInformationReplies
|
||||
// @Tags RequestForInformationReplies
|
||||
// @Security Bearer
|
||||
// @Param req query request.RequestForInformationRepliesQueryRequest 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 /request-for-information-replies [get]
|
||||
func (_i *requestForInformationRepliesController) All(c *fiber.Ctx) error {
|
||||
paginate, err := paginator.Paginate(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
reqContext := request.RequestForInformationRepliesQueryRequestContext{
|
||||
RequestForInformationItemId: c.Query("requestForInformationItemId"),
|
||||
FileUrl: c.Query("fileUrl"),
|
||||
Response: c.Query("response"),
|
||||
StatusId: c.Query("statusId"),
|
||||
}
|
||||
req := reqContext.ToParamRequest()
|
||||
req.Pagination = paginate
|
||||
|
||||
requestForInformationRepliesData, paging, err := _i.requestForInformationRepliesService.All(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationReplies list successfully retrieved"},
|
||||
Data: requestForInformationRepliesData,
|
||||
Meta: paging,
|
||||
})
|
||||
}
|
||||
|
||||
// Show get one RequestForInformationReplies
|
||||
// @Summary Get one RequestForInformationReplies
|
||||
// @Description API for getting one RequestForInformationReplies
|
||||
// @Tags RequestForInformationReplies
|
||||
// @Security Bearer
|
||||
// @Param id path int true "RequestForInformationReplies ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-replies/{id} [get]
|
||||
func (_i *requestForInformationRepliesController) Show(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
requestForInformationRepliesData, err := _i.requestForInformationRepliesService.Show(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationReplies successfully retrieved"},
|
||||
Data: requestForInformationRepliesData,
|
||||
})
|
||||
}
|
||||
|
||||
// Save create RequestForInformationReplies
|
||||
// @Summary Create RequestForInformationReplies
|
||||
// @Description API for create RequestForInformationReplies
|
||||
// @Tags RequestForInformationReplies
|
||||
// @Security Bearer
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.RequestForInformationRepliesCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-replies [post]
|
||||
func (_i *requestForInformationRepliesController) Save(c *fiber.Ctx) error {
|
||||
req := new(request.RequestForInformationRepliesCreateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
authToken := c.Get("Authorization")
|
||||
dataResult, err := _i.requestForInformationRepliesService.Save(*req, authToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationReplies successfully created"},
|
||||
Data: dataResult,
|
||||
})
|
||||
}
|
||||
|
||||
// Update update RequestForInformationReplies
|
||||
// @Summary update RequestForInformationReplies
|
||||
// @Description API for update RequestForInformationReplies
|
||||
// @Tags RequestForInformationReplies
|
||||
// @Security Bearer
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.RequestForInformationRepliesUpdateRequest true "Required payload"
|
||||
// @Param id path int true "RequestForInformationReplies ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-replies/{id} [put]
|
||||
func (_i *requestForInformationRepliesController) Update(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := new(request.RequestForInformationRepliesUpdateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.requestForInformationRepliesService.Update(uint(id), *req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationReplies successfully updated"},
|
||||
})
|
||||
}
|
||||
|
||||
// Delete delete RequestForInformationReplies
|
||||
// @Summary delete RequestForInformationReplies
|
||||
// @Description API for delete RequestForInformationReplies
|
||||
// @Tags RequestForInformationReplies
|
||||
// @Security Bearer
|
||||
// @Param id path int true "RequestForInformationReplies ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-information-replies/{id} [delete]
|
||||
func (_i *requestForInformationRepliesController) Delete(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.requestForInformationRepliesService.Delete(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformationReplies successfully deleted"},
|
||||
})
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
res "go-humas-be/app/module/request_for_information_replies/response"
|
||||
)
|
||||
|
||||
func RequestForInformationRepliesResponseMapper(requestForInformationRepliesReq *entity.RequestForInformationReplies) (requestForInformationRepliesRes *res.RequestForInformationRepliesResponse) {
|
||||
if requestForInformationRepliesReq != nil {
|
||||
requestForInformationRepliesRes = &res.RequestForInformationRepliesResponse{
|
||||
ID: requestForInformationRepliesReq.ID,
|
||||
RequestForInformationItemId: requestForInformationRepliesReq.RequestForInformationItemId,
|
||||
FileUrl: requestForInformationRepliesReq.FileUrl,
|
||||
Response: requestForInformationRepliesReq.Response,
|
||||
StatusId: requestForInformationRepliesReq.StatusId,
|
||||
CreatedById: requestForInformationRepliesReq.CreatedById,
|
||||
IsActive: requestForInformationRepliesReq.IsActive,
|
||||
CreatedAt: requestForInformationRepliesReq.CreatedAt,
|
||||
UpdatedAt: requestForInformationRepliesReq.UpdatedAt,
|
||||
}
|
||||
}
|
||||
return requestForInformationRepliesRes
|
||||
}
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/request_for_information_replies/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type requestForInformationRepliesRepository struct {
|
||||
DB *database.Database
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// RequestForInformationRepliesRepository define interface of IRequestForInformationRepliesRepository
|
||||
type RequestForInformationRepliesRepository interface {
|
||||
GetAll(req request.RequestForInformationRepliesQueryRequest) (requestForInformationRepliess []*entity.RequestForInformationReplies, paging paginator.Pagination, err error)
|
||||
FindOne(id uint) (requestForInformationReplies *entity.RequestForInformationReplies, err error)
|
||||
Create(requestForInformationReplies *entity.RequestForInformationReplies) (requestForInformationRepliesReturn *entity.RequestForInformationReplies, err error)
|
||||
Update(id uint, requestForInformationReplies *entity.RequestForInformationReplies) (err error)
|
||||
Delete(id uint) (err error)
|
||||
}
|
||||
|
||||
func NewRequestForInformationRepliesRepository(db *database.Database, logger zerolog.Logger) RequestForInformationRepliesRepository {
|
||||
return &requestForInformationRepliesRepository{
|
||||
DB: db,
|
||||
Log: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// implement interface of IRequestForInformationRepliesRepository
|
||||
func (_i *requestForInformationRepliesRepository) GetAll(req request.RequestForInformationRepliesQueryRequest) (requestForInformationRepliess []*entity.RequestForInformationReplies, paging paginator.Pagination, err error) {
|
||||
var count int64
|
||||
|
||||
query := _i.DB.DB.Model(&entity.RequestForInformationReplies{})
|
||||
query = query.Where("is_active = ?", true)
|
||||
|
||||
if req.RequestForInformationItemId != nil {
|
||||
query = query.Where("request_for_information_item_id = ?", req.RequestForInformationItemId)
|
||||
}
|
||||
if req.FileUrl != nil && *req.FileUrl != "" {
|
||||
fileUrl := strings.ToLower(*req.FileUrl)
|
||||
query = query.Where("LOWER(file_url) LIKE ?", "%"+strings.ToLower(fileUrl)+"%")
|
||||
}
|
||||
if req.Response != nil && *req.Response != "" {
|
||||
response := strings.ToLower(*req.Response)
|
||||
query = query.Where("LOWER(response) LIKE ?", "%"+strings.ToLower(response)+"%")
|
||||
}
|
||||
if req.StatusId != nil {
|
||||
query = query.Where("status_id = ?", req.StatusId)
|
||||
}
|
||||
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(&requestForInformationRepliess).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
paging = *req.Pagination
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *requestForInformationRepliesRepository) FindOne(id uint) (requestForInformationReplies *entity.RequestForInformationReplies, err error) {
|
||||
if err := _i.DB.DB.First(&requestForInformationReplies, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return requestForInformationReplies, nil
|
||||
}
|
||||
|
||||
func (_i *requestForInformationRepliesRepository) Create(requestForInformationReplies *entity.RequestForInformationReplies) (requestForInformationRepliesReturn *entity.RequestForInformationReplies, err error) {
|
||||
result := _i.DB.DB.Create(requestForInformationReplies)
|
||||
return requestForInformationReplies, result.Error
|
||||
}
|
||||
|
||||
func (_i *requestForInformationRepliesRepository) Update(id uint, requestForInformationReplies *entity.RequestForInformationReplies) (err error) {
|
||||
return _i.DB.DB.Model(&entity.RequestForInformationReplies{}).
|
||||
Where(&entity.RequestForInformationReplies{ID: id}).
|
||||
Updates(requestForInformationReplies).Error
|
||||
}
|
||||
|
||||
func (_i *requestForInformationRepliesRepository) Delete(id uint) error {
|
||||
return _i.DB.DB.Delete(&entity.RequestForInformationReplies{}, id).Error
|
||||
}
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RequestForInformationRepliesGeneric interface {
|
||||
ToEntity()
|
||||
}
|
||||
|
||||
type RequestForInformationRepliesQueryRequest struct {
|
||||
RequestForInformationItemId *int `json:"requestForInformationItemId"`
|
||||
FileUrl *string `json:"fileUrl"`
|
||||
Response *string `json:"response"`
|
||||
StatusId *int `json:"statusId"`
|
||||
CreatedById *int `json:"createdById"`
|
||||
Pagination *paginator.Pagination `json:"pagination"`
|
||||
}
|
||||
|
||||
type RequestForInformationRepliesCreateRequest struct {
|
||||
RequestForInformationItemId int `json:"requestForInformationItemId" validate:"required"`
|
||||
FileUrl string `json:"fileUrl" validate:"required"`
|
||||
Response string `json:"response" validate:"required"`
|
||||
StatusId int `json:"statusId" validate:"required"`
|
||||
}
|
||||
|
||||
func (req RequestForInformationRepliesCreateRequest) ToEntity() *entity.RequestForInformationReplies {
|
||||
return &entity.RequestForInformationReplies{
|
||||
RequestForInformationItemId: req.RequestForInformationItemId,
|
||||
FileUrl: req.FileUrl,
|
||||
Response: req.Response,
|
||||
StatusId: req.StatusId,
|
||||
IsActive: func() *bool { b := true; return &b }(),
|
||||
}
|
||||
}
|
||||
|
||||
type RequestForInformationRepliesUpdateRequest struct {
|
||||
ID uint `json:"id" validate:"required"`
|
||||
RequestForInformationItemId int `json:"requestForInformationItemId" validate:"required"`
|
||||
FileUrl string `json:"fileUrl" validate:"required"`
|
||||
Response string `json:"response" validate:"required"`
|
||||
StatusId int `json:"statusId" validate:"required"`
|
||||
}
|
||||
|
||||
func (req RequestForInformationRepliesUpdateRequest) ToEntity() *entity.RequestForInformationReplies {
|
||||
return &entity.RequestForInformationReplies{
|
||||
ID: req.ID,
|
||||
RequestForInformationItemId: req.RequestForInformationItemId,
|
||||
FileUrl: req.FileUrl,
|
||||
Response: req.Response,
|
||||
StatusId: req.StatusId,
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
type RequestForInformationRepliesQueryRequestContext struct {
|
||||
RequestForInformationItemId string `json:"requestForInformationItemId"`
|
||||
FileUrl string `json:"fileUrl"`
|
||||
Response string `json:"response"`
|
||||
StatusId string `json:"statusId"`
|
||||
CreatedById string `json:"createdById"`
|
||||
}
|
||||
|
||||
func (req RequestForInformationRepliesQueryRequestContext) ToParamRequest() RequestForInformationRepliesQueryRequest {
|
||||
var request RequestForInformationRepliesQueryRequest
|
||||
|
||||
if requestForInformationItemIdStr := req.RequestForInformationItemId; requestForInformationItemIdStr != "" {
|
||||
requestForInformationItemId, err := strconv.Atoi(requestForInformationItemIdStr)
|
||||
if err == nil {
|
||||
request.RequestForInformationItemId = &requestForInformationItemId
|
||||
}
|
||||
}
|
||||
if fileUrl := req.FileUrl; fileUrl != "" {
|
||||
request.FileUrl = &fileUrl
|
||||
}
|
||||
if response := req.Response; response != "" {
|
||||
request.Response = &response
|
||||
}
|
||||
if statusIdStr := req.StatusId; statusIdStr != "" {
|
||||
statusId, err := strconv.Atoi(statusIdStr)
|
||||
if err == nil {
|
||||
request.StatusId = &statusId
|
||||
}
|
||||
}
|
||||
if createdByIdStr := req.CreatedById; createdByIdStr != "" {
|
||||
createdById, err := strconv.Atoi(createdByIdStr)
|
||||
if err == nil {
|
||||
request.CreatedById = &createdById
|
||||
}
|
||||
}
|
||||
|
||||
return request
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
package request_for_information_replies
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go-humas-be/app/module/request_for_information_replies/controller"
|
||||
"go-humas-be/app/module/request_for_information_replies/repository"
|
||||
"go-humas-be/app/module/request_for_information_replies/service"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
// struct of RequestForInformationRepliesRouter
|
||||
type RequestForInformationRepliesRouter struct {
|
||||
App fiber.Router
|
||||
Controller *controller.Controller
|
||||
}
|
||||
|
||||
// register bulky of RequestForInformationReplies module
|
||||
var NewRequestForInformationRepliesModule = fx.Options(
|
||||
// register repository of RequestForInformationReplies module
|
||||
fx.Provide(repository.NewRequestForInformationRepliesRepository),
|
||||
|
||||
// register service of RequestForInformationReplies module
|
||||
fx.Provide(service.NewRequestForInformationRepliesService),
|
||||
|
||||
// register controller of RequestForInformationReplies module
|
||||
fx.Provide(controller.NewController),
|
||||
|
||||
// register router of RequestForInformationReplies module
|
||||
fx.Provide(NewRequestForInformationRepliesRouter),
|
||||
)
|
||||
|
||||
// init RequestForInformationRepliesRouter
|
||||
func NewRequestForInformationRepliesRouter(fiber *fiber.App, controller *controller.Controller) *RequestForInformationRepliesRouter {
|
||||
return &RequestForInformationRepliesRouter{
|
||||
App: fiber,
|
||||
Controller: controller,
|
||||
}
|
||||
}
|
||||
|
||||
// register routes of RequestForInformationReplies module
|
||||
func (_i *RequestForInformationRepliesRouter) RegisterRequestForInformationRepliesRoutes() {
|
||||
// define controllers
|
||||
requestForInformationRepliesController := _i.Controller.RequestForInformationReplies
|
||||
|
||||
// define routes
|
||||
_i.App.Route("/request-for-information-replies", func(router fiber.Router) {
|
||||
router.Get("/", requestForInformationRepliesController.All)
|
||||
router.Get("/:id", requestForInformationRepliesController.Show)
|
||||
router.Post("/", requestForInformationRepliesController.Save)
|
||||
router.Put("/:id", requestForInformationRepliesController.Update)
|
||||
router.Delete("/:id", requestForInformationRepliesController.Delete)
|
||||
})
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package response
|
||||
|
||||
import "time"
|
||||
|
||||
type RequestForInformationRepliesResponse struct {
|
||||
ID uint `json:"id"`
|
||||
RequestForInformationItemId int `json:"requestForInformationItemId"`
|
||||
FileUrl string `json:"fileUrl"`
|
||||
Response string `json:"response"`
|
||||
StatusId int `json:"statusId"`
|
||||
CreatedById *uint `json:"createdById"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/request_for_information_replies/mapper"
|
||||
"go-humas-be/app/module/request_for_information_replies/repository"
|
||||
"go-humas-be/app/module/request_for_information_replies/request"
|
||||
"go-humas-be/app/module/request_for_information_replies/response"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
"go-humas-be/utils/paginator"
|
||||
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
)
|
||||
|
||||
// RequestForInformationRepliesService
|
||||
type requestForInformationRepliesService struct {
|
||||
Repo repository.RequestForInformationRepliesRepository
|
||||
UsersRepo usersRepository.UsersRepository
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// RequestForInformationRepliesService define interface of IRequestForInformationRepliesService
|
||||
type RequestForInformationRepliesService interface {
|
||||
All(req request.RequestForInformationRepliesQueryRequest) (requestForInformationReplies []*response.RequestForInformationRepliesResponse, paging paginator.Pagination, err error)
|
||||
Show(id uint) (requestForInformationReplies *response.RequestForInformationRepliesResponse, err error)
|
||||
Save(req request.RequestForInformationRepliesCreateRequest, authToken string) (requestForInformationReplies *entity.RequestForInformationReplies, err error)
|
||||
Update(id uint, req request.RequestForInformationRepliesUpdateRequest) (err error)
|
||||
Delete(id uint) error
|
||||
}
|
||||
|
||||
// NewRequestForInformationRepliesService init RequestForInformationRepliesService
|
||||
func NewRequestForInformationRepliesService(repo repository.RequestForInformationRepliesRepository, log zerolog.Logger, usersRepo usersRepository.UsersRepository) RequestForInformationRepliesService {
|
||||
|
||||
return &requestForInformationRepliesService{
|
||||
Repo: repo,
|
||||
Log: log,
|
||||
UsersRepo: usersRepo,
|
||||
}
|
||||
}
|
||||
|
||||
// All implement interface of RequestForInformationRepliesService
|
||||
func (_i *requestForInformationRepliesService) All(req request.RequestForInformationRepliesQueryRequest) (requestForInformationRepliess []*response.RequestForInformationRepliesResponse, paging paginator.Pagination, err error) {
|
||||
results, paging, err := _i.Repo.GetAll(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
requestForInformationRepliess = append(requestForInformationRepliess, mapper.RequestForInformationRepliesResponseMapper(result))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *requestForInformationRepliesService) Show(id uint) (requestForInformationReplies *response.RequestForInformationRepliesResponse, err error) {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mapper.RequestForInformationRepliesResponseMapper(result), nil
|
||||
}
|
||||
|
||||
func (_i *requestForInformationRepliesService) Save(req request.RequestForInformationRepliesCreateRequest, authToken string) (requestForInformationReplies *entity.RequestForInformationReplies, err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
|
||||
newReq := req.ToEntity()
|
||||
|
||||
createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||
newReq.CreatedById = &createdBy.ID
|
||||
|
||||
return _i.Repo.Create(newReq)
|
||||
}
|
||||
|
||||
func (_i *requestForInformationRepliesService) Update(id uint, req request.RequestForInformationRepliesUpdateRequest) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
return _i.Repo.Update(id, req.ToEntity())
|
||||
}
|
||||
|
||||
func (_i *requestForInformationRepliesService) Delete(id uint) error {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
isActive := false
|
||||
result.IsActive = &isActive
|
||||
return _i.Repo.Update(id, result)
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/request_for_informations/service"
|
||||
)
|
||||
|
||||
type Controller struct {
|
||||
RequestForInformations RequestForInformationsController
|
||||
}
|
||||
|
||||
func NewController(RequestForInformationsService service.RequestForInformationsService, log zerolog.Logger) *Controller {
|
||||
return &Controller{
|
||||
RequestForInformations: NewRequestForInformationsController(RequestForInformationsService, log),
|
||||
}
|
||||
}
|
||||
|
|
@ -1,197 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/module/request_for_informations/request"
|
||||
"go-humas-be/app/module/request_for_informations/service"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilRes "go-humas-be/utils/response"
|
||||
utilVal "go-humas-be/utils/validator"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type requestForInformationsController struct {
|
||||
requestForInformationsService service.RequestForInformationsService
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
type RequestForInformationsController 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 NewRequestForInformationsController(requestForInformationsService service.RequestForInformationsService, log zerolog.Logger) RequestForInformationsController {
|
||||
return &requestForInformationsController{
|
||||
requestForInformationsService: requestForInformationsService,
|
||||
Log: log,
|
||||
}
|
||||
}
|
||||
|
||||
// All get all RequestForInformations
|
||||
// @Summary Get all RequestForInformations
|
||||
// @Description API for getting all RequestForInformations
|
||||
// @Tags RequestForInformations
|
||||
// @Security Bearer
|
||||
// @Param req query request.RequestForInformationsQueryRequest 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 /request-for-informations [get]
|
||||
func (_i *requestForInformationsController) All(c *fiber.Ctx) error {
|
||||
paginate, err := paginator.Paginate(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
reqContext := request.RequestForInformationsQueryRequestContext{
|
||||
TicketNumber: c.Query("ticketNumber"),
|
||||
HowToGetInfo: c.Query("howToGetInfo"),
|
||||
HowToGetFiles: c.Query("howToGetFiles"),
|
||||
NextAction: c.Query("nextAction"),
|
||||
CreatedById: c.Query("createdById"),
|
||||
StatusId: c.Query("statusId"),
|
||||
}
|
||||
req := reqContext.ToParamRequest()
|
||||
req.Pagination = paginate
|
||||
|
||||
requestForInformationsData, paging, err := _i.requestForInformationsService.All(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformations list successfully retrieved"},
|
||||
Data: requestForInformationsData,
|
||||
Meta: paging,
|
||||
})
|
||||
}
|
||||
|
||||
// Show get one RequestForInformations
|
||||
// @Summary Get one RequestForInformations
|
||||
// @Description API for getting one RequestForInformations
|
||||
// @Tags RequestForInformations
|
||||
// @Security Bearer
|
||||
// @Param id path int true "RequestForInformations ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-informations/{id} [get]
|
||||
func (_i *requestForInformationsController) Show(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
requestForInformationsData, err := _i.requestForInformationsService.Show(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformations successfully retrieved"},
|
||||
Data: requestForInformationsData,
|
||||
})
|
||||
}
|
||||
|
||||
// Save create RequestForInformations
|
||||
// @Summary Create RequestForInformations
|
||||
// @Description API for create RequestForInformations
|
||||
// @Tags RequestForInformations
|
||||
// @Security Bearer
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.RequestForInformationsCreateRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-informations [post]
|
||||
func (_i *requestForInformationsController) Save(c *fiber.Ctx) error {
|
||||
req := new(request.RequestForInformationsCreateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
authToken := c.Get("Authorization")
|
||||
dataResult, err := _i.requestForInformationsService.Save(*req, authToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformations successfully created"},
|
||||
Data: dataResult,
|
||||
})
|
||||
}
|
||||
|
||||
// Update update RequestForInformations
|
||||
// @Summary update RequestForInformations
|
||||
// @Description API for update RequestForInformations
|
||||
// @Tags RequestForInformations
|
||||
// @Security Bearer
|
||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||
// @Param payload body request.RequestForInformationsUpdateRequest true "Required payload"
|
||||
// @Param id path int true "RequestForInformations ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-informations/{id} [put]
|
||||
func (_i *requestForInformationsController) Update(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := new(request.RequestForInformationsUpdateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.requestForInformationsService.Update(uint(id), *req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformations successfully updated"},
|
||||
})
|
||||
}
|
||||
|
||||
// Delete delete RequestForInformations
|
||||
// @Summary delete RequestForInformations
|
||||
// @Description API for delete RequestForInformations
|
||||
// @Tags RequestForInformations
|
||||
// @Security Bearer
|
||||
// @Param id path int true "RequestForInformations ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /request-for-informations/{id} [delete]
|
||||
func (_i *requestForInformationsController) Delete(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = _i.requestForInformationsService.Delete(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"RequestForInformations successfully deleted"},
|
||||
})
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
package mapper
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
res "go-humas-be/app/module/request_for_informations/response"
|
||||
)
|
||||
|
||||
func RequestForInformationsResponseMapper(requestForInformationsReq *entity.RequestForInformations) (requestForInformationsRes *res.RequestForInformationsResponse) {
|
||||
if requestForInformationsReq != nil {
|
||||
requestForInformationsRes = &res.RequestForInformationsResponse{
|
||||
ID: requestForInformationsReq.ID,
|
||||
TicketNumber: requestForInformationsReq.TicketNumber,
|
||||
HowToGetInfo: requestForInformationsReq.HowToGetInfo,
|
||||
HowToGetFiles: requestForInformationsReq.HowToGetFiles,
|
||||
NextAction: requestForInformationsReq.NextAction,
|
||||
CreatedById: requestForInformationsReq.CreatedById,
|
||||
StatusId: requestForInformationsReq.StatusId,
|
||||
IsActive: requestForInformationsReq.IsActive,
|
||||
CreatedAt: requestForInformationsReq.CreatedAt,
|
||||
UpdatedAt: requestForInformationsReq.UpdatedAt,
|
||||
}
|
||||
}
|
||||
return requestForInformationsRes
|
||||
}
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/request_for_informations/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type requestForInformationsRepository struct {
|
||||
DB *database.Database
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// RequestForInformationsRepository define interface of IRequestForInformationsRepository
|
||||
type RequestForInformationsRepository interface {
|
||||
GetAll(req request.RequestForInformationsQueryRequest) (requestForInformationss []*entity.RequestForInformations, paging paginator.Pagination, err error)
|
||||
FindOne(id uint) (requestForInformations *entity.RequestForInformations, err error)
|
||||
Create(requestForInformations *entity.RequestForInformations) (requestForInformationsReturn *entity.RequestForInformations, err error)
|
||||
Update(id uint, requestForInformations *entity.RequestForInformations) (err error)
|
||||
Delete(id uint) (err error)
|
||||
}
|
||||
|
||||
func NewRequestForInformationsRepository(db *database.Database, logger zerolog.Logger) RequestForInformationsRepository {
|
||||
return &requestForInformationsRepository{
|
||||
DB: db,
|
||||
Log: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// implement interface of IRequestForInformationsRepository
|
||||
func (_i *requestForInformationsRepository) GetAll(req request.RequestForInformationsQueryRequest) (requestForInformationss []*entity.RequestForInformations, paging paginator.Pagination, err error) {
|
||||
var count int64
|
||||
|
||||
query := _i.DB.DB.Model(&entity.RequestForInformations{})
|
||||
query = query.Where("is_active = ?", true)
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:Create", "PpidData:Create").
|
||||
Interface("Request : ", req).Msg("")
|
||||
|
||||
if req.TicketNumber != nil && *req.TicketNumber != "" {
|
||||
ticketNumber := strings.ToLower(*req.TicketNumber)
|
||||
query = query.Where("LOWER(ticket_number) LIKE ?", "%"+strings.ToLower(ticketNumber)+"%")
|
||||
}
|
||||
if req.HowToGetInfo != nil && *req.HowToGetInfo != "" {
|
||||
howToGetInfo := strings.ToLower(*req.HowToGetInfo)
|
||||
query = query.Where("LOWER(how_to_get_info) LIKE ?", "%"+strings.ToLower(howToGetInfo)+"%")
|
||||
}
|
||||
if req.HowToGetFiles != nil && *req.HowToGetFiles != "" {
|
||||
howToGetFiles := strings.ToLower(*req.HowToGetFiles)
|
||||
query = query.Where("LOWER(how_to_get_files) LIKE ?", "%"+strings.ToLower(howToGetFiles)+"%")
|
||||
}
|
||||
if req.NextAction != nil && *req.NextAction != "" {
|
||||
nextAction := strings.ToLower(*req.NextAction)
|
||||
query = query.Where("LOWER(next_action) LIKE ?", "%"+strings.ToLower(nextAction)+"%")
|
||||
}
|
||||
if req.CreatedById != nil {
|
||||
query = query.Where("created_by_id = ?", req.CreatedById)
|
||||
}
|
||||
if req.StatusId != nil {
|
||||
query = query.Where("status_id = ?", req.StatusId)
|
||||
}
|
||||
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(&requestForInformationss).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
paging = *req.Pagination
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *requestForInformationsRepository) FindOne(id uint) (requestForInformations *entity.RequestForInformations, err error) {
|
||||
if err := _i.DB.DB.First(&requestForInformations, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return requestForInformations, nil
|
||||
}
|
||||
|
||||
func (_i *requestForInformationsRepository) Create(requestForInformations *entity.RequestForInformations) (requestForInformationsReturn *entity.RequestForInformations, err error) {
|
||||
result := _i.DB.DB.Create(requestForInformations)
|
||||
return requestForInformations, result.Error
|
||||
}
|
||||
|
||||
func (_i *requestForInformationsRepository) Update(id uint, requestForInformations *entity.RequestForInformations) (err error) {
|
||||
return _i.DB.DB.Model(&entity.RequestForInformations{}).
|
||||
Where(&entity.RequestForInformations{ID: id}).
|
||||
Updates(requestForInformations).Error
|
||||
}
|
||||
|
||||
func (_i *requestForInformationsRepository) Delete(id uint) error {
|
||||
return _i.DB.DB.Delete(&entity.RequestForInformations{}, id).Error
|
||||
}
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
package request
|
||||
|
||||
import (
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RequestForInformationsGeneric interface {
|
||||
ToEntity()
|
||||
}
|
||||
|
||||
type RequestForInformationsQueryRequest struct {
|
||||
TicketNumber *string `json:"ticketNumber"`
|
||||
HowToGetInfo *string `json:"howToGetInfo"`
|
||||
HowToGetFiles *string `json:"howToGetFiles"`
|
||||
NextAction *string `json:"nextAction"`
|
||||
CreatedById *int `json:"createdById"`
|
||||
StatusId *int `json:"statusId"`
|
||||
Pagination *paginator.Pagination `json:"pagination"`
|
||||
}
|
||||
|
||||
type RequestForInformationsCreateRequest struct {
|
||||
TicketNumber string `json:"ticketNumber" validate:"required"`
|
||||
HowToGetInfo string `json:"howToGetInfo" validate:"required"`
|
||||
HowToGetFiles string `json:"howToGetFiles" validate:"required"`
|
||||
NextAction string `json:"nextAction" validate:"required"`
|
||||
StatusId int `json:"statusId" validate:"required"`
|
||||
}
|
||||
|
||||
func (req RequestForInformationsCreateRequest) ToEntity() *entity.RequestForInformations {
|
||||
return &entity.RequestForInformations{
|
||||
TicketNumber: req.TicketNumber,
|
||||
HowToGetInfo: req.HowToGetInfo,
|
||||
HowToGetFiles: req.HowToGetFiles,
|
||||
NextAction: req.NextAction,
|
||||
StatusId: req.StatusId,
|
||||
IsActive: func() *bool { b := true; return &b }(),
|
||||
}
|
||||
}
|
||||
|
||||
type RequestForInformationsUpdateRequest struct {
|
||||
ID uint `json:"id" validate:"required"`
|
||||
TicketNumber string `json:"ticketNumber" validate:"required"`
|
||||
HowToGetInfo string `json:"howToGetInfo" validate:"required"`
|
||||
HowToGetFiles string `json:"howToGetFiles" validate:"required"`
|
||||
NextAction string `json:"nextAction" validate:"required"`
|
||||
StatusId int `json:"statusId" validate:"required"`
|
||||
}
|
||||
|
||||
func (req RequestForInformationsUpdateRequest) ToEntity() *entity.RequestForInformations {
|
||||
return &entity.RequestForInformations{
|
||||
ID: req.ID,
|
||||
TicketNumber: req.TicketNumber,
|
||||
HowToGetInfo: req.HowToGetInfo,
|
||||
HowToGetFiles: req.HowToGetFiles,
|
||||
NextAction: req.NextAction,
|
||||
StatusId: req.StatusId,
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
type RequestForInformationsQueryRequestContext struct {
|
||||
TicketNumber string `json:"ticketNumber"`
|
||||
HowToGetInfo string `json:"howToGetInfo"`
|
||||
HowToGetFiles string `json:"howToGetFiles"`
|
||||
NextAction string `json:"nextAction"`
|
||||
CreatedById string `json:"createdById"`
|
||||
StatusId string `json:"statusId"`
|
||||
}
|
||||
|
||||
func (req RequestForInformationsQueryRequestContext) ToParamRequest() RequestForInformationsQueryRequest {
|
||||
var request RequestForInformationsQueryRequest
|
||||
|
||||
if ticketNumber := req.TicketNumber; ticketNumber != "" {
|
||||
request.TicketNumber = &ticketNumber
|
||||
}
|
||||
if howToGetInfo := req.HowToGetInfo; howToGetInfo != "" {
|
||||
request.HowToGetInfo = &howToGetInfo
|
||||
}
|
||||
if howToGetFiles := req.HowToGetFiles; howToGetFiles != "" {
|
||||
request.HowToGetFiles = &howToGetFiles
|
||||
}
|
||||
if nextAction := req.NextAction; nextAction != "" {
|
||||
request.NextAction = &nextAction
|
||||
}
|
||||
if createdByIdStr := req.CreatedById; createdByIdStr != "" {
|
||||
createdById, err := strconv.Atoi(createdByIdStr)
|
||||
if err == nil {
|
||||
request.CreatedById = &createdById
|
||||
}
|
||||
}
|
||||
if statusIdStr := req.StatusId; statusIdStr != "" {
|
||||
statusId, err := strconv.Atoi(statusIdStr)
|
||||
if err == nil {
|
||||
request.StatusId = &statusId
|
||||
}
|
||||
}
|
||||
|
||||
return request
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
package request_for_informations
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go-humas-be/app/module/request_for_informations/controller"
|
||||
"go-humas-be/app/module/request_for_informations/repository"
|
||||
"go-humas-be/app/module/request_for_informations/service"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
// struct of RequestForInformationsRouter
|
||||
type RequestForInformationsRouter struct {
|
||||
App fiber.Router
|
||||
Controller *controller.Controller
|
||||
}
|
||||
|
||||
// register bulky of RequestForInformations module
|
||||
var NewRequestForInformationsModule = fx.Options(
|
||||
// register repository of RequestForInformations module
|
||||
fx.Provide(repository.NewRequestForInformationsRepository),
|
||||
|
||||
// register service of RequestForInformations module
|
||||
fx.Provide(service.NewRequestForInformationsService),
|
||||
|
||||
// register controller of RequestForInformations module
|
||||
fx.Provide(controller.NewController),
|
||||
|
||||
// register router of RequestForInformations module
|
||||
fx.Provide(NewRequestForInformationsRouter),
|
||||
)
|
||||
|
||||
// init RequestForInformationsRouter
|
||||
func NewRequestForInformationsRouter(fiber *fiber.App, controller *controller.Controller) *RequestForInformationsRouter {
|
||||
return &RequestForInformationsRouter{
|
||||
App: fiber,
|
||||
Controller: controller,
|
||||
}
|
||||
}
|
||||
|
||||
// register routes of RequestForInformations module
|
||||
func (_i *RequestForInformationsRouter) RegisterRequestForInformationsRoutes() {
|
||||
// define controllers
|
||||
requestForInformationsController := _i.Controller.RequestForInformations
|
||||
|
||||
// define routes
|
||||
_i.App.Route("/request-for-informations", func(router fiber.Router) {
|
||||
router.Get("/", requestForInformationsController.All)
|
||||
router.Get("/:id", requestForInformationsController.Show)
|
||||
router.Post("/", requestForInformationsController.Save)
|
||||
router.Put("/:id", requestForInformationsController.Update)
|
||||
router.Delete("/:id", requestForInformationsController.Delete)
|
||||
})
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package response
|
||||
|
||||
import "time"
|
||||
|
||||
type RequestForInformationsResponse struct {
|
||||
ID uint `json:"id"`
|
||||
TicketNumber string `json:"ticketNumber"`
|
||||
HowToGetInfo string `json:"howToGetInfo"`
|
||||
HowToGetFiles string `json:"howToGetFiles"`
|
||||
NextAction string `json:"nextAction"`
|
||||
CreatedById *uint `json:"createdById"`
|
||||
StatusId int `json:"statusId"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/request_for_informations/mapper"
|
||||
"go-humas-be/app/module/request_for_informations/repository"
|
||||
"go-humas-be/app/module/request_for_informations/request"
|
||||
"go-humas-be/app/module/request_for_informations/response"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilSvc "go-humas-be/utils/service"
|
||||
)
|
||||
|
||||
// RequestForInformationsService
|
||||
type requestForInformationsService struct {
|
||||
Repo repository.RequestForInformationsRepository
|
||||
UsersRepo usersRepository.UsersRepository
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// RequestForInformationsService define interface of IRequestForInformationsService
|
||||
type RequestForInformationsService interface {
|
||||
All(req request.RequestForInformationsQueryRequest) (requestForInformations []*response.RequestForInformationsResponse, paging paginator.Pagination, err error)
|
||||
Show(id uint) (requestForInformations *response.RequestForInformationsResponse, err error)
|
||||
Save(req request.RequestForInformationsCreateRequest, authToken string) (requestForInformations *entity.RequestForInformations, err error)
|
||||
Update(id uint, req request.RequestForInformationsUpdateRequest) (err error)
|
||||
Delete(id uint) error
|
||||
}
|
||||
|
||||
// NewRequestForInformationsService init RequestForInformationsService
|
||||
func NewRequestForInformationsService(repo repository.RequestForInformationsRepository, log zerolog.Logger, usersRepo usersRepository.UsersRepository) RequestForInformationsService {
|
||||
|
||||
return &requestForInformationsService{
|
||||
Repo: repo,
|
||||
Log: log,
|
||||
UsersRepo: usersRepo,
|
||||
}
|
||||
}
|
||||
|
||||
// All implement interface of RequestForInformationsService
|
||||
func (_i *requestForInformationsService) All(req request.RequestForInformationsQueryRequest) (requestForInformationss []*response.RequestForInformationsResponse, paging paginator.Pagination, err error) {
|
||||
results, paging, err := _i.Repo.GetAll(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
requestForInformationss = append(requestForInformationss, mapper.RequestForInformationsResponseMapper(result))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (_i *requestForInformationsService) Show(id uint) (requestForInformations *response.RequestForInformationsResponse, err error) {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mapper.RequestForInformationsResponseMapper(result), nil
|
||||
}
|
||||
|
||||
func (_i *requestForInformationsService) Save(req request.RequestForInformationsCreateRequest, authToken string) (requestForInformations *entity.RequestForInformations, err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
|
||||
newReq := req.ToEntity()
|
||||
|
||||
createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||
newReq.CreatedById = &createdBy.ID
|
||||
|
||||
return _i.Repo.Create(newReq)
|
||||
}
|
||||
|
||||
func (_i *requestForInformationsService) Update(id uint, req request.RequestForInformationsUpdateRequest) (err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
return _i.Repo.Update(id, req.ToEntity())
|
||||
}
|
||||
|
||||
func (_i *requestForInformationsService) Delete(id uint) error {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
isActive := false
|
||||
result.IsActive = &isActive
|
||||
return _i.Repo.Update(id, result)
|
||||
}
|
||||
|
|
@ -13,15 +13,7 @@ import (
|
|||
"go-humas-be/app/module/magazines"
|
||||
"go-humas-be/app/module/master_menus"
|
||||
"go-humas-be/app/module/master_modules"
|
||||
"go-humas-be/app/module/ppid_data_categories"
|
||||
"go-humas-be/app/module/ppid_data_files"
|
||||
"go-humas-be/app/module/ppid_datas"
|
||||
"go-humas-be/app/module/provinces"
|
||||
"go-humas-be/app/module/request_for_information_items"
|
||||
"go-humas-be/app/module/request_for_information_objection"
|
||||
"go-humas-be/app/module/request_for_information_objection_replies"
|
||||
"go-humas-be/app/module/request_for_information_replies"
|
||||
"go-humas-be/app/module/request_for_informations"
|
||||
"go-humas-be/app/module/user_levels"
|
||||
"go-humas-be/app/module/user_role_accesses"
|
||||
"go-humas-be/app/module/user_roles"
|
||||
|
|
@ -44,15 +36,7 @@ type Router struct {
|
|||
MagazinesRouter *magazines.MagazinesRouter
|
||||
MasterMenusRouter *master_menus.MasterMenusRouter
|
||||
MasterModulesRouter *master_modules.MasterModulesRouter
|
||||
PpidDataCategoriesRouter *ppid_data_categories.PpidDataCategoriesRouter
|
||||
PpidDataFilesRouter *ppid_data_files.PpidDataFilesRouter
|
||||
PpidDatasRouter *ppid_datas.PpidDatasRouter
|
||||
ProvincesRouter *provinces.ProvincesRouter
|
||||
RequestForInformationsRouter *request_for_informations.RequestForInformationsRouter
|
||||
RequestForInformationItemsRouter *request_for_information_items.RequestForInformationItemsRouter
|
||||
RequestForInformationRepliesRouter *request_for_information_replies.RequestForInformationRepliesRouter
|
||||
RequestForInformationObjectionRouter *request_for_information_objection.RequestForInformationObjectionRouter
|
||||
RequestForInformationObjectionRepliesRouter *request_for_information_objection_replies.RequestForInformationObjectionRepliesRouter
|
||||
UserLevelsRouter *user_levels.UserLevelsRouter
|
||||
UserRoleAccessesRouter *user_role_accesses.UserRoleAccessesRouter
|
||||
UserRolesRouter *user_roles.UserRolesRouter
|
||||
|
|
@ -73,15 +57,7 @@ func NewRouter(
|
|||
magazinesRouter *magazines.MagazinesRouter,
|
||||
masterMenuRouter *master_menus.MasterMenusRouter,
|
||||
masterModuleRouter *master_modules.MasterModulesRouter,
|
||||
ppidDataCategoriesRouter *ppid_data_categories.PpidDataCategoriesRouter,
|
||||
ppidDataFilesRouter *ppid_data_files.PpidDataFilesRouter,
|
||||
ppidDatasRouter *ppid_datas.PpidDatasRouter,
|
||||
provincesRouter *provinces.ProvincesRouter,
|
||||
requestForInformationsRouter *request_for_informations.RequestForInformationsRouter,
|
||||
requestForInformationItemsRouter *request_for_information_items.RequestForInformationItemsRouter,
|
||||
requestForInformationRepliesRouter *request_for_information_replies.RequestForInformationRepliesRouter,
|
||||
requestForInformationObjectionRouter *request_for_information_objection.RequestForInformationObjectionRouter,
|
||||
requestForInformationObjectionRepliesRouter *request_for_information_objection_replies.RequestForInformationObjectionRepliesRouter,
|
||||
userLevelsRouter *user_levels.UserLevelsRouter,
|
||||
userRoleAccessesRouter *user_role_accesses.UserRoleAccessesRouter,
|
||||
userRolesRouter *user_roles.UserRolesRouter,
|
||||
|
|
@ -100,15 +76,7 @@ func NewRouter(
|
|||
MagazinesRouter: magazinesRouter,
|
||||
MasterMenusRouter: masterMenuRouter,
|
||||
MasterModulesRouter: masterModuleRouter,
|
||||
PpidDataCategoriesRouter: ppidDataCategoriesRouter,
|
||||
PpidDataFilesRouter: ppidDataFilesRouter,
|
||||
PpidDatasRouter: ppidDatasRouter,
|
||||
ProvincesRouter: provincesRouter,
|
||||
RequestForInformationsRouter: requestForInformationsRouter,
|
||||
RequestForInformationItemsRouter: requestForInformationItemsRouter,
|
||||
RequestForInformationRepliesRouter: requestForInformationRepliesRouter,
|
||||
RequestForInformationObjectionRouter: requestForInformationObjectionRouter,
|
||||
RequestForInformationObjectionRepliesRouter: requestForInformationObjectionRepliesRouter,
|
||||
UserLevelsRouter: userLevelsRouter,
|
||||
UserRoleAccessesRouter: userRoleAccessesRouter,
|
||||
UserRolesRouter: userRolesRouter,
|
||||
|
|
@ -137,15 +105,7 @@ func (r *Router) Register() {
|
|||
r.MagazineFilesRouter.RegisterMagazineFilesRoutes()
|
||||
r.MasterMenusRouter.RegisterMasterMenusRoutes()
|
||||
r.MasterModulesRouter.RegisterMasterModulesRoutes()
|
||||
r.PpidDataCategoriesRouter.RegisterPpidDataCategoriesRoutes()
|
||||
r.PpidDataFilesRouter.RegisterPpidDataFilesRoutes()
|
||||
r.PpidDatasRouter.RegisterPpidDatasRoutes()
|
||||
r.ProvincesRouter.RegisterProvincesRoutes()
|
||||
r.RequestForInformationsRouter.RegisterRequestForInformationsRoutes()
|
||||
r.RequestForInformationItemsRouter.RegisterRequestForInformationItemsRoutes()
|
||||
r.RequestForInformationRepliesRouter.RegisterRequestForInformationRepliesRoutes()
|
||||
r.RequestForInformationObjectionRouter.RegisterRequestForInformationObjectionRoutes()
|
||||
r.RequestForInformationObjectionRepliesRouter.RegisterRequestForInformationObjectionRepliesRoutes()
|
||||
r.UserLevelsRouter.RegisterUserLevelsRoutes()
|
||||
r.UserRoleAccessesRouter.RegisterUserRoleAccessesRoutes()
|
||||
r.UsersRouter.RegisterUsersRoutes()
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ name = "Fiber starter"
|
|||
host = "http://103.82.242.92"
|
||||
port = ":8800"
|
||||
domain = "https://103.82.242.92"
|
||||
external-port = ":8888"
|
||||
external-port = ":8802"
|
||||
idle-timeout = 5 # As seconds
|
||||
print-routes = false
|
||||
prefork = true
|
||||
|
|
|
|||
3793
docs/swagger/docs.go
3793
docs/swagger/docs.go
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
18
main.go
18
main.go
|
|
@ -14,16 +14,7 @@ import (
|
|||
"go-humas-be/app/module/magazines"
|
||||
"go-humas-be/app/module/master_menus"
|
||||
"go-humas-be/app/module/master_modules"
|
||||
"go-humas-be/app/module/ppid_data_approval_histories"
|
||||
"go-humas-be/app/module/ppid_data_categories"
|
||||
"go-humas-be/app/module/ppid_data_files"
|
||||
"go-humas-be/app/module/ppid_datas"
|
||||
"go-humas-be/app/module/provinces"
|
||||
"go-humas-be/app/module/request_for_information_items"
|
||||
"go-humas-be/app/module/request_for_information_objection"
|
||||
"go-humas-be/app/module/request_for_information_objection_replies"
|
||||
"go-humas-be/app/module/request_for_information_replies"
|
||||
"go-humas-be/app/module/request_for_informations"
|
||||
"go-humas-be/app/module/user_levels"
|
||||
"go-humas-be/app/module/user_role_accesses"
|
||||
"go-humas-be/app/module/user_role_level_details"
|
||||
|
|
@ -68,21 +59,12 @@ func main() {
|
|||
magazine_files.NewMagazineFilesModule,
|
||||
master_menus.NewMasterMenusModule,
|
||||
master_modules.NewMasterModulesModule,
|
||||
ppid_data_files.NewPpidDataFilesModule,
|
||||
ppid_data_categories.NewPpidDataCategoriesModule,
|
||||
ppid_data_approval_histories.NewPpidDataApprovalHistoriesModule,
|
||||
ppid_datas.NewPpidDatasModule,
|
||||
provinces.NewProvincesModule,
|
||||
user_levels.NewUserLevelsModule,
|
||||
user_roles.NewUserRolesModule,
|
||||
user_role_accesses.NewUserRoleAccessesModule,
|
||||
users.NewUsersModule,
|
||||
user_role_level_details.NewUserRoleLevelDetailsModule,
|
||||
request_for_informations.NewRequestForInformationsModule,
|
||||
request_for_information_items.NewRequestForInformationItemsModule,
|
||||
request_for_information_replies.NewRequestForInformationRepliesModule,
|
||||
request_for_information_objection.NewRequestForInformationObjectionModule,
|
||||
request_for_information_objection_replies.NewRequestForInformationObjectionRepliesModule,
|
||||
|
||||
// start aplication
|
||||
fx.Invoke(webserver.Start),
|
||||
|
|
|
|||
Loading…
Reference in New Issue