feat: update ppid data and ppid data files
This commit is contained in:
parent
9e9edcf68a
commit
e031997fcd
|
|
@ -4,15 +4,13 @@ import "time"
|
|||
|
||||
type PpidDataFiles struct {
|
||||
ID uint `json:"id" gorm:"primaryKey;type:int4;autoIncrement"`
|
||||
Title string `json:"title" gorm:"type:varchar"`
|
||||
PpidDataId int `json:"ppid_data_id" gorm:"type:int4"`
|
||||
Description string `json:"description" gorm:"type:varchar"`
|
||||
Unit string `json:"unit" gorm:"type:varchar"`
|
||||
FileType string `json:"file_type" gorm:"type:varchar"`
|
||||
Title *string `json:"title" gorm:"type:varchar"`
|
||||
FileType *string `json:"file_type" gorm:"type:varchar"`
|
||||
FileName *string `json:"file_name" gorm:"type:varchar"`
|
||||
FilePath *string `json:"file_path" gorm:"type:varchar"`
|
||||
Size *string `json:"size" gorm:"type:varchar"`
|
||||
DownloadCount *int `json:"download_count" gorm:"type:int4"`
|
||||
DownloadCount *int `json:"download_count" gorm:"type:int4;default:0"`
|
||||
CreatedById *int `json:"created_by_id" gorm:"type:int4"`
|
||||
StatusId *int `json:"status_id" gorm:"type:int4"`
|
||||
IsPublish *bool `json:"is_publish" gorm:"type:bool;default:false"`
|
||||
|
|
|
|||
|
|
@ -109,7 +109,6 @@ func (_i *ppidDataFilesController) Show(c *fiber.Ctx) error {
|
|||
// @Security Bearer
|
||||
// @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
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
|
|
@ -195,16 +194,13 @@ func (_i *ppidDataFilesController) Delete(c *fiber.Ctx) error {
|
|||
// @Description API for create PpidDataFiles
|
||||
// @Tags PPID Files
|
||||
// @Security Bearer
|
||||
// @Param id path string true "Ppid Data ID"
|
||||
// @Param filename path string true "Ppid Data Filename"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 400 {object} response.BadRequestError
|
||||
// @Failure 401 {object} response.UnauthorizedError
|
||||
// @Failure 500 {object} response.InternalServerError
|
||||
// @Router /ppid-data-files/viewer/{id} [get]
|
||||
// @Router /ppid-data-files/viewer/{filename} [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))
|
||||
filename := c.Params("filename")
|
||||
return _i.ppidDataFilesService.Viewer(c, filename)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,21 +8,20 @@ import (
|
|||
func PpidDataFilesResponseMapper(ppidDataFilesReq *entity.PpidDataFiles) (ppidDataFilesRes *res.PpidDataFilesResponse) {
|
||||
if ppidDataFilesReq != nil {
|
||||
ppidDataFilesRes = &res.PpidDataFilesResponse{
|
||||
ID: ppidDataFilesReq.ID,
|
||||
Title: ppidDataFilesReq.Title,
|
||||
ID: ppidDataFilesReq.ID,
|
||||
Title: ppidDataFilesReq.Title,
|
||||
PpidDataId: ppidDataFilesReq.PpidDataId,
|
||||
Description: ppidDataFilesReq.Description,
|
||||
Unit: ppidDataFilesReq.Unit,
|
||||
FileType: ppidDataFilesReq.FileType,
|
||||
DownloadCount: ppidDataFilesReq.DownloadCount,
|
||||
CreatedById: ppidDataFilesReq.CreatedById,
|
||||
StatusId: ppidDataFilesReq.StatusId,
|
||||
IsPublish: ppidDataFilesReq.IsPublish,
|
||||
PublishedAt: ppidDataFilesReq.PublishedAt,
|
||||
IsActive: ppidDataFilesReq.IsActive,
|
||||
CreatedAt: ppidDataFilesReq.CreatedAt,
|
||||
UpdatedAt: ppidDataFilesReq.UpdatedAt,
|
||||
FileUrl: "/ppid-data-files/viewer/" + *ppidDataFilesReq.FileName,
|
||||
FileType: ppidDataFilesReq.FileType,
|
||||
DownloadCount: ppidDataFilesReq.DownloadCount,
|
||||
CreatedById: ppidDataFilesReq.CreatedById,
|
||||
StatusId: ppidDataFilesReq.StatusId,
|
||||
IsPublish: ppidDataFilesReq.IsPublish,
|
||||
PublishedAt: ppidDataFilesReq.PublishedAt,
|
||||
IsActive: ppidDataFilesReq.IsActive,
|
||||
CreatedAt: ppidDataFilesReq.CreatedAt,
|
||||
UpdatedAt: ppidDataFilesReq.UpdatedAt,
|
||||
}
|
||||
}
|
||||
return ppidDataFilesRes
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ func (_i *PpidDataFilesRouter) RegisterPpidDataFilesRoutes() {
|
|||
_i.App.Route("/ppid-data-files", func(router fiber.Router) {
|
||||
router.Get("/", ppidDataFilesController.All)
|
||||
router.Get("/:id", ppidDataFilesController.Show)
|
||||
router.Post("/", ppidDataFilesController.Save)
|
||||
router.Post("/:ppidDataId", ppidDataFilesController.Save)
|
||||
router.Put("/:id", ppidDataFilesController.Update)
|
||||
router.Delete("/:id", ppidDataFilesController.Delete)
|
||||
router.Get("/viewer/:id", ppidDataFilesController.Viewer)
|
||||
router.Get("/viewer/:filename", ppidDataFilesController.Viewer)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/ppid_data_files/request"
|
||||
|
|
@ -8,21 +9,25 @@ import (
|
|||
)
|
||||
|
||||
type ppidDataFilesRepository struct {
|
||||
DB *database.Database
|
||||
DB *database.Database
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// PpidDataFilesRepository define interface of IPpidDataFilesRepository
|
||||
type PpidDataFilesRepository interface {
|
||||
GetAll(req request.PpidDataFilesQueryRequest) (ppidDataFiless []*entity.PpidDataFiles, paging paginator.Pagination, err error)
|
||||
FindOne(id uint) (ppidDataFiles *entity.PpidDataFiles, err error)
|
||||
FindByFilename(filename string) (ppidDataFiles *entity.PpidDataFiles, err error)
|
||||
FindByPpidData(ppidDataId uint) (ppidDataFiless []*entity.PpidDataFiles, err error)
|
||||
Create(ppidDataFiles *entity.PpidDataFiles) (err error)
|
||||
Update(id uint, ppidDataFiles *entity.PpidDataFiles) (err error)
|
||||
Delete(id uint) (err error)
|
||||
}
|
||||
|
||||
func NewPpidDataFilesRepository(db *database.Database) PpidDataFilesRepository {
|
||||
func NewPpidDataFilesRepository(db *database.Database, logger zerolog.Logger) PpidDataFilesRepository {
|
||||
return &ppidDataFilesRepository{
|
||||
DB: db,
|
||||
DB: db,
|
||||
Log: logger,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +59,23 @@ func (_i *ppidDataFilesRepository) FindOne(id uint) (ppidDataFiles *entity.PpidD
|
|||
return ppidDataFiles, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesRepository) FindByFilename(filename string) (ppidDataFiles *entity.PpidDataFiles, err error) {
|
||||
|
||||
if err := _i.DB.DB.Where("file_name = ?", filename).First(&ppidDataFiles).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ppidDataFiles, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesRepository) FindByPpidData(ppidDataId uint) (ppidDataFiles []*entity.PpidDataFiles, err error) {
|
||||
if err := _i.DB.DB.Where("ppid_data_id = ?", ppidDataId).Find(&ppidDataFiles).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ppidDataFiles, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesRepository) Create(ppidDataFiles *entity.PpidDataFiles) (err error) {
|
||||
return _i.DB.DB.Create(ppidDataFiles).Error
|
||||
}
|
||||
|
|
@ -66,4 +88,4 @@ func (_i *ppidDataFilesRepository) Update(id uint, ppidDataFiles *entity.PpidDat
|
|||
|
||||
func (_i *ppidDataFilesRepository) Delete(id uint) error {
|
||||
return _i.DB.DB.Delete(&entity.PpidDataFiles{}, id).Error
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,11 +23,9 @@ type PpidDataFilesQueryRequest struct {
|
|||
}
|
||||
|
||||
type PpidDataFilesCreateRequest struct {
|
||||
Title string `json:"title" validate:"required"`
|
||||
PpidDataId int `json:"ppidDataId" validate:"required"`
|
||||
Description string `json:"description" validate:"required"`
|
||||
Unit string `json:"unit" validate:"required"`
|
||||
FileType string `json:"fileType" validate:"required"`
|
||||
Title *string `json:"title" validate:"required"`
|
||||
FileType *string `json:"fileType"`
|
||||
FileName *string `json:"fileName"`
|
||||
FilePath *string `json:"filePath"`
|
||||
Size *string `json:"size"`
|
||||
|
|
@ -39,8 +37,6 @@ func (req PpidDataFilesCreateRequest) ToEntity() *entity.PpidDataFiles {
|
|||
return &entity.PpidDataFiles{
|
||||
Title: req.Title,
|
||||
PpidDataId: req.PpidDataId,
|
||||
Description: req.Description,
|
||||
Unit: req.Unit,
|
||||
FileType: req.FileType,
|
||||
FileName: req.FileName,
|
||||
FilePath: req.FilePath,
|
||||
|
|
@ -52,11 +48,9 @@ func (req PpidDataFilesCreateRequest) ToEntity() *entity.PpidDataFiles {
|
|||
|
||||
type PpidDataFilesUpdateRequest struct {
|
||||
ID uint `json:"id" validate:"required"`
|
||||
Title string `json:"title" validate:"required"`
|
||||
PpidDataId int `json:"ppidDataId" validate:"required"`
|
||||
Description string `json:"description" validate:"required"`
|
||||
Unit string `json:"unit" validate:"required"`
|
||||
FileType string `json:"fileType" validate:"required"`
|
||||
Title *string `json:"title"`
|
||||
FileType *string `json:"fileType"`
|
||||
FilePath *string `json:"filePath"`
|
||||
CreatedById *int `json:"createdById"`
|
||||
StatusId *int `json:"statusId"`
|
||||
|
|
@ -69,8 +63,6 @@ func (req PpidDataFilesUpdateRequest) ToEntity() *entity.PpidDataFiles {
|
|||
ID: req.ID,
|
||||
Title: req.Title,
|
||||
PpidDataId: req.PpidDataId,
|
||||
Description: req.Description,
|
||||
Unit: req.Unit,
|
||||
FileType: req.FileType,
|
||||
FilePath: req.FilePath,
|
||||
CreatedById: req.CreatedById,
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ import "time"
|
|||
|
||||
type PpidDataFilesResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
PpidDataId int `json:"ppid_data_id"`
|
||||
Description string `json:"description"`
|
||||
Unit string `json:"unit"`
|
||||
FileType string `json:"file_type"`
|
||||
DownloadCount *int `json:"download_count"`
|
||||
CreatedById *int `json:"created_by_id"`
|
||||
Title *string `json:"title"`
|
||||
PpidDataId int `json:"ppidDataId"`
|
||||
FileName uint `json:"fileName"`
|
||||
FileType *string `json:"fileType"`
|
||||
FileUrl string `json:"fileUrl"`
|
||||
DownloadCount *int `json:"downloadCount"`
|
||||
CreatedById *int `json:"createdById"`
|
||||
StatusId *int `json:"status_id"`
|
||||
IsPublish *bool `json:"is_publish"`
|
||||
PublishedAt *time.Time `json:"published_at"`
|
||||
|
|
|
|||
|
|
@ -11,10 +11,11 @@ import (
|
|||
"go-humas-be/app/module/ppid_data_files/response"
|
||||
minioStorage "go-humas-be/config/config"
|
||||
"go-humas-be/utils/paginator"
|
||||
utilVal "go-humas-be/utils/validator"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"mime"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -34,7 +35,7 @@ type PpidDataFilesService interface {
|
|||
Save(c *fiber.Ctx) error
|
||||
Update(id uint, req request.PpidDataFilesUpdateRequest) (err error)
|
||||
Delete(id uint) error
|
||||
Viewer(c *fiber.Ctx, id uint) error
|
||||
Viewer(c *fiber.Ctx, filename string) error
|
||||
}
|
||||
|
||||
// NewPpidDataFilesService init PpidDataFilesService
|
||||
|
|
@ -71,12 +72,8 @@ func (_i *ppidDataFilesService) Show(id uint) (ppidDataFiles *response.PpidDataF
|
|||
}
|
||||
|
||||
func (_i *ppidDataFilesService) Save(c *fiber.Ctx) (err error) {
|
||||
req := new(request.PpidDataFilesCreateRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
id, err := strconv.ParseUint(c.Params("ppidDataId"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -112,19 +109,28 @@ func (_i *ppidDataFilesService) Save(c *fiber.Ctx) (err error) {
|
|||
}
|
||||
defer src.Close()
|
||||
|
||||
objectName := "ppid/upload/" + file.Filename
|
||||
//filenameOnly := file.Filename[:len(file.Filename)-len(filepath.Ext(file.Filename))]
|
||||
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/upload/" + newFilename
|
||||
size := strconv.FormatInt(file.Size, 10)
|
||||
statusId := 1
|
||||
|
||||
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,
|
||||
PpidDataId: int(id),
|
||||
Title: &newFilenameWithoutExt,
|
||||
FileType: &extension,
|
||||
FileName: &newFilename,
|
||||
FilePath: &objectName,
|
||||
Size: &size,
|
||||
StatusId: &statusId,
|
||||
}
|
||||
|
||||
err = _i.Repo.Create(req.ToEntity())
|
||||
|
|
@ -155,8 +161,8 @@ func (_i *ppidDataFilesService) Delete(id uint) error {
|
|||
return _i.Repo.Delete(id)
|
||||
}
|
||||
|
||||
func (_i *ppidDataFilesService) Viewer(c *fiber.Ctx, id uint) (err error) {
|
||||
result, err := _i.Repo.FindOne(id)
|
||||
func (_i *ppidDataFilesService) Viewer(c *fiber.Ctx, filename string) (err error) {
|
||||
result, err := _i.Repo.FindByFilename(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ func (_i *ppidDatasController) Save(c *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
authToken := c.Get("Authorization")
|
||||
err := _i.ppidDatasService.Save(*req, authToken)
|
||||
dataResult, err := _i.ppidDatasService.Save(*req, authToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -128,6 +128,7 @@ func (_i *ppidDatasController) Save(c *fiber.Ctx) error {
|
|||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"PpidDatas successfully created"},
|
||||
Data: dataResult,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,20 @@ import (
|
|||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database/entity"
|
||||
ppidDataCategoriesRepository "go-humas-be/app/module/ppid_data_categories/repository"
|
||||
ppidDataFilesMapper "go-humas-be/app/module/ppid_data_files/mapper"
|
||||
ppidDataFilesRepository "go-humas-be/app/module/ppid_data_files/repository"
|
||||
ppidDataFilesResponse "go-humas-be/app/module/ppid_data_files/response"
|
||||
res "go-humas-be/app/module/ppid_datas/response"
|
||||
usersRepository "go-humas-be/app/module/users/repository"
|
||||
"time"
|
||||
)
|
||||
|
||||
func PpidDatasResponseMapper(log zerolog.Logger, ppidDataCategoriesRepo ppidDataCategoriesRepository.PpidDataCategoriesRepository, usersRepo usersRepository.UsersRepository, ppidDatasReq *entity.PpidDatas) (ppidDatasRes *res.PpidDatasResponse) {
|
||||
func PpidDatasResponseMapper(
|
||||
log zerolog.Logger,
|
||||
ppidDataCategoriesRepo ppidDataCategoriesRepository.PpidDataCategoriesRepository,
|
||||
ppidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository,
|
||||
usersRepo usersRepository.UsersRepository,
|
||||
ppidDatasReq *entity.PpidDatas,
|
||||
) (ppidDatasRes *res.PpidDatasResponse) {
|
||||
if ppidDatasReq != nil {
|
||||
findCategory, _ := ppidDataCategoriesRepo.FindOne(ppidDatasReq.CategoryId)
|
||||
categoryName := ""
|
||||
|
|
@ -23,9 +31,18 @@ func PpidDatasResponseMapper(log zerolog.Logger, ppidDataCategoriesRepo ppidData
|
|||
createdByName = findUser.Fullname
|
||||
}
|
||||
|
||||
log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:PpidDatasResponseMapper", "UserInfo:PpidData").
|
||||
Interface("payload", findCategory).Msg("")
|
||||
ppidDataFiles, _ := ppidDataFilesRepo.FindByPpidData(ppidDatasReq.ID)
|
||||
|
||||
var ppidDataFilesArr []*ppidDataFilesResponse.PpidDataFilesResponse
|
||||
if len(ppidDataFiles) > 0 {
|
||||
for _, result := range ppidDataFiles {
|
||||
ppidDataFilesArr = append(ppidDataFilesArr, ppidDataFilesMapper.PpidDataFilesResponseMapper(result))
|
||||
}
|
||||
}
|
||||
|
||||
//log.Info().Str("timestamp", time.Now().
|
||||
// Format(time.RFC3339)).Str("Service:PpidDatasResponseMapper", "UserInfo:PpidData").
|
||||
// Interface("payload", ppidDataFiles).Msg("")
|
||||
|
||||
ppidDatasRes = &res.PpidDatasResponse{
|
||||
ID: ppidDatasReq.ID,
|
||||
|
|
@ -41,6 +58,8 @@ func PpidDatasResponseMapper(log zerolog.Logger, ppidDataCategoriesRepo ppidData
|
|||
IsActive: ppidDatasReq.IsActive,
|
||||
CreatedAt: ppidDatasReq.CreatedAt,
|
||||
UpdatedAt: ppidDatasReq.UpdatedAt,
|
||||
|
||||
PpidDataFiles: ppidDataFilesArr,
|
||||
}
|
||||
}
|
||||
return ppidDatasRes
|
||||
|
|
|
|||
|
|
@ -2,29 +2,33 @@ package repository
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database"
|
||||
"go-humas-be/app/database/entity"
|
||||
"go-humas-be/app/module/ppid_datas/request"
|
||||
"go-humas-be/utils/paginator"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ppidDatasRepository struct {
|
||||
DB *database.Database
|
||||
DB *database.Database
|
||||
Log zerolog.Logger
|
||||
}
|
||||
|
||||
// PpidDatasRepository define interface of IPpidDatasRepository
|
||||
type PpidDatasRepository interface {
|
||||
GetAll(req request.PpidDatasQueryRequest) (ppidDatass []*entity.PpidDatas, paging paginator.Pagination, err error)
|
||||
FindOne(id uint) (ppidDatas *entity.PpidDatas, err error)
|
||||
Create(ppidDatas *entity.PpidDatas) (err error)
|
||||
Create(ppidDatas *entity.PpidDatas) (ppidDataReturn *entity.PpidDatas, err error)
|
||||
Update(id uint, ppidDatas *entity.PpidDatas) (err error)
|
||||
Delete(id uint) (err error)
|
||||
}
|
||||
|
||||
func NewPpidDatasRepository(db *database.Database) PpidDatasRepository {
|
||||
func NewPpidDatasRepository(db *database.Database, logger zerolog.Logger) PpidDatasRepository {
|
||||
return &ppidDatasRepository{
|
||||
DB: db,
|
||||
DB: db,
|
||||
Log: logger,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -90,8 +94,14 @@ func (_i *ppidDatasRepository) FindOne(id uint) (ppidDatas *entity.PpidDatas, er
|
|||
return ppidDatas, nil
|
||||
}
|
||||
|
||||
func (_i *ppidDatasRepository) Create(ppidDatas *entity.PpidDatas) (err error) {
|
||||
return _i.DB.DB.Create(ppidDatas).Error
|
||||
func (_i *ppidDatasRepository) Create(ppidDatas *entity.PpidDatas) (ppidDataReturn *entity.PpidDatas, err error) {
|
||||
result := _i.DB.DB.Create(ppidDatas)
|
||||
|
||||
_i.Log.Info().Str("timestamp", time.Now().
|
||||
Format(time.RFC3339)).Str("Service:Create", "PpidData:Create").
|
||||
Interface("result", ppidDatas).Msg("")
|
||||
|
||||
return ppidDatas, result.Error
|
||||
}
|
||||
|
||||
func (_i *ppidDatasRepository) Update(id uint, ppidDatas *entity.PpidDatas) (err error) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package response
|
||||
|
||||
import "time"
|
||||
import (
|
||||
ppidDataFilesResponse "go-humas-be/app/module/ppid_data_files/response"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PpidDatasResponse struct {
|
||||
ID uint `json:"id"`
|
||||
|
|
@ -17,4 +20,6 @@ type PpidDatasResponse struct {
|
|||
IsActive *bool `json:"isActive"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
|
||||
PpidDataFiles []*ppidDataFilesResponse.PpidDataFilesResponse `json:"files"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package service
|
|||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"go-humas-be/app/database/entity"
|
||||
ppidDataCategoriesRepository "go-humas-be/app/module/ppid_data_categories/repository"
|
||||
ppidDataFilesRepository "go-humas-be/app/module/ppid_data_files/repository"
|
||||
"go-humas-be/app/module/ppid_datas/mapper"
|
||||
"go-humas-be/app/module/ppid_datas/repository"
|
||||
"go-humas-be/app/module/ppid_datas/request"
|
||||
|
|
@ -17,6 +19,7 @@ import (
|
|||
type ppidDatasService struct {
|
||||
Repo repository.PpidDatasRepository
|
||||
PpidDataCategoriesRepo ppidDataCategoriesRepository.PpidDataCategoriesRepository
|
||||
PpidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository
|
||||
UsersRepo usersRepository.UsersRepository
|
||||
UserLevelsRepo userLevelsRepository.UserLevelsRepository
|
||||
Log zerolog.Logger
|
||||
|
|
@ -26,17 +29,25 @@ type ppidDatasService struct {
|
|||
type PpidDatasService interface {
|
||||
All(req request.PpidDatasQueryRequest) (ppidDatas []*response.PpidDatasResponse, paging paginator.Pagination, err error)
|
||||
Show(id uint) (ppidDatas *response.PpidDatasResponse, err error)
|
||||
Save(req request.PpidDatasCreateRequest, authToken string) (err error)
|
||||
Save(req request.PpidDatasCreateRequest, authToken string) (ppidDatas *entity.PpidDatas, err error)
|
||||
Update(id uint, req request.PpidDatasUpdateRequest) (err error)
|
||||
Delete(id uint) error
|
||||
}
|
||||
|
||||
// NewPpidDatasService init PpidDatasService
|
||||
func NewPpidDatasService(repo repository.PpidDatasRepository, ppidCategoriesRepository ppidDataCategoriesRepository.PpidDataCategoriesRepository, usersRepo usersRepository.UsersRepository, userLevelsRepo userLevelsRepository.UserLevelsRepository, log zerolog.Logger) PpidDatasService {
|
||||
func NewPpidDatasService(
|
||||
repo repository.PpidDatasRepository,
|
||||
ppidDataCategoriesRepo ppidDataCategoriesRepository.PpidDataCategoriesRepository,
|
||||
ppidDataFilesRepo ppidDataFilesRepository.PpidDataFilesRepository,
|
||||
usersRepo usersRepository.UsersRepository,
|
||||
userLevelsRepo userLevelsRepository.UserLevelsRepository,
|
||||
log zerolog.Logger,
|
||||
) PpidDatasService {
|
||||
|
||||
return &ppidDatasService{
|
||||
Repo: repo,
|
||||
PpidDataCategoriesRepo: ppidCategoriesRepository,
|
||||
PpidDataCategoriesRepo: ppidDataCategoriesRepo,
|
||||
PpidDataFilesRepo: ppidDataFilesRepo,
|
||||
UsersRepo: usersRepo,
|
||||
UserLevelsRepo: userLevelsRepo,
|
||||
Log: log,
|
||||
|
|
@ -51,7 +62,7 @@ func (_i *ppidDatasService) All(req request.PpidDatasQueryRequest) (ppidDatass [
|
|||
}
|
||||
|
||||
for _, result := range results {
|
||||
ppidDatass = append(ppidDatass, mapper.PpidDatasResponseMapper(_i.Log, _i.PpidDataCategoriesRepo, _i.UsersRepo, result))
|
||||
ppidDatass = append(ppidDatass, mapper.PpidDatasResponseMapper(_i.Log, _i.PpidDataCategoriesRepo, _i.PpidDataFilesRepo, _i.UsersRepo, result))
|
||||
}
|
||||
|
||||
return
|
||||
|
|
@ -63,10 +74,10 @@ func (_i *ppidDatasService) Show(id uint) (ppidDatas *response.PpidDatasResponse
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return mapper.PpidDatasResponseMapper(_i.Log, _i.PpidDataCategoriesRepo, _i.UsersRepo, result), nil
|
||||
return mapper.PpidDatasResponseMapper(_i.Log, _i.PpidDataCategoriesRepo, _i.PpidDataFilesRepo, _i.UsersRepo, result), nil
|
||||
}
|
||||
|
||||
func (_i *ppidDatasService) Save(req request.PpidDatasCreateRequest, authToken string) (err error) {
|
||||
func (_i *ppidDatasService) Save(req request.PpidDatasCreateRequest, authToken string) (ppidDatas *entity.PpidDatas, err error) {
|
||||
_i.Log.Info().Interface("data", req).Msg("")
|
||||
newReq := req.ToEntity()
|
||||
|
||||
|
|
@ -76,7 +87,7 @@ func (_i *ppidDatasService) Save(req request.PpidDatasCreateRequest, authToken s
|
|||
|
||||
userLevels, err := _i.UserLevelsRepo.FindOne(uint(createdBy.UserLevelId))
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
newReq.Group = userLevels.Group
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ level = 0 # panic -> 5, fatal -> 4, error -> 3, warn -> 2, info -> 1, debug -> 0
|
|||
prettier = true
|
||||
|
||||
[objectstorage.miniostorage]
|
||||
endpoint = "103.82.242.92:9009 "
|
||||
endpoint = "103.82.242.92:9009"
|
||||
access-key-id = "A7USQd6iyinj38nDwnFE"
|
||||
secret-access-key = "rTXDKRL8fhXUOaLDonwYThvDBPgNGPxvReTgfVGR"
|
||||
use-ssl = false
|
||||
|
|
|
|||
|
|
@ -3457,7 +3457,7 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/ppid-data-files/viewer/{id}": {
|
||||
"/ppid-data-files/viewer/{filename}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
|
|
@ -3472,8 +3472,8 @@ const docTemplate = `{
|
|||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Ppid Data ID",
|
||||
"name": "id",
|
||||
"description": "Ppid Data Filename",
|
||||
"name": "filename",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
|
|
@ -3681,15 +3681,6 @@ const docTemplate = `{
|
|||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Required payload",
|
||||
"name": "payload",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/request.PpidDataFilesCreateRequest"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Ppid Data ID",
|
||||
|
|
@ -5829,65 +5820,16 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"request.PpidDataFilesCreateRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"description",
|
||||
"fileType",
|
||||
"ppidDataId",
|
||||
"title",
|
||||
"unit"
|
||||
],
|
||||
"properties": {
|
||||
"createdById": {
|
||||
"type": "integer"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"fileName": {
|
||||
"type": "string"
|
||||
},
|
||||
"filePath": {
|
||||
"type": "string"
|
||||
},
|
||||
"fileType": {
|
||||
"type": "string"
|
||||
},
|
||||
"ppidDataId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"size": {
|
||||
"type": "string"
|
||||
},
|
||||
"statusId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"unit": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"request.PpidDataFilesUpdateRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"description",
|
||||
"fileType",
|
||||
"id",
|
||||
"ppidDataId",
|
||||
"title",
|
||||
"unit"
|
||||
"ppidDataId"
|
||||
],
|
||||
"properties": {
|
||||
"createdById": {
|
||||
"type": "integer"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"filePath": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
@ -5911,9 +5853,6 @@ const docTemplate = `{
|
|||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"unit": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3446,7 +3446,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/ppid-data-files/viewer/{id}": {
|
||||
"/ppid-data-files/viewer/{filename}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
|
|
@ -3461,8 +3461,8 @@
|
|||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Ppid Data ID",
|
||||
"name": "id",
|
||||
"description": "Ppid Data Filename",
|
||||
"name": "filename",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
|
|
@ -3670,15 +3670,6 @@
|
|||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Required payload",
|
||||
"name": "payload",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/request.PpidDataFilesCreateRequest"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Ppid Data ID",
|
||||
|
|
@ -5818,65 +5809,16 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"request.PpidDataFilesCreateRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"description",
|
||||
"fileType",
|
||||
"ppidDataId",
|
||||
"title",
|
||||
"unit"
|
||||
],
|
||||
"properties": {
|
||||
"createdById": {
|
||||
"type": "integer"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"fileName": {
|
||||
"type": "string"
|
||||
},
|
||||
"filePath": {
|
||||
"type": "string"
|
||||
},
|
||||
"fileType": {
|
||||
"type": "string"
|
||||
},
|
||||
"ppidDataId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"size": {
|
||||
"type": "string"
|
||||
},
|
||||
"statusId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"unit": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"request.PpidDataFilesUpdateRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"description",
|
||||
"fileType",
|
||||
"id",
|
||||
"ppidDataId",
|
||||
"title",
|
||||
"unit"
|
||||
"ppidDataId"
|
||||
],
|
||||
"properties": {
|
||||
"createdById": {
|
||||
"type": "integer"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"filePath": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
@ -5900,9 +5842,6 @@
|
|||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"unit": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -214,41 +214,10 @@ definitions:
|
|||
- slug
|
||||
- title
|
||||
type: object
|
||||
request.PpidDataFilesCreateRequest:
|
||||
properties:
|
||||
createdById:
|
||||
type: integer
|
||||
description:
|
||||
type: string
|
||||
fileName:
|
||||
type: string
|
||||
filePath:
|
||||
type: string
|
||||
fileType:
|
||||
type: string
|
||||
ppidDataId:
|
||||
type: integer
|
||||
size:
|
||||
type: string
|
||||
statusId:
|
||||
type: integer
|
||||
title:
|
||||
type: string
|
||||
unit:
|
||||
type: string
|
||||
required:
|
||||
- description
|
||||
- fileType
|
||||
- ppidDataId
|
||||
- title
|
||||
- unit
|
||||
type: object
|
||||
request.PpidDataFilesUpdateRequest:
|
||||
properties:
|
||||
createdById:
|
||||
type: integer
|
||||
description:
|
||||
type: string
|
||||
filePath:
|
||||
type: string
|
||||
fileType:
|
||||
|
|
@ -265,15 +234,9 @@ definitions:
|
|||
type: integer
|
||||
title:
|
||||
type: string
|
||||
unit:
|
||||
type: string
|
||||
required:
|
||||
- description
|
||||
- fileType
|
||||
- id
|
||||
- ppidDataId
|
||||
- title
|
||||
- unit
|
||||
type: object
|
||||
request.PpidDatasCreateRequest:
|
||||
properties:
|
||||
|
|
@ -2859,12 +2822,6 @@ paths:
|
|||
name: files
|
||||
required: true
|
||||
type: file
|
||||
- description: Required payload
|
||||
in: body
|
||||
name: payload
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/request.PpidDataFilesCreateRequest'
|
||||
- description: Ppid Data ID
|
||||
in: path
|
||||
name: ppidDataId
|
||||
|
|
@ -2894,13 +2851,13 @@ paths:
|
|||
summary: Create PpidDataFiles
|
||||
tags:
|
||||
- PPID Files
|
||||
/ppid-data-files/viewer/{id}:
|
||||
/ppid-data-files/viewer/{filename}:
|
||||
get:
|
||||
description: API for create PpidDataFiles
|
||||
parameters:
|
||||
- description: Ppid Data ID
|
||||
- description: Ppid Data Filename
|
||||
in: path
|
||||
name: id
|
||||
name: filename
|
||||
required: true
|
||||
type: string
|
||||
responses:
|
||||
|
|
|
|||
Loading…
Reference in New Issue