add methods in Repository and Model for importing data
This commit is contained in:
@@ -37,6 +37,23 @@ type MailAccountDTO struct {
|
|||||||
StartTLS bool `json:"start_tls"`
|
StartTLS bool `json:"start_tls"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dto MailAccountDTO) ConvertDTOToModel() MailAccount {
|
||||||
|
model := MailAccount{
|
||||||
|
ID: dto.ID,
|
||||||
|
CreatedAt: dto.CreatedAt.Time,
|
||||||
|
UpdatedAt: dto.UpdatedAt.Time,
|
||||||
|
DeletedAt: dto.DeletedAt,
|
||||||
|
Version: dto.Version,
|
||||||
|
Host: dto.Host,
|
||||||
|
Port: dto.Port,
|
||||||
|
Protocol: dto.Protocol,
|
||||||
|
UserName: dto.UserName,
|
||||||
|
Password: dto.Password,
|
||||||
|
StartTLS: dto.StartTLS,
|
||||||
|
}
|
||||||
|
return model
|
||||||
|
}
|
||||||
|
|
||||||
func ConvertMailAccountsToDtos(mailaccounts []MailAccount) []MailAccountDTO {
|
func ConvertMailAccountsToDtos(mailaccounts []MailAccount) []MailAccountDTO {
|
||||||
dtos := make([]MailAccountDTO, len(mailaccounts))
|
dtos := make([]MailAccountDTO, len(mailaccounts))
|
||||||
for i, mailaccount := range mailaccounts {
|
for i, mailaccount := range mailaccounts {
|
||||||
|
|||||||
@@ -36,6 +36,19 @@ type MediaActorDTO struct {
|
|||||||
WebLink string `json:"url"`
|
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 {
|
type MediaActorAdd struct {
|
||||||
WebLink string `json:"url"`
|
WebLink string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,19 @@ type MediaActorFileDTO struct {
|
|||||||
MediaFileID *string `json:"media_file_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 {
|
func ConvertMediaActorFilesToDtos(actor_files []MediaActorFile) []MediaActorFileDTO {
|
||||||
dtos := make([]MediaActorFileDTO, len(actor_files))
|
dtos := make([]MediaActorFileDTO, len(actor_files))
|
||||||
for i, actor_file := range actor_files {
|
for i, actor_file := range actor_files {
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"kontor-api-gin/internal/helpers"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
type MediaArticle struct {
|
type MediaArticle struct {
|
||||||
ID string `gorm:"type:string;primary_key;" json:"id"`
|
ID string `gorm:"type:string;primary_key;" json:"id"`
|
||||||
@@ -13,34 +16,53 @@ type MediaArticle struct {
|
|||||||
WebLink string `gorm:"column:url" json:"url"`
|
WebLink string `gorm:"column:url" json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
func (media_article *MediaArticle) TableName() string {
|
func (media_article *MediaArticle) TableName() string {
|
||||||
return "media_article"
|
return "media_article"
|
||||||
}
|
}
|
||||||
|
|
||||||
type MediaArticleDTO struct {
|
type MediaArticleDTO struct {
|
||||||
ID string `json:"id" binding:"required"`
|
ID string `json:"id" binding:"required"`
|
||||||
CreatedAt time.Time `json:"created_date"`
|
CreatedAt helpers.KontorTime `json:"created_date"`
|
||||||
UpdatedAt time.Time `json:"last_modified_date"`
|
UpdatedAt helpers.KontorTime `json:"last_modified_date"`
|
||||||
DeletedAt *time.Time `json:"deleted_date"`
|
DeletedAt *time.Time `json:"deleted_date"`
|
||||||
Version int `json:"version"`
|
Version int `json:"version"`
|
||||||
Review bool `json:"review"`
|
Review bool `json:"review"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
WebLink string `json:"url"`
|
WebLink string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConvertMediaArticlesToDtos(media_articles []MediaArticle) []MediaArticleDTO {
|
func (dto MediaArticleDTO) ConvertDTOToModel() MediaArticle {
|
||||||
dtos := make([]MediaArticleDTO, len(media_articles))
|
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 {
|
for i, media_article := range media_articles {
|
||||||
dtos[i] = MediaArticleDTO{
|
dtos[i] = media_article.ConvertMediaArticleToDTO()
|
||||||
ID: media_article.ID,
|
|
||||||
CreatedAt: media_article.CreatedAt,
|
|
||||||
UpdatedAt: media_article.UpdatedAt,
|
|
||||||
DeletedAt: media_article.DeletedAt,
|
|
||||||
Version: media_article.Version,
|
|
||||||
Review: media_article.Review,
|
|
||||||
Title: media_article.Title,
|
|
||||||
WebLink: media_article.WebLink,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return dtos
|
return dtos
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,24 @@ type MediaFileDTO struct {
|
|||||||
ShouldDownload bool `json:"should_download"`
|
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 {
|
func ConvertMediaFilesToDtos(media_files []MediaFile) []MediaFileDTO {
|
||||||
dtos := make([]MediaFileDTO, len(media_files))
|
dtos := make([]MediaFileDTO, len(media_files))
|
||||||
for i, media_file := range media_files {
|
for i, media_file := range media_files {
|
||||||
|
|||||||
@@ -79,6 +79,22 @@ type MediaLoFiDTO struct {
|
|||||||
WebLink string `json:"url"`
|
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 {
|
func (source MediaLoFiDTO) Equals(target MediaLoFiDTO) bool {
|
||||||
if config.Verbose > 1 {
|
if config.Verbose > 1 {
|
||||||
slog.Info("MediaLoFiDTO#Equals", "id", source.ID)
|
slog.Info("MediaLoFiDTO#Equals", "id", source.ID)
|
||||||
|
|||||||
@@ -79,6 +79,22 @@ type MediaMusicDTO struct {
|
|||||||
WebLink string `json:"url"`
|
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 {
|
func (source MediaMusicDTO) Equals(target MediaMusicDTO) bool {
|
||||||
if config.Verbose > 1 {
|
if config.Verbose > 1 {
|
||||||
slog.Info("MediaMusicDTO#Equals", "id", source.ID)
|
slog.Info("MediaMusicDTO#Equals", "id", source.ID)
|
||||||
|
|||||||
@@ -60,6 +60,20 @@ type MediaVideoDTO struct {
|
|||||||
ShouldDownload bool `json:"should_download"`
|
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 {
|
func ConvertMediaVideosToDtos(media_videos []MediaVideo) []MediaVideoDTO {
|
||||||
dtos := make([]MediaVideoDTO, len(media_videos))
|
dtos := make([]MediaVideoDTO, len(media_videos))
|
||||||
for i, media_video := range media_videos {
|
for i, media_video := range media_videos {
|
||||||
|
|||||||
@@ -24,13 +24,32 @@ func (token *Token) TableName() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TokenDTO struct {
|
type TokenDTO struct {
|
||||||
ID string `json:"id" binding:"required"`
|
ID string `json:"id" binding:"required"`
|
||||||
CreatedAt helpers.KontorTime `json:"created_date"`
|
CreatedAt helpers.KontorTime `json:"created_date"`
|
||||||
UpdatedAt helpers.KontorTime `json:"last_modified_date"`
|
UpdatedAt helpers.KontorTime `json:"last_modified_date"`
|
||||||
DeletedAt *time.Time `json:"deleted_date.omitempty"`
|
DeletedAt *time.Time `json:"deleted_date,omitempty"`
|
||||||
Version int `json:"version"`
|
Version int `json:"version"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
ProfileID *string `json:"profile_id"`
|
Name string `json:"name"`
|
||||||
|
LastUsedAt *time.Time `json:"last_used_date"`
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
|
ProfileID *string `json:"profile_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dto TokenDTO) ConvertDTOToModel() Token {
|
||||||
|
model := Token{
|
||||||
|
ID: dto.ID,
|
||||||
|
CreatedAt: dto.CreatedAt.Time,
|
||||||
|
UpdatedAt: dto.UpdatedAt.Time,
|
||||||
|
DeletedAt: dto.DeletedAt,
|
||||||
|
Version: dto.Version,
|
||||||
|
Token: dto.Token,
|
||||||
|
Name: dto.Name,
|
||||||
|
LastUsedAt: *dto.LastUsedAt,
|
||||||
|
Enabled: dto.Enabled,
|
||||||
|
ProfileID: dto.ProfileID,
|
||||||
|
}
|
||||||
|
return model
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConvertTokensToDtos(tokens []Token) []TokenDTO {
|
func ConvertTokensToDtos(tokens []Token) []TokenDTO {
|
||||||
|
|||||||
@@ -12,6 +12,29 @@ type MailAccountRepository struct {
|
|||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repository *MailAccountRepository) Import(dtos models.MailAccountDTOList) {
|
||||||
|
slog.Info("MailAccountRepository#Import")
|
||||||
|
for index, dto := range dtos {
|
||||||
|
slog.Info("importing", "index", index, "profile", dto)
|
||||||
|
model := dto.ConvertDTOToModel()
|
||||||
|
existing_item := models.MailAccount{ID: dto.ID}
|
||||||
|
result_existing := repository.db.First(&existing_item)
|
||||||
|
if result_existing.Error != nil {
|
||||||
|
slog.Info("check existing id: not found - inserting")
|
||||||
|
result := repository.db.Create(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during import", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
slog.Info("check existing id: found - updating")
|
||||||
|
result := repository.db.Save(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during updating", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewMailAccountRepository(db *gorm.DB) *MailAccountRepository {
|
func NewMailAccountRepository(db *gorm.DB) *MailAccountRepository {
|
||||||
repository := &MailAccountRepository{db: db}
|
repository := &MailAccountRepository{db: db}
|
||||||
return repository
|
return repository
|
||||||
|
|||||||
@@ -13,6 +13,29 @@ type MediaActorRepository struct {
|
|||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repository *MediaActorRepository) Import(dtos models.MediaActorDTOList) {
|
||||||
|
slog.Info("MediaActorRepository#Import")
|
||||||
|
for index, dto := range dtos {
|
||||||
|
slog.Info("importing", "index", index, "video", dto)
|
||||||
|
model := dto.ConvertDTOToModel()
|
||||||
|
existing_item := models.MediaActor{ID: dto.ID}
|
||||||
|
result_existing := repository.db.First(&existing_item)
|
||||||
|
if result_existing.Error != nil {
|
||||||
|
slog.Info("check existing id: not found - inserting")
|
||||||
|
result := repository.db.Create(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during import", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
slog.Info("check existing id: found - updating")
|
||||||
|
result := repository.db.Save(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during updating", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewMediaActorRepository(db *gorm.DB) *MediaActorRepository {
|
func NewMediaActorRepository(db *gorm.DB) *MediaActorRepository {
|
||||||
repo := &MediaActorRepository{db: db}
|
repo := &MediaActorRepository{db: db}
|
||||||
return repo
|
return repo
|
||||||
|
|||||||
@@ -13,6 +13,29 @@ type MediaActorFileRepository struct {
|
|||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repository *MediaActorFileRepository) Import(dtos models.MediaActorFileDTOList) {
|
||||||
|
slog.Info("MediaActorFileRepository#Import")
|
||||||
|
for index, dto := range dtos {
|
||||||
|
slog.Info("importing", "index", index, "video", dto)
|
||||||
|
model := dto.ConvertDTOToModel()
|
||||||
|
existing_item := models.MediaActorFile{ID: dto.ID}
|
||||||
|
result_existing := repository.db.First(&existing_item)
|
||||||
|
if result_existing.Error != nil {
|
||||||
|
slog.Info("check existing id: not found - inserting")
|
||||||
|
result := repository.db.Create(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during import", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
slog.Info("check existing id: found - updating")
|
||||||
|
result := repository.db.Save(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during updating", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewMediaActorFileRepository(db *gorm.DB) *MediaActorFileRepository {
|
func NewMediaActorFileRepository(db *gorm.DB) *MediaActorFileRepository {
|
||||||
repo := &MediaActorFileRepository{db: db}
|
repo := &MediaActorFileRepository{db: db}
|
||||||
return repo
|
return repo
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"kontor-api-gin/internal/models"
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MediaArticleRepository struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repository *MediaArticleRepository) Import(dtos models.MediaArticleDTOList) {
|
||||||
|
slog.Info("MediaArticleRepository#Import")
|
||||||
|
for index, dto := range dtos {
|
||||||
|
slog.Info("importing", "index", index, "profile", dto)
|
||||||
|
model := dto.ConvertDTOToModel()
|
||||||
|
existing_item := models.MediaArticle{ID: dto.ID}
|
||||||
|
result_existing := repository.db.First(&existing_item)
|
||||||
|
if result_existing.Error != nil {
|
||||||
|
slog.Info("check existing id: not found - inserting")
|
||||||
|
result := repository.db.Create(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during import", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
slog.Info("check existing id: found - updating")
|
||||||
|
result := repository.db.Save(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during updating", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMediaArticleRepository(db *gorm.DB) *MediaArticleRepository {
|
||||||
|
repo := &MediaArticleRepository{db: db}
|
||||||
|
return repo
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repository *MediaArticleRepository) FindAll(context context.Context) ([]models.MediaArticle, error) {
|
||||||
|
var articles []models.MediaArticle
|
||||||
|
|
||||||
|
result := repository.db.Find(&articles)
|
||||||
|
slog.Info("MediaArticleRepository#FindAll", "count", result.RowsAffected)
|
||||||
|
|
||||||
|
return articles, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repository *MediaArticleRepository) GetById(context context.Context, id string) (*models.MediaArticle, error) {
|
||||||
|
var file = models.MediaArticle{ID: id}
|
||||||
|
slog.Info("MediaArticleRepository#GetById", "id", id)
|
||||||
|
result := repository.db.First(&file)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("MediaArticleRepository#GetById", "error", result.Error.Error())
|
||||||
|
return nil, result.Error
|
||||||
|
}
|
||||||
|
return &file, result.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repository *MediaArticleRepository) Add(context context.Context, url string) (*models.MediaArticle, error) {
|
||||||
|
slog.Info("MediaArticleRepository#Add", "url", url)
|
||||||
|
return nil, fmt.Errorf("unimplemented method MediaArticleRepository#Add")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repository *MediaArticleRepository) Delete(context context.Context, id string) error {
|
||||||
|
var file = models.MediaArticle{ID: id}
|
||||||
|
slog.Info("MediaArticleRepository#Delete", "id", id)
|
||||||
|
result := repository.db.Delete(&file)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("MediaArticleRepository#Delete", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
return result.Error
|
||||||
|
}
|
||||||
@@ -13,6 +13,29 @@ type MediaFileRepository struct {
|
|||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repository *MediaFileRepository) Import(dtos models.MediaFileDTOList) {
|
||||||
|
slog.Info("MediaFileRepository#Import")
|
||||||
|
for index, dto := range dtos {
|
||||||
|
slog.Info("importing", "index", index, "video", dto)
|
||||||
|
model := dto.ConvertDTOToModel()
|
||||||
|
existing_item := models.MediaFile{ID: dto.ID}
|
||||||
|
result_existing := repository.db.First(&existing_item)
|
||||||
|
if result_existing.Error != nil {
|
||||||
|
slog.Info("check existing id: not found - inserting")
|
||||||
|
result := repository.db.Create(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during import", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
slog.Info("check existing id: found - updating")
|
||||||
|
result := repository.db.Save(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during updating", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewMediaFileRepository(db *gorm.DB) *MediaFileRepository {
|
func NewMediaFileRepository(db *gorm.DB) *MediaFileRepository {
|
||||||
repo := &MediaFileRepository{db: db}
|
repo := &MediaFileRepository{db: db}
|
||||||
return repo
|
return repo
|
||||||
|
|||||||
@@ -17,6 +17,29 @@ type MediaLoFiRepository struct {
|
|||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repository *MediaLoFiRepository) Import(dtos models.MediaLoFiDTOList) {
|
||||||
|
slog.Info("MediaLoFiRepository#Import")
|
||||||
|
for index, dto := range dtos {
|
||||||
|
slog.Info("importing", "index", index, "video", dto)
|
||||||
|
model := dto.ConvertDTOToModel()
|
||||||
|
existing_item := models.MediaLoFi{ID: dto.ID}
|
||||||
|
result_existing := repository.db.First(&existing_item)
|
||||||
|
if result_existing.Error != nil {
|
||||||
|
slog.Info("check existing id: not found - inserting")
|
||||||
|
result := repository.db.Create(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during import", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
slog.Info("check existing id: found - updating")
|
||||||
|
result := repository.db.Save(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during updating", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewMediaLoFiRepository(db *gorm.DB) *MediaLoFiRepository {
|
func NewMediaLoFiRepository(db *gorm.DB) *MediaLoFiRepository {
|
||||||
repo := &MediaLoFiRepository{db: db}
|
repo := &MediaLoFiRepository{db: db}
|
||||||
return repo
|
return repo
|
||||||
|
|||||||
@@ -17,6 +17,29 @@ type MediaMusicRepository struct {
|
|||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repository *MediaMusicRepository) Import(dtos models.MediaMusicDTOList) {
|
||||||
|
slog.Info("MediaMusicRepository#Import")
|
||||||
|
for index, dto := range dtos {
|
||||||
|
slog.Info("importing", "index", index, "video", dto)
|
||||||
|
model := dto.ConvertDTOToModel()
|
||||||
|
existing_item := models.MediaMusic{ID: dto.ID}
|
||||||
|
result_existing := repository.db.First(&existing_item)
|
||||||
|
if result_existing.Error != nil {
|
||||||
|
slog.Info("check existing id: not found - inserting")
|
||||||
|
result := repository.db.Create(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during import", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
slog.Info("check existing id: found - updating")
|
||||||
|
result := repository.db.Save(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during updating", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewMediaMusicRepository(db *gorm.DB) *MediaMusicRepository {
|
func NewMediaMusicRepository(db *gorm.DB) *MediaMusicRepository {
|
||||||
repo := &MediaMusicRepository{db: db}
|
repo := &MediaMusicRepository{db: db}
|
||||||
return repo
|
return repo
|
||||||
|
|||||||
+23
@@ -17,6 +17,29 @@ type MediaVideoRepository struct {
|
|||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repository *MediaVideoRepository) Import(dtos models.MediaVideoDTOList) {
|
||||||
|
slog.Info("MediaVideoRepository#Import")
|
||||||
|
for index, dto := range dtos {
|
||||||
|
slog.Info("importing", "index", index, "video", dto)
|
||||||
|
model := dto.ConvertDTOToModel()
|
||||||
|
existing_item := models.MediaVideo{ID: dto.ID}
|
||||||
|
result_existing := repository.db.First(&existing_item)
|
||||||
|
if result_existing.Error != nil {
|
||||||
|
slog.Info("check existing id: not found - inserting")
|
||||||
|
result := repository.db.Create(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during import", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
slog.Info("check existing id: found - updating")
|
||||||
|
result := repository.db.Save(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during updating", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewMediaVideoRepository(db *gorm.DB) *MediaVideoRepository {
|
func NewMediaVideoRepository(db *gorm.DB) *MediaVideoRepository {
|
||||||
repo := &MediaVideoRepository{db: db}
|
repo := &MediaVideoRepository{db: db}
|
||||||
return repo
|
return repo
|
||||||
@@ -12,6 +12,29 @@ type TokenRepository struct {
|
|||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repository *TokenRepository) Import(dtos models.TokenDTOList) {
|
||||||
|
slog.Info("TokenRepository#Import")
|
||||||
|
for index, dto := range dtos {
|
||||||
|
slog.Info("importing", "index", index, "video", dto)
|
||||||
|
model := dto.ConvertDTOToModel()
|
||||||
|
existing_item := models.Token{ID: dto.ID}
|
||||||
|
result_existing := repository.db.First(&existing_item)
|
||||||
|
if result_existing.Error != nil {
|
||||||
|
slog.Info("check existing id: not found - inserting")
|
||||||
|
result := repository.db.Create(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during import", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
slog.Info("check existing id: found - updating")
|
||||||
|
result := repository.db.Save(&model)
|
||||||
|
if result.Error != nil {
|
||||||
|
slog.Info("error during updating", "error", result.Error.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewTokenRepository(db *gorm.DB) *TokenRepository {
|
func NewTokenRepository(db *gorm.DB) *TokenRepository {
|
||||||
repository := &TokenRepository{db: db}
|
repository := &TokenRepository{db: db}
|
||||||
return repository
|
return repository
|
||||||
|
|||||||
Reference in New Issue
Block a user