feat: update for upload file in ppid data files and fixing response
This commit is contained in:
parent
20b914697d
commit
00e2938ae3
|
|
@ -10,6 +10,7 @@ type PpidDataCategories struct {
|
||||||
ParentId *uint `json:"parent_id" gorm:"type:int4"`
|
ParentId *uint `json:"parent_id" gorm:"type:int4"`
|
||||||
Position *int `json:"position" gorm:"type:int4"`
|
Position *int `json:"position" gorm:"type:int4"`
|
||||||
ThumbnailPath *string `json:"thumbnail_path" gorm:"type:varchar"`
|
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"`
|
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()"`
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ type PpidDataFiles struct {
|
||||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||||
PpidDataId int `json:"ppid_data_id" gorm:"type:int4"`
|
PpidDataId int `json:"ppid_data_id" gorm:"type:int4"`
|
||||||
Title *string `json:"title" gorm:"type:varchar"`
|
Title *string `json:"title" gorm:"type:varchar"`
|
||||||
|
Type *string `json:"type" gorm:"type:varchar"`
|
||||||
FileType *string `json:"file_type" gorm:"type:varchar"`
|
FileType *string `json:"file_type" gorm:"type:varchar"`
|
||||||
FileName *string `json:"file_name" gorm:"type:varchar"`
|
FileName *string `json:"file_name" gorm:"type:varchar"`
|
||||||
FilePath *string `json:"file_path" gorm:"type:varchar"`
|
FilePath *string `json:"file_path" gorm:"type:varchar"`
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"go-humas-be/app/module/ppid_datas/response"
|
"go-humas-be/app/module/ppid_datas/response"
|
||||||
usersRepository "go-humas-be/app/module/users/repository"
|
usersRepository "go-humas-be/app/module/users/repository"
|
||||||
"go-humas-be/utils/paginator"
|
"go-humas-be/utils/paginator"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func PpidDataCategoriesResponseMapper(ppidDataCategoriesReq *entity.PpidDataCategories, childPpidDataCategoriesReq []*entity.PpidDataCategories) (ppidDataCategoriesRes *res.PpidDataCategoriesResponse) {
|
func PpidDataCategoriesResponseMapper(ppidDataCategoriesReq *entity.PpidDataCategories, childPpidDataCategoriesReq []*entity.PpidDataCategories) (ppidDataCategoriesRes *res.PpidDataCategoriesResponse) {
|
||||||
|
|
@ -31,7 +30,7 @@ func PpidDataCategoriesResponseMapper(ppidDataCategoriesReq *entity.PpidDataCate
|
||||||
Slug: ppidDataCategoriesReq.Slug,
|
Slug: ppidDataCategoriesReq.Slug,
|
||||||
ParentId: ppidDataCategoriesReq.ParentId,
|
ParentId: ppidDataCategoriesReq.ParentId,
|
||||||
Position: ppidDataCategoriesReq.Position,
|
Position: ppidDataCategoriesReq.Position,
|
||||||
ThumbnailUrl: "/ppid-data-categories/thumbnail/viewer/" + strconv.Itoa(int(ppidDataCategoriesReq.ID)),
|
ThumbnailUrl: ppidDataCategoriesReq.ThumbnailUrl,
|
||||||
IsActive: ppidDataCategoriesReq.IsActive,
|
IsActive: ppidDataCategoriesReq.IsActive,
|
||||||
CreatedAt: ppidDataCategoriesReq.CreatedAt,
|
CreatedAt: ppidDataCategoriesReq.CreatedAt,
|
||||||
UpdatedAt: ppidDataCategoriesReq.UpdatedAt,
|
UpdatedAt: ppidDataCategoriesReq.UpdatedAt,
|
||||||
|
|
@ -76,7 +75,7 @@ func PpidDataCategoriesWithPpidDataResponseMapper(
|
||||||
Slug: ppidDataCategoriesReq.Slug,
|
Slug: ppidDataCategoriesReq.Slug,
|
||||||
ParentId: ppidDataCategoriesReq.ParentId,
|
ParentId: ppidDataCategoriesReq.ParentId,
|
||||||
Position: ppidDataCategoriesReq.Position,
|
Position: ppidDataCategoriesReq.Position,
|
||||||
ThumbnailUrl: "/ppid-data-categories/thumbnail/viewer/" + strconv.Itoa(int(ppidDataCategoriesReq.ID)),
|
ThumbnailUrl: ppidDataCategoriesReq.ThumbnailUrl,
|
||||||
IsActive: ppidDataCategoriesReq.IsActive,
|
IsActive: ppidDataCategoriesReq.IsActive,
|
||||||
CreatedAt: ppidDataCategoriesReq.CreatedAt,
|
CreatedAt: ppidDataCategoriesReq.CreatedAt,
|
||||||
UpdatedAt: ppidDataCategoriesReq.UpdatedAt,
|
UpdatedAt: ppidDataCategoriesReq.UpdatedAt,
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ type PpidDataCategoriesResponse struct {
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
ParentId *uint `json:"parentId"`
|
ParentId *uint `json:"parentId"`
|
||||||
Position *int `json:"position"`
|
Position *int `json:"position"`
|
||||||
ThumbnailUrl string `json:"thumbnailUrl"`
|
ThumbnailUrl *string `json:"thumbnailUrl"`
|
||||||
IsActive *bool `json:"isActive"`
|
IsActive *bool `json:"isActive"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
|
@ -27,7 +27,7 @@ type PpidDataCategoriesWithPpidDataResponse struct {
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
ParentId *uint `json:"parentId"`
|
ParentId *uint `json:"parentId"`
|
||||||
Position *int `json:"position"`
|
Position *int `json:"position"`
|
||||||
ThumbnailUrl string `json:"thumbnailUrl"`
|
ThumbnailUrl *string `json:"thumbnailUrl"`
|
||||||
IsActive *bool `json:"isActive"`
|
IsActive *bool `json:"isActive"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import (
|
||||||
ppidDataFilesRepository "go-humas-be/app/module/ppid_data_files/repository"
|
ppidDataFilesRepository "go-humas-be/app/module/ppid_data_files/repository"
|
||||||
ppidDatasRepository "go-humas-be/app/module/ppid_datas/repository"
|
ppidDatasRepository "go-humas-be/app/module/ppid_datas/repository"
|
||||||
usersRepository "go-humas-be/app/module/users/repository"
|
usersRepository "go-humas-be/app/module/users/repository"
|
||||||
minioStorage "go-humas-be/config/config"
|
config "go-humas-be/config/config"
|
||||||
"go-humas-be/utils/paginator"
|
"go-humas-be/utils/paginator"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
|
@ -31,8 +31,9 @@ type ppidDataCategoriesService struct {
|
||||||
PpidDatasRepo ppidDatasRepository.PpidDatasRepository
|
PpidDatasRepo ppidDatasRepository.PpidDatasRepository
|
||||||
PpidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository
|
PpidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository
|
||||||
UsersRepo usersRepository.UsersRepository
|
UsersRepo usersRepository.UsersRepository
|
||||||
MinioStorage *minioStorage.MinioStorage
|
MinioStorage *config.MinioStorage
|
||||||
Log zerolog.Logger
|
Log zerolog.Logger
|
||||||
|
Cfg *config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// PpidDataCategoriesService define interface of IPpidDataCategoriesService
|
// PpidDataCategoriesService define interface of IPpidDataCategoriesService
|
||||||
|
|
@ -55,8 +56,9 @@ func NewPpidDataCategoriesService(
|
||||||
ppidDatasRepo ppidDatasRepository.PpidDatasRepository,
|
ppidDatasRepo ppidDatasRepository.PpidDatasRepository,
|
||||||
ppidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository,
|
ppidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository,
|
||||||
usersRepo usersRepository.UsersRepository,
|
usersRepo usersRepository.UsersRepository,
|
||||||
minioStorage *minioStorage.MinioStorage,
|
minioStorage *config.MinioStorage,
|
||||||
log zerolog.Logger,
|
log zerolog.Logger,
|
||||||
|
cfg *config.Config,
|
||||||
) PpidDataCategoriesService {
|
) PpidDataCategoriesService {
|
||||||
|
|
||||||
return &ppidDataCategoriesService{
|
return &ppidDataCategoriesService{
|
||||||
|
|
@ -66,6 +68,7 @@ func NewPpidDataCategoriesService(
|
||||||
UsersRepo: usersRepo,
|
UsersRepo: usersRepo,
|
||||||
MinioStorage: minioStorage,
|
MinioStorage: minioStorage,
|
||||||
Log: log,
|
Log: log,
|
||||||
|
Cfg: cfg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,6 +162,9 @@ func (_i *ppidDataCategoriesService) SaveThumbnail(c *fiber.Ctx) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
host := _i.Cfg.App.Host
|
||||||
|
port := _i.Cfg.App.ExternalPort
|
||||||
|
|
||||||
_i.Log.Info().Str("timestamp", time.Now().
|
_i.Log.Info().Str("timestamp", time.Now().
|
||||||
Format(time.RFC3339)).Str("Service:SaveThumbnail", "Categories:SaveThumbnail").
|
Format(time.RFC3339)).Str("Service:SaveThumbnail", "Categories:SaveThumbnail").
|
||||||
Interface("id", id).Msg("")
|
Interface("id", id).Msg("")
|
||||||
|
|
@ -207,7 +213,12 @@ func (_i *ppidDataCategoriesService) SaveThumbnail(c *fiber.Ctx) (err error) {
|
||||||
objectName := "ppid/category/thumbnail/" + newFilename
|
objectName := "ppid/category/thumbnail/" + newFilename
|
||||||
|
|
||||||
findCategory, err := _i.Repo.FindOne(uint(id))
|
findCategory, err := _i.Repo.FindOne(uint(id))
|
||||||
|
|
||||||
|
thumbnailUrl := host + port + "/ppid-data-categories/thumbnail/viewer/" + strconv.Itoa(int(id))
|
||||||
|
|
||||||
findCategory.ThumbnailPath = &objectName
|
findCategory.ThumbnailPath = &objectName
|
||||||
|
findCategory.ThumbnailUrl = &thumbnailUrl
|
||||||
|
|
||||||
err = _i.Repo.Update(uint(id), findCategory)
|
err = _i.Repo.Update(uint(id), findCategory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,10 @@ func (_i *ppidDataFilesController) Show(c *fiber.Ctx) error {
|
||||||
// @Tags PPID Files
|
// @Tags PPID Files
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param files formData file true "Upload file"
|
// @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"
|
// @Param ppidDataId path int true "Ppid Data ID"
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 400 {object} response.BadRequestError
|
// @Failure 400 {object} response.BadRequestError
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func PpidDataFilesResponseMapper(ppidDataFilesReq *entity.PpidDataFiles) (ppidDataFilesRes *res.PpidDataFilesResponse) {
|
func PpidDataFilesResponseMapper(ppidDataFilesReq *entity.PpidDataFiles) (ppidDataFilesRes *res.PpidDataFilesResponse) {
|
||||||
fileUrl := "/ppid-data-files/viewer/"
|
|
||||||
if ppidDataFilesReq.FileName != nil {
|
|
||||||
fileUrl += *ppidDataFilesReq.FileName
|
|
||||||
}
|
|
||||||
if ppidDataFilesReq != nil {
|
if ppidDataFilesReq != nil {
|
||||||
ppidDataFilesRes = &res.PpidDataFilesResponse{
|
ppidDataFilesRes = &res.PpidDataFilesResponse{
|
||||||
ID: ppidDataFilesReq.ID,
|
ID: ppidDataFilesReq.ID,
|
||||||
Title: ppidDataFilesReq.Title,
|
Title: ppidDataFilesReq.Title,
|
||||||
|
Type: ppidDataFilesReq.Type,
|
||||||
PpidDataId: ppidDataFilesReq.PpidDataId,
|
PpidDataId: ppidDataFilesReq.PpidDataId,
|
||||||
FileUrl: fileUrl,
|
FileName: ppidDataFilesReq.FileName,
|
||||||
|
FileUrl: ppidDataFilesReq.FileUrl,
|
||||||
FileType: ppidDataFilesReq.FileType,
|
FileType: ppidDataFilesReq.FileType,
|
||||||
DownloadCount: ppidDataFilesReq.DownloadCount,
|
DownloadCount: ppidDataFilesReq.DownloadCount,
|
||||||
Position: ppidDataFilesReq.Position,
|
Position: ppidDataFilesReq.Position,
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,13 @@ type PpidDataFilesQueryRequest struct {
|
||||||
|
|
||||||
type PpidDataFilesCreateRequest struct {
|
type PpidDataFilesCreateRequest struct {
|
||||||
PpidDataId int `json:"ppidDataId" validate:"required"`
|
PpidDataId int `json:"ppidDataId" validate:"required"`
|
||||||
Title *string `json:"title" validate:"required"`
|
Title *string `json:"title"`
|
||||||
|
Type *string `json:"type"`
|
||||||
|
Position *int `json:"position"`
|
||||||
FileType *string `json:"fileType"`
|
FileType *string `json:"fileType"`
|
||||||
FileName *string `json:"fileName"`
|
FileName *string `json:"fileName"`
|
||||||
FilePath *string `json:"filePath"`
|
FilePath *string `json:"filePath"`
|
||||||
|
FileUrl *string `json:"fileUrl"`
|
||||||
Size *string `json:"size"`
|
Size *string `json:"size"`
|
||||||
CreatedById *int `json:"createdById"`
|
CreatedById *int `json:"createdById"`
|
||||||
StatusId *int `json:"statusId"`
|
StatusId *int `json:"statusId"`
|
||||||
|
|
@ -36,10 +39,13 @@ type PpidDataFilesCreateRequest struct {
|
||||||
func (req PpidDataFilesCreateRequest) ToEntity() *entity.PpidDataFiles {
|
func (req PpidDataFilesCreateRequest) ToEntity() *entity.PpidDataFiles {
|
||||||
return &entity.PpidDataFiles{
|
return &entity.PpidDataFiles{
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
|
Type: req.Type,
|
||||||
|
Position: req.Position,
|
||||||
PpidDataId: req.PpidDataId,
|
PpidDataId: req.PpidDataId,
|
||||||
FileType: req.FileType,
|
FileType: req.FileType,
|
||||||
FileName: req.FileName,
|
FileName: req.FileName,
|
||||||
FilePath: req.FilePath,
|
FilePath: req.FilePath,
|
||||||
|
FileUrl: req.FileUrl,
|
||||||
Size: req.Size,
|
Size: req.Size,
|
||||||
CreatedById: req.CreatedById,
|
CreatedById: req.CreatedById,
|
||||||
StatusId: req.StatusId,
|
StatusId: req.StatusId,
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,11 @@ import "time"
|
||||||
type PpidDataFilesResponse struct {
|
type PpidDataFilesResponse struct {
|
||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
Title *string `json:"title"`
|
Title *string `json:"title"`
|
||||||
|
Type *string `json:"type"`
|
||||||
PpidDataId int `json:"ppidDataId"`
|
PpidDataId int `json:"ppidDataId"`
|
||||||
FileName uint `json:"fileName"`
|
FileName *string `json:"fileName"`
|
||||||
FileType *string `json:"fileType"`
|
FileType *string `json:"fileType"`
|
||||||
FileUrl string `json:"fileUrl"`
|
FileUrl *string `json:"fileUrl"`
|
||||||
DownloadCount *int `json:"downloadCount"`
|
DownloadCount *int `json:"downloadCount"`
|
||||||
CreatedById *int `json:"createdById"`
|
CreatedById *int `json:"createdById"`
|
||||||
Position *int `json:"position"`
|
Position *int `json:"position"`
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,13 @@ import (
|
||||||
"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"
|
config "go-humas-be/config/config"
|
||||||
"go-humas-be/utils/paginator"
|
"go-humas-be/utils/paginator"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"mime"
|
"mime"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -26,7 +27,8 @@ import (
|
||||||
type ppidDataFilesService struct {
|
type ppidDataFilesService struct {
|
||||||
Repo repository.PpidDataFilesRepository
|
Repo repository.PpidDataFilesRepository
|
||||||
Log zerolog.Logger
|
Log zerolog.Logger
|
||||||
MinioStorage *minioStorage.MinioStorage
|
MinioStorage *config.MinioStorage
|
||||||
|
Cfg *config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// PpidDataFilesService define interface of IPpidDataFilesService
|
// PpidDataFilesService define interface of IPpidDataFilesService
|
||||||
|
|
@ -41,12 +43,13 @@ type PpidDataFilesService interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPpidDataFilesService init PpidDataFilesService
|
// NewPpidDataFilesService init PpidDataFilesService
|
||||||
func NewPpidDataFilesService(repo repository.PpidDataFilesRepository, log zerolog.Logger, minioStorage *minioStorage.MinioStorage) PpidDataFilesService {
|
func NewPpidDataFilesService(repo repository.PpidDataFilesRepository, log zerolog.Logger, minioStorage *config.MinioStorage, cfg *config.Config) PpidDataFilesService {
|
||||||
|
|
||||||
return &ppidDataFilesService{
|
return &ppidDataFilesService{
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
Log: log,
|
Log: log,
|
||||||
MinioStorage: minioStorage,
|
MinioStorage: minioStorage,
|
||||||
|
Cfg: cfg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,13 +83,64 @@ func (_i *ppidDataFilesService) Save(c *fiber.Ctx) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
bucketName := _i.MinioStorage.Cfg.ObjectStorage.MinioStorage.BucketName
|
host := _i.Cfg.App.Host
|
||||||
|
port := _i.Cfg.App.ExternalPort
|
||||||
|
|
||||||
form, err := c.MultipartForm()
|
form, err := c.MultipartForm()
|
||||||
|
|
||||||
|
_i.Log.Info().Str("timestamp", time.Now().
|
||||||
|
Format(time.RFC3339)).Str("Service", "Save").
|
||||||
|
Interface("form", form).Msg("")
|
||||||
|
|
||||||
|
typesString := form.Value["types"]
|
||||||
|
types := strings.Split(typesString[0], ",")
|
||||||
|
positionsString := form.Value["positions"]
|
||||||
|
positions := strings.Split(positionsString[0], ",")
|
||||||
|
urlsString := form.Value["urls"]
|
||||||
|
urls := strings.Split(urlsString[0], ",")
|
||||||
|
files := form.File["files"]
|
||||||
|
|
||||||
|
fileCounter := 0
|
||||||
|
urlCounter := 0
|
||||||
|
|
||||||
|
_i.Log.Info().Str("timestamp", time.Now().
|
||||||
|
Format(time.RFC3339)).Str("Service", "Save").
|
||||||
|
Interface("form", types).Msg("")
|
||||||
|
|
||||||
|
for index, fileType := range types {
|
||||||
|
position := &positions[index]
|
||||||
|
positionInt64, err := strconv.ParseInt(*position, 10, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
files := form.File["files"]
|
positionInt := int(positionInt64)
|
||||||
|
statusId := 1
|
||||||
|
req := request.PpidDataFilesCreateRequest{
|
||||||
|
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 = &filename
|
||||||
|
req.FileUrl = &url
|
||||||
|
|
||||||
|
urlCounter += 1
|
||||||
|
} else {
|
||||||
|
bucketName := _i.MinioStorage.Cfg.ObjectStorage.MinioStorage.BucketName
|
||||||
|
|
||||||
// Create minio connection.
|
// Create minio connection.
|
||||||
minioClient, err := _i.MinioStorage.ConnectMinio()
|
minioClient, err := _i.MinioStorage.ConnectMinio()
|
||||||
|
|
@ -99,7 +153,7 @@ func (_i *ppidDataFilesService) Save(c *fiber.Ctx) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterasi semua file yang diunggah
|
// Iterasi semua file yang diunggah
|
||||||
for _, file := range files {
|
file := files[fileCounter]
|
||||||
|
|
||||||
_i.Log.Info().Str("timestamp", time.Now().
|
_i.Log.Info().Str("timestamp", time.Now().
|
||||||
Format(time.RFC3339)).Str("Service:Resource", "Uploader:: loop1").
|
Format(time.RFC3339)).Str("Service:Resource", "Uploader:: loop1").
|
||||||
|
|
@ -124,25 +178,26 @@ func (_i *ppidDataFilesService) Save(c *fiber.Ctx) (err error) {
|
||||||
objectName := "ppid/upload/" + newFilename
|
objectName := "ppid/upload/" + newFilename
|
||||||
|
|
||||||
size := strconv.FormatInt(file.Size, 10)
|
size := strconv.FormatInt(file.Size, 10)
|
||||||
statusId := 1
|
fileUrl := "/ppid-data-files/viewer/"
|
||||||
|
fileUrl += host + port + newFilename
|
||||||
|
|
||||||
req := request.PpidDataFilesCreateRequest{
|
req.Title = &newFilenameWithoutExt
|
||||||
PpidDataId: int(id),
|
req.FileType = &extension
|
||||||
Title: &newFilenameWithoutExt,
|
req.FileName = &newFilename
|
||||||
FileType: &extension,
|
req.FilePath = &objectName
|
||||||
FileName: &newFilename,
|
req.FileUrl = &fileUrl
|
||||||
FilePath: &objectName,
|
req.Size = &size
|
||||||
Size: &size,
|
|
||||||
StatusId: &statusId,
|
|
||||||
}
|
|
||||||
|
|
||||||
err = _i.Repo.Create(req.ToEntity())
|
// Upload file to MinIO
|
||||||
|
_, err = minioClient.PutObject(context.Background(), bucketName, objectName, src, file.Size, minio.PutObjectOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload file ke MinIO
|
fileCounter += 1
|
||||||
_, err = minioClient.PutObject(context.Background(), bucketName, objectName, src, file.Size, minio.PutObjectOptions{})
|
}
|
||||||
|
|
||||||
|
err = _i.Repo.Create(req.ToEntity())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ func (_i *ppidDatasController) Show(c *fiber.Ctx) error {
|
||||||
// @Description API for create PpidDatas
|
// @Description API for create PpidDatas
|
||||||
// @Tags PPID Data
|
// @Tags PPID Data
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
// @Param Authorization header string true "Insert your access token" default (Bearer <Add access token here>)
|
||||||
// @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
|
||||||
// @Failure 400 {object} response.BadRequestError
|
// @Failure 400 {object} response.BadRequestError
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,9 @@ import (
|
||||||
|
|
||||||
type app = struct {
|
type app = struct {
|
||||||
Name string `toml:"name"`
|
Name string `toml:"name"`
|
||||||
|
Host string `toml:"host"`
|
||||||
Port string `toml:"port"`
|
Port string `toml:"port"`
|
||||||
|
ExternalPort string `toml:"external-port"`
|
||||||
PrintRoutes bool `toml:"print-routes"`
|
PrintRoutes bool `toml:"print-routes"`
|
||||||
Prefork bool `toml:"prefork"`
|
Prefork bool `toml:"prefork"`
|
||||||
Production bool `toml:"production"`
|
Production bool `toml:"production"`
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
# Configuration vars for cmd/app
|
# Configuration vars for cmd/app
|
||||||
[app]
|
[app]
|
||||||
name = "Fiber starter"
|
name = "Fiber starter"
|
||||||
|
host = "http://103.82.242.92"
|
||||||
port = ":8800"
|
port = ":8800"
|
||||||
|
external-port = ":8888"
|
||||||
idle-timeout = 5 # As seconds
|
idle-timeout = 5 # As seconds
|
||||||
print-routes = false
|
print-routes = false
|
||||||
prefork = true
|
prefork = true
|
||||||
|
|
@ -10,7 +12,7 @@ body-limit = 104857600 # "100 * 1024 * 1024"
|
||||||
|
|
||||||
[db.postgres]
|
[db.postgres]
|
||||||
dsn = "postgresql://humas_polri:P@ssw0rd.1@103.82.242.92:5432/humas_polri" # <driver>://<username>:<password>@<host>:<port>/<database>
|
dsn = "postgresql://humas_polri:P@ssw0rd.1@103.82.242.92:5432/humas_polri" # <driver>://<username>:<password>@<host>:<port>/<database>
|
||||||
migrate = false
|
migrate = true
|
||||||
seed = false
|
seed = false
|
||||||
|
|
||||||
[logger]
|
[logger]
|
||||||
|
|
|
||||||
|
|
@ -4521,12 +4521,29 @@ const docTemplate = `{
|
||||||
],
|
],
|
||||||
"summary": "Create PpidDataFiles",
|
"summary": "Create PpidDataFiles",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Types",
|
||||||
|
"name": "types",
|
||||||
|
"in": "formData"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Positions",
|
||||||
|
"name": "positions",
|
||||||
|
"in": "formData"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Upload Url",
|
||||||
|
"name": "urls",
|
||||||
|
"in": "formData"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "file",
|
"type": "file",
|
||||||
"description": "Upload file",
|
"description": "Upload File",
|
||||||
"name": "files",
|
"name": "files",
|
||||||
"in": "formData",
|
"in": "formData"
|
||||||
"required": true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
|
@ -4717,7 +4734,6 @@ const docTemplate = `{
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "Bearer \u003cAdd access token here\u003e",
|
|
||||||
"description": "Insert your access token",
|
"description": "Insert your access token",
|
||||||
"name": "Authorization",
|
"name": "Authorization",
|
||||||
"in": "header",
|
"in": "header",
|
||||||
|
|
|
||||||
|
|
@ -4510,12 +4510,29 @@
|
||||||
],
|
],
|
||||||
"summary": "Create PpidDataFiles",
|
"summary": "Create PpidDataFiles",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Types",
|
||||||
|
"name": "types",
|
||||||
|
"in": "formData"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Positions",
|
||||||
|
"name": "positions",
|
||||||
|
"in": "formData"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Upload Url",
|
||||||
|
"name": "urls",
|
||||||
|
"in": "formData"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "file",
|
"type": "file",
|
||||||
"description": "Upload file",
|
"description": "Upload File",
|
||||||
"name": "files",
|
"name": "files",
|
||||||
"in": "formData",
|
"in": "formData"
|
||||||
"required": true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
|
@ -4706,7 +4723,6 @@
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "Bearer \u003cAdd access token here\u003e",
|
|
||||||
"description": "Insert your access token",
|
"description": "Insert your access token",
|
||||||
"name": "Authorization",
|
"name": "Authorization",
|
||||||
"in": "header",
|
"in": "header",
|
||||||
|
|
|
||||||
|
|
@ -3445,10 +3445,21 @@ paths:
|
||||||
post:
|
post:
|
||||||
description: API for create PpidDataFiles
|
description: API for create PpidDataFiles
|
||||||
parameters:
|
parameters:
|
||||||
- description: Upload file
|
- description: Types
|
||||||
|
in: formData
|
||||||
|
name: types
|
||||||
|
type: string
|
||||||
|
- description: Positions
|
||||||
|
in: formData
|
||||||
|
name: positions
|
||||||
|
type: string
|
||||||
|
- description: Upload Url
|
||||||
|
in: formData
|
||||||
|
name: urls
|
||||||
|
type: string
|
||||||
|
- description: Upload File
|
||||||
in: formData
|
in: formData
|
||||||
name: files
|
name: files
|
||||||
required: true
|
|
||||||
type: file
|
type: file
|
||||||
- description: Ppid Data ID
|
- description: Ppid Data ID
|
||||||
in: path
|
in: path
|
||||||
|
|
@ -3631,8 +3642,7 @@ paths:
|
||||||
post:
|
post:
|
||||||
description: API for create PpidDatas
|
description: API for create PpidDatas
|
||||||
parameters:
|
parameters:
|
||||||
- default: Bearer <Add access token here>
|
- description: Insert your access token
|
||||||
description: Insert your access token
|
|
||||||
in: header
|
in: header
|
||||||
name: Authorization
|
name: Authorization
|
||||||
required: true
|
required: true
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue