feat(database): validation
- check for user source
This commit is contained in:
parent
0f1e6c6aaa
commit
ef31399ab6
@ -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})
|
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)
|
result := client.WithContext(ctx).Create(&scrapeHistory)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
|
if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
|
||||||
|
Loading…
Reference in New Issue
Block a user