add methods in Repository and Model for importing data
This commit is contained in:
@@ -25,8 +25,7 @@ func main() {
|
||||
log.Fatalf("Failed to initialize config: %v", err)
|
||||
}
|
||||
|
||||
|
||||
db, err := config.NewDB()
|
||||
db, err := config.NewDB(config.ServerConfig.DB)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -19,43 +19,43 @@ type LoginResponse struct {
|
||||
}
|
||||
|
||||
type ExportData struct {
|
||||
Sport models.SportDTOList `json:"sport"`
|
||||
Player models.PlayerDTOList `json:"player"`
|
||||
Team []models.TeamDTO `json:"team"`
|
||||
Position []models.PositionDTO `json:"field_position"`
|
||||
Rooster []models.RoosterDTO `json:"rooster"`
|
||||
Vendor []models.VendorDTO `json:"vendor"`
|
||||
CardSet []models.CardSetDTO `json:"card_set"`
|
||||
Card []models.CardDTO `json:"card"`
|
||||
Artist []models.ArtistDTO `json:"artist"`
|
||||
Publisher []models.PublisherDTO `json:"publisher"`
|
||||
Worktype []models.WorkTypeDTO `json:"worktype"`
|
||||
Comic []models.ComicDTO `json:"comic"`
|
||||
Volume []models.VolumeDTO `json:"volume"`
|
||||
StoryArc []models.StoryArcDTO `json:"story_arc"`
|
||||
Issue []models.IssueDTO `json:"issue"`
|
||||
TradePaperback []models.TradePaperbackDTO `json:"trade_paperback"`
|
||||
ComicWork []models.ComicworkDTO `json:"comic_work"`
|
||||
IssueWork []models.IssueworkDTO `json:"issue_work"`
|
||||
Article []models.ArticleDTO `json:"article"`
|
||||
BookshelfPublisher []models.BookshelfPublisherDTO `json:"bookshelf_publisher"`
|
||||
Book []models.BookDTO `json:"book"`
|
||||
Author []models.AuthorDTO `json:"author"`
|
||||
ArticleAuthor []models.ArticleAuthorDTO `json:"article_author"`
|
||||
BookAuthor []models.BookAuthorDTO `json:"book_author"`
|
||||
MediaArticle []models.MediaArticleDTO `json:"media_article"`
|
||||
MediaVideo []models.MediaVideoDTO `json:"media_video"`
|
||||
MediaLoFi models.MediaLoFiDTOList `json:"media_lofi"`
|
||||
MediaMusic models.MediaMusicDTOList `json:"media_music"`
|
||||
MediaFile []models.MediaFileDTO `json:"media_file"`
|
||||
MediaActor []models.MediaActorDTO `json:"media_actor"`
|
||||
MediaActorFile []models.MediaActorFileDTO `json:"media_actor_file"`
|
||||
Profile models.ProfileDTOList `json:"profile"`
|
||||
Permission []models.PermissionDTO `json:"permission"`
|
||||
Assignment []models.AssignmentDTO `json:"assignment"`
|
||||
Token []models.TokenDTO `json:"token"`
|
||||
MailAccount []models.MailAccountDTO `json:"mail_account"`
|
||||
Mail []models.MailDTO `json:"mail"`
|
||||
Sport models.SportDTOList `json:"sport"`
|
||||
Player models.PlayerDTOList `json:"player"`
|
||||
Team models.TeamDTOList `json:"team"`
|
||||
Position models.PositionDTOList `json:"field_position"`
|
||||
Rooster models.RoosterDTOList `json:"rooster"`
|
||||
Vendor models.VendorDTOList `json:"vendor"`
|
||||
CardSet models.CardSetDTOList `json:"card_set"`
|
||||
Card models.CardDTOList `json:"card"`
|
||||
Artist models.ArtistDTOList `json:"artist"`
|
||||
Publisher models.PublisherDTOList `json:"publisher"`
|
||||
Worktype models.WorkTypeDTOList `json:"worktype"`
|
||||
Comic models.ComicDTOList `json:"comic"`
|
||||
Volume models.VolumeDTOList `json:"volume"`
|
||||
StoryArc models.StoryArcDTOList `json:"story_arc"`
|
||||
Issue models.IssueDTOList `json:"issue"`
|
||||
TradePaperback models.TradePaperbackDTOList `json:"trade_paperback"`
|
||||
ComicWork models.ComicworkDTOList `json:"comic_work"`
|
||||
IssueWork models.IssueworkDTOList `json:"issue_work"`
|
||||
Article models.ArticleDTOList `json:"article"`
|
||||
BookshelfPublisher models.BookshelfPublisherDTOList `json:"bookshelf_publisher"`
|
||||
Book models.BookDTOList `json:"book"`
|
||||
Author models.AuthorDTOList `json:"author"`
|
||||
ArticleAuthor models.ArticleAuthorDTOList `json:"article_author"`
|
||||
BookAuthor models.BookAuthorDTOList `json:"book_author"`
|
||||
MediaArticle models.MediaArticleDTOList `json:"media_article"`
|
||||
MediaVideo models.MediaVideoDTOList `json:"media_video"`
|
||||
MediaLoFi models.MediaLoFiDTOList `json:"media_lofi"`
|
||||
MediaMusic models.MediaMusicDTOList `json:"media_music"`
|
||||
MediaFile models.MediaFileDTOList `json:"media_file"`
|
||||
MediaActor models.MediaActorDTOList `json:"media_actor"`
|
||||
MediaActorFile models.MediaActorFileDTOList `json:"media_actor_file"`
|
||||
Profile models.ProfileDTOList `json:"profile"`
|
||||
Permission models.PermissionDTOList `json:"permission"`
|
||||
Assignment models.AssignmentDTOList `json:"assignment"`
|
||||
Token models.TokenDTOList `json:"token"`
|
||||
MailAccount models.MailAccountDTOList `json:"mail_account"`
|
||||
Mail models.MailDTOList `json:"mail"`
|
||||
}
|
||||
|
||||
func (e *ExportData) GetMap() map[string]any {
|
||||
@@ -74,41 +74,41 @@ func (e *ExportData) GetMap() map[string]any {
|
||||
var (
|
||||
Sports models.SportDTOList
|
||||
Players models.PlayerDTOList
|
||||
Teams []models.TeamDTO
|
||||
Positions []models.PositionDTO
|
||||
Roosters []models.RoosterDTO
|
||||
Vendors []models.VendorDTO
|
||||
Cardsets []models.CardSetDTO
|
||||
Cards []models.CardDTO
|
||||
Artists []models.ArtistDTO
|
||||
Publishers []models.PublisherDTO
|
||||
Worktypes []models.WorkTypeDTO
|
||||
Comics []models.ComicDTO
|
||||
Volumes []models.VolumeDTO
|
||||
Storyarcs []models.StoryArcDTO
|
||||
Issues []models.IssueDTO
|
||||
Tradepaperbacks []models.TradePaperbackDTO
|
||||
Comicworks []models.ComicworkDTO
|
||||
Issueworks []models.IssueworkDTO
|
||||
Articles []models.ArticleDTO
|
||||
Bookshelf_publishers []models.BookshelfPublisherDTO
|
||||
Books []models.BookDTO
|
||||
Authors []models.AuthorDTO
|
||||
Article_authors []models.ArticleAuthorDTO
|
||||
Book_authors []models.BookAuthorDTO
|
||||
Mediaarticles []models.MediaArticleDTO
|
||||
Mediavideos []models.MediaVideoDTO
|
||||
Mediaactors []models.MediaActorDTO
|
||||
Mediaactorfiles []models.MediaActorFileDTO
|
||||
Mediafiles []models.MediaFileDTO
|
||||
Teams models.TeamDTOList
|
||||
Positions models.PositionDTOList
|
||||
Roosters models.RoosterDTOList
|
||||
Vendors models.VendorDTOList
|
||||
Cardsets models.CardSetDTOList
|
||||
Cards models.CardDTOList
|
||||
Artists models.ArtistDTOList
|
||||
Publishers models.PublisherDTOList
|
||||
Worktypes models.WorkTypeDTOList
|
||||
Comics models.ComicDTOList
|
||||
Volumes models.VolumeDTOList
|
||||
Storyarcs models.StoryArcDTOList
|
||||
Issues models.IssueDTOList
|
||||
Tradepaperbacks models.TradePaperbackDTOList
|
||||
Comicworks models.ComicworkDTOList
|
||||
Issueworks models.IssueworkDTOList
|
||||
Articles models.ArticleDTOList
|
||||
Bookshelf_publishers models.BookshelfPublisherDTOList
|
||||
Books models.BookDTOList
|
||||
Authors models.AuthorDTOList
|
||||
Article_authors models.ArticleAuthorDTOList
|
||||
Book_authors models.BookAuthorDTOList
|
||||
Mediaarticles models.MediaArticleDTOList
|
||||
Mediavideos models.MediaVideoDTOList
|
||||
Mediaactors models.MediaActorDTOList
|
||||
Mediaactorfiles models.MediaActorFileDTOList
|
||||
Mediafiles models.MediaFileDTOList
|
||||
Medialofis models.MediaLoFiDTOList
|
||||
MediaMusics models.MediaMusicDTOList
|
||||
Profiles models.ProfileDTOList
|
||||
Permissions []models.PermissionDTO
|
||||
Assignments []models.AssignmentDTO
|
||||
Tokens []models.TokenDTO
|
||||
Mailaccounts []models.MailAccountDTO
|
||||
Mail []models.MailDTO
|
||||
Permissions models.PermissionDTOList
|
||||
Assignments models.AssignmentDTOList
|
||||
Tokens models.TokenDTOList
|
||||
Mailaccounts models.MailAccountDTOList
|
||||
Mail models.MailDTOList
|
||||
)
|
||||
|
||||
var Registry map[string]any
|
||||
|
||||
@@ -3,6 +3,9 @@ package cmd
|
||||
import (
|
||||
"kontor-api-gin/internal/api"
|
||||
"kontor-api-gin/internal/config"
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/repository"
|
||||
"log"
|
||||
"log/slog"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -21,6 +24,83 @@ var importCmd = &cobra.Command{
|
||||
if err != nil {
|
||||
slog.Info("Error importing data", "Error", err.Error())
|
||||
}
|
||||
db, err := config.NewDB(config.Config.DB)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if config.Config.DB.Type == "sqlite" {
|
||||
if err := db.AutoMigrate(
|
||||
models.Profile{},
|
||||
models.Permission{},
|
||||
models.Assignment{},
|
||||
models.Sport{},
|
||||
models.Player{},
|
||||
models.Team{},
|
||||
models.Position{},
|
||||
models.Rooster{},
|
||||
models.Vendor{},
|
||||
models.CardSet{},
|
||||
models.Card{},
|
||||
models.Artist{},
|
||||
models.Publisher{},
|
||||
models.WorkType{},
|
||||
models.Comic{},
|
||||
models.Volume{},
|
||||
models.StoryArc{},
|
||||
models.Issue{},
|
||||
models.TradePaperback{},
|
||||
models.ComicWork{},
|
||||
models.IssueWork{},
|
||||
models.Article{},
|
||||
models.BookshelfPublisher{},
|
||||
models.Book{},
|
||||
models.Author{},
|
||||
models.ArticleAuthor{},
|
||||
models.BookAuthor{},
|
||||
models.MediaArticle{},
|
||||
models.MediaVideo{},
|
||||
models.MediaLoFi{},
|
||||
models.MediaFile{},
|
||||
models.MediaActor{},
|
||||
models.MediaActorFile{},
|
||||
models.Token{},
|
||||
models.MailAccount{},
|
||||
models.Mail{},
|
||||
); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
profileRepository := repository.NewProfileRepository(db)
|
||||
profileRepository.Import(data.Profile)
|
||||
permissionRepository := repository.NewPermissionRepository(db)
|
||||
permissionRepository.Import(data.Permission)
|
||||
assignmentRepository := repository.NewAssignmentRepository(db)
|
||||
assignmentRepository.Import(data.Assignment)
|
||||
sportRepository := repository.NewSportRepository(db)
|
||||
sportRepository.Import(data.Sport)
|
||||
playerRepository := repository.NewPlayerRepository(db)
|
||||
playerRepository.Import(data.Player)
|
||||
teamRepository := repository.NewTeamRepository(db)
|
||||
teamRepository.Import(data.Team)
|
||||
roosterRepository := repository.NewRoosterRepository(db)
|
||||
roosterRepository.Import(data.Rooster)
|
||||
vendorRepository := repository.NewVendorRepository(db)
|
||||
vendorRepository.Import(data.Vendor)
|
||||
cardSetRepository := repository.NewCardSetRepository(db)
|
||||
cardSetRepository.Import(data.CardSet)
|
||||
cardRepository := repository.NewCardRepository(db)
|
||||
cardRepository.Import(data.Card)
|
||||
artistRepository := repository.NewArtistRepository(db)
|
||||
artistRepository.Import(data.Artist)
|
||||
publisherRepository := repository.NewPublisherRepository(db)
|
||||
publisherRepository.Import(data.Publisher)
|
||||
workTypeRepository := repository.NewWorkTypeRepository(db)
|
||||
workTypeRepository.Import(data.Worktype)
|
||||
comicRepository := repository.NewComicRepository(db)
|
||||
comicRepository.Import(data.Comic)
|
||||
volumeRepository := repository.NewVolumeRepository(db)
|
||||
volumeRepository.Import(data.Volume)
|
||||
|
||||
slog.Info("importing Profiles", "count", len(data.Profile))
|
||||
slog.Info("importing Permissions", "count", len(data.Permission))
|
||||
slog.Info("importing Assignments", "count", len(data.Assignment))
|
||||
|
||||
@@ -2,34 +2,34 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
"log/slog"
|
||||
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
func NewDB() (*gorm.DB, error) {
|
||||
db_type := ServerConfig.DB.Type
|
||||
func NewDB(db Database) (*gorm.DB, error) {
|
||||
db_type := db.Type
|
||||
slog.Info("using database", "type", db_type)
|
||||
|
||||
switch db_type {
|
||||
case "postgres":
|
||||
dsn := fmt.Sprintf(
|
||||
"host=%s user=%s password=%s dbname=%s port=%d sslmode=disable",
|
||||
viper.GetString("db.host"),
|
||||
viper.GetString("db.user"),
|
||||
viper.GetString("db.password"),
|
||||
viper.GetString("db.name"),
|
||||
viper.GetInt("db.port"),
|
||||
db.Host,
|
||||
db.User,
|
||||
db.Password,
|
||||
db.Name,
|
||||
db.Port,
|
||||
)
|
||||
|
||||
return gorm.Open(postgres.Open(dsn), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Info),
|
||||
})
|
||||
case "sqlite":
|
||||
return gorm.Open(sqlite.Open(viper.GetString("db.path")), &gorm.Config{
|
||||
return gorm.Open(sqlite.Open(db.Path), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Info),
|
||||
})
|
||||
default:
|
||||
|
||||
@@ -43,6 +43,8 @@ func ConvertArticlesToDtos(articles []Article) []ArticleDTO {
|
||||
return dtos
|
||||
}
|
||||
|
||||
type ArticleDTOList []ArticleDTO
|
||||
|
||||
type CreateArticleDTO struct {
|
||||
Title string `json:"title" binding:"required"`
|
||||
}
|
||||
|
||||
@@ -46,3 +46,5 @@ func ConvertArticleAuthorsToDtos(article_authors []ArticleAuthor) []ArticleAutho
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type ArticleAuthorDTOList []ArticleAuthorDTO
|
||||
|
||||
@@ -29,6 +29,19 @@ type ArtistDTO struct {
|
||||
WebLink string `json:"weblink"`
|
||||
}
|
||||
|
||||
func (dto ArtistDTO) ConvertDTOToModel() Artist {
|
||||
model := Artist{
|
||||
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
|
||||
}
|
||||
|
||||
func ConvertArtistsToDtos(artists []Artist) []ArtistDTO {
|
||||
dtos := make([]ArtistDTO, len(artists))
|
||||
for i, artist := range artists {
|
||||
@@ -49,3 +62,5 @@ type CreateArtistDTO struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
WebLink string `json:"weblink" binding:"required"`
|
||||
}
|
||||
|
||||
type ArtistDTOList []ArtistDTO
|
||||
|
||||
@@ -31,6 +31,19 @@ type AssignmentDTO struct {
|
||||
PermissionID *string `json:"permission_id"`
|
||||
}
|
||||
|
||||
func (dto *AssignmentDTO) ConvertDTOToModel() Assignment {
|
||||
model := Assignment{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
ProfileID: dto.ProfileID,
|
||||
PermissionID: dto.PermissionID,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertAssignmentsToDtos(assignments []Assignment) []AssignmentDTO {
|
||||
dtos := make([]AssignmentDTO, len(assignments))
|
||||
for i, assignment := range assignments {
|
||||
@@ -46,3 +59,5 @@ func ConvertAssignmentsToDtos(assignments []Assignment) []AssignmentDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type AssignmentDTOList []AssignmentDTO
|
||||
|
||||
@@ -46,3 +46,5 @@ func ConvertAuthorsToDtos(authors []Author) []AuthorDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type AuthorDTOList []AuthorDTO
|
||||
|
||||
@@ -46,3 +46,5 @@ func ConvertBooksToDtos(books []Book) []BookDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type BookDTOList []BookDTO
|
||||
|
||||
@@ -46,3 +46,5 @@ func ConvertBookAuthorsToDtos(book_authors []BookAuthor) []BookAuthorDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type BookAuthorDTOList []BookAuthorDTO
|
||||
|
||||
@@ -42,3 +42,5 @@ func ConvertBookshelfPublishersToDtos(publishers []BookshelfPublisher) []Bookshe
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type BookshelfPublisherDTOList []BookshelfPublisherDTO
|
||||
|
||||
@@ -38,6 +38,22 @@ type CardDTO struct {
|
||||
VendorID string `json:"vendor_id" binding:"required"`
|
||||
}
|
||||
|
||||
func (dto CardDTO) ConvertDTOToModel() Card {
|
||||
model := Card{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
CardNumber: dto.CardNumber,
|
||||
Year: dto.Year,
|
||||
CardSetID: dto.CardSetID,
|
||||
RoosterID: dto.RoosterID,
|
||||
VendorID: dto.VendorID,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertCardsToDtos(cards []Card) []CardDTO {
|
||||
dtos := make([]CardDTO, len(cards))
|
||||
for i, card := range cards {
|
||||
@@ -56,3 +72,5 @@ func ConvertCardsToDtos(cards []Card) []CardDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type CardDTOList []CardDTO
|
||||
|
||||
@@ -35,6 +35,21 @@ type CardSetDTO struct {
|
||||
VendorID string `json:"vendor_id" binding:"required"`
|
||||
}
|
||||
|
||||
func (dto CardSetDTO) ConvertDTOToModel() CardSet {
|
||||
model := CardSet{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
Name: dto.Name,
|
||||
ParallelSet: dto.ParallelSet,
|
||||
InsertSet: dto.InsertSet,
|
||||
VendorID: dto.VendorID,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertCardSetsToDtos(cardsets []CardSet) []CardSetDTO {
|
||||
dtos := make([]CardSetDTO, len(cardsets))
|
||||
for i, cardset := range cardsets {
|
||||
@@ -52,3 +67,5 @@ func ConvertCardSetsToDtos(cardsets []CardSet) []CardSetDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type CardSetDTOList []CardSetDTO
|
||||
|
||||
@@ -41,6 +41,22 @@ type ComicDTO struct {
|
||||
WebLink string `json:"weblink"`
|
||||
}
|
||||
|
||||
func (dto ComicDTO) ConvertDTOToModel() Comic {
|
||||
model := Comic{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
Title: dto.Title,
|
||||
PublisherID: dto.PublisherID,
|
||||
CurrentOrder: dto.CurrentOrder,
|
||||
Completed: dto.Completed,
|
||||
WebLink: dto.WebLink,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertComicsToDtos(comics []Comic) []ComicDTO {
|
||||
dtos := make([]ComicDTO, len(comics))
|
||||
for i, comic := range comics {
|
||||
@@ -60,6 +76,8 @@ func ConvertComicsToDtos(comics []Comic) []ComicDTO {
|
||||
return dtos
|
||||
}
|
||||
|
||||
type ComicDTOList []ComicDTO
|
||||
|
||||
type CreateComicDTO struct {
|
||||
Title string `json:"title" binding:"required"`
|
||||
}
|
||||
|
||||
@@ -50,3 +50,5 @@ func ConvertComicworksToDtos(comicworks []ComicWork) []ComicworkDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type ComicworkDTOList []ComicworkDTO
|
||||
|
||||
@@ -65,3 +65,5 @@ func ConvertIssuesToDtos(issues []Issue) []IssueDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type IssueDTOList []IssueDTO
|
||||
|
||||
@@ -50,3 +50,5 @@ func ConvertIssueworksToDtos(issueworks []IssueWork) []IssueworkDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type IssueworkDTOList []IssueworkDTO
|
||||
|
||||
@@ -53,3 +53,5 @@ func ConvertMailsToDtos(mails []Mail) []MailDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type MailDTOList []MailDTO
|
||||
|
||||
@@ -56,3 +56,5 @@ func ConvertMailAccountsToDtos(mailaccounts []MailAccount) []MailAccountDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type MailAccountDTOList []MailAccountDTO
|
||||
|
||||
@@ -55,3 +55,5 @@ func ConvertMediaActorsToDtos(actors []MediaActor) []MediaActorDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type MediaActorDTOList []MediaActorDTO
|
||||
|
||||
@@ -51,3 +51,5 @@ func ConvertMediaActorFilesToDtos(actor_files []MediaActorFile) []MediaActorFile
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type MediaActorFileDTOList []MediaActorFileDTO
|
||||
|
||||
@@ -44,3 +44,5 @@ func ConvertMediaArticlesToDtos(media_articles []MediaArticle) []MediaArticleDTO
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type MediaArticleDTOList []MediaArticleDTO
|
||||
|
||||
@@ -75,3 +75,5 @@ func ConvertMediaFilesToDtos(media_files []MediaFile) []MediaFileDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type MediaFileDTOList []MediaFileDTO
|
||||
|
||||
@@ -80,3 +80,5 @@ func ConvertMediaVideosToDtos(media_videos []MediaVideo) []MediaVideoDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type MediaVideoDTOList []MediaVideoDTO
|
||||
|
||||
@@ -28,6 +28,18 @@ type PermissionDTO struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
}
|
||||
|
||||
func (permission *PermissionDTO) ConvertDTOToModel() Permission {
|
||||
model := Permission{
|
||||
ID: permission.ID,
|
||||
CreatedAt: permission.CreatedAt.Time,
|
||||
UpdatedAt: permission.UpdatedAt.Time,
|
||||
DeletedAt: permission.DeletedAt,
|
||||
Version: permission.Version,
|
||||
Name: permission.Name,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertPermissionsToDtos(permissions []Permission) []PermissionDTO {
|
||||
dtos := make([]PermissionDTO, len(permissions))
|
||||
for i, permission := range permissions {
|
||||
@@ -42,3 +54,5 @@ func ConvertPermissionsToDtos(permissions []Permission) []PermissionDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type PermissionDTOList []PermissionDTO
|
||||
|
||||
@@ -32,6 +32,19 @@ type PlayerDTO struct {
|
||||
LastName string `json:"last_name" binding:"required"`
|
||||
}
|
||||
|
||||
func (dto PlayerDTO) ConvertDTOToModel() Player {
|
||||
model := Player{
|
||||
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
|
||||
}
|
||||
|
||||
type PlayerDTOList []PlayerDTO
|
||||
|
||||
func (playerList *PlayerDTOList) CompareIds(target *PlayerDTOList) (missing, obsolete []string) {
|
||||
|
||||
@@ -49,3 +49,5 @@ func ConvertPositionsToDtos(positions []Position) []PositionDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type PositionDTOList []PositionDTO
|
||||
|
||||
@@ -52,6 +52,23 @@ type ProfileDTO struct {
|
||||
Enabled bool `json:"enabled" binding:"required"`
|
||||
}
|
||||
|
||||
func (profile *ProfileDTO) ConvertDTOToModel() Profile {
|
||||
model := Profile{
|
||||
ID: profile.ID,
|
||||
CreatedAt: profile.CreatedAt.Time,
|
||||
UpdatedAt: profile.UpdatedAt.Time,
|
||||
DeletedAt: profile.DeletedAt,
|
||||
Version: profile.Version,
|
||||
First_Name: profile.First_Name,
|
||||
Last_Name: profile.Last_Name,
|
||||
User_Name: profile.User_Name,
|
||||
Email: profile.Email,
|
||||
Password: profile.Password,
|
||||
Enabled: profile.Enabled,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertProfilesToDtos(profiles []Profile) []ProfileDTO {
|
||||
dtos := make([]ProfileDTO, len(profiles))
|
||||
for i, profile := range profiles {
|
||||
|
||||
@@ -34,6 +34,20 @@ type PublisherDTO struct {
|
||||
ParentPublisherID *string `json:"parent_publisher_id"`
|
||||
}
|
||||
|
||||
func (dto PublisherDTO) ConvertDTOToModel() Publisher {
|
||||
model := Publisher{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
Name: dto.Name,
|
||||
WebLink: dto.WebLink,
|
||||
ParentPublisherID: dto.ParentPublisherID,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertPublishersToDtos(publishers []Publisher) []PublisherDTO {
|
||||
dtos := make([]PublisherDTO, len(publishers))
|
||||
for i, publisher := range publishers {
|
||||
@@ -55,3 +69,5 @@ type CreatePublisherDTO struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
WebLink string `json:"weblink" binding:"required"`
|
||||
}
|
||||
|
||||
type PublisherDTOList []PublisherDTO
|
||||
|
||||
@@ -37,6 +37,21 @@ type RoosterDTO struct {
|
||||
PositionID string `json:"position_id" binding:"required"`
|
||||
}
|
||||
|
||||
func (dto RoosterDTO) ConvertDTOToModel() Rooster {
|
||||
model := Rooster{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
Year: dto.Year,
|
||||
TeamID: dto.TeamID,
|
||||
PlayerID: dto.PlayerID,
|
||||
PositionID: dto.PositionID,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertRoostersToDtos(roosters []Rooster) []RoosterDTO {
|
||||
dtos := make([]RoosterDTO, len(roosters))
|
||||
for i, rooster := range roosters {
|
||||
@@ -54,3 +69,5 @@ func ConvertRoostersToDtos(roosters []Rooster) []RoosterDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type RoosterDTOList []RoosterDTO
|
||||
|
||||
@@ -29,6 +29,18 @@ type SportDTO struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
}
|
||||
|
||||
func (dto SportDTO) ConvertDTOToModel() Sport {
|
||||
model := Sport{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
Name: dto.Name,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
type SportDTOList []SportDTO
|
||||
|
||||
func (sportList *SportDTOList) CompareIds(target *SportDTOList) (missing, obsolete []string) {
|
||||
|
||||
@@ -49,3 +49,5 @@ func ConvertStoryArcsToDtos(storyarcs []StoryArc) []StoryArcDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type StoryArcDTOList []StoryArcDTO
|
||||
|
||||
@@ -33,6 +33,20 @@ type TeamDTO struct {
|
||||
SportID string `json:"sport_id" binding:"required"`
|
||||
}
|
||||
|
||||
func (dto TeamDTO) ConvertDTOToModel() Team {
|
||||
model := Team{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
Name: dto.Name,
|
||||
ShortName: dto.ShortName,
|
||||
SportID: dto.SportID,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertTeamsToDtos(teams []Team) []TeamDTO {
|
||||
dtos := make([]TeamDTO, len(teams))
|
||||
for i, team := range teams {
|
||||
@@ -49,3 +63,5 @@ func ConvertTeamsToDtos(teams []Team) []TeamDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type TeamDTOList []TeamDTO
|
||||
|
||||
@@ -47,3 +47,5 @@ func ConvertTokensToDtos(tokens []Token) []TokenDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type TokenDTOList []TokenDTO
|
||||
|
||||
@@ -51,3 +51,5 @@ func ConvertTradePaperbacksToDtos(tradepaperbacks []TradePaperback) []TradePaper
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type TradePaperbackDTOList []TradePaperbackDTO
|
||||
|
||||
@@ -29,6 +29,18 @@ type VendorDTO struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
}
|
||||
|
||||
func (dto VendorDTO) ConvertDTOToModel() Vendor {
|
||||
model := Vendor{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
Name: dto.Name,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertVendorsToDtos(vendors []Vendor) []VendorDTO {
|
||||
dtos := make([]VendorDTO, len(vendors))
|
||||
for i, vendor := range vendors {
|
||||
@@ -43,3 +55,5 @@ func ConvertVendorsToDtos(vendors []Vendor) []VendorDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type VendorDTOList []VendorDTO
|
||||
|
||||
@@ -30,6 +30,19 @@ type VolumeDTO struct {
|
||||
ComicID *string `json:"comic_id"`
|
||||
}
|
||||
|
||||
func (dto VolumeDTO) ConvertDTOToModel() Volume {
|
||||
model := Volume{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
Name: dto.Name,
|
||||
ComicID: dto.ComicID,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertVolumesToDtos(volumes []Volume) []VolumeDTO {
|
||||
dtos := make([]VolumeDTO, len(volumes))
|
||||
for i, volume := range volumes {
|
||||
@@ -45,3 +58,5 @@ func ConvertVolumesToDtos(volumes []Volume) []VolumeDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type VolumeDTOList []VolumeDTO
|
||||
|
||||
@@ -27,6 +27,18 @@ type WorkTypeDTO struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (dto WorkTypeDTO) ConvertDTOToModel() WorkType {
|
||||
model := WorkType{
|
||||
ID: dto.ID,
|
||||
CreatedAt: dto.CreatedAt.Time,
|
||||
UpdatedAt: dto.UpdatedAt.Time,
|
||||
DeletedAt: dto.DeletedAt,
|
||||
Version: dto.Version,
|
||||
Name: dto.Name,
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func ConvertWorkTypesToDtos(worktypes []WorkType) []WorkTypeDTO {
|
||||
dtos := make([]WorkTypeDTO, len(worktypes))
|
||||
for i, worktype := range worktypes {
|
||||
@@ -41,3 +53,5 @@ func ConvertWorkTypesToDtos(worktypes []WorkType) []WorkTypeDTO {
|
||||
}
|
||||
return dtos
|
||||
}
|
||||
|
||||
type WorkTypeDTOList []WorkTypeDTO
|
||||
|
||||
@@ -12,6 +12,29 @@ type ArtistRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (repository *ArtistRepository) Import(dtos models.ArtistDTOList) {
|
||||
slog.Info("PlayerRepository#Import")
|
||||
for index, dto := range dtos {
|
||||
slog.Info("importing", "index", index, "profile", dto)
|
||||
model := dto.ConvertDTOToModel()
|
||||
existing_item := models.Artist{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 NewArtistRepository(db *gorm.DB) *ArtistRepository {
|
||||
repo := &ArtistRepository{db: db}
|
||||
return repo
|
||||
|
||||
@@ -35,3 +35,26 @@ func (repository *AssignmentRepository) GetById(context context.Context, id stri
|
||||
}
|
||||
return assignment, result.Error
|
||||
}
|
||||
|
||||
func (repository *AssignmentRepository) Import(assignments models.AssignmentDTOList) {
|
||||
slog.Info("AssignmentRepository#Import")
|
||||
for index, assignment := range assignments {
|
||||
slog.Info("importing", "index", index, "profile", assignment)
|
||||
model := assignment.ConvertDTOToModel()
|
||||
existing_item := models.Assignment{ID: assignment.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())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,29 @@ type CardRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (repository *CardRepository) Import(dtos models.CardDTOList) {
|
||||
slog.Info("CardRepository#Import")
|
||||
for index, dto := range dtos {
|
||||
slog.Info("importing", "index", index, "profile", dto)
|
||||
model := dto.ConvertDTOToModel()
|
||||
existing_item := models.Card{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 NewCardRepository(db *gorm.DB) *CardRepository {
|
||||
repo := &CardRepository{db: db}
|
||||
return repo
|
||||
|
||||
@@ -12,6 +12,29 @@ type CardSetRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (repository *CardSetRepository) Import(dtos models.CardSetDTOList) {
|
||||
slog.Info("CardSetRepository#Import")
|
||||
for index, dto := range dtos {
|
||||
slog.Info("importing", "index", index, "profile", dto)
|
||||
model := dto.ConvertDTOToModel()
|
||||
existing_item := models.CardSet{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 NewCardSetRepository(db *gorm.DB) *CardSetRepository {
|
||||
repo := &CardSetRepository{db: db}
|
||||
return repo
|
||||
|
||||
@@ -12,6 +12,29 @@ type ComicRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (repository *ComicRepository) Import(dtos models.ComicDTOList) {
|
||||
slog.Info("ComicRepository#Import")
|
||||
for index, dto := range dtos {
|
||||
slog.Info("importing", "index", index, "profile", dto)
|
||||
model := dto.ConvertDTOToModel()
|
||||
existing_item := models.Comic{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 NewComicRepository(db *gorm.DB) *ComicRepository {
|
||||
repo := &ComicRepository{db: db}
|
||||
return repo
|
||||
|
||||
@@ -12,6 +12,11 @@ type PermissionRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewPermissionRepository(db *gorm.DB) *PermissionRepository {
|
||||
repository := &PermissionRepository{db: db}
|
||||
return repository
|
||||
}
|
||||
|
||||
func (repository *PermissionRepository) FindAll(context context.Context) ([]models.Permission, error) {
|
||||
|
||||
var permissions []models.Permission
|
||||
@@ -22,7 +27,25 @@ func (repository *PermissionRepository) FindAll(context context.Context) ([]mode
|
||||
return permissions, nil
|
||||
}
|
||||
|
||||
func NewPermissionRepository(db *gorm.DB) *PermissionRepository {
|
||||
repository := &PermissionRepository{db: db}
|
||||
return repository
|
||||
func (repository *PermissionRepository) Import(permissions models.PermissionDTOList) {
|
||||
slog.Info("PermissionRepository#Import")
|
||||
for index, permission := range permissions {
|
||||
slog.Info("importing", "index", index, "profile", permission)
|
||||
model := permission.ConvertDTOToModel()
|
||||
existing_item := models.Permission{ID: permission.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())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,29 @@ type PlayerRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (repository *PlayerRepository) Import(dtos models.PlayerDTOList) {
|
||||
slog.Info("PlayerRepository#Import")
|
||||
for index, dto := range dtos {
|
||||
slog.Info("importing", "index", index, "profile", dto)
|
||||
model := dto.ConvertDTOToModel()
|
||||
existing_item := models.Player{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 NewPlayerRepository(db *gorm.DB) *PlayerRepository {
|
||||
repo := &PlayerRepository{db: db}
|
||||
return repo
|
||||
|
||||
@@ -36,3 +36,26 @@ func (repository *ProfileRepository) FindProfileByEmail(email string) (*models.P
|
||||
}
|
||||
return &profile, nil
|
||||
}
|
||||
|
||||
func (repository *ProfileRepository) Import(profiles models.ProfileDTOList) {
|
||||
slog.Info("ProfileRepository#Import")
|
||||
for index, profile := range profiles {
|
||||
slog.Info("importing", "index", index, "profile", profile)
|
||||
model := profile.ConvertDTOToModel()
|
||||
existing_profile := models.Profile{ID: profile.ID}
|
||||
result_existing := repository.db.First(&existing_profile)
|
||||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,29 @@ type PublisherRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (repository *PublisherRepository) Import(dtos models.PublisherDTOList) {
|
||||
slog.Info("PublisherRepository#Import")
|
||||
for index, dto := range dtos {
|
||||
slog.Info("importing", "index", index, "profile", dto)
|
||||
model := dto.ConvertDTOToModel()
|
||||
existing_item := models.Publisher{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 NewPublisherRepository(db *gorm.DB) *PublisherRepository {
|
||||
repo := &PublisherRepository{db: db}
|
||||
return repo
|
||||
|
||||
@@ -12,6 +12,29 @@ type RoosterRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (repository *RoosterRepository) Import(dtos models.RoosterDTOList) {
|
||||
slog.Info("RoosterRepository#Import")
|
||||
for index, dto := range dtos {
|
||||
slog.Info("importing", "index", index, "profile", dto)
|
||||
model := dto.ConvertDTOToModel()
|
||||
existing_item := models.Rooster{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 NewRoosterRepository(db *gorm.DB) *RoosterRepository {
|
||||
repo := &RoosterRepository{db: db}
|
||||
return repo
|
||||
|
||||
@@ -12,6 +12,29 @@ type SportRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (repository *SportRepository) Import(sports models.SportDTOList) {
|
||||
slog.Info("SportRepository#Import")
|
||||
for index, sport := range sports {
|
||||
slog.Info("importing", "index", index, "profile", sport)
|
||||
model := sport.ConvertDTOToModel()
|
||||
existing_item := models.Sport{ID: sport.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 NewSportRepository(db *gorm.DB) *SportRepository {
|
||||
repo := &SportRepository{db: db}
|
||||
return repo
|
||||
|
||||
@@ -12,6 +12,29 @@ type TeamRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (repository *TeamRepository) Import(dtos models.TeamDTOList) {
|
||||
slog.Info("TeamRepository#Import")
|
||||
for index, dto := range dtos {
|
||||
slog.Info("importing", "index", index, "profile", dto)
|
||||
model := dto.ConvertDTOToModel()
|
||||
existing_item := models.Team{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 NewTeamRepository(db *gorm.DB) *TeamRepository {
|
||||
repo := &TeamRepository{db: db}
|
||||
return repo
|
||||
|
||||
@@ -12,6 +12,29 @@ type VendorRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (repository *VendorRepository) Import(dtos models.VendorDTOList) {
|
||||
slog.Info("VendorRepository#Import")
|
||||
for index, dto := range dtos {
|
||||
slog.Info("importing", "index", index, "profile", dto)
|
||||
model := dto.ConvertDTOToModel()
|
||||
existing_item := models.Vendor{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 NewVendorRepository(db *gorm.DB) *VendorRepository {
|
||||
repo := &VendorRepository{db: db}
|
||||
return repo
|
||||
|
||||
@@ -12,6 +12,29 @@ type VolumeRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (repository *VolumeRepository) Import(dtos models.VolumeDTOList) {
|
||||
slog.Info("VolumeRepository#Import")
|
||||
for index, dto := range dtos {
|
||||
slog.Info("importing", "index", index, "profile", dto)
|
||||
model := dto.ConvertDTOToModel()
|
||||
existing_item := models.Volume{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 NewVolumeRepository(db *gorm.DB) *VolumeRepository {
|
||||
repo := &VolumeRepository{db: db}
|
||||
return repo
|
||||
|
||||
@@ -12,6 +12,29 @@ type WorkTypeRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (repository *WorkTypeRepository) Import(dtos models.WorkTypeDTOList) {
|
||||
slog.Info("WorkTypeRepository#Import")
|
||||
for index, dto := range dtos {
|
||||
slog.Info("importing", "index", index, "profile", dto)
|
||||
model := dto.ConvertDTOToModel()
|
||||
existing_item := models.WorkType{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 NewWorkTypeRepository(db *gorm.DB) *WorkTypeRepository {
|
||||
repo := &WorkTypeRepository{db: db}
|
||||
return repo
|
||||
|
||||
Reference in New Issue
Block a user