Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Basket.API/Model/BasketItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ public IEnumerable<ValidationResult> Validate(ValidationContext validationContex
results.Add(new ValidationResult("Invalid number of units", new[] { "Quantity" }));
}

// New validation for Id
if (string.IsNullOrWhiteSpace(Id))
{
results.Add(new ValidationResult("Id must not be empty", new[] { "Id" }));
}

// New validation for Id
if (string.IsNullOrWhiteSpace(ProductId.ToString()))
{
results.Add(new ValidationResult("Quantity must not be empty", new[] { "ProductId" }));
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message incorrectly references 'Quantity' when validating ProductId. It should be 'ProductId must not be empty' instead.

Suggested change
results.Add(new ValidationResult("Quantity must not be empty", new[] { "ProductId" }));
results.Add(new ValidationResult("ProductId must not be empty", new[] { "ProductId" }));

Copilot uses AI. Check for mistakes.
Comment on lines +28 to +31
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using ToString() on ProductId will never return null or whitespace since ToString() always returns a string representation. For GUID validation, check if ProductId equals Guid.Empty instead.

Suggested change
// New validation for Id
if (string.IsNullOrWhiteSpace(ProductId.ToString()))
{
results.Add(new ValidationResult("Quantity must not be empty", new[] { "ProductId" }));
// New validation for ProductId
if (ProductId <= 0)
{
results.Add(new ValidationResult("ProductId must be a positive integer", new[] { "ProductId" }));

Copilot uses AI. Check for mistakes.
}

return results;
}
}