feat: update ppidDataCategories for Thumbnail
This commit is contained in:
parent
c4cffd4308
commit
66e51218d9
|
|
@ -3,11 +3,12 @@ package entity
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type PpidDataCategories struct {
|
type PpidDataCategories struct {
|
||||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||||
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;default:true"`
|
ThumbnailPath *string `json:"thumbnail_path" gorm:"type:varchar"`
|
||||||
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
IsActive *bool `json:"is_active" gorm:"type:bool;default:true"`
|
||||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,10 @@ type PpidDataCategoriesController interface {
|
||||||
All(c *fiber.Ctx) error
|
All(c *fiber.Ctx) error
|
||||||
Show(c *fiber.Ctx) error
|
Show(c *fiber.Ctx) error
|
||||||
Save(c *fiber.Ctx) error
|
Save(c *fiber.Ctx) error
|
||||||
|
SaveThumbnail(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 NewPpidDataCategoriesController(ppidDataCategoriesService service.PpidDataCategoriesService) PpidDataCategoriesController {
|
func NewPpidDataCategoriesController(ppidDataCategoriesService service.PpidDataCategoriesService) PpidDataCategoriesController {
|
||||||
|
|
@ -124,6 +126,31 @@ func (_i *ppidDataCategoriesController) Save(c *fiber.Ctx) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SaveThumbnail PpidDataFiles
|
||||||
|
// @Summary Upload PpidDataCategories Thumbnail
|
||||||
|
// @Description API for Upload PpidDataCategories Thumbnail
|
||||||
|
// @Tags PPID Categories
|
||||||
|
// @Security Bearer
|
||||||
|
// @Produce json
|
||||||
|
// @Param files formData file true "Upload thumbnail"
|
||||||
|
// @Param id path int true "Ppid Data Category ID"
|
||||||
|
// @Success 200 {object} response.Response
|
||||||
|
// @Failure 400 {object} response.BadRequestError
|
||||||
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
|
// @Failure 500 {object} response.InternalServerError
|
||||||
|
// @Router /ppid-data-categories/thumbnail/{id} [post]
|
||||||
|
func (_i *ppidDataCategoriesController) SaveThumbnail(c *fiber.Ctx) error {
|
||||||
|
err := _i.ppidDataCategoriesService.SaveThumbnail(c)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return utilRes.Resp(c, utilRes.Response{
|
||||||
|
Success: true,
|
||||||
|
Messages: utilRes.Messages{"PpidDataFiles successfully created"},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Update PpidDataCategories
|
// Update PpidDataCategories
|
||||||
// @Summary update PpidDataCategories
|
// @Summary update PpidDataCategories
|
||||||
// @Description API for update PpidDataCategories
|
// @Description API for update PpidDataCategories
|
||||||
|
|
@ -159,7 +186,7 @@ func (_i *ppidDataCategoriesController) Update(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete PpidDataCategories
|
// Delete PpidDataCategories
|
||||||
// @Summary delete PpidDataCategories
|
// @Summary Delete PpidDataCategories
|
||||||
// @Description API for delete PpidDataCategories
|
// @Description API for delete PpidDataCategories
|
||||||
// @Tags PPID Categories
|
// @Tags PPID Categories
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
|
|
@ -185,3 +212,18 @@ func (_i *ppidDataCategoriesController) Delete(c *fiber.Ctx) error {
|
||||||
Messages: utilRes.Messages{"PpidDataCategories successfully deleted"},
|
Messages: utilRes.Messages{"PpidDataCategories successfully deleted"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Viewer PpidDataCategories
|
||||||
|
// @Summary Viewer PpidDataCategories
|
||||||
|
// @Description API for View Thumbnail of PpidDataCategories
|
||||||
|
// @Tags PPID Categories
|
||||||
|
// @Security Bearer
|
||||||
|
// @Param id path string true "PPID Categories ID"
|
||||||
|
// @Success 200 {object} response.Response
|
||||||
|
// @Failure 400 {object} response.BadRequestError
|
||||||
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
|
// @Failure 500 {object} response.InternalServerError
|
||||||
|
// @Router /ppid-data-categories/viewer/{id} [get]
|
||||||
|
func (_i *ppidDataCategoriesController) Viewer(c *fiber.Ctx) error {
|
||||||
|
return _i.ppidDataCategoriesService.Viewer(c)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,21 @@ package mapper
|
||||||
import (
|
import (
|
||||||
"go-humas-be/app/database/entity"
|
"go-humas-be/app/database/entity"
|
||||||
res "go-humas-be/app/module/ppid_data_categories/response"
|
res "go-humas-be/app/module/ppid_data_categories/response"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PpidDataCategoriesResponseMapper(ppidDataCategoriesReq *entity.PpidDataCategories) (ppidDataCategoriesRes *res.PpidDataCategoriesResponse) {
|
func PpidDataCategoriesResponseMapper(ppidDataCategoriesReq *entity.PpidDataCategories) (ppidDataCategoriesRes *res.PpidDataCategoriesResponse) {
|
||||||
if ppidDataCategoriesReq != nil {
|
if ppidDataCategoriesReq != nil {
|
||||||
ppidDataCategoriesRes = &res.PpidDataCategoriesResponse{
|
ppidDataCategoriesRes = &res.PpidDataCategoriesResponse{
|
||||||
ID: ppidDataCategoriesReq.ID,
|
ID: ppidDataCategoriesReq.ID,
|
||||||
Title: ppidDataCategoriesReq.Title,
|
Title: ppidDataCategoriesReq.Title,
|
||||||
Description: ppidDataCategoriesReq.Description,
|
Description: ppidDataCategoriesReq.Description,
|
||||||
Slug: ppidDataCategoriesReq.Slug,
|
Slug: ppidDataCategoriesReq.Slug,
|
||||||
IsActive: ppidDataCategoriesReq.IsActive,
|
ThumbnailUrl: "/ppid-data-categories/viewer/" + strconv.Itoa(int(ppidDataCategoriesReq.ID)),
|
||||||
|
IsActive: ppidDataCategoriesReq.IsActive,
|
||||||
CreatedAt: ppidDataCategoriesReq.CreatedAt,
|
CreatedAt: ppidDataCategoriesReq.CreatedAt,
|
||||||
UpdatedAt: ppidDataCategoriesReq.UpdatedAt,
|
UpdatedAt: ppidDataCategoriesReq.UpdatedAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ppidDataCategoriesRes
|
return ppidDataCategoriesRes
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,8 @@ func (_i *PpidDataCategoriesRouter) RegisterPpidDataCategoriesRoutes() {
|
||||||
router.Get("/", ppidDataCategoriesController.All)
|
router.Get("/", ppidDataCategoriesController.All)
|
||||||
router.Get("/:id", ppidDataCategoriesController.Show)
|
router.Get("/:id", ppidDataCategoriesController.Show)
|
||||||
router.Post("/", ppidDataCategoriesController.Save)
|
router.Post("/", ppidDataCategoriesController.Save)
|
||||||
|
router.Get("/viewer/:id", ppidDataCategoriesController.Viewer)
|
||||||
|
router.Post("/thumbnail/:id", ppidDataCategoriesController.SaveThumbnail)
|
||||||
router.Put("/:id", ppidDataCategoriesController.Update)
|
router.Put("/:id", ppidDataCategoriesController.Update)
|
||||||
router.Delete("/:id", ppidDataCategoriesController.Delete)
|
router.Delete("/:id", ppidDataCategoriesController.Delete)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -17,33 +17,37 @@ type PpidDataCategoriesQueryRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PpidDataCategoriesCreateRequest struct {
|
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"`
|
||||||
|
ThumbnailPath *string `json:"thumbnailPath"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (req PpidDataCategoriesCreateRequest) ToEntity() *entity.PpidDataCategories {
|
func (req PpidDataCategoriesCreateRequest) ToEntity() *entity.PpidDataCategories {
|
||||||
return &entity.PpidDataCategories{
|
return &entity.PpidDataCategories{
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Slug: req.Slug,
|
Slug: req.Slug,
|
||||||
|
ThumbnailPath: req.ThumbnailPath,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PpidDataCategoriesUpdateRequest struct {
|
type PpidDataCategoriesUpdateRequest 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"`
|
||||||
Description string `json:"description" validate:"required"`
|
Description string `json:"description" validate:"required"`
|
||||||
Slug string `json:"slug" validate:"required"`
|
Slug string `json:"slug" validate:"required"`
|
||||||
|
ThumbnailPath *string `json:"thumbnailPath"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (req PpidDataCategoriesUpdateRequest) ToEntity() *entity.PpidDataCategories {
|
func (req PpidDataCategoriesUpdateRequest) ToEntity() *entity.PpidDataCategories {
|
||||||
return &entity.PpidDataCategories{
|
return &entity.PpidDataCategories{
|
||||||
ID: req.ID,
|
ID: req.ID,
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Slug: req.Slug,
|
Slug: req.Slug,
|
||||||
UpdatedAt: time.Now(),
|
ThumbnailPath: req.ThumbnailPath,
|
||||||
|
UpdatedAt: time.Now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,12 @@ package response
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type PpidDataCategoriesResponse struct {
|
type PpidDataCategoriesResponse struct {
|
||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
IsActive *bool `json:"is_active"`
|
ThumbnailUrl string `json:"thumbnailUrl"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
IsActive *bool `json:"isActive"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,31 @@
|
||||||
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_categories/mapper"
|
"go-humas-be/app/module/ppid_data_categories/mapper"
|
||||||
"go-humas-be/app/module/ppid_data_categories/repository"
|
"go-humas-be/app/module/ppid_data_categories/repository"
|
||||||
"go-humas-be/app/module/ppid_data_categories/request"
|
"go-humas-be/app/module/ppid_data_categories/request"
|
||||||
"go-humas-be/app/module/ppid_data_categories/response"
|
"go-humas-be/app/module/ppid_data_categories/response"
|
||||||
|
minioStorage "go-humas-be/config/config"
|
||||||
"go-humas-be/utils/paginator"
|
"go-humas-be/utils/paginator"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"math/rand"
|
||||||
|
"mime"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PpidDataCategoriesService
|
// PpidDataCategoriesService
|
||||||
type ppidDataCategoriesService struct {
|
type ppidDataCategoriesService struct {
|
||||||
Repo repository.PpidDataCategoriesRepository
|
Repo repository.PpidDataCategoriesRepository
|
||||||
Log zerolog.Logger
|
Log zerolog.Logger
|
||||||
|
MinioStorage *minioStorage.MinioStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
// PpidDataCategoriesService define interface of IPpidDataCategoriesService
|
// PpidDataCategoriesService define interface of IPpidDataCategoriesService
|
||||||
|
|
@ -20,16 +33,19 @@ type PpidDataCategoriesService interface {
|
||||||
All(req request.PpidDataCategoriesQueryRequest) (ppidDataCategories []*response.PpidDataCategoriesResponse, paging paginator.Pagination, err error)
|
All(req request.PpidDataCategoriesQueryRequest) (ppidDataCategories []*response.PpidDataCategoriesResponse, paging paginator.Pagination, err error)
|
||||||
Show(id uint) (ppidDataCategories *response.PpidDataCategoriesResponse, err error)
|
Show(id uint) (ppidDataCategories *response.PpidDataCategoriesResponse, err error)
|
||||||
Save(req request.PpidDataCategoriesCreateRequest) (err error)
|
Save(req request.PpidDataCategoriesCreateRequest) (err error)
|
||||||
|
SaveThumbnail(c *fiber.Ctx) (err error)
|
||||||
Update(id uint, req request.PpidDataCategoriesUpdateRequest) (err error)
|
Update(id uint, req request.PpidDataCategoriesUpdateRequest) (err error)
|
||||||
Delete(id uint) error
|
Delete(id uint) error
|
||||||
|
Viewer(c *fiber.Ctx) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPpidDataCategoriesService init PpidDataCategoriesService
|
// NewPpidDataCategoriesService init PpidDataCategoriesService
|
||||||
func NewPpidDataCategoriesService(repo repository.PpidDataCategoriesRepository, log zerolog.Logger) PpidDataCategoriesService {
|
func NewPpidDataCategoriesService(repo repository.PpidDataCategoriesRepository, log zerolog.Logger, minioStorage *minioStorage.MinioStorage) PpidDataCategoriesService {
|
||||||
|
|
||||||
return &ppidDataCategoriesService{
|
return &ppidDataCategoriesService{
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
Log: log,
|
Log: log,
|
||||||
|
MinioStorage: minioStorage,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,6 +78,80 @@ func (_i *ppidDataCategoriesService) Save(req request.PpidDataCategoriesCreateRe
|
||||||
return _i.Repo.Create(req.ToEntity())
|
return _i.Repo.Create(req.ToEntity())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (_i *ppidDataCategoriesService) SaveThumbnail(c *fiber.Ctx) (err error) {
|
||||||
|
|
||||||
|
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_i.Log.Info().Str("timestamp", time.Now().
|
||||||
|
Format(time.RFC3339)).Str("Service:SaveThumbnail", "Categories:SaveThumbnail").
|
||||||
|
Interface("id", id).Msg("")
|
||||||
|
|
||||||
|
bucketName := _i.MinioStorage.Cfg.ObjectStorage.MinioStorage.BucketName
|
||||||
|
|
||||||
|
form, err := c.MultipartForm()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
files := form.File["files"]
|
||||||
|
|
||||||
|
// Create minio connection.
|
||||||
|
minioClient, err := _i.MinioStorage.ConnectMinio()
|
||||||
|
if err != nil {
|
||||||
|
// Return status 500 and minio connection error.
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"error": true,
|
||||||
|
"msg": err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterasi semua file yang diunggah
|
||||||
|
for _, file := range files {
|
||||||
|
|
||||||
|
_i.Log.Info().Str("timestamp", time.Now().
|
||||||
|
Format(time.RFC3339)).Str("Service:Resource", "Uploader:: loop1").
|
||||||
|
Interface("data", file).Msg("")
|
||||||
|
|
||||||
|
src, err := file.Open()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer src.Close()
|
||||||
|
|
||||||
|
filename := filepath.Base(file.Filename)
|
||||||
|
filenameWithoutExt := filepath.Clean(filename[:len(filename)-len(filepath.Ext(filename))])
|
||||||
|
extension := filepath.Ext(file.Filename)[1:]
|
||||||
|
|
||||||
|
rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
|
randUniqueId := rand.Intn(1000000)
|
||||||
|
|
||||||
|
newFilenameWithoutExt := filenameWithoutExt + "_" + strconv.Itoa(randUniqueId)
|
||||||
|
newFilename := newFilenameWithoutExt + "." + extension
|
||||||
|
objectName := "ppid/category/thumbnail/" + newFilename
|
||||||
|
|
||||||
|
findCategory, err := _i.Repo.FindOne(uint(id))
|
||||||
|
findCategory.ThumbnailPath = &objectName
|
||||||
|
err = _i.Repo.Update(uint(id), findCategory)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upload file ke MinIO
|
||||||
|
_, err = minioClient.PutObject(context.Background(), bucketName, objectName, src, file.Size, minio.PutObjectOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_i.Log.Info().Str("timestamp", time.Now().
|
||||||
|
Format(time.RFC3339)).Str("Service:Resource", "User:All").
|
||||||
|
Interface("data", "Successfully uploaded").Msg("")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (_i *ppidDataCategoriesService) Update(id uint, req request.PpidDataCategoriesUpdateRequest) (err error) {
|
func (_i *ppidDataCategoriesService) Update(id uint, req request.PpidDataCategoriesUpdateRequest) (err error) {
|
||||||
_i.Log.Info().Interface("data", req).Msg("")
|
_i.Log.Info().Interface("data", req).Msg("")
|
||||||
return _i.Repo.Update(id, req.ToEntity())
|
return _i.Repo.Update(id, req.ToEntity())
|
||||||
|
|
@ -77,3 +167,65 @@ func (_i *ppidDataCategoriesService) Delete(id uint) error {
|
||||||
result.IsActive = &isActive
|
result.IsActive = &isActive
|
||||||
return _i.Repo.Update(id, result)
|
return _i.Repo.Update(id, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (_i *ppidDataCategoriesService) Viewer(c *fiber.Ctx) (err error) {
|
||||||
|
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||||
|
result, err := _i.Repo.FindOne(uint(id))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.ThumbnailPath == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
bucketName := _i.MinioStorage.Cfg.ObjectStorage.MinioStorage.BucketName
|
||||||
|
objectName := result.ThumbnailPath
|
||||||
|
|
||||||
|
_i.Log.Info().Str("timestamp", time.Now().
|
||||||
|
Format(time.RFC3339)).Str("Service:Resource", "Article:Uploads").
|
||||||
|
Interface("data", objectName).Msg("")
|
||||||
|
|
||||||
|
// Create minio connection.
|
||||||
|
minioClient, err := _i.MinioStorage.ConnectMinio()
|
||||||
|
if err != nil {
|
||||||
|
// Return status 500 and minio connection error.
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"error": true,
|
||||||
|
"msg": err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fileContent, err := minioClient.GetObject(ctx, bucketName, *objectName, minio.GetObjectOptions{})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
defer fileContent.Close()
|
||||||
|
|
||||||
|
contentType := mime.TypeByExtension("." + getFileExtension(*objectName))
|
||||||
|
if contentType == "" {
|
||||||
|
contentType = "application/octet-stream"
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Set("Content-Type", contentType)
|
||||||
|
|
||||||
|
if _, err := io.Copy(c.Response().BodyWriter(), fileContent); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFileExtension(filename string) string {
|
||||||
|
// split file name
|
||||||
|
parts := strings.Split(filename, ".")
|
||||||
|
|
||||||
|
// jika tidak ada ekstensi, kembalikan string kosong
|
||||||
|
if len(parts) == 1 || (len(parts) == 2 && parts[0] == "") {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// ambil ekstensi terakhir
|
||||||
|
return parts[len(parts)-1]
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,10 @@ func (_i *ppidDataFilesService) Viewer(c *fiber.Ctx, filename string) (err error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if result.FilePath == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
bucketName := _i.MinioStorage.Cfg.ObjectStorage.MinioStorage.BucketName
|
bucketName := _i.MinioStorage.Cfg.ObjectStorage.MinioStorage.BucketName
|
||||||
objectName := result.FilePath
|
objectName := result.FilePath
|
||||||
|
|
|
||||||
|
|
@ -3289,6 +3289,114 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/ppid-data-categories/thumbnail/{id}": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "API for Upload PpidDataCategories Thumbnail",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"PPID Categories"
|
||||||
|
],
|
||||||
|
"summary": "Upload PpidDataCategories Thumbnail",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "file",
|
||||||
|
"description": "Upload thumbnail",
|
||||||
|
"name": "files",
|
||||||
|
"in": "formData",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Ppid Data Category ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.BadRequestError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.UnauthorizedError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.InternalServerError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/ppid-data-categories/viewer/{id}": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "API for View Thumbnail of PpidDataCategories",
|
||||||
|
"tags": [
|
||||||
|
"PPID Categories"
|
||||||
|
],
|
||||||
|
"summary": "Viewer PpidDataCategories",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "PPID Categories ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.BadRequestError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.UnauthorizedError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.InternalServerError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/ppid-data-categories/{id}": {
|
"/ppid-data-categories/{id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
|
|
@ -3403,7 +3511,7 @@ const docTemplate = `{
|
||||||
"tags": [
|
"tags": [
|
||||||
"PPID Categories"
|
"PPID Categories"
|
||||||
],
|
],
|
||||||
"summary": "delete PpidDataCategories",
|
"summary": "Delete PpidDataCategories",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
|
@ -5977,6 +6085,9 @@ const docTemplate = `{
|
||||||
"slug": {
|
"slug": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"thumbnailPath": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"title": {
|
"title": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
|
@ -6000,6 +6111,9 @@ const docTemplate = `{
|
||||||
"slug": {
|
"slug": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"thumbnailPath": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"title": {
|
"title": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3278,6 +3278,114 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/ppid-data-categories/thumbnail/{id}": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "API for Upload PpidDataCategories Thumbnail",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"PPID Categories"
|
||||||
|
],
|
||||||
|
"summary": "Upload PpidDataCategories Thumbnail",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "file",
|
||||||
|
"description": "Upload thumbnail",
|
||||||
|
"name": "files",
|
||||||
|
"in": "formData",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Ppid Data Category ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.BadRequestError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.UnauthorizedError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.InternalServerError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/ppid-data-categories/viewer/{id}": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "API for View Thumbnail of PpidDataCategories",
|
||||||
|
"tags": [
|
||||||
|
"PPID Categories"
|
||||||
|
],
|
||||||
|
"summary": "Viewer PpidDataCategories",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "PPID Categories ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.Response"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.BadRequestError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.UnauthorizedError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.InternalServerError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/ppid-data-categories/{id}": {
|
"/ppid-data-categories/{id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
|
|
@ -3392,7 +3500,7 @@
|
||||||
"tags": [
|
"tags": [
|
||||||
"PPID Categories"
|
"PPID Categories"
|
||||||
],
|
],
|
||||||
"summary": "delete PpidDataCategories",
|
"summary": "Delete PpidDataCategories",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
|
@ -5966,6 +6074,9 @@
|
||||||
"slug": {
|
"slug": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"thumbnailPath": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"title": {
|
"title": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
|
@ -5989,6 +6100,9 @@
|
||||||
"slug": {
|
"slug": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"thumbnailPath": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"title": {
|
"title": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -250,6 +250,8 @@ definitions:
|
||||||
type: string
|
type: string
|
||||||
slug:
|
slug:
|
||||||
type: string
|
type: string
|
||||||
|
thumbnailPath:
|
||||||
|
type: string
|
||||||
title:
|
title:
|
||||||
type: string
|
type: string
|
||||||
required:
|
required:
|
||||||
|
|
@ -265,6 +267,8 @@ definitions:
|
||||||
type: integer
|
type: integer
|
||||||
slug:
|
slug:
|
||||||
type: string
|
type: string
|
||||||
|
thumbnailPath:
|
||||||
|
type: string
|
||||||
title:
|
title:
|
||||||
type: string
|
type: string
|
||||||
required:
|
required:
|
||||||
|
|
@ -2696,7 +2700,7 @@ paths:
|
||||||
$ref: '#/definitions/response.InternalServerError'
|
$ref: '#/definitions/response.InternalServerError'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: delete PpidDataCategories
|
summary: Delete PpidDataCategories
|
||||||
tags:
|
tags:
|
||||||
- PPID Categories
|
- PPID Categories
|
||||||
get:
|
get:
|
||||||
|
|
@ -2765,6 +2769,75 @@ paths:
|
||||||
summary: update PpidDataCategories
|
summary: update PpidDataCategories
|
||||||
tags:
|
tags:
|
||||||
- PPID Categories
|
- PPID Categories
|
||||||
|
/ppid-data-categories/thumbnail/{id}:
|
||||||
|
post:
|
||||||
|
description: API for Upload PpidDataCategories Thumbnail
|
||||||
|
parameters:
|
||||||
|
- description: Upload thumbnail
|
||||||
|
in: formData
|
||||||
|
name: files
|
||||||
|
required: true
|
||||||
|
type: file
|
||||||
|
- description: Ppid Data Category ID
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.BadRequestError'
|
||||||
|
"401":
|
||||||
|
description: Unauthorized
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.UnauthorizedError'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.InternalServerError'
|
||||||
|
security:
|
||||||
|
- Bearer: []
|
||||||
|
summary: Upload PpidDataCategories Thumbnail
|
||||||
|
tags:
|
||||||
|
- PPID Categories
|
||||||
|
/ppid-data-categories/viewer/{id}:
|
||||||
|
get:
|
||||||
|
description: API for View Thumbnail of PpidDataCategories
|
||||||
|
parameters:
|
||||||
|
- description: PPID Categories ID
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.Response'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.BadRequestError'
|
||||||
|
"401":
|
||||||
|
description: Unauthorized
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.UnauthorizedError'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.InternalServerError'
|
||||||
|
security:
|
||||||
|
- Bearer: []
|
||||||
|
summary: Viewer PpidDataCategories
|
||||||
|
tags:
|
||||||
|
- PPID Categories
|
||||||
/ppid-data-files:
|
/ppid-data-files:
|
||||||
get:
|
get:
|
||||||
description: API for getting all PpidDataFiles
|
description: API for getting all PpidDataFiles
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue