package models import ( "kontor-api-gin/internal/helpers" "time" ) type MediaVideo 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:"uniqueIndex;column:url" json:"url"` ShouldDownload bool `gorm:"column:should_download" json:"should_download"` } func (media_video *MediaVideo) TableName() string { return "media_video" } 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