feat: update user, user_role, user_level, ppid_datas, ppid_data_files, ppid_categories, article, article_categories, article_files, etc
This commit is contained in:
parent
71ca446560
commit
a3fd7e7fe7
|
|
@ -2,6 +2,6 @@ package entity
|
||||||
|
|
||||||
type Districts struct {
|
type Districts struct {
|
||||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||||
DisNam string `json:"dis_nam" gorm:"type:varchar"`
|
DisName string `json:"dis_name" gorm:"type:varchar"`
|
||||||
CityId int `json:"city_id" gorm:"type:int4"`
|
CityId int `json:"city_id" gorm:"type:int4"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ type PpidDataCategories struct {
|
||||||
Title string `json:"title" gorm:"type:varchar"`
|
Title string `json:"title" gorm:"type:varchar"`
|
||||||
Description string `json:"description" gorm:"type:varchar"`
|
Description string `json:"description" gorm:"type:varchar"`
|
||||||
Slug string `json:"slug" gorm:"type:varchar"`
|
Slug string `json:"slug" gorm:"type:varchar"`
|
||||||
IsActive bool `json:"is_active" gorm:"type:bool"`
|
IsActive *bool `json:"is_active" gorm:"type:bool;default:true"`
|
||||||
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
||||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||||
}
|
}
|
||||||
|
|
@ -9,12 +9,15 @@ type PpidDataFiles struct {
|
||||||
Description string `json:"description" gorm:"type:varchar"`
|
Description string `json:"description" gorm:"type:varchar"`
|
||||||
Unit string `json:"unit" gorm:"type:varchar"`
|
Unit string `json:"unit" gorm:"type:varchar"`
|
||||||
FileType string `json:"file_type" gorm:"type:varchar"`
|
FileType string `json:"file_type" gorm:"type:varchar"`
|
||||||
DownloadCount int `json:"download_count" gorm:"type:int4"`
|
FileName *string `json:"file_name" gorm:"type:varchar"`
|
||||||
CreatedById int `json:"created_by_id" gorm:"type:int4"`
|
FilePath *string `json:"file_path" gorm:"type:varchar"`
|
||||||
StatusId int `json:"status_id" gorm:"type:int4"`
|
Size *string `json:"size" gorm:"type:varchar"`
|
||||||
IsPublish bool `json:"is_publish" gorm:"type:bool"`
|
DownloadCount *int `json:"download_count" gorm:"type:int4"`
|
||||||
PublishedAt time.Time `json:"published_at" gorm:"type:timestamp"`
|
CreatedById *int `json:"created_by_id" gorm:"type:int4"`
|
||||||
IsActive bool `json:"is_active" gorm:"type:bool"`
|
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:false"`
|
||||||
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
||||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||||
}
|
}
|
||||||
|
|
@ -8,6 +8,8 @@ type PpidDatas struct {
|
||||||
Description string `json:"description" gorm:"type:varchar"`
|
Description string `json:"description" gorm:"type:varchar"`
|
||||||
CategoryId int `json:"category_id" gorm:"type:int4"`
|
CategoryId int `json:"category_id" gorm:"type:int4"`
|
||||||
CreatedById int `json:"created_by_id" gorm:"type:int4"`
|
CreatedById int `json:"created_by_id" gorm:"type:int4"`
|
||||||
|
LevelGroupId *int `json:"level_group_id" gorm:"type:int4"`
|
||||||
|
Group *string `json:"group" gorm:"type:varchar"`
|
||||||
StatusId int `json:"status_id" gorm:"type:int4"`
|
StatusId int `json:"status_id" gorm:"type:int4"`
|
||||||
IsPublish *bool `json:"is_publish" gorm:"type:bool;default:false"`
|
IsPublish *bool `json:"is_publish" gorm:"type:bool;default:false"`
|
||||||
PublishedAt *time.Time `json:"published_at" gorm:"type:timestamp"`
|
PublishedAt *time.Time `json:"published_at" gorm:"type:timestamp"`
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ type UserLevels struct {
|
||||||
LevelNumber int `json:"level_number" gorm:"type:int4"`
|
LevelNumber int `json:"level_number" gorm:"type:int4"`
|
||||||
ParentLevelId int `json:"parent_level_id" gorm:"type:int4"`
|
ParentLevelId int `json:"parent_level_id" gorm:"type:int4"`
|
||||||
ProvinceId int `json:"province_id" gorm:"type:int4"`
|
ProvinceId int `json:"province_id" gorm:"type:int4"`
|
||||||
|
Group *string `json:"group" gorm:"type:varchar"`
|
||||||
IsActive *bool `json:"is_active" gorm:"type:bool"`
|
IsActive *bool `json:"is_active" gorm:"type:bool"`
|
||||||
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
||||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ type UserRoles struct {
|
||||||
Description string `json:"description" gorm:"type:varchar"`
|
Description string `json:"description" gorm:"type:varchar"`
|
||||||
Code string `json:"code" gorm:"type:varchar"`
|
Code string `json:"code" gorm:"type:varchar"`
|
||||||
LevelNumber int `json:"level_number" gorm:"type:int4"`
|
LevelNumber int `json:"level_number" gorm:"type:int4"`
|
||||||
StatusId *int `json:"status_id" gorm:"type:int4;default:1"`
|
StatusId int `json:"status_id" gorm:"type:int4;default:1"`
|
||||||
CreatedById *int `json:"created_by_id" gorm:"type:int4"`
|
CreatedById *uint `json:"created_by_id" gorm:"type:int4"`
|
||||||
IsActive *bool `json:"is_active" gorm:"type:bool;default:true"`
|
IsActive *bool `json:"is_active" gorm:"type:bool;default:true"`
|
||||||
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
||||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ func NewArticleCategoriesController(articleCategoriesService service.ArticleCate
|
||||||
// @Tags ArticleCategories
|
// @Tags ArticleCategories
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param req query request.ArticleCategoriesQueryRequest false "query parameters"
|
// @Param req query request.ArticleCategoriesQueryRequest false "query parameters"
|
||||||
|
// @Param req query paginator.Pagination false "pagination parameters"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 400 {object} response.BadRequestError
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 401 {object} response.UnauthorizedError
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"go-humas-be/app/database"
|
"go-humas-be/app/database"
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity"
|
||||||
"go-humas-be/app/module/article_categories/request"
|
"go-humas-be/app/module/article_categories/request"
|
||||||
|
|
@ -59,6 +60,14 @@ func (_i *articleCategoriesRepository) GetAll(req request.ArticleCategoriesQuery
|
||||||
}
|
}
|
||||||
query.Count(&count)
|
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.Count = count
|
||||||
req.Pagination = paginator.Paging(req.Pagination)
|
req.Pagination = paginator.Paging(req.Pagination)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ func NewArticleFilesController(articleFilesService service.ArticleFilesService)
|
||||||
// @Description API for getting all ArticleFiles
|
// @Description API for getting all ArticleFiles
|
||||||
// @Tags ArticleFiles
|
// @Tags ArticleFiles
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
|
// @Param req query request.ArticleFilesQueryRequest false "query parameters"
|
||||||
|
// @Param req query paginator.Pagination false "pagination parameters"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 400 {object} response.BadRequestError
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 401 {object} response.UnauthorizedError
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"go-humas-be/app/database"
|
"go-humas-be/app/database"
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity"
|
||||||
"go-humas-be/app/module/article_files/request"
|
"go-humas-be/app/module/article_files/request"
|
||||||
|
|
@ -49,6 +50,14 @@ func (_i *articleFilesRepository) GetAll(req request.ArticleFilesQueryRequest) (
|
||||||
}
|
}
|
||||||
query.Count(&count)
|
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.Count = count
|
||||||
req.Pagination = paginator.Paging(req.Pagination)
|
req.Pagination = paginator.Paging(req.Pagination)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,6 @@ func (_i *articleFilesService) Delete(id uint) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
result.IsActive = false
|
result.IsActive = false
|
||||||
return _i.Repo.Update(id, result)
|
return _i.Repo.Update(id, result)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ func NewArticlesController(articlesService service.ArticlesService) ArticlesCont
|
||||||
// @Tags Articles
|
// @Tags Articles
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param req query request.ArticlesQueryRequest false "query parameters"
|
// @Param req query request.ArticlesQueryRequest false "query parameters"
|
||||||
|
// @Param req query paginator.Pagination false "pagination parameters"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 400 {object} response.BadRequestError
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 401 {object} response.UnauthorizedError
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"go-humas-be/app/database"
|
"go-humas-be/app/database"
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity"
|
||||||
|
|
@ -63,6 +64,14 @@ func (_i *articlesRepository) GetAll(req request.ArticlesQueryRequest) (articles
|
||||||
}
|
}
|
||||||
query.Count(&count)
|
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.Count = count
|
||||||
req.Pagination = paginator.Paging(req.Pagination)
|
req.Pagination = paginator.Paging(req.Pagination)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ func DistrictsResponseMapper(districtsReq *entity.Districts) (districtsRes *res.
|
||||||
if districtsReq != nil {
|
if districtsReq != nil {
|
||||||
districtsRes = &res.DistrictsResponse{
|
districtsRes = &res.DistrictsResponse{
|
||||||
ID: districtsReq.ID,
|
ID: districtsReq.ID,
|
||||||
DisNam: districtsReq.DisNam,
|
DisNam: districtsReq.DisName,
|
||||||
CityId: districtsReq.CityId,
|
CityId: districtsReq.CityId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,34 +10,33 @@ type DistrictsGeneric interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type DistrictsQueryRequest struct {
|
type DistrictsQueryRequest struct {
|
||||||
DisNam string `json:"dis_nam" validate:"required"`
|
DisName string `json:"disName" validate:"required"`
|
||||||
CityId int `json:"city_id" validate:"required"`
|
CityId int `json:"cityId" validate:"required"`
|
||||||
Pagination *paginator.Pagination `json:"pagination"`
|
Pagination *paginator.Pagination `json:"pagination"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type DistrictsCreateRequest struct {
|
type DistrictsCreateRequest struct {
|
||||||
DisNam string `json:"dis_nam" validate:"required"`
|
DisName string `json:"disName" validate:"required"`
|
||||||
CityId int `json:"city_id" validate:"required"`
|
CityId int `json:"cityId" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (req DistrictsCreateRequest) ToEntity() *entity.Districts {
|
func (req DistrictsCreateRequest) ToEntity() *entity.Districts {
|
||||||
return &entity.Districts{
|
return &entity.Districts{
|
||||||
DisNam: req.DisNam,
|
DisName: req.DisName,
|
||||||
CityId: req.CityId,
|
CityId: req.CityId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type DistrictsUpdateRequest struct {
|
type DistrictsUpdateRequest struct {
|
||||||
ID uint `json:"id" validate:"required"`
|
ID uint `json:"id" validate:"required"`
|
||||||
DisNam string `json:"dis_nam" validate:"required"`
|
DisName string `json:"disName" validate:"required"`
|
||||||
CityId int `json:"city_id" validate:"required"`
|
CityId int `json:"cityId" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (req DistrictsUpdateRequest) ToEntity() *entity.Districts {
|
func (req DistrictsUpdateRequest) ToEntity() *entity.Districts {
|
||||||
return &entity.Districts{
|
return &entity.Districts{
|
||||||
ID: req.ID,
|
ID: req.ID,
|
||||||
DisNam: req.DisNam,
|
DisName: req.DisName,
|
||||||
CityId: req.CityId,
|
CityId: req.CityId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -29,16 +29,17 @@ func NewPpidDataCategoriesController(ppidDataCategoriesService service.PpidDataC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// All get all PpidDataCategories
|
// All PpidDataCategories
|
||||||
// @Summary Get all PpidDataCategories
|
// @Summary Get all PpidDataCategories
|
||||||
// @Description API for getting all PpidDataCategories
|
// @Description API for getting all PpidDataCategories
|
||||||
// @Tags Task
|
// @Tags PPID Categories
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
|
// @Param req query request.PpidDataCategoriesQueryRequest false "query parameters"
|
||||||
|
// @Param req query paginator.Pagination false "pagination parameters"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 401 {object} response.Response
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 404 {object} response.Response
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
// @Failure 422 {object} response.Response
|
// @Failure 500 {object} response.InternalServerError
|
||||||
// @Failure 500 {object} response.Response
|
|
||||||
// @Router /ppid-data-categories [get]
|
// @Router /ppid-data-categories [get]
|
||||||
func (_i *ppidDataCategoriesController) All(c *fiber.Ctx) error {
|
func (_i *ppidDataCategoriesController) All(c *fiber.Ctx) error {
|
||||||
paginate, err := paginator.Paginate(c)
|
paginate, err := paginator.Paginate(c)
|
||||||
|
|
@ -46,7 +47,11 @@ func (_i *ppidDataCategoriesController) All(c *fiber.Ctx) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var req request.PpidDataCategoriesQueryRequest
|
reqContext := request.PpidDataCategoriesQueryRequestContext{
|
||||||
|
Title: c.Query("title"),
|
||||||
|
Description: c.Query("description"),
|
||||||
|
}
|
||||||
|
req := reqContext.ToParamRequest()
|
||||||
req.Pagination = paginate
|
req.Pagination = paginate
|
||||||
|
|
||||||
ppidDataCategoriesData, paging, err := _i.ppidDataCategoriesService.All(req)
|
ppidDataCategoriesData, paging, err := _i.ppidDataCategoriesService.All(req)
|
||||||
|
|
@ -55,23 +60,23 @@ func (_i *ppidDataCategoriesController) All(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return utilRes.Resp(c, utilRes.Response{
|
return utilRes.Resp(c, utilRes.Response{
|
||||||
|
Success: true,
|
||||||
Messages: utilRes.Messages{"PpidDataCategories list successfully retrieved"},
|
Messages: utilRes.Messages{"PpidDataCategories list successfully retrieved"},
|
||||||
Data: ppidDataCategoriesData,
|
Data: ppidDataCategoriesData,
|
||||||
Meta: paging,
|
Meta: paging,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show get one PpidDataCategories
|
// Show PpidDataCategories
|
||||||
// @Summary Get one PpidDataCategories
|
// @Summary Get one PpidDataCategories
|
||||||
// @Description API for getting one PpidDataCategories
|
// @Description API for getting one PpidDataCategories
|
||||||
// @Tags Task
|
// @Tags PPID Categories
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param id path int true "PpidDataCategories ID"
|
// @Param id path int true "PpidDataCategories ID"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 401 {object} response.Response
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 404 {object} response.Response
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
// @Failure 422 {object} response.Response
|
// @Failure 500 {object} response.InternalServerError
|
||||||
// @Failure 500 {object} response.Response
|
|
||||||
// @Router /ppid-data-categories/{id} [get]
|
// @Router /ppid-data-categories/{id} [get]
|
||||||
func (_i *ppidDataCategoriesController) Show(c *fiber.Ctx) error {
|
func (_i *ppidDataCategoriesController) Show(c *fiber.Ctx) error {
|
||||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||||
|
|
@ -85,22 +90,22 @@ func (_i *ppidDataCategoriesController) Show(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return utilRes.Resp(c, utilRes.Response{
|
return utilRes.Resp(c, utilRes.Response{
|
||||||
|
Success: true,
|
||||||
Messages: utilRes.Messages{"PpidDataCategories successfully retrieved"},
|
Messages: utilRes.Messages{"PpidDataCategories successfully retrieved"},
|
||||||
Data: ppidDataCategoriesData,
|
Data: ppidDataCategoriesData,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save create PpidDataCategories
|
// Save PpidDataCategories
|
||||||
// @Summary Create PpidDataCategories
|
// @Summary Create PpidDataCategories
|
||||||
// @Description API for create PpidDataCategories
|
// @Description API for create PpidDataCategories
|
||||||
// @Tags Task
|
// @Tags PPID Categories
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Body request.PpidDataCategoriesCreateRequest
|
// @Param payload body request.PpidDataCategoriesCreateRequest true "Required payload"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 401 {object} response.Response
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 404 {object} response.Response
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
// @Failure 422 {object} response.Response
|
// @Failure 500 {object} response.InternalServerError
|
||||||
// @Failure 500 {object} response.Response
|
|
||||||
// @Router /ppid-data-categories [post]
|
// @Router /ppid-data-categories [post]
|
||||||
func (_i *ppidDataCategoriesController) Save(c *fiber.Ctx) error {
|
func (_i *ppidDataCategoriesController) Save(c *fiber.Ctx) error {
|
||||||
req := new(request.PpidDataCategoriesCreateRequest)
|
req := new(request.PpidDataCategoriesCreateRequest)
|
||||||
|
|
@ -114,22 +119,22 @@ func (_i *ppidDataCategoriesController) Save(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return utilRes.Resp(c, utilRes.Response{
|
return utilRes.Resp(c, utilRes.Response{
|
||||||
|
Success: true,
|
||||||
Messages: utilRes.Messages{"PpidDataCategories successfully created"},
|
Messages: utilRes.Messages{"PpidDataCategories successfully created"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update update PpidDataCategories
|
// Update PpidDataCategories
|
||||||
// @Summary update PpidDataCategories
|
// @Summary update PpidDataCategories
|
||||||
// @Description API for update PpidDataCategories
|
// @Description API for update PpidDataCategories
|
||||||
// @Tags Task
|
// @Tags PPID Categories
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Body request.PpidDataCategoriesUpdateRequest
|
// @Param payload body request.PpidDataCategoriesUpdateRequest true "Required payload"
|
||||||
// @Param id path int true "PpidDataCategories ID"
|
// @Param id path int true "PpidDataCategories ID"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 401 {object} response.Response
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 404 {object} response.Response
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
// @Failure 422 {object} response.Response
|
// @Failure 500 {object} response.InternalServerError
|
||||||
// @Failure 500 {object} response.Response
|
|
||||||
// @Router /ppid-data-categories/{id} [put]
|
// @Router /ppid-data-categories/{id} [put]
|
||||||
func (_i *ppidDataCategoriesController) Update(c *fiber.Ctx) error {
|
func (_i *ppidDataCategoriesController) Update(c *fiber.Ctx) error {
|
||||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||||
|
|
@ -148,21 +153,21 @@ func (_i *ppidDataCategoriesController) Update(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return utilRes.Resp(c, utilRes.Response{
|
return utilRes.Resp(c, utilRes.Response{
|
||||||
|
Success: true,
|
||||||
Messages: utilRes.Messages{"PpidDataCategories successfully updated"},
|
Messages: utilRes.Messages{"PpidDataCategories successfully updated"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete delete PpidDataCategories
|
// Delete PpidDataCategories
|
||||||
// @Summary delete PpidDataCategories
|
// @Summary delete PpidDataCategories
|
||||||
// @Description API for delete PpidDataCategories
|
// @Description API for delete PpidDataCategories
|
||||||
// @Tags Task
|
// @Tags PPID Categories
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param id path int true "PpidDataCategories ID"
|
// @Param id path int true "PpidDataCategories ID"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 401 {object} response.Response
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 404 {object} response.Response
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
// @Failure 422 {object} response.Response
|
// @Failure 500 {object} response.InternalServerError
|
||||||
// @Failure 500 {object} response.Response
|
|
||||||
// @Router /ppid-data-categories/{id} [delete]
|
// @Router /ppid-data-categories/{id} [delete]
|
||||||
func (_i *ppidDataCategoriesController) Delete(c *fiber.Ctx) error {
|
func (_i *ppidDataCategoriesController) Delete(c *fiber.Ctx) error {
|
||||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||||
|
|
@ -176,6 +181,7 @@ func (_i *ppidDataCategoriesController) Delete(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return utilRes.Resp(c, utilRes.Response{
|
return utilRes.Resp(c, utilRes.Response{
|
||||||
|
Success: true,
|
||||||
Messages: utilRes.Messages{"PpidDataCategories successfully deleted"},
|
Messages: utilRes.Messages{"PpidDataCategories successfully deleted"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"go-humas-be/app/database"
|
"go-humas-be/app/database"
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity"
|
||||||
"go-humas-be/app/module/ppid_data_categories/request"
|
"go-humas-be/app/module/ppid_data_categories/request"
|
||||||
"go-humas-be/utils/paginator"
|
"go-humas-be/utils/paginator"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ppidDataCategoriesRepository struct {
|
type ppidDataCategoriesRepository struct {
|
||||||
|
|
@ -31,8 +33,26 @@ func (_i *ppidDataCategoriesRepository) GetAll(req request.PpidDataCategoriesQue
|
||||||
var count int64
|
var count int64
|
||||||
|
|
||||||
query := _i.DB.DB.Model(&entity.PpidDataCategories{})
|
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)+"%")
|
||||||
|
}
|
||||||
query.Count(&count)
|
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.Count = count
|
||||||
req.Pagination = paginator.Paging(req.Pagination)
|
req.Pagination = paginator.Paging(req.Pagination)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,8 @@ type PpidDataCategoriesGeneric interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PpidDataCategoriesQueryRequest struct {
|
type PpidDataCategoriesQueryRequest struct {
|
||||||
Title string `json:"title" validate:"required"`
|
Title *string `json:"title"`
|
||||||
Description string `json:"description" validate:"required"`
|
Description *string `json:"description"`
|
||||||
Slug string `json:"slug" validate:"required"`
|
|
||||||
IsActive bool `json:"is_active" validate:"required"`
|
|
||||||
Pagination *paginator.Pagination `json:"pagination"`
|
Pagination *paginator.Pagination `json:"pagination"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,7 +20,6 @@ type PpidDataCategoriesCreateRequest struct {
|
||||||
Title string `json:"title" validate:"required"`
|
Title string `json:"title" validate:"required"`
|
||||||
Description string `json:"description" validate:"required"`
|
Description string `json:"description" validate:"required"`
|
||||||
Slug string `json:"slug" validate:"required"`
|
Slug string `json:"slug" validate:"required"`
|
||||||
IsActive bool `json:"is_active" validate:"required"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (req PpidDataCategoriesCreateRequest) ToEntity() *entity.PpidDataCategories {
|
func (req PpidDataCategoriesCreateRequest) ToEntity() *entity.PpidDataCategories {
|
||||||
|
|
@ -30,7 +27,6 @@ func (req PpidDataCategoriesCreateRequest) ToEntity() *entity.PpidDataCategories
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Slug: req.Slug,
|
Slug: req.Slug,
|
||||||
IsActive: req.IsActive,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,9 +35,6 @@ type PpidDataCategoriesUpdateRequest struct {
|
||||||
Title string `json:"title" validate:"required"`
|
Title string `json:"title" validate:"required"`
|
||||||
Description string `json:"description" validate:"required"`
|
Description string `json:"description" validate:"required"`
|
||||||
Slug string `json:"slug" validate:"required"`
|
Slug string `json:"slug" validate:"required"`
|
||||||
IsActive bool `json:"is_active" validate:"required"`
|
|
||||||
CreatedAt time.Time `json:"created_at"`
|
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (req PpidDataCategoriesUpdateRequest) ToEntity() *entity.PpidDataCategories {
|
func (req PpidDataCategoriesUpdateRequest) ToEntity() *entity.PpidDataCategories {
|
||||||
|
|
@ -50,8 +43,24 @@ func (req PpidDataCategoriesUpdateRequest) ToEntity() *entity.PpidDataCategories
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Slug: req.Slug,
|
Slug: req.Slug,
|
||||||
IsActive: req.IsActive,
|
UpdatedAt: time.Now(),
|
||||||
CreatedAt: req.CreatedAt,
|
|
||||||
UpdatedAt: req.UpdatedAt,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PpidDataCategoriesQueryRequestContext struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (req PpidDataCategoriesQueryRequestContext) ToParamRequest() PpidDataCategoriesQueryRequest {
|
||||||
|
var request PpidDataCategoriesQueryRequest
|
||||||
|
|
||||||
|
if title := req.Title; title != "" {
|
||||||
|
request.Title = &title
|
||||||
|
}
|
||||||
|
if description := req.Description; description != "" {
|
||||||
|
request.Description = &description
|
||||||
|
}
|
||||||
|
|
||||||
|
return request
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ type PpidDataCategoriesResponse struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
IsActive bool `json:"is_active"`
|
IsActive *bool `json:"is_active"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
@ -68,5 +68,12 @@ func (_i *ppidDataCategoriesService) Update(id uint, req request.PpidDataCategor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *ppidDataCategoriesService) Delete(id uint) error {
|
func (_i *ppidDataCategoriesService) Delete(id uint) error {
|
||||||
return _i.Repo.Delete(id)
|
result, err := _i.Repo.FindOne(id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
isActive := false
|
||||||
|
result.IsActive = &isActive
|
||||||
|
return _i.Repo.Update(id, result)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ type PpidDataFilesController interface {
|
||||||
Save(c *fiber.Ctx) error
|
Save(c *fiber.Ctx) error
|
||||||
Update(c *fiber.Ctx) error
|
Update(c *fiber.Ctx) error
|
||||||
Delete(c *fiber.Ctx) error
|
Delete(c *fiber.Ctx) error
|
||||||
|
Viewer(c *fiber.Ctx) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPpidDataFilesController(ppidDataFilesService service.PpidDataFilesService) PpidDataFilesController {
|
func NewPpidDataFilesController(ppidDataFilesService service.PpidDataFilesService) PpidDataFilesController {
|
||||||
|
|
@ -29,16 +30,17 @@ func NewPpidDataFilesController(ppidDataFilesService service.PpidDataFilesServic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// All get all PpidDataFiles
|
// All PpidDataFiles
|
||||||
// @Summary Get all PpidDataFiles
|
// @Summary Get all PpidDataFiles
|
||||||
// @Description API for getting all PpidDataFiles
|
// @Description API for getting all PpidDataFiles
|
||||||
// @Tags Task
|
// @Tags PPID Files
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
|
// @Param req query request.PpidDataFilesQueryRequest false "query parameters"
|
||||||
|
// @Param req query paginator.Pagination false "pagination parameters"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 401 {object} response.Response
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 404 {object} response.Response
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
// @Failure 422 {object} response.Response
|
// @Failure 500 {object} response.InternalServerError
|
||||||
// @Failure 500 {object} response.Response
|
|
||||||
// @Router /ppid-data-files [get]
|
// @Router /ppid-data-files [get]
|
||||||
func (_i *ppidDataFilesController) All(c *fiber.Ctx) error {
|
func (_i *ppidDataFilesController) All(c *fiber.Ctx) error {
|
||||||
paginate, err := paginator.Paginate(c)
|
paginate, err := paginator.Paginate(c)
|
||||||
|
|
@ -46,7 +48,16 @@ func (_i *ppidDataFilesController) All(c *fiber.Ctx) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var req request.PpidDataFilesQueryRequest
|
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
|
req.Pagination = paginate
|
||||||
|
|
||||||
ppidDataFilesData, paging, err := _i.ppidDataFilesService.All(req)
|
ppidDataFilesData, paging, err := _i.ppidDataFilesService.All(req)
|
||||||
|
|
@ -55,23 +66,23 @@ func (_i *ppidDataFilesController) All(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return utilRes.Resp(c, utilRes.Response{
|
return utilRes.Resp(c, utilRes.Response{
|
||||||
|
Success: true,
|
||||||
Messages: utilRes.Messages{"PpidDataFiles list successfully retrieved"},
|
Messages: utilRes.Messages{"PpidDataFiles list successfully retrieved"},
|
||||||
Data: ppidDataFilesData,
|
Data: ppidDataFilesData,
|
||||||
Meta: paging,
|
Meta: paging,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show get one PpidDataFiles
|
// Show PpidDataFiles
|
||||||
// @Summary Get one PpidDataFiles
|
// @Summary Get one PpidDataFiles
|
||||||
// @Description API for getting one PpidDataFiles
|
// @Description API for getting one PpidDataFiles
|
||||||
// @Tags Task
|
// @Tags PPID Files
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param id path int true "PpidDataFiles ID"
|
// @Param id path int true "PpidDataFiles ID"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 401 {object} response.Response
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 404 {object} response.Response
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
// @Failure 422 {object} response.Response
|
// @Failure 500 {object} response.InternalServerError
|
||||||
// @Failure 500 {object} response.Response
|
|
||||||
// @Router /ppid-data-files/{id} [get]
|
// @Router /ppid-data-files/{id} [get]
|
||||||
func (_i *ppidDataFilesController) Show(c *fiber.Ctx) error {
|
func (_i *ppidDataFilesController) Show(c *fiber.Ctx) error {
|
||||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||||
|
|
@ -85,51 +96,49 @@ func (_i *ppidDataFilesController) Show(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return utilRes.Resp(c, utilRes.Response{
|
return utilRes.Resp(c, utilRes.Response{
|
||||||
|
Success: true,
|
||||||
Messages: utilRes.Messages{"PpidDataFiles successfully retrieved"},
|
Messages: utilRes.Messages{"PpidDataFiles successfully retrieved"},
|
||||||
Data: ppidDataFilesData,
|
Data: ppidDataFilesData,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save create PpidDataFiles
|
// Save PpidDataFiles
|
||||||
// @Summary Create PpidDataFiles
|
// @Summary Create PpidDataFiles
|
||||||
// @Description API for create PpidDataFiles
|
// @Description API for create PpidDataFiles
|
||||||
// @Tags Task
|
// @Tags PPID Files
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Body request.PpidDataFilesCreateRequest
|
// @Produce json
|
||||||
|
// @Param files formData file true "Upload file"
|
||||||
|
// @Param payload body request.PpidDataFilesCreateRequest true "Required payload"
|
||||||
|
// @Param ppidDataId path int true "Ppid Data ID"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 401 {object} response.Response
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 404 {object} response.Response
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
// @Failure 422 {object} response.Response
|
// @Failure 500 {object} response.InternalServerError
|
||||||
// @Failure 500 {object} response.Response
|
// @Router /ppid-data-files/{ppidDataId} [post]
|
||||||
// @Router /ppid-data-files [post]
|
|
||||||
func (_i *ppidDataFilesController) Save(c *fiber.Ctx) error {
|
func (_i *ppidDataFilesController) Save(c *fiber.Ctx) error {
|
||||||
req := new(request.PpidDataFilesCreateRequest)
|
err := _i.ppidDataFilesService.Save(c)
|
||||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err := _i.ppidDataFilesService.Save(*req)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return utilRes.Resp(c, utilRes.Response{
|
return utilRes.Resp(c, utilRes.Response{
|
||||||
|
Success: true,
|
||||||
Messages: utilRes.Messages{"PpidDataFiles successfully created"},
|
Messages: utilRes.Messages{"PpidDataFiles successfully created"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update update PpidDataFiles
|
// Update PpidDataFiles
|
||||||
// @Summary update PpidDataFiles
|
// @Summary update PpidDataFiles
|
||||||
// @Description API for update PpidDataFiles
|
// @Description API for update PpidDataFiles
|
||||||
// @Tags Task
|
// @Tags PPID Files
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Body request.PpidDataFilesUpdateRequest
|
// @Param payload body request.PpidDataFilesUpdateRequest true "Required payload"
|
||||||
// @Param id path int true "PpidDataFiles ID"
|
// @Param id path int true "Ppid Data ID"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 401 {object} response.Response
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 404 {object} response.Response
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
// @Failure 422 {object} response.Response
|
// @Failure 500 {object} response.InternalServerError
|
||||||
// @Failure 500 {object} response.Response
|
|
||||||
// @Router /ppid-data-files/{id} [put]
|
// @Router /ppid-data-files/{id} [put]
|
||||||
func (_i *ppidDataFilesController) Update(c *fiber.Ctx) error {
|
func (_i *ppidDataFilesController) Update(c *fiber.Ctx) error {
|
||||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||||
|
|
@ -148,21 +157,21 @@ func (_i *ppidDataFilesController) Update(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return utilRes.Resp(c, utilRes.Response{
|
return utilRes.Resp(c, utilRes.Response{
|
||||||
|
Success: true,
|
||||||
Messages: utilRes.Messages{"PpidDataFiles successfully updated"},
|
Messages: utilRes.Messages{"PpidDataFiles successfully updated"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete delete PpidDataFiles
|
// Delete PpidDataFiles
|
||||||
// @Summary delete PpidDataFiles
|
// @Summary delete PpidDataFiles
|
||||||
// @Description API for delete PpidDataFiles
|
// @Description API for delete PpidDataFiles
|
||||||
// @Tags Task
|
// @Tags PPID Files
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param id path int true "PpidDataFiles ID"
|
// @Param id path int true "PpidDataFiles ID"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 401 {object} response.Response
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 404 {object} response.Response
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
// @Failure 422 {object} response.Response
|
// @Failure 500 {object} response.InternalServerError
|
||||||
// @Failure 500 {object} response.Response
|
|
||||||
// @Router /ppid-data-files/{id} [delete]
|
// @Router /ppid-data-files/{id} [delete]
|
||||||
func (_i *ppidDataFilesController) Delete(c *fiber.Ctx) error {
|
func (_i *ppidDataFilesController) Delete(c *fiber.Ctx) error {
|
||||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||||
|
|
@ -176,6 +185,26 @@ func (_i *ppidDataFilesController) Delete(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return utilRes.Resp(c, utilRes.Response{
|
return utilRes.Resp(c, utilRes.Response{
|
||||||
|
Success: true,
|
||||||
Messages: utilRes.Messages{"PpidDataFiles successfully deleted"},
|
Messages: utilRes.Messages{"PpidDataFiles successfully deleted"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Viewer PpidDataFiles
|
||||||
|
// @Summary Create PpidDataFiles
|
||||||
|
// @Description API for create PpidDataFiles
|
||||||
|
// @Tags PPID Files
|
||||||
|
// @Security Bearer
|
||||||
|
// @Param id path string 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/viewer/{id} [get]
|
||||||
|
func (_i *ppidDataFilesController) Viewer(c *fiber.Ctx) error {
|
||||||
|
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return _i.ppidDataFilesService.Viewer(c, uint(id))
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,5 +49,6 @@ func (_i *PpidDataFilesRouter) RegisterPpidDataFilesRoutes() {
|
||||||
router.Post("/", ppidDataFilesController.Save)
|
router.Post("/", ppidDataFilesController.Save)
|
||||||
router.Put("/:id", ppidDataFilesController.Update)
|
router.Put("/:id", ppidDataFilesController.Update)
|
||||||
router.Delete("/:id", ppidDataFilesController.Delete)
|
router.Delete("/:id", ppidDataFilesController.Delete)
|
||||||
|
router.Get("/viewer/:id", ppidDataFilesController.Viewer)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package request
|
||||||
import (
|
import (
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity"
|
||||||
"go-humas-be/utils/paginator"
|
"go-humas-be/utils/paginator"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -11,32 +12,27 @@ type PpidDataFilesGeneric interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PpidDataFilesQueryRequest struct {
|
type PpidDataFilesQueryRequest struct {
|
||||||
Title string `json:"title" validate:"required"`
|
Title *string `json:"title"`
|
||||||
PpidDataId int `json:"ppid_data_id" validate:"required"`
|
PpidDataId *int `json:"ppidDataId"`
|
||||||
Description string `json:"description" validate:"required"`
|
Description *string `json:"description"`
|
||||||
Unit string `json:"unit" validate:"required"`
|
Unit *string `json:"unit"`
|
||||||
FileType string `json:"file_type" validate:"required"`
|
FileType *string `json:"fileType"`
|
||||||
DownloadCount int `json:"download_count" validate:"required"`
|
StatusId *int `json:"statusId"`
|
||||||
CreatedById int `json:"created_by_id" validate:"required"`
|
IsPublish *bool `json:"isPublish"`
|
||||||
StatusId int `json:"status_id" validate:"required"`
|
|
||||||
IsPublish bool `json:"is_publish" validate:"required"`
|
|
||||||
PublishedAt time.Time `json:"published_at" validate:"required"`
|
|
||||||
IsActive bool `json:"is_active" validate:"required"`
|
|
||||||
Pagination *paginator.Pagination `json:"pagination"`
|
Pagination *paginator.Pagination `json:"pagination"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PpidDataFilesCreateRequest struct {
|
type PpidDataFilesCreateRequest struct {
|
||||||
Title string `json:"title" validate:"required"`
|
Title string `json:"title" validate:"required"`
|
||||||
PpidDataId int `json:"ppid_data_id" validate:"required"`
|
PpidDataId int `json:"ppidDataId" validate:"required"`
|
||||||
Description string `json:"description" validate:"required"`
|
Description string `json:"description" validate:"required"`
|
||||||
Unit string `json:"unit" validate:"required"`
|
Unit string `json:"unit" validate:"required"`
|
||||||
FileType string `json:"file_type" validate:"required"`
|
FileType string `json:"fileType" validate:"required"`
|
||||||
DownloadCount int `json:"download_count" validate:"required"`
|
FileName *string `json:"fileName"`
|
||||||
CreatedById int `json:"created_by_id" validate:"required"`
|
FilePath *string `json:"filePath"`
|
||||||
StatusId int `json:"status_id" validate:"required"`
|
Size *string `json:"size"`
|
||||||
IsPublish bool `json:"is_publish" validate:"required"`
|
CreatedById *int `json:"createdById"`
|
||||||
PublishedAt time.Time `json:"published_at" validate:"required"`
|
StatusId *int `json:"statusId"`
|
||||||
IsActive bool `json:"is_active" validate:"required"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (req PpidDataFilesCreateRequest) ToEntity() *entity.PpidDataFiles {
|
func (req PpidDataFilesCreateRequest) ToEntity() *entity.PpidDataFiles {
|
||||||
|
|
@ -46,30 +42,26 @@ func (req PpidDataFilesCreateRequest) ToEntity() *entity.PpidDataFiles {
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Unit: req.Unit,
|
Unit: req.Unit,
|
||||||
FileType: req.FileType,
|
FileType: req.FileType,
|
||||||
DownloadCount: req.DownloadCount,
|
FileName: req.FileName,
|
||||||
|
FilePath: req.FilePath,
|
||||||
|
Size: req.Size,
|
||||||
CreatedById: req.CreatedById,
|
CreatedById: req.CreatedById,
|
||||||
StatusId: req.StatusId,
|
StatusId: req.StatusId,
|
||||||
IsPublish: req.IsPublish,
|
|
||||||
PublishedAt: req.PublishedAt,
|
|
||||||
IsActive: req.IsActive,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PpidDataFilesUpdateRequest struct {
|
type PpidDataFilesUpdateRequest struct {
|
||||||
ID uint `json:"id" validate:"required"`
|
ID uint `json:"id" validate:"required"`
|
||||||
Title string `json:"title" validate:"required"`
|
Title string `json:"title" validate:"required"`
|
||||||
PpidDataId int `json:"ppid_data_id" validate:"required"`
|
PpidDataId int `json:"ppidDataId" validate:"required"`
|
||||||
Description string `json:"description" validate:"required"`
|
Description string `json:"description" validate:"required"`
|
||||||
Unit string `json:"unit" validate:"required"`
|
Unit string `json:"unit" validate:"required"`
|
||||||
FileType string `json:"file_type" validate:"required"`
|
FileType string `json:"fileType" validate:"required"`
|
||||||
DownloadCount int `json:"download_count" validate:"required"`
|
FilePath *string `json:"filePath"`
|
||||||
CreatedById int `json:"created_by_id" validate:"required"`
|
CreatedById *int `json:"createdById"`
|
||||||
StatusId int `json:"status_id" validate:"required"`
|
StatusId *int `json:"statusId"`
|
||||||
IsPublish bool `json:"is_publish" validate:"required"`
|
IsPublish *bool `json:"isPublish"`
|
||||||
PublishedAt time.Time `json:"published_at" validate:"required"`
|
PublishedAt *time.Time `json:"publishedAt"`
|
||||||
IsActive bool `json:"is_active" validate:"required"`
|
|
||||||
CreatedAt time.Time `json:"created_at"`
|
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (req PpidDataFilesUpdateRequest) ToEntity() *entity.PpidDataFiles {
|
func (req PpidDataFilesUpdateRequest) ToEntity() *entity.PpidDataFiles {
|
||||||
|
|
@ -80,13 +72,58 @@ func (req PpidDataFilesUpdateRequest) ToEntity() *entity.PpidDataFiles {
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Unit: req.Unit,
|
Unit: req.Unit,
|
||||||
FileType: req.FileType,
|
FileType: req.FileType,
|
||||||
DownloadCount: req.DownloadCount,
|
FilePath: req.FilePath,
|
||||||
CreatedById: req.CreatedById,
|
CreatedById: req.CreatedById,
|
||||||
StatusId: req.StatusId,
|
StatusId: req.StatusId,
|
||||||
IsPublish: req.IsPublish,
|
IsPublish: req.IsPublish,
|
||||||
PublishedAt: req.PublishedAt,
|
PublishedAt: req.PublishedAt,
|
||||||
IsActive: req.IsActive,
|
UpdatedAt: time.Now(),
|
||||||
CreatedAt: req.CreatedAt,
|
|
||||||
UpdatedAt: req.UpdatedAt,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PpidDataFilesQueryRequestContext struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
PpidDataId string `json:"ppidDataId"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Unit string `json:"unit"`
|
||||||
|
FileType string `json:"fileType"`
|
||||||
|
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 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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,12 @@ type PpidDataFilesResponse struct {
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Unit string `json:"unit"`
|
Unit string `json:"unit"`
|
||||||
FileType string `json:"file_type"`
|
FileType string `json:"file_type"`
|
||||||
DownloadCount int `json:"download_count"`
|
DownloadCount *int `json:"download_count"`
|
||||||
CreatedById int `json:"created_by_id"`
|
CreatedById *int `json:"created_by_id"`
|
||||||
StatusId int `json:"status_id"`
|
StatusId *int `json:"status_id"`
|
||||||
IsPublish bool `json:"is_publish"`
|
IsPublish *bool `json:"is_publish"`
|
||||||
PublishedAt time.Time `json:"published_at"`
|
PublishedAt *time.Time `json:"published_at"`
|
||||||
IsActive bool `json:"is_active"`
|
IsActive *bool `json:"is_active"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
@ -1,35 +1,49 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/minio/minio-go/v7"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"go-humas-be/app/module/ppid_data_files/mapper"
|
"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/repository"
|
||||||
"go-humas-be/app/module/ppid_data_files/request"
|
"go-humas-be/app/module/ppid_data_files/request"
|
||||||
"go-humas-be/app/module/ppid_data_files/response"
|
"go-humas-be/app/module/ppid_data_files/response"
|
||||||
|
minioStorage "go-humas-be/config/config"
|
||||||
"go-humas-be/utils/paginator"
|
"go-humas-be/utils/paginator"
|
||||||
|
utilVal "go-humas-be/utils/validator"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"mime"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PpidDataFilesService
|
// PpidDataFilesService
|
||||||
type ppidDataFilesService struct {
|
type ppidDataFilesService struct {
|
||||||
Repo repository.PpidDataFilesRepository
|
Repo repository.PpidDataFilesRepository
|
||||||
Log zerolog.Logger
|
Log zerolog.Logger
|
||||||
|
MinioStorage *minioStorage.MinioStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
// PpidDataFilesService define interface of IPpidDataFilesService
|
// PpidDataFilesService define interface of IPpidDataFilesService
|
||||||
type PpidDataFilesService interface {
|
type PpidDataFilesService interface {
|
||||||
All(req request.PpidDataFilesQueryRequest) (ppidDataFiles []*response.PpidDataFilesResponse, paging paginator.Pagination, err error)
|
All(req request.PpidDataFilesQueryRequest) (ppidDataFiles []*response.PpidDataFilesResponse, paging paginator.Pagination, err error)
|
||||||
Show(id uint) (ppidDataFiles *response.PpidDataFilesResponse, err error)
|
Show(id uint) (ppidDataFiles *response.PpidDataFilesResponse, err error)
|
||||||
Save(req request.PpidDataFilesCreateRequest) (err error)
|
Save(c *fiber.Ctx) error
|
||||||
Update(id uint, req request.PpidDataFilesUpdateRequest) (err error)
|
Update(id uint, req request.PpidDataFilesUpdateRequest) (err error)
|
||||||
Delete(id uint) error
|
Delete(id uint) error
|
||||||
|
Viewer(c *fiber.Ctx, id uint) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPpidDataFilesService init PpidDataFilesService
|
// NewPpidDataFilesService init PpidDataFilesService
|
||||||
func NewPpidDataFilesService(repo repository.PpidDataFilesRepository, log zerolog.Logger) PpidDataFilesService {
|
func NewPpidDataFilesService(repo repository.PpidDataFilesRepository, log zerolog.Logger, minioStorage *minioStorage.MinioStorage) PpidDataFilesService {
|
||||||
|
|
||||||
return &ppidDataFilesService{
|
return &ppidDataFilesService{
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
Log: log,
|
Log: log,
|
||||||
|
MinioStorage: minioStorage,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,10 +70,80 @@ func (_i *ppidDataFilesService) Show(id uint) (ppidDataFiles *response.PpidDataF
|
||||||
return mapper.PpidDataFilesResponseMapper(result), nil
|
return mapper.PpidDataFilesResponseMapper(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *ppidDataFilesService) Save(req request.PpidDataFilesCreateRequest) (err error) {
|
func (_i *ppidDataFilesService) Save(c *fiber.Ctx) (err error) {
|
||||||
_i.Log.Info().Interface("data", req).Msg("")
|
req := new(request.PpidDataFilesCreateRequest)
|
||||||
|
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return _i.Repo.Create(req.ToEntity())
|
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
objectName := "ppid/upload/" + file.Filename
|
||||||
|
//filenameOnly := file.Filename[:len(file.Filename)-len(filepath.Ext(file.Filename))]
|
||||||
|
size := strconv.FormatInt(file.Size, 10)
|
||||||
|
|
||||||
|
req := request.PpidDataFilesCreateRequest{
|
||||||
|
Title: req.Title,
|
||||||
|
Description: req.Description,
|
||||||
|
Unit: req.Unit,
|
||||||
|
PpidDataId: int(id),
|
||||||
|
FileType: req.FileType,
|
||||||
|
FileName: &file.Filename,
|
||||||
|
FilePath: &objectName,
|
||||||
|
Size: &size,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = _i.Repo.Create(req.ToEntity())
|
||||||
|
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 *ppidDataFilesService) Update(id uint, req request.PpidDataFilesUpdateRequest) (err error) {
|
func (_i *ppidDataFilesService) Update(id uint, req request.PpidDataFilesUpdateRequest) (err error) {
|
||||||
|
|
@ -70,3 +154,61 @@ func (_i *ppidDataFilesService) Update(id uint, req request.PpidDataFilesUpdateR
|
||||||
func (_i *ppidDataFilesService) Delete(id uint) error {
|
func (_i *ppidDataFilesService) Delete(id uint) error {
|
||||||
return _i.Repo.Delete(id)
|
return _i.Repo.Delete(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (_i *ppidDataFilesService) Viewer(c *fiber.Ctx, id uint) (err error) {
|
||||||
|
result, err := _i.Repo.FindOne(id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
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]
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,10 @@ func NewPpidDatasController(ppidDatasService service.PpidDatasService) PpidDatas
|
||||||
// All PpidDatas
|
// All PpidDatas
|
||||||
// @Summary Get all PpidDatas
|
// @Summary Get all PpidDatas
|
||||||
// @Description API for getting all PpidDatas
|
// @Description API for getting all PpidDatas
|
||||||
// @Tags Task
|
// @Tags PPID Data
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param req query request.PpidDatasQueryRequestContext false "query parameters"
|
// @Param req query request.PpidDatasQueryRequest false "query parameters"
|
||||||
|
// @Param req query paginator.Pagination false "pagination parameters"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 400 {object} response.BadRequestError
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 401 {object} response.UnauthorizedError
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
|
|
@ -74,7 +75,7 @@ func (_i *ppidDatasController) All(c *fiber.Ctx) error {
|
||||||
// Show PpidDatas
|
// Show PpidDatas
|
||||||
// @Summary Get one PpidDatas
|
// @Summary Get one PpidDatas
|
||||||
// @Description API for getting one PpidDatas
|
// @Description API for getting one PpidDatas
|
||||||
// @Tags Task
|
// @Tags PPID Data
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param id path int true "PpidDatas ID"
|
// @Param id path int true "PpidDatas ID"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
|
|
@ -103,7 +104,7 @@ func (_i *ppidDatasController) Show(c *fiber.Ctx) error {
|
||||||
// Save PpidDatas
|
// Save PpidDatas
|
||||||
// @Summary Create PpidDatas
|
// @Summary Create PpidDatas
|
||||||
// @Description API for create PpidDatas
|
// @Description API for create PpidDatas
|
||||||
// @Tags Task
|
// @Tags PPID Data
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param payload body request.PpidDatasCreateRequest true "Required payload"
|
// @Param payload body request.PpidDatasCreateRequest true "Required payload"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
|
|
@ -131,7 +132,7 @@ func (_i *ppidDatasController) Save(c *fiber.Ctx) error {
|
||||||
// Update PpidDatas
|
// Update PpidDatas
|
||||||
// @Summary update PpidDatas
|
// @Summary update PpidDatas
|
||||||
// @Description API for update PpidDatas
|
// @Description API for update PpidDatas
|
||||||
// @Tags Task
|
// @Tags PPID Data
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param payload body request.PpidDatasCreateRequest true "Required payload"
|
// @Param payload body request.PpidDatasCreateRequest true "Required payload"
|
||||||
// @Param id path int true "PpidDatas ID"
|
// @Param id path int true "PpidDatas ID"
|
||||||
|
|
@ -165,7 +166,7 @@ func (_i *ppidDatasController) Update(c *fiber.Ctx) error {
|
||||||
// Delete PpidDatas
|
// Delete PpidDatas
|
||||||
// @Summary delete PpidDatas
|
// @Summary delete PpidDatas
|
||||||
// @Description API for delete PpidDatas
|
// @Description API for delete PpidDatas
|
||||||
// @Tags Task
|
// @Tags PPID Data
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param id path int true "PpidDatas ID"
|
// @Param id path int true "PpidDatas ID"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"go-humas-be/app/database"
|
"go-humas-be/app/database"
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity"
|
||||||
"go-humas-be/app/module/ppid_datas/request"
|
"go-humas-be/app/module/ppid_datas/request"
|
||||||
"go-humas-be/utils/paginator"
|
"go-humas-be/utils/paginator"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ppidDatasRepository struct {
|
type ppidDatasRepository struct {
|
||||||
|
|
@ -31,8 +33,42 @@ func (_i *ppidDatasRepository) GetAll(req request.PpidDatasQueryRequest) (ppidDa
|
||||||
var count int64
|
var count int64
|
||||||
|
|
||||||
query := _i.DB.DB.Model(&entity.PpidDatas{})
|
query := _i.DB.DB.Model(&entity.PpidDatas{})
|
||||||
|
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.Group != nil && *req.Group != "" {
|
||||||
|
title := strings.ToLower(*req.Title)
|
||||||
|
query = query.Where("LOWER(title) LIKE ?", "%"+strings.ToLower(title)+"%")
|
||||||
|
}
|
||||||
|
if req.IsPublish != nil {
|
||||||
|
query = query.Where("is_publish = ?", req.IsPublish)
|
||||||
|
}
|
||||||
|
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)
|
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.Count = count
|
||||||
req.Pagination = paginator.Paging(req.Pagination)
|
req.Pagination = paginator.Paging(req.Pagination)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ type PpidDatasQueryRequest struct {
|
||||||
Title *string `json:"title"`
|
Title *string `json:"title"`
|
||||||
Description *string `json:"description"`
|
Description *string `json:"description"`
|
||||||
CategoryId *int `json:"categoryId"`
|
CategoryId *int `json:"categoryId"`
|
||||||
|
LevelGroupId *int `json:"levelGroupId"`
|
||||||
|
Group *string `json:"group"`
|
||||||
CreatedById *int `json:"createdById"`
|
CreatedById *int `json:"createdById"`
|
||||||
StatusId *int `json:"statusId"`
|
StatusId *int `json:"statusId"`
|
||||||
IsPublish *bool `json:"isPublish"`
|
IsPublish *bool `json:"isPublish"`
|
||||||
|
|
@ -27,6 +29,8 @@ type PpidDatasCreateRequest struct {
|
||||||
CategoryId int `json:"categoryId" validate:"required"`
|
CategoryId int `json:"categoryId" validate:"required"`
|
||||||
CreatedById int `json:"createdById" validate:"required"`
|
CreatedById int `json:"createdById" validate:"required"`
|
||||||
StatusId int `json:"statusId" validate:"required"`
|
StatusId int `json:"statusId" validate:"required"`
|
||||||
|
LevelGroupId *int `json:"levelGroupId"`
|
||||||
|
Group *string `json:"group"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (req PpidDatasCreateRequest) ToEntity() *entity.PpidDatas {
|
func (req PpidDatasCreateRequest) ToEntity() *entity.PpidDatas {
|
||||||
|
|
@ -36,6 +40,8 @@ func (req PpidDatasCreateRequest) ToEntity() *entity.PpidDatas {
|
||||||
CategoryId: req.CategoryId,
|
CategoryId: req.CategoryId,
|
||||||
CreatedById: req.CreatedById,
|
CreatedById: req.CreatedById,
|
||||||
StatusId: req.StatusId,
|
StatusId: req.StatusId,
|
||||||
|
LevelGroupId: req.LevelGroupId,
|
||||||
|
Group: req.Group,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,8 +52,10 @@ type PpidDatasUpdateRequest struct {
|
||||||
CategoryId int `json:"category_id" validate:"required"`
|
CategoryId int `json:"category_id" validate:"required"`
|
||||||
CreatedById int `json:"created_by_id" validate:"required"`
|
CreatedById int `json:"created_by_id" validate:"required"`
|
||||||
StatusId int `json:"status_id" validate:"required"`
|
StatusId int `json:"status_id" validate:"required"`
|
||||||
IsPublish *bool `json:"is_publish" validate:"required"`
|
IsPublish *bool `json:"is_publish"`
|
||||||
PublishedAt *time.Time `json:"published_at" validate:"required"`
|
PublishedAt *time.Time `json:"published_at"`
|
||||||
|
LevelGroupId *int `json:"levelGroupId"`
|
||||||
|
Group *string `json:"group"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (req PpidDatasUpdateRequest) ToEntity() *entity.PpidDatas {
|
func (req PpidDatasUpdateRequest) ToEntity() *entity.PpidDatas {
|
||||||
|
|
@ -60,6 +68,8 @@ func (req PpidDatasUpdateRequest) ToEntity() *entity.PpidDatas {
|
||||||
StatusId: req.StatusId,
|
StatusId: req.StatusId,
|
||||||
IsPublish: req.IsPublish,
|
IsPublish: req.IsPublish,
|
||||||
PublishedAt: req.PublishedAt,
|
PublishedAt: req.PublishedAt,
|
||||||
|
LevelGroupId: req.LevelGroupId,
|
||||||
|
Group: req.Group,
|
||||||
UpdatedAt: time.Now(),
|
UpdatedAt: time.Now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -68,6 +78,7 @@ type PpidDatasQueryRequestContext struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
CategoryId string `json:"categoryId"`
|
CategoryId string `json:"categoryId"`
|
||||||
|
Group string `json:"group"`
|
||||||
CreatedById string `json:"createdById"`
|
CreatedById string `json:"createdById"`
|
||||||
StatusId string `json:"statusId"`
|
StatusId string `json:"statusId"`
|
||||||
IsPublish string `json:"isPublish"`
|
IsPublish string `json:"isPublish"`
|
||||||
|
|
@ -82,6 +93,9 @@ func (req PpidDatasQueryRequestContext) ToParamRequest() PpidDatasQueryRequest {
|
||||||
if description := req.Description; description != "" {
|
if description := req.Description; description != "" {
|
||||||
request.Description = &description
|
request.Description = &description
|
||||||
}
|
}
|
||||||
|
if group := req.Group; group != "" {
|
||||||
|
request.Group = &group
|
||||||
|
}
|
||||||
if categoryIdStr := req.CategoryId; categoryIdStr != "" {
|
if categoryIdStr := req.CategoryId; categoryIdStr != "" {
|
||||||
categoryId, err := strconv.Atoi(categoryIdStr)
|
categoryId, err := strconv.Atoi(categoryIdStr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
||||||
|
|
@ -68,5 +68,12 @@ func (_i *ppidDatasService) Update(id uint, req request.PpidDatasUpdateRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *ppidDatasService) Delete(id uint) error {
|
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.Delete(id)
|
return _i.Repo.Delete(id)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ func NewUserLevelsController(userLevelsService service.UserLevelsService) UserLe
|
||||||
// @Tags UserLevels
|
// @Tags UserLevels
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param req query request.UserLevelsQueryRequest false "query parameters"
|
// @Param req query request.UserLevelsQueryRequest false "query parameters"
|
||||||
|
// @Param req query paginator.Pagination false "pagination parameters"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 400 {object} response.BadRequestError
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 401 {object} response.UnauthorizedError
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"go-humas-be/app/database"
|
"go-humas-be/app/database"
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity"
|
||||||
"go-humas-be/app/module/user_levels/request"
|
"go-humas-be/app/module/user_levels/request"
|
||||||
|
|
@ -49,6 +50,15 @@ func (_i *userLevelsRepository) GetAll(req request.UserLevelsQueryRequest) (user
|
||||||
}
|
}
|
||||||
query.Count(&count)
|
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)
|
req.Pagination = paginator.Paging(req.Pagination)
|
||||||
|
|
||||||
err = query.Offset(req.Pagination.Offset).Limit(req.Pagination.Limit).Find(&userLevelss).Error
|
err = query.Offset(req.Pagination.Offset).Limit(req.Pagination.Limit).Find(&userLevelss).Error
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ func NewUserRolesController(userRolesService service.UserRolesService, log zerol
|
||||||
// @Tags UserRoles
|
// @Tags UserRoles
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param req query request.UserRolesQueryRequest false "query parameters"
|
// @Param req query request.UserRolesQueryRequest false "query parameters"
|
||||||
|
// @Param req query paginator.Pagination false "pagination parameters"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 400 {object} response.BadRequestError
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 401 {object} response.UnauthorizedError
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
|
|
@ -105,6 +106,7 @@ func (_i *userRolesController) Show(c *fiber.Ctx) error {
|
||||||
// @Description API for create UserRoles
|
// @Description API for create UserRoles
|
||||||
// @Tags UserRoles
|
// @Tags UserRoles
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
|
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||||
// @Param payload body request.UserRolesCreateRequest true "Required payload"
|
// @Param payload body request.UserRolesCreateRequest true "Required payload"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 400 {object} response.BadRequestError
|
// @Failure 400 {object} response.BadRequestError
|
||||||
|
|
@ -117,7 +119,9 @@ func (_i *userRolesController) Save(c *fiber.Ctx) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err := _i.userRolesService.Save(*req)
|
authorizationHeader := c.Get("Authorization")
|
||||||
|
|
||||||
|
err := _i.userRolesService.Save(*req, authorizationHeader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"go-humas-be/app/database"
|
"go-humas-be/app/database"
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity"
|
||||||
"go-humas-be/app/module/user_roles/request"
|
"go-humas-be/app/module/user_roles/request"
|
||||||
"go-humas-be/utils/paginator"
|
"go-humas-be/utils/paginator"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type userRolesRepository struct {
|
type userRolesRepository struct {
|
||||||
|
|
@ -33,6 +33,8 @@ func NewUserRolesRepository(db *database.Database, log zerolog.Logger) UserRoles
|
||||||
|
|
||||||
// implement interface of IUserRolesRepository
|
// implement interface of IUserRolesRepository
|
||||||
func (_i *userRolesRepository) GetAll(req request.UserRolesQueryRequest) (userRoless []*entity.UserRoles, paging paginator.Pagination, err error) {
|
func (_i *userRolesRepository) GetAll(req request.UserRolesQueryRequest) (userRoless []*entity.UserRoles, paging paginator.Pagination, err error) {
|
||||||
|
_i.Log.Info().Interface("data", req).Msg("")
|
||||||
|
|
||||||
var count int64
|
var count int64
|
||||||
|
|
||||||
query := _i.DB.DB.Model(&entity.UserRoles{})
|
query := _i.DB.DB.Model(&entity.UserRoles{})
|
||||||
|
|
@ -53,9 +55,13 @@ func (_i *userRolesRepository) GetAll(req request.UserRolesQueryRequest) (userRo
|
||||||
}
|
}
|
||||||
query.Count(&count)
|
query.Count(&count)
|
||||||
|
|
||||||
_i.Log.Info().Str("timestamp", time.Now().
|
if req.Pagination.SortBy != "" {
|
||||||
Format(time.RFC3339)).Str("Service:userRolesRepository", "UserRoles:GetAll").
|
direction := "ASC"
|
||||||
Interface("req query", req).Msg("")
|
if req.Pagination.Sort == "desc" {
|
||||||
|
direction = "DESC"
|
||||||
|
}
|
||||||
|
query.Order(fmt.Sprintf("%s %s", req.Pagination.SortBy, direction))
|
||||||
|
}
|
||||||
|
|
||||||
req.Pagination.Count = count
|
req.Pagination.Count = count
|
||||||
req.Pagination = paginator.Paging(req.Pagination)
|
req.Pagination = paginator.Paging(req.Pagination)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ type UserRolesCreateRequest struct {
|
||||||
Name string `json:"name" validate:"required"`
|
Name string `json:"name" validate:"required"`
|
||||||
Description string `json:"description" validate:"required"`
|
Description string `json:"description" validate:"required"`
|
||||||
Code string `json:"code" validate:"required"`
|
Code string `json:"code" validate:"required"`
|
||||||
LevelNumber int `json:"level_number" validate:"required"`
|
LevelNumber int `json:"levelNumber" validate:"required"`
|
||||||
|
StatusId int `json:"statusId" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (req UserRolesCreateRequest) ToEntity() *entity.UserRoles {
|
func (req UserRolesCreateRequest) ToEntity() *entity.UserRoles {
|
||||||
|
|
@ -33,6 +34,7 @@ func (req UserRolesCreateRequest) ToEntity() *entity.UserRoles {
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Code: req.Code,
|
Code: req.Code,
|
||||||
LevelNumber: req.LevelNumber,
|
LevelNumber: req.LevelNumber,
|
||||||
|
StatusId: req.StatusId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,7 +43,7 @@ type UserRolesUpdateRequest struct {
|
||||||
Description string `json:"description" validate:"required"`
|
Description string `json:"description" validate:"required"`
|
||||||
Code string `json:"code" validate:"required"`
|
Code string `json:"code" validate:"required"`
|
||||||
LevelNumber int `json:"level_number" validate:"required"`
|
LevelNumber int `json:"level_number" validate:"required"`
|
||||||
StatusId *int `json:"status_id"`
|
StatusId int `json:"status_id" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (req UserRolesUpdateRequest) ToEntity() *entity.UserRoles {
|
func (req UserRolesUpdateRequest) ToEntity() *entity.UserRoles {
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ type UserRolesResponse struct {
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
LevelNumber int `json:"level_number"`
|
LevelNumber int `json:"level_number"`
|
||||||
StatusId *int `json:"status_id"`
|
StatusId int `json:"status_id"`
|
||||||
CreatedById *int `json:"created_by_id"`
|
CreatedById *uint `json:"created_by_id"`
|
||||||
IsActive *bool `json:"is_active"`
|
IsActive *bool `json:"is_active"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,15 @@ import (
|
||||||
"go-humas-be/app/module/user_roles/repository"
|
"go-humas-be/app/module/user_roles/repository"
|
||||||
"go-humas-be/app/module/user_roles/request"
|
"go-humas-be/app/module/user_roles/request"
|
||||||
"go-humas-be/app/module/user_roles/response"
|
"go-humas-be/app/module/user_roles/response"
|
||||||
|
usersRepository "go-humas-be/app/module/users/repository"
|
||||||
"go-humas-be/utils/paginator"
|
"go-humas-be/utils/paginator"
|
||||||
|
utilSvc "go-humas-be/utils/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UserRolesService
|
// UserRolesService
|
||||||
type userRolesService struct {
|
type userRolesService struct {
|
||||||
Repo repository.UserRolesRepository
|
Repo repository.UserRolesRepository
|
||||||
|
UsersRepo usersRepository.UsersRepository
|
||||||
Log zerolog.Logger
|
Log zerolog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -19,16 +22,17 @@ type userRolesService struct {
|
||||||
type UserRolesService interface {
|
type UserRolesService interface {
|
||||||
All(req request.UserRolesQueryRequest) (userRoles []*response.UserRolesResponse, paging paginator.Pagination, err error)
|
All(req request.UserRolesQueryRequest) (userRoles []*response.UserRolesResponse, paging paginator.Pagination, err error)
|
||||||
Show(id uint) (userRoles *response.UserRolesResponse, err error)
|
Show(id uint) (userRoles *response.UserRolesResponse, err error)
|
||||||
Save(req request.UserRolesCreateRequest) (err error)
|
Save(req request.UserRolesCreateRequest, header string) (err error)
|
||||||
Update(id uint, req request.UserRolesUpdateRequest) (err error)
|
Update(id uint, req request.UserRolesUpdateRequest) (err error)
|
||||||
Delete(id uint) error
|
Delete(id uint) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUserRolesService init UserRolesService
|
// NewUserRolesService init UserRolesService
|
||||||
func NewUserRolesService(repo repository.UserRolesRepository, log zerolog.Logger) UserRolesService {
|
func NewUserRolesService(repo repository.UserRolesRepository, usersRepo usersRepository.UsersRepository, log zerolog.Logger) UserRolesService {
|
||||||
|
|
||||||
return &userRolesService{
|
return &userRolesService{
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
|
UsersRepo: usersRepo,
|
||||||
Log: log,
|
Log: log,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -57,12 +61,12 @@ func (_i *userRolesService) Show(id uint) (userRoles *response.UserRolesResponse
|
||||||
return mapper.UserRolesResponseMapper(result), nil
|
return mapper.UserRolesResponseMapper(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *userRolesService) Save(req request.UserRolesCreateRequest) (err error) {
|
func (_i *userRolesService) Save(req request.UserRolesCreateRequest, header string) (err error) {
|
||||||
_i.Log.Info().Interface("data", req).Msg("")
|
_i.Log.Info().Interface("data", req).Msg("")
|
||||||
newReq := req.ToEntity()
|
newReq := req.ToEntity()
|
||||||
|
|
||||||
statusId := 1
|
createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, header)
|
||||||
newReq.StatusId = &statusId
|
newReq.CreatedById = &createdBy.ID
|
||||||
|
|
||||||
return _i.Repo.Create(newReq)
|
return _i.Repo.Create(newReq)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ func NewUsersController(usersService service.UsersService) UsersController {
|
||||||
// @Tags Users
|
// @Tags Users
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param req query request.UsersQueryRequest false "query parameters"
|
// @Param req query request.UsersQueryRequest false "query parameters"
|
||||||
|
// @Param req query paginator.Pagination false "pagination parameters"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 400 {object} response.BadRequestError
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 401 {object} response.UnauthorizedError
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"go-humas-be/app/database"
|
"go-humas-be/app/database"
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity"
|
||||||
|
|
@ -18,6 +19,7 @@ type usersRepository struct {
|
||||||
type UsersRepository interface {
|
type UsersRepository interface {
|
||||||
GetAll(req request.UsersQueryRequest) (userss []*entity.Users, paging paginator.Pagination, err error)
|
GetAll(req request.UsersQueryRequest) (userss []*entity.Users, paging paginator.Pagination, err error)
|
||||||
FindOne(id uint) (users *entity.Users, err error)
|
FindOne(id uint) (users *entity.Users, err error)
|
||||||
|
FindByKeycloakId(keycloakId string) (users *entity.Users, err error)
|
||||||
Create(users *entity.Users) (err error)
|
Create(users *entity.Users) (err error)
|
||||||
Update(id uint, users *entity.Users) (err error)
|
Update(id uint, users *entity.Users) (err error)
|
||||||
Delete(id uint) (err error)
|
Delete(id uint) (err error)
|
||||||
|
|
@ -62,6 +64,14 @@ func (_i *usersRepository) GetAll(req request.UsersQueryRequest) (userss []*enti
|
||||||
}
|
}
|
||||||
query.Count(&count)
|
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.Count = count
|
||||||
req.Pagination = paginator.Paging(req.Pagination)
|
req.Pagination = paginator.Paging(req.Pagination)
|
||||||
|
|
||||||
|
|
@ -83,6 +93,14 @@ func (_i *usersRepository) FindOne(id uint) (users *entity.Users, err error) {
|
||||||
return users, nil
|
return users, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (_i *usersRepository) FindByKeycloakId(keycloakId string) (users *entity.Users, err error) {
|
||||||
|
if err := _i.DB.DB.Where("keycloak_id = ?", keycloakId).First(&users).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return users, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (_i *usersRepository) Create(users *entity.Users) (err error) {
|
func (_i *usersRepository) Create(users *entity.Users) (err error) {
|
||||||
return _i.DB.DB.Create(users).Error
|
return _i.DB.DB.Create(users).Error
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1153
docs/swagger/docs.go
1153
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
1
go.mod
1
go.mod
|
|
@ -9,6 +9,7 @@ require (
|
||||||
github.com/go-playground/universal-translator v0.18.1
|
github.com/go-playground/universal-translator v0.18.1
|
||||||
github.com/go-playground/validator/v10 v10.17.0
|
github.com/go-playground/validator/v10 v10.17.0
|
||||||
github.com/gofiber/fiber/v2 v2.52.4
|
github.com/gofiber/fiber/v2 v2.52.4
|
||||||
|
github.com/golang-jwt/jwt/v5 v5.2.1
|
||||||
github.com/minio/minio-go/v7 v7.0.68
|
github.com/minio/minio-go/v7 v7.0.68
|
||||||
github.com/pelletier/go-toml/v2 v2.1.1
|
github.com/pelletier/go-toml/v2 v2.1.1
|
||||||
github.com/rs/zerolog v1.31.0
|
github.com/rs/zerolog v1.31.0
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -50,6 +50,8 @@ github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x
|
||||||
github.com/gofiber/fiber/v2 v2.31.0/go.mod h1:1Ega6O199a3Y7yDGuM9FyXDPYQfv+7/y48wl6WCwUF4=
|
github.com/gofiber/fiber/v2 v2.31.0/go.mod h1:1Ega6O199a3Y7yDGuM9FyXDPYQfv+7/y48wl6WCwUF4=
|
||||||
github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM=
|
github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM=
|
||||||
github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
|
github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
|
||||||
|
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
|
||||||
|
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultLimit = 10
|
defaultLimit = 10
|
||||||
|
defaultSort = "desc"
|
||||||
|
defaultSortBy = "id"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Pagination struct {
|
type Pagination struct {
|
||||||
|
|
@ -19,6 +21,8 @@ type Pagination struct {
|
||||||
PreviousPage int `json:"previousPage,omitempty"`
|
PreviousPage int `json:"previousPage,omitempty"`
|
||||||
Count int64 `json:"count,omitempty"`
|
Count int64 `json:"count,omitempty"`
|
||||||
TotalPage int `json:"totalPage,omitempty"`
|
TotalPage int `json:"totalPage,omitempty"`
|
||||||
|
Sort string `json:"sort,omitempty"`
|
||||||
|
SortBy string `json:"sortBy,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Paging(p *Pagination) *Pagination {
|
func Paging(p *Pagination) *Pagination {
|
||||||
|
|
@ -45,9 +49,19 @@ func Paginate(c *fiber.Ctx) (*Pagination, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
page = 1
|
page = 1
|
||||||
}
|
}
|
||||||
|
sort := c.Query("sort")
|
||||||
|
if sort == "" {
|
||||||
|
sort = defaultSort
|
||||||
|
}
|
||||||
|
sortBy := c.Query("sortBy")
|
||||||
|
if sortBy == "" {
|
||||||
|
sortBy = defaultSortBy
|
||||||
|
}
|
||||||
p := &Pagination{
|
p := &Pagination{
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
Page: page,
|
Page: page,
|
||||||
|
Sort: sort,
|
||||||
|
SortBy: sortBy,
|
||||||
}
|
}
|
||||||
if p.Page == 0 {
|
if p.Page == 0 {
|
||||||
p.Page = 1
|
p.Page = 1
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/golang-jwt/jwt/v5"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
"go-humas-be/app/database/entity"
|
||||||
|
"go-humas-be/app/module/users/repository"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetUserInfo(log zerolog.Logger, repo repository.UsersRepository, bearerToken string) *entity.Users {
|
||||||
|
tokenString := strings.TrimPrefix(bearerToken, "Bearer ")
|
||||||
|
token, _, err := new(jwt.Parser).ParseUnverified(tokenString, jwt.MapClaims{})
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
claims := token.Claims.(jwt.MapClaims)
|
||||||
|
sub := claims["sub"].(string)
|
||||||
|
|
||||||
|
user, err := repo.FindByKeycloakId(sub)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info().Str("timestamp", time.Now().
|
||||||
|
Format(time.RFC3339)).Str("Service:GetUserInfo", "UserInfo:GetUserInfo").
|
||||||
|
Interface("payload", user).Msg("")
|
||||||
|
|
||||||
|
return user
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue