Files
kontor/kontor-echo/internal/models/media_video.go
T
Thomas Peetz 50e2da8a66
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 9s
Gitea Actions Demo / build-and-test (push) Failing after 14s
update kontor-echo
2026-11-06 16:48:15 +01:00

99 lines
3.2 KiB
Go

package models
import (
"kontor-api-echo/internal/helpers"
"time"
"github.com/uptrace/bun"
)
type MediaVideo struct {
bun.BaseModel `bun:"table:media_video"`
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"`
}
func (media_music *MediaVideo) Update(update MediaVideoDTO) {
media_music.CreatedAt = update.CreatedAt.Time
media_music.UpdatedAt = time.Now()
media_music.Version = media_music.Version + 1
media_music.WebLink = update.WebLink
media_music.Review = update.Review
media_music.ShouldDownload = update.ShouldDownload
media_music.Title = update.Title
media_music.FileName = update.FileName
}
type MediaVideoForm struct {
Title string `form:"title" binding:"required"`
Url string `form:"url" binding:"required"`
}
func (form *MediaVideoForm) ConvertFormToMediaVideoDTO() MediaVideoDTO {
media_video := MediaVideoDTO{}
return media_video
}
type MediaVideoDTO 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 MediaVideoDTO) ConvertDTOToModel() MediaVideo {
model := MediaVideo{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
Review: dto.Review,
Title: dto.Title,
WebLink: dto.WebLink,
}
return model
}
func ConvertMediaVideosToDtos(media_videos []MediaVideo) []MediaVideoDTO {
dtos := make([]MediaVideoDTO, len(media_videos))
for i, media_video := range media_videos {
dtos[i] = MediaVideoDTO{
ID: media_video.ID,
CreatedAt: helpers.KontorTime{Time: media_video.CreatedAt},
UpdatedAt: helpers.KontorTime{Time: media_video.UpdatedAt},
DeletedAt: media_video.DeletedAt,
Version: media_video.Version,
CloudLink: media_video.CloudLink,
FileName: media_video.FileName,
Path: media_video.Path,
Review: media_video.Review,
Title: media_video.Title,
WebLink: media_video.WebLink,
ShouldDownload: media_video.ShouldDownload,
}
}
return dtos
}
type MediaVideoDTOList []MediaVideoDTO