From ef31399ab61cd9fea36232e30c08ee0e659484b7 Mon Sep 17 00:00:00 2001 From: SoXX Date: Tue, 15 Oct 2024 12:45:46 +0200 Subject: [PATCH] feat(database): validation - check for user source --- pkg/database/scrape_history.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/database/scrape_history.go b/pkg/database/scrape_history.go index c57412f..60dcae1 100644 --- a/pkg/database/scrape_history.go +++ b/pkg/database/scrape_history.go @@ -40,6 +40,14 @@ func CreateScrapeHistory(ctx context.Context, scrapeHistory models.ScrapeHistory return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsWrongLength}) } + if len(scrapeHistory.UserSourceID) == 0 { + return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.UserSourceIDIsEmpty}) + } + + if len(scrapeHistory.UserSourceID) != 25 { + return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.UserSourceIsWrongLength}) + } + result := client.WithContext(ctx).Create(&scrapeHistory) if result.Error != nil { if errors.Is(result.Error, gorm.ErrDuplicatedKey) {