From 32d1192a3e9d0937d63bd1487e7d6cc282da203f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20Jurmanovi=C4=87?= Date: Thu, 17 Oct 2024 23:48:35 +0200 Subject: [PATCH] fix concerts deleting when nothing is scraped --- local/repository/concert.go | 2 +- local/service/concert.go | 6 +++++- local/utl/configs/configs.go | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/local/repository/concert.go b/local/repository/concert.go index d6ef263..66e1b1e 100644 --- a/local/repository/concert.go +++ b/local/repository/concert.go @@ -27,7 +27,7 @@ func NewConcertRepository(db *gorm.DB) *ConcertRepository { func (as ConcertRepository) GetAll(ctx context.Context) *[]model.ConcertModel { db := as.db.WithContext(ctx) ConcertModel := new([]model.ConcertModel) - db.Find(&ConcertModel) + db.Unscoped().Find(&ConcertModel) return ConcertModel } diff --git a/local/service/concert.go b/local/service/concert.go index b75cbfa..c3e90a1 100644 --- a/local/service/concert.go +++ b/local/service/concert.go @@ -38,7 +38,11 @@ func (as ConcertService) CheckAndUpdateConcerts(ctx context.Context) []model.Con cm := as.GetAll(ctx) fmt.Printf("Currently there are %d concerts\n", len(*cm)) NewConcerts := scrapeData(ctx) - fmt.Printf("There are %d new concerts\n", len(*NewConcerts)) + concertCount := len(*NewConcerts) + fmt.Printf("There are %d new concerts\n", concertCount) + if concertCount == 0 { + return *NewConcerts + } forInsert, forDelete, _ := partitionConcerts(*cm, *NewConcerts) tx := as.repository.CreateTransaction() diff --git a/local/utl/configs/configs.go b/local/utl/configs/configs.go index 6f21a63..31f9588 100644 --- a/local/utl/configs/configs.go +++ b/local/utl/configs/configs.go @@ -1,7 +1,7 @@ package configs const ( - Version = "0.0.1" + Version = "0.0.3" Prefix = "v1" Secret = "Donde4sta" SecretCode = "brasno"