Files
kontor/kontor-gin/internal/models/media_file.go
T
Thomas Peetz b0cc5f0cd1
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
Gitea Actions Demo / build-and-test (push) Failing after 14m37s
add methods in Repository and Model for importing data
2026-10-30 09:15:19 +01:00

98 lines
3.4 KiB
Go

package models
import (
"kontor-api-gin/internal/helpers"
"time"
)
type MediaFile struct {
ID string `gorm:"type:string;primary_key;" json:"id"`
CreatedAt time.Time `gorm:"column:created_date" json:"created_date"`
UpdatedAt time.Time `gorm:"column:last_modified_date" json:"last_modified_date"`
DeletedAt *time.Time `gorm:"column:deleted_date" json:"deleted_date"`
Version int `gorm:"default:0" json:"version"`
CloudLink string `gorm:"column:cloud_link" json:"cloud_link"`
FileName string `gorm:"column:file_name" json:"file_name"`
Path string `gorm:"column:path" json:"path"`
Review bool `gorm:"column:review" json:"review"`
Title string `gorm:"size:300, column:title" json:"title"`
WebLink string `gorm:"column:url" json:"url"`
ShouldDownload bool `gorm:"column:should_download" json:"should_download"`
MediaActorFiles []MediaActorFile `gorm:"foreignKey:MediaFileID" json:"media_actor_files"`
}
func (media_file *MediaFile) TableName() string {
return "media_file"
}
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