98 lines
3.1 KiB
Go
98 lines
3.1 KiB
Go
package models
|
|
|
|
import (
|
|
"kontor-api-echo/internal/helpers"
|
|
"time"
|
|
|
|
"github.com/uptrace/bun"
|
|
)
|
|
|
|
type MediaFile struct {
|
|
bun.BaseModel `bun:"table:media_file"`
|
|
|
|
ID string `bun:"id,pk"`
|
|
CreatedAt time.Time `bun:"created_date,nullzero,notnull,default:current_timestamp"`
|
|
UpdatedAt time.Time `bun:"last_modified_date,nullzero,notnull,default:current_timestamp"`
|
|
DeletedAt *time.Time `bun:"deleted_date,nullzero"`
|
|
Version int `bun:"version,default:0"`
|
|
CloudLink string `bun:"cloud_link"`
|
|
FileName string `bun:"file_name"`
|
|
Path string `bun:"path"`
|
|
Review bool `bun:"review"`
|
|
Title string `bun:"title"`
|
|
WebLink string `bun:"url,unique:url"`
|
|
ShouldDownload bool `bun:"should_download"`
|
|
|
|
MediaActorFiles []MediaActorFile `bun:"rel:has-many,join:id=media_file_id"`
|
|
}
|
|
|
|
type MediaFileAdd struct {
|
|
Url string `json:"url"`
|
|
}
|
|
|
|
type MediaFileForm struct {
|
|
Title string `form:"title" binding:"required"`
|
|
Url string `form:"url" binding:"required"`
|
|
}
|
|
|
|
func (form *MediaFileForm) ConvertFormToMediaFileDTO() MediaFileDTO {
|
|
media_file := MediaFileDTO{}
|
|
return media_file
|
|
}
|
|
|
|
type MediaFileDTO struct {
|
|
ID string `json:"id" binding:"required"`
|
|
CreatedAt helpers.KontorTime `json:"created_date"`
|
|
UpdatedAt helpers.KontorTime `json:"last_modified_date"`
|
|
DeletedAt *time.Time `json:"deleted_date,omitempty"`
|
|
Version int `json:"version"`
|
|
CloudLink string `json:"cloud_link"`
|
|
FileName string `json:"file_name"`
|
|
Path string `json:"path"`
|
|
Review bool `json:"review"`
|
|
Title string `json:"title"`
|
|
WebLink string `json:"url"`
|
|
ShouldDownload bool `json:"should_download"`
|
|
}
|
|
|
|
func (dto MediaFileDTO) ConvertDTOToModel() MediaFile {
|
|
model := MediaFile{
|
|
ID: dto.ID,
|
|
CreatedAt: dto.CreatedAt.Time,
|
|
UpdatedAt: dto.UpdatedAt.Time,
|
|
DeletedAt: dto.DeletedAt,
|
|
Version: dto.Version,
|
|
CloudLink: dto.CloudLink,
|
|
FileName: dto.FileName,
|
|
Path: dto.Path,
|
|
Review: dto.Review,
|
|
ShouldDownload: dto.ShouldDownload,
|
|
Title: dto.Title,
|
|
WebLink: dto.WebLink,
|
|
}
|
|
return model
|
|
}
|
|
|
|
func ConvertMediaFilesToDtos(media_files []MediaFile) []MediaFileDTO {
|
|
dtos := make([]MediaFileDTO, len(media_files))
|
|
for i, media_file := range media_files {
|
|
dtos[i] = MediaFileDTO{
|
|
ID: media_file.ID,
|
|
CreatedAt: helpers.KontorTime{Time: media_file.CreatedAt},
|
|
UpdatedAt: helpers.KontorTime{Time: media_file.UpdatedAt},
|
|
DeletedAt: media_file.DeletedAt,
|
|
Version: media_file.Version,
|
|
CloudLink: media_file.CloudLink,
|
|
FileName: media_file.FileName,
|
|
Path: media_file.Path,
|
|
Review: media_file.Review,
|
|
Title: media_file.Title,
|
|
WebLink: media_file.WebLink,
|
|
ShouldDownload: media_file.ShouldDownload,
|
|
}
|
|
}
|
|
return dtos
|
|
}
|
|
|
|
type MediaFileDTOList []MediaFileDTO
|