Add Scrape History #15

Merged
SoXX merged 8 commits from dev/scrape-history into main 2024-10-15 10:46:41 +00:00
2 changed files with 21 additions and 13 deletions
Showing only changes of commit f70879cf8d - Show all commits

View File

@ -32,6 +32,14 @@ func CreateScrapeHistory(ctx context.Context, scrapeHistory models.ScrapeHistory
return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
}
if len(scrapeHistory.ScrapeTaskID) == 0 {
Alphyron marked this conversation as resolved Outdated

keine ID validierung / verifizierung?

keine ID validierung / verifizierung?
return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsEmpty})
}
if len(scrapeHistory.ScrapeTaskID) != 25 {
return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsWrongLength})
}
Alphyron marked this conversation as resolved
Review

UserSourceID validation is missing

UserSourceID validation is missing
result := client.WithContext(ctx).Create(&scrapeHistory)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
@ -60,14 +68,14 @@ func GetScrapeHistoryByID(ctx context.Context, id models.ScrapeTaskID) (models.S
var post models.ScrapeHistory
if client == nil {
return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
}
if len(id) == 0 {
Alphyron marked this conversation as resolved
Review

ID wrong length check is missing

ID wrong length check is missing
return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsEmpty})
}
if len(id) != 25 {
return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsWrongLength})
}
result := client.WithContext(ctx).First(&post, "scrape_task_id = ?", id)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
@ -100,14 +108,14 @@ func UpdateScrapeHistory(ctx context.Context, scrapeHistory models.ScrapeHistory
utils.HandleEvent(span, localLogger, "Starting scrapeHistory update")
Alphyron marked this conversation as resolved
Review

ID wrong length check is missing

ID wrong length check is missing
if client == nil {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
}
if len(scrapeHistory.ScrapeTaskID) == 0 {
return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsEmpty})
}
if len(scrapeHistory.ScrapeTaskID) != 25 {
return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsWrongLength})
}
updateScrapeHistory := models.ScrapeHistory{
ScrapeTaskID: scrapeHistory.ScrapeTaskID,
UserSourceID: scrapeHistory.UserSourceID,
@ -145,14 +153,14 @@ func DeleteScrapeHistory(ctx context.Context, id models.ScrapeTaskID) error {
var scrapeHistory models.ScrapeHistory
Alphyron marked this conversation as resolved
Review

ID wrong length check is missing

ID wrong length check is missing
if client == nil {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
}
if len(id) == 0 {
return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsEmpty})
}
if len(id) != 25 {
return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsWrongLength})
}
result := client.WithContext(ctx).Delete(&scrapeHistory, "scrape_task_id = ?", id)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {

View File

@ -37,7 +37,7 @@ const (
PoolURLIsEmpty = "PoolURL cannot be empty"
ScrapeTaskIDIsEmpty = "ScrapeTaskID cannot be empty"
ScrapeTaskIDIsWrongLength = "ScrapeTaskID has the wrong length"
ScrapeTaskIDIsWrongLength = "ScrapeTaskID has the wrong length, needs to be 25 characters long"
)
type EntityValidationFailed struct {