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
+23
View File
@@ -25,3 +25,26 @@ func (repository *ArticleRepository) FindAll(context context.Context) ([]models.
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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())
}
}
}
}