add methods in Repository an dModel for importing data
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 6s
Gitea Actions Demo / build-and-test (push) Failing after 13m11s

This commit is contained in:
Thomas Peetz
2026-10-30 00:19:25 +01:00
parent 0750621b96
commit 8706b3880f
25 changed files with 486 additions and 0 deletions
+43
View File
@@ -60,6 +60,7 @@ var importCmd = &cobra.Command{
models.MediaArticle{}, models.MediaArticle{},
models.MediaVideo{}, models.MediaVideo{},
models.MediaLoFi{}, models.MediaLoFi{},
models.MediaMusic{},
models.MediaFile{}, models.MediaFile{},
models.MediaActor{}, models.MediaActor{},
models.MediaActorFile{}, models.MediaActorFile{},
@@ -100,6 +101,48 @@ var importCmd = &cobra.Command{
comicRepository.Import(data.Comic) comicRepository.Import(data.Comic)
volumeRepository := repository.NewVolumeRepository(db) volumeRepository := repository.NewVolumeRepository(db)
volumeRepository.Import(data.Volume) volumeRepository.Import(data.Volume)
storyArcRepository := repository.NewStoryArcRepository(db)
storyArcRepository.Import(data.StoryArc)
issueRepository := repository.NewIssueRepository(db)
issueRepository.Import(data.Issue)
tradePaperbackRepository := repository.NewTradePaperbackRepository(db)
tradePaperbackRepository.Import(data.TradePaperback)
comicWorkRepository := repository.NewComicworkRepository(db)
comicWorkRepository.Import(data.ComicWork)
issueWorkRepository := repository.NewIssueworkRepository(db)
issueWorkRepository.Import(data.IssueWork)
articleRepository := repository.NewArticleRepository(db)
articleRepository.Import(data.Article)
bookshelfPublisherRepository := repository.NewBookshelfPublisherRepository(db)
bookshelfPublisherRepository.Import(data.BookshelfPublisher)
bookRepository := repository.NewBookRepository(db)
bookRepository.Import(data.Book)
authorRepository := repository.NewAuthorRepository(db)
authorRepository.Import(data.Author)
articleAuthorRepository := repository.NewArticleAuthorRepository(db)
articleAuthorRepository.Import(data.ArticleAuthor)
bookAuthorRepository := repository.NewBookAuthorRepository(db)
bookAuthorRepository.Import(data.BookAuthor)
mediaArticleRepository := repository.NewMediaArticleRepository(db)
mediaArticleRepository.Import(data.MediaArticle)
mediaVideoRepository := repository.NewMediaVideoRepository(db)
mediaVideoRepository.Import(data.MediaVideo)
mediaLoFiRepository := repository.NewMediaLoFiRepository(db)
mediaLoFiRepository.Import(data.MediaLoFi)
mediaMusicRepository := repository.NewMediaMusicRepository(db)
mediaMusicRepository.Import(data.MediaMusic)
mediaFileRepository := repository.NewMediaFileRepository(db)
mediaFileRepository.Import(data.MediaFile)
mediaActorRepository := repository.NewMediaActorRepository(db)
mediaActorRepository.Import(data.MediaActor)
mediaActorFileRepository := repository.NewMediaActorFileRepository(db)
mediaActorFileRepository.Import(data.MediaActorFile)
tokenRepository := repository.NewTokenRepository(db)
tokenRepository.Import(data.Token)
mailAccountRepository := repository.NewMailAccountRepository(db)
mailAccountRepository.Import(data.MailAccount)
mailRepository := repository.NewMailRepository(db)
mailRepository.Import(data.Mail)
slog.Info("importing Profiles", "count", len(data.Profile)) slog.Info("importing Profiles", "count", len(data.Profile))
slog.Info("importing Permissions", "count", len(data.Permission)) slog.Info("importing Permissions", "count", len(data.Permission))
+12
View File
@@ -28,6 +28,18 @@ type ArticleDTO struct {
Title string `json:"title"` Title string `json:"title"`
} }
func (dto ArticleDTO) ConvertDTOToModel() Article {
model := Article{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
Title: dto.Title,
}
return model
}
func ConvertArticlesToDtos(articles []Article) []ArticleDTO { func ConvertArticlesToDtos(articles []Article) []ArticleDTO {
dtos := make([]ArticleDTO, len(articles)) dtos := make([]ArticleDTO, len(articles))
for i, article := range articles { for i, article := range articles {
@@ -31,6 +31,19 @@ type ArticleAuthorDTO struct {
AuthorID *string `json:"author_id"` AuthorID *string `json:"author_id"`
} }
func (dto ArticleAuthorDTO) ConvertDTOToModel() ArticleAuthor {
model := ArticleAuthor{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
ArticleID: dto.ArticleID,
AuthorID: dto.AuthorID,
}
return model
}
func ConvertArticleAuthorsToDtos(article_authors []ArticleAuthor) []ArticleAuthorDTO { func ConvertArticleAuthorsToDtos(article_authors []ArticleAuthor) []ArticleAuthorDTO {
dtos := make([]ArticleAuthorDTO, len(article_authors)) dtos := make([]ArticleAuthorDTO, len(article_authors))
for i, article_author := range article_authors { for i, article_author := range article_authors {
+13
View File
@@ -31,6 +31,19 @@ type AuthorDTO struct {
LastName string `json:"last_name"` LastName string `json:"last_name"`
} }
func (dto AuthorDTO) ConvertDTOToModel() Author {
model := Author{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
FirstName: dto.FirstName,
LastName: dto.LastName,
}
return model
}
func ConvertAuthorsToDtos(authors []Author) []AuthorDTO { func ConvertAuthorsToDtos(authors []Author) []AuthorDTO {
dtos := make([]AuthorDTO, len(authors)) dtos := make([]AuthorDTO, len(authors))
for i, author := range authors { for i, author := range authors {
+12
View File
@@ -32,6 +32,18 @@ type BookDTO struct {
Title string `json:"title"` Title string `json:"title"`
} }
func (dto BookDTO) ConvertDTOToModel() Book {
model := Book{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
Title: dto.Title,
}
return model
}
func ConvertBooksToDtos(books []Book) []BookDTO { func ConvertBooksToDtos(books []Book) []BookDTO {
dtos := make([]BookDTO, len(books)) dtos := make([]BookDTO, len(books))
for i, book := range books { for i, book := range books {
+13
View File
@@ -31,6 +31,19 @@ type BookAuthorDTO struct {
AuthorID *string `json:"author_id"` AuthorID *string `json:"author_id"`
} }
func (dto BookAuthorDTO) ConvertDTOToModel() BookAuthor {
model := BookAuthor{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
BookID: dto.BookID,
AuthorID: dto.AuthorID,
}
return model
}
func ConvertBookAuthorsToDtos(book_authors []BookAuthor) []BookAuthorDTO { func ConvertBookAuthorsToDtos(book_authors []BookAuthor) []BookAuthorDTO {
dtos := make([]BookAuthorDTO, len(book_authors)) dtos := make([]BookAuthorDTO, len(book_authors))
for i, book_author := range book_authors { for i, book_author := range book_authors {
@@ -28,6 +28,18 @@ type BookshelfPublisherDTO struct {
Name string `json:"name"` Name string `json:"name"`
} }
func (dto BookshelfPublisherDTO) ConvertDTOToModel() BookshelfPublisher {
model := BookshelfPublisher{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
Name: dto.Name,
}
return model
}
func ConvertBookshelfPublishersToDtos(publishers []BookshelfPublisher) []BookshelfPublisherDTO { func ConvertBookshelfPublishersToDtos(publishers []BookshelfPublisher) []BookshelfPublisherDTO {
dtos := make([]BookshelfPublisherDTO, len(publishers)) dtos := make([]BookshelfPublisherDTO, len(publishers))
for i, publisher := range publishers { for i, publisher := range publishers {
+14
View File
@@ -34,6 +34,20 @@ type ComicworkDTO struct {
WorkTypeID *string `json:"work_type_id"` WorkTypeID *string `json:"work_type_id"`
} }
func (dto ComicworkDTO) ConvertDTOToModel() ComicWork {
model := ComicWork{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
ComicID: dto.ComicID,
ArtistID: dto.ArtistID,
WorkTypeID: dto.WorkTypeID,
}
return model
}
func ConvertComicworksToDtos(comicworks []ComicWork) []ComicworkDTO { func ConvertComicworksToDtos(comicworks []ComicWork) []ComicworkDTO {
dtos := make([]ComicworkDTO, len(comicworks)) dtos := make([]ComicworkDTO, len(comicworks))
for i, comicwork := range comicworks { for i, comicwork := range comicworks {
+19
View File
@@ -44,6 +44,25 @@ type IssueDTO struct {
StoryArcID *string `json:"story_arc_id"` StoryArcID *string `json:"story_arc_id"`
} }
func (dto IssueDTO) ConvertDTOToModel() Issue {
model := Issue{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
IssueNumber: dto.IssueNumber,
Title: dto.Title,
PublishedOn: dto.PublishedOn.Time,
InStock: dto.InStock,
IsRead: dto.IsRead,
ComicID: dto.ComicID,
VolumeID: dto.VolumeID,
StoryArcID: dto.StoryArcID,
}
return model
}
func ConvertIssuesToDtos(issues []Issue) []IssueDTO { func ConvertIssuesToDtos(issues []Issue) []IssueDTO {
dtos := make([]IssueDTO, len(issues)) dtos := make([]IssueDTO, len(issues))
for i, issue := range issues { for i, issue := range issues {
+14
View File
@@ -34,6 +34,20 @@ type IssueworkDTO struct {
WorkTypeID *string `json:"work_type_id"` WorkTypeID *string `json:"work_type_id"`
} }
func (dto IssueworkDTO) ConvertDTOToModel() IssueWork {
model := IssueWork{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
IssueID: dto.IssueID,
ArtistID: dto.ArtistID,
WorkTypeID: dto.WorkTypeID,
}
return model
}
func ConvertIssueworksToDtos(issueworks []IssueWork) []IssueworkDTO { func ConvertIssueworksToDtos(issueworks []IssueWork) []IssueworkDTO {
dtos := make([]IssueworkDTO, len(issueworks)) dtos := make([]IssueworkDTO, len(issueworks))
for i, issuework := range issueworks { for i, issuework := range issueworks {
+16
View File
@@ -35,6 +35,22 @@ type MailDTO struct {
ReceivedAt time.Time `json:"received_date"` ReceivedAt time.Time `json:"received_date"`
} }
func (dto MailDTO) ConvertDTOToModel() Mail {
model := Mail{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
Folder: dto.Folder,
Subject: dto.Subject,
Body: dto.Body,
SendAt: dto.SendAt,
ReceivedAt: dto.ReceivedAt,
}
return model
}
func ConvertMailsToDtos(mails []Mail) []MailDTO { func ConvertMailsToDtos(mails []Mail) []MailDTO {
dtos := make([]MailDTO, len(mails)) dtos := make([]MailDTO, len(mails))
for i, mail := range mails { for i, mail := range mails {
+14
View File
@@ -33,6 +33,20 @@ type StoryArcDTO struct {
VolumeID *string `json:"volume_id"` VolumeID *string `json:"volume_id"`
} }
func (dto StoryArcDTO) ConvertDTOToModel() StoryArc {
model := StoryArc{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
Name: dto.Name,
ComicID: dto.ComicID,
VolumeID: dto.VolumeID,
}
return model
}
func ConvertStoryArcsToDtos(storyarcs []StoryArc) []StoryArcDTO { func ConvertStoryArcsToDtos(storyarcs []StoryArc) []StoryArcDTO {
dtos := make([]StoryArcDTO, len(storyarcs)) dtos := make([]StoryArcDTO, len(storyarcs))
for i, storyarc := range storyarcs { for i, storyarc := range storyarcs {
@@ -34,6 +34,21 @@ type TradePaperbackDTO struct {
ComicID *string `json:"comic_id"` ComicID *string `json:"comic_id"`
} }
func (dto TradePaperbackDTO) ConvertDTOToModel() TradePaperback {
model := TradePaperback{
ID: dto.ID,
CreatedAt: dto.CreatedAt.Time,
UpdatedAt: dto.UpdatedAt.Time,
DeletedAt: dto.DeletedAt,
Version: dto.Version,
Name: dto.Name,
IssueStart: dto.IssueStart,
IssueEnd: dto.IssueEnd,
ComicID: dto.ComicID,
}
return model
}
func ConvertTradePaperbacksToDtos(tradepaperbacks []TradePaperback) []TradePaperbackDTO { func ConvertTradePaperbacksToDtos(tradepaperbacks []TradePaperback) []TradePaperbackDTO {
dtos := make([]TradePaperbackDTO, len(tradepaperbacks)) dtos := make([]TradePaperbackDTO, len(tradepaperbacks))
for i, tradepaperback := range tradepaperbacks { for i, tradepaperback := range tradepaperbacks {
+23
View File
@@ -25,3 +25,26 @@ func (repository *ArticleRepository) FindAll(context context.Context) ([]models.
return articles, nil return articles, nil
} }
func (repository *ArticleRepository) Import(dtos models.ArticleDTOList) {
slog.Info("ArticleRepository#Import")
for index, dto := range dtos {
slog.Info("importing", "index", index, "profile", dto)
model := dto.ConvertDTOToModel()
existing_item := models.Article{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())
}
}
}
}
@@ -25,3 +25,26 @@ func (repository *ArticleAuthorRepository) FindAll(context context.Context) ([]m
return articleAuthors, nil return articleAuthors, nil
} }
func (repository *ArticleAuthorRepository) Import(dtos models.ArticleAuthorDTOList) {
slog.Info("ArticleAuthorRepository#Import")
for index, dto := range dtos {
slog.Info("importing", "index", index, "profile", dto)
model := dto.ConvertDTOToModel()
existing_item := models.ArticleAuthor{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())
}
}
}
}
+23
View File
@@ -25,3 +25,26 @@ func (repository *AuthorRepository) FindAll(context context.Context) ([]models.A
return authors, nil return authors, nil
} }
func (repository *AuthorRepository) Import(dtos models.AuthorDTOList) {
slog.Info("AuthorRepository#Import")
for index, dto := range dtos {
slog.Info("importing", "index", index, "author", dto)
model := dto.ConvertDTOToModel()
existing_item := models.Author{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())
}
}
}
}
+23
View File
@@ -25,3 +25,26 @@ func (repository *BookRepository) FindAll(context context.Context) ([]models.Boo
return books, nil return books, nil
} }
func (repository *BookRepository) Import(dtos models.BookDTOList) {
slog.Info("BookRepository#Import")
for index, dto := range dtos {
slog.Info("importing", "index", index, "profile", dto)
model := dto.ConvertDTOToModel()
existing_item := models.Book{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())
}
}
}
}
@@ -25,3 +25,26 @@ func (repository *BookAuthorRepository) FindAll(context context.Context) ([]mode
return bookAuthors, nil return bookAuthors, nil
} }
func (repository *BookAuthorRepository) Import(dtos models.BookAuthorDTOList) {
slog.Info("BookAuthorRepository#Import")
for index, dto := range dtos {
slog.Info("importing", "index", index, "profile", dto)
model := dto.ConvertDTOToModel()
existing_item := models.BookAuthor{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())
}
}
}
}
@@ -25,3 +25,26 @@ func (repository *BookshelfPublisherRepository) FindAll(context context.Context)
return bookshelfPublishers, nil return bookshelfPublishers, nil
} }
func (repository *BookshelfPublisherRepository) Import(dtos models.BookshelfPublisherDTOList) {
slog.Info("BookshelfPublisherRepository#Import")
for index, dto := range dtos {
slog.Info("importing", "index", index, "profile", dto)
model := dto.ConvertDTOToModel()
existing_item := models.BookshelfPublisher{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())
}
}
}
}
@@ -25,3 +25,26 @@ func (repository *ComicworkRepository) FindAll(context context.Context) ([]model
return comicworks, nil return comicworks, nil
} }
func (repository *ComicworkRepository) Import(dtos models.ComicworkDTOList) {
slog.Info("ComicworkRepository#Import")
for index, dto := range dtos {
slog.Info("importing", "index", index, "profile", dto)
model := dto.ConvertDTOToModel()
existing_item := models.ComicWork{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())
}
}
}
}
+23
View File
@@ -25,3 +25,26 @@ func (repository *IssueRepository) FindAll(context context.Context) ([]models.Is
return issues, nil return issues, nil
} }
func (repository *IssueRepository) Import(dtos models.IssueDTOList) {
slog.Info("IssueRepository#Import")
for index, dto := range dtos {
slog.Info("importing", "index", index, "profile", dto)
model := dto.ConvertDTOToModel()
existing_item := models.Issue{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())
}
}
}
}
@@ -25,3 +25,26 @@ func (repository *IssueworkRepository) FindAll(context context.Context) ([]model
return issueworks, nil return issueworks, nil
} }
func (repository *IssueworkRepository) Import(dtos models.IssueworkDTOList) {
slog.Info("IssueworkRepository#Import")
for index, dto := range dtos {
slog.Info("importing", "index", index, "profile", dto)
model := dto.ConvertDTOToModel()
existing_item := models.IssueWork{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())
}
}
}
}
+23
View File
@@ -35,3 +35,26 @@ func (repository *MailRepository) GetById(context context.Context, id string) (m
} }
return mail, result.Error return mail, result.Error
} }
func (repository *MailRepository) Import(dtos models.MailDTOList) {
slog.Info("MailRepository#Import")
for index, dto := range dtos {
slog.Info("importing", "index", index, "profile", dto)
model := dto.ConvertDTOToModel()
existing_item := models.Mail{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())
}
}
}
}
@@ -25,3 +25,26 @@ func (repository *StoryArcRepository) FindAll(context context.Context) ([]models
return storyArcs, nil return storyArcs, nil
} }
func (repository *StoryArcRepository) Import(dtos models.StoryArcDTOList) {
slog.Info("StoryArcRepository#Import")
for index, dto := range dtos {
slog.Info("importing", "index", index, "profile", dto)
model := dto.ConvertDTOToModel()
existing_item := models.StoryArc{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())
}
}
}
}
@@ -25,3 +25,26 @@ func (repository *TradePaperbackRepository) FindAll(context context.Context) ([]
return tradepaperbacks, nil return tradepaperbacks, nil
} }
func (repository *TradePaperbackRepository) Import(dtos models.TradePaperbackDTOList) {
slog.Info("IssueRepository#Import")
for index, dto := range dtos {
slog.Info("importing", "index", index, "profile", dto)
model := dto.ConvertDTOToModel()
existing_item := models.TradePaperback{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())
}
}
}
}