update kontor-echo
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package schema
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-echo/internal/helpers"
|
||||
"time"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
@@ -9,13 +10,63 @@ import (
|
||||
type MediaActor struct {
|
||||
bun.BaseModel `bun:"table:media_actor"`
|
||||
|
||||
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"`
|
||||
Version int `bun:"version,default:0"`
|
||||
Name string `bun:"name"`
|
||||
WebLink string `bun:"url,unique:url"`
|
||||
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"`
|
||||
Name string `bun:"name"`
|
||||
WebLink string `bun:"url,unique:url"`
|
||||
|
||||
MediaActorFiles []MediaActorFile `bun:"rel:has-many,join:id=media_actor_id"`
|
||||
}
|
||||
|
||||
type MediaActorForm struct {
|
||||
Name string `form:"name" binding:"required"`
|
||||
Weblink string `form:"weblink" binding:"required"`
|
||||
}
|
||||
|
||||
type MediaActorDTO 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"`
|
||||
Name string `json:"name"`
|
||||
WebLink string `json:"url"`
|
||||
}
|
||||
|
||||
func (dto MediaActorDTO) ConvertDTOToModel() MediaActor {
|
||||
model := MediaActor{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
Name: dto.Name,
|
||||
WebLink: dto.WebLink,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
type MediaActorAdd struct {
|
||||
WebLink string `json:"url"`
|
||||
}
|
||||
|
||||
func ConvertMediaActorsToDtos(actors []MediaActor) []MediaActorDTO {
|
||||
dtos := make([]MediaActorDTO, len(actors))
|
||||
for i, actor := range actors {
|
||||
dtos[i] = MediaActorDTO{
|
||||
ID: actor.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: actor.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: actor.UpdatedAt},
|
||||
DeletedAt: actor.DeletedAt,
|
||||
Version: actor.Version,
|
||||
Name: actor.Name,
|
||||
WebLink: actor.WebLink,
|
||||
}
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type MediaActorDTOList []MediaActorDTO
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package schema
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-echo/internal/helpers"
|
||||
"time"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
@@ -12,6 +13,7 @@ type MediaActorFile struct {
|
||||
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"`
|
||||
MediaActorID *string `bun:"media_actor_id"`
|
||||
MediaActor *MediaActor `bun:"rel:belongs-to,join:media_actor_id=id"`
|
||||
@@ -19,3 +21,48 @@ type MediaActorFile struct {
|
||||
MediaFile *MediaFile `bun:"rel:belongs-to,join:media_file_id=id"`
|
||||
}
|
||||
|
||||
type MediaActorFileAdd struct {
|
||||
MediaActorID string `json:"media_actor_id"`
|
||||
MediaFileID string `json:"media_file_id"`
|
||||
}
|
||||
|
||||
type MediaActorFileDTO 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"`
|
||||
MediaActorID *string `json:"media_actor_id"`
|
||||
MediaFileID *string `json:"media_file_id"`
|
||||
}
|
||||
|
||||
func (dto MediaActorFileDTO) ConvertDTOToModel() MediaActorFile {
|
||||
model := MediaActorFile{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
MediaActorID: dto.MediaActorID,
|
||||
MediaFileID: dto.MediaFileID,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertMediaActorFilesToDtos(actor_files []MediaActorFile) []MediaActorFileDTO {
|
||||
dtos := make([]MediaActorFileDTO, len(actor_files))
|
||||
for i, actor_file := range actor_files {
|
||||
dtos[i] = MediaActorFileDTO{
|
||||
ID: actor_file.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: actor_file.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: actor_file.UpdatedAt},
|
||||
DeletedAt: actor_file.DeletedAt,
|
||||
Version: actor_file.Version,
|
||||
MediaActorID: actor_file.MediaActorID,
|
||||
MediaFileID: actor_file.MediaFileID,
|
||||
}
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type MediaActorFileDTOList []MediaActorFileDTO
|
||||
|
||||
@@ -1,79 +1,80 @@
|
||||
package schema
|
||||
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"`
|
||||
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 MediaActor struct {
|
||||
bun.BaseModel `bun:"table:media_actor"`
|
||||
|
||||
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"`
|
||||
Version int `bun:"version,default:0"`
|
||||
Name string `bun:"name"`
|
||||
WebLink string `bun:"url,unique:url"`
|
||||
|
||||
MediaActorFiles []MediaActorFile `bun:"rel:has-many,join:id=media_actor_id"`
|
||||
}
|
||||
|
||||
type MediaActorFile struct {
|
||||
bun.BaseModel `bun:"table:media_actor_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"`
|
||||
Version int `bun:"version,default:0"`
|
||||
MediaActorID *string `bun:"media_actor_id"`
|
||||
MediaActor *MediaActor `bun:"rel:belongs-to,join:media_actor_id=id"`
|
||||
MediaFileID *string `bun:"media_file_id"`
|
||||
MediaFile *MediaFile `bun:"rel:belongs-to,join:media_file_id=id"`
|
||||
}
|
||||
|
||||
type MediaArticle struct {
|
||||
bun.BaseModel `bun:"table:media_article"`
|
||||
|
||||
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"`
|
||||
Version int `bun:"version,default:0"`
|
||||
Review bool `bun:"review"`
|
||||
Title string `bun:"title"`
|
||||
WebLink string `bun:"url,unique:url"`
|
||||
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"`
|
||||
Review bool `bun:"review"`
|
||||
Title string `bun:"title"`
|
||||
WebLink string `bun:"url,unique:url"`
|
||||
}
|
||||
|
||||
type MediaVideo struct {
|
||||
bun.BaseModel `bun:"table:media_article"`
|
||||
|
||||
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"`
|
||||
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_article MediaArticle) ConvertMediaArticleToDTO() MediaArticleDTO {
|
||||
dto := MediaArticleDTO{
|
||||
ID: media_article.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: media_article.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: media_article.UpdatedAt},
|
||||
DeletedAt: media_article.DeletedAt,
|
||||
Version: media_article.Version,
|
||||
Review: media_article.Review,
|
||||
Title: media_article.Title,
|
||||
WebLink: media_article.WebLink,
|
||||
}
|
||||
return dto
|
||||
}
|
||||
|
||||
type MediaArticleForm struct {
|
||||
Title string `form:"title" binding:"required"`
|
||||
Url string `form:"url" binding:"required"`
|
||||
}
|
||||
|
||||
func (form *MediaArticleForm) ConvertFormToMediaArticleDTO() MediaArticleDTO {
|
||||
dto := MediaArticleDTO{}
|
||||
return dto
|
||||
}
|
||||
|
||||
type MediaArticleDTO 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"`
|
||||
Version int `json:"version"`
|
||||
Review bool `json:"review"`
|
||||
Title string `json:"title"`
|
||||
WebLink string `json:"url"`
|
||||
}
|
||||
|
||||
func (dto MediaArticleDTO) ConvertDTOToModel() MediaArticle {
|
||||
model := MediaArticle{
|
||||
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 ConvertMediaArticlesToDtos(media_articles []MediaArticle) MediaArticleDTOList {
|
||||
dtos := make(MediaArticleDTOList, len(media_articles))
|
||||
for i, media_article := range media_articles {
|
||||
dtos[i] = media_article.ConvertMediaArticleToDTO()
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type MediaArticleDTOList []MediaArticleDTO
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-echo/internal/helpers"
|
||||
"time"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
@@ -9,18 +10,88 @@ import (
|
||||
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"`
|
||||
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"`
|
||||
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
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"kontor-api-echo/internal/config"
|
||||
"kontor-api-echo/internal/helpers"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type MediaLoFi struct {
|
||||
bun.BaseModel `bun:"table:media_lofi"`
|
||||
|
||||
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"`
|
||||
WebLink string `bun:"url,unique:url"`
|
||||
Review bool `bun:"review"`
|
||||
ShouldDownload bool `bun:"should_download"`
|
||||
Title string `bun:"title"`
|
||||
FileName string `bun:"file_name"`
|
||||
}
|
||||
|
||||
func (media_lofi *MediaLoFi) Update(update MediaLoFiDTO) {
|
||||
media_lofi.CreatedAt = update.CreatedAt.Time
|
||||
media_lofi.UpdatedAt = time.Now()
|
||||
media_lofi.Version = media_lofi.Version + 1
|
||||
media_lofi.WebLink = update.WebLink
|
||||
media_lofi.Review = update.Review
|
||||
media_lofi.ShouldDownload = update.ShouldDownload
|
||||
media_lofi.Title = update.Title
|
||||
media_lofi.FileName = update.FileName
|
||||
}
|
||||
|
||||
func (media_lofi *MediaLoFi) ConvertMediaLoFiToDTO() MediaLoFiDTO {
|
||||
dto := MediaLoFiDTO{
|
||||
ID: media_lofi.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: media_lofi.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: media_lofi.UpdatedAt},
|
||||
DeletedAt: media_lofi.DeletedAt,
|
||||
Version: media_lofi.Version,
|
||||
WebLink: media_lofi.WebLink,
|
||||
Review: media_lofi.Review,
|
||||
ShouldDownload: media_lofi.ShouldDownload,
|
||||
Title: media_lofi.Title,
|
||||
FileName: media_lofi.FileName,
|
||||
}
|
||||
return dto
|
||||
}
|
||||
|
||||
type MediaLofiAdd struct {
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type MediaLoFiForm struct {
|
||||
Title string `form:"title" binding:"required"`
|
||||
Url string `form:"url" binding:"required"`
|
||||
}
|
||||
|
||||
func (form *MediaLoFiForm) ConvertFormToMediaLofiDTO() MediaLoFiDTO {
|
||||
media_lofi := MediaLoFiDTO{}
|
||||
return media_lofi
|
||||
}
|
||||
|
||||
type MediaLoFiDTO 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"`
|
||||
FileName string `json:"file_name"`
|
||||
Review bool `json:"review"`
|
||||
ShouldDownload bool `json:"should_download"`
|
||||
Title string `json:"title"`
|
||||
WebLink string `json:"url"`
|
||||
}
|
||||
|
||||
func (dto MediaLoFiDTO) ConvertDTOToModel() MediaLoFi {
|
||||
model := MediaLoFi{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
FileName: dto.FileName,
|
||||
Review: dto.Review,
|
||||
ShouldDownload: dto.ShouldDownload,
|
||||
Title: dto.Title,
|
||||
WebLink: dto.WebLink,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func (source MediaLoFiDTO) Equals(target MediaLoFiDTO) bool {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info("MediaLoFiDTO#Equals", "id", source.ID)
|
||||
}
|
||||
equals := true
|
||||
if source.Title != target.Title {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info("MediaLoFiDTO#Equals: Title changed")
|
||||
}
|
||||
equals = false
|
||||
}
|
||||
if source.WebLink != target.WebLink {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info("MediaLoFiDTO#Equals: WebLink changed")
|
||||
}
|
||||
equals = false
|
||||
}
|
||||
if source.Version != target.Version {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info("MediaLoFiDTO#Equals: Version changed")
|
||||
}
|
||||
equals = false
|
||||
}
|
||||
if source.FileName != target.FileName {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info("MediaLoFiDTO#Equals: FileName changed")
|
||||
}
|
||||
equals = false
|
||||
}
|
||||
if source.Review != target.Review {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info("MediaLoFiDTO#Equals: Review changed")
|
||||
}
|
||||
equals = false
|
||||
}
|
||||
if source.ShouldDownload != target.ShouldDownload {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info("MediaLoFiDTO#Equals: ShouldDownload changed")
|
||||
}
|
||||
equals = false
|
||||
}
|
||||
return equals
|
||||
}
|
||||
|
||||
type MediaLoFiDTOList []MediaLoFiDTO
|
||||
|
||||
func (source MediaLoFiDTOList) GetMediaLofi(lofi_id string) *MediaLoFiDTO {
|
||||
for _, lofi := range source {
|
||||
if lofi.ID == lofi_id {
|
||||
return &lofi
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (source *MediaLoFiDTOList) CompareIds(target *MediaLoFiDTOList) (missing, obsolete, changed []string) {
|
||||
sources := make(map[string]MediaLoFiDTO, len(*source))
|
||||
targets := make(map[string]MediaLoFiDTO, len(*target))
|
||||
for _, source := range *source {
|
||||
sources[source.ID] = source
|
||||
}
|
||||
for _, target := range *target {
|
||||
targets[target.ID] = target
|
||||
}
|
||||
// iterate source IDs
|
||||
for id := range sources {
|
||||
if _, ok := targets[id]; ok {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info(fmt.Sprintf("ID %s found in both lists", id))
|
||||
}
|
||||
if !sources[id].Equals(targets[id]) {
|
||||
changed = append(changed, id)
|
||||
}
|
||||
} else {
|
||||
missing = append(missing, id)
|
||||
}
|
||||
}
|
||||
for id := range targets {
|
||||
if _, ok := sources[id]; ok {
|
||||
slog.Debug(fmt.Sprintf("ID %s found in both lists", id))
|
||||
} else {
|
||||
obsolete = append(obsolete, id)
|
||||
}
|
||||
}
|
||||
slog.Info("CompareIds", "missing", len(missing), "obsolete", len(obsolete), "changed", len(changed))
|
||||
slog.Debug("CompareIds", "missing", missing, "obsolete", obsolete)
|
||||
return missing, obsolete, changed
|
||||
}
|
||||
|
||||
func ConvertMediaLoFisToDtos(media_lofis []MediaLoFi) MediaLoFiDTOList {
|
||||
dtos := make(MediaLoFiDTOList, len(media_lofis))
|
||||
for i, media_lofi := range media_lofis {
|
||||
dtos[i] = media_lofi.ConvertMediaLoFiToDTO()
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"kontor-api-echo/internal/config"
|
||||
"kontor-api-echo/internal/helpers"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type MediaMusic struct {
|
||||
bun.BaseModel `bun:"table:media_music"`
|
||||
|
||||
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"`
|
||||
WebLink string `bun:"url,unique:url"`
|
||||
Review bool `bun:"review"`
|
||||
ShouldDownload bool `bun:"should_download"`
|
||||
Title string `bun:"title"`
|
||||
FileName string `bun:"file_name"`
|
||||
}
|
||||
|
||||
func (media_music *MediaMusic) Update(update MediaMusicDTO) {
|
||||
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
|
||||
}
|
||||
|
||||
func (media_music *MediaMusic) ConvertMediaMusicToDTO() MediaMusicDTO {
|
||||
dto := MediaMusicDTO{
|
||||
ID: media_music.ID,
|
||||
CreatedAt: helpers.KontorTime{Time: media_music.CreatedAt},
|
||||
UpdatedAt: helpers.KontorTime{Time: media_music.UpdatedAt},
|
||||
DeletedAt: media_music.DeletedAt,
|
||||
Version: media_music.Version,
|
||||
WebLink: media_music.WebLink,
|
||||
Review: media_music.Review,
|
||||
ShouldDownload: media_music.ShouldDownload,
|
||||
Title: media_music.Title,
|
||||
FileName: media_music.FileName,
|
||||
}
|
||||
return dto
|
||||
}
|
||||
|
||||
type MediaMusicAdd struct {
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type MediaMusicForm struct {
|
||||
Title string `form:"title" binding:"required"`
|
||||
Url string `form:"url" binding:"required"`
|
||||
}
|
||||
|
||||
func (form *MediaMusicForm) ConvertFormToMediaMusicDTO() MediaMusicDTO {
|
||||
media_music := MediaMusicDTO{}
|
||||
return media_music
|
||||
}
|
||||
|
||||
type MediaMusicDTO 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"`
|
||||
FileName string `json:"file_name"`
|
||||
Review bool `json:"review"`
|
||||
ShouldDownload bool `json:"should_download"`
|
||||
Title string `json:"title"`
|
||||
WebLink string `json:"url"`
|
||||
}
|
||||
|
||||
func (dto MediaMusicDTO) ConvertDTOToModel() MediaMusic {
|
||||
model := MediaMusic{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
FileName: dto.FileName,
|
||||
Review: dto.Review,
|
||||
ShouldDownload: dto.ShouldDownload,
|
||||
Title: dto.Title,
|
||||
WebLink: dto.WebLink,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func (source MediaMusicDTO) Equals(target MediaMusicDTO) bool {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info("MediaMusicDTO#Equals", "id", source.ID)
|
||||
}
|
||||
equals := true
|
||||
if source.Title != target.Title {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info("MediaMusicDTO#Equals: Title changed")
|
||||
}
|
||||
equals = false
|
||||
}
|
||||
if source.WebLink != target.WebLink {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info("MediaMusicDTO#Equals: WebLink changed")
|
||||
}
|
||||
equals = false
|
||||
}
|
||||
if source.Version != target.Version {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info("MediaMusicDTO#Equals: Version changed")
|
||||
}
|
||||
equals = false
|
||||
}
|
||||
if source.FileName != target.FileName {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info("MediaMusicDTO#Equals: FileName changed")
|
||||
}
|
||||
equals = false
|
||||
}
|
||||
if source.Review != target.Review {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info("MediaMusicDTO#Equals: Review changed")
|
||||
}
|
||||
equals = false
|
||||
}
|
||||
if source.ShouldDownload != target.ShouldDownload {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info("MediaMusicDTO#Equals: ShouldDownload changed")
|
||||
}
|
||||
equals = false
|
||||
}
|
||||
return equals
|
||||
}
|
||||
|
||||
type MediaMusicDTOList []MediaMusicDTO
|
||||
|
||||
func (source MediaMusicDTOList) GetMediaMusic(music_id string) *MediaMusicDTO {
|
||||
for _, music := range source {
|
||||
if music.ID == music_id {
|
||||
return &music
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (source *MediaMusicDTOList) CompareIds(target *MediaMusicDTOList) (missing, obsolete, changed []string) {
|
||||
sources := make(map[string]MediaMusicDTO, len(*source))
|
||||
targets := make(map[string]MediaMusicDTO, len(*target))
|
||||
for _, source := range *source {
|
||||
sources[source.ID] = source
|
||||
}
|
||||
for _, target := range *target {
|
||||
targets[target.ID] = target
|
||||
}
|
||||
// iterate source IDs
|
||||
for id := range sources {
|
||||
if _, ok := targets[id]; ok {
|
||||
if config.Verbose > 1 {
|
||||
slog.Info(fmt.Sprintf("ID %s found in both lists", id))
|
||||
}
|
||||
if !sources[id].Equals(targets[id]) {
|
||||
changed = append(changed, id)
|
||||
}
|
||||
} else {
|
||||
missing = append(missing, id)
|
||||
}
|
||||
}
|
||||
for id := range targets {
|
||||
if _, ok := sources[id]; ok {
|
||||
slog.Debug(fmt.Sprintf("ID %s found in both lists", id))
|
||||
} else {
|
||||
obsolete = append(obsolete, id)
|
||||
}
|
||||
}
|
||||
slog.Info("CompareIds", "missing", len(missing), "obsolete", len(obsolete), "changed", len(changed))
|
||||
slog.Debug("CompareIds", "missing", missing, "obsolete", obsolete)
|
||||
return missing, obsolete, changed
|
||||
}
|
||||
|
||||
func ConvertMediaMusicsToDtos(media_musics []MediaMusic) MediaMusicDTOList {
|
||||
dtos := make(MediaMusicDTOList, len(media_musics))
|
||||
for i, media_music := range media_musics {
|
||||
dtos[i] = media_music.ConvertMediaMusicToDTO()
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
@@ -1,24 +1,98 @@
|
||||
package schema
|
||||
package models
|
||||
|
||||
import (
|
||||
"kontor-api-echo/internal/helpers"
|
||||
"time"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type MediaVideo struct {
|
||||
bun.BaseModel `bun:"table:media_article"`
|
||||
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"`
|
||||
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"`
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user