-
Notifications
You must be signed in to change notification settings - Fork 0
Fix bug: user should not be able to set stock to negative numbers #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Fixes #3 Add validation to prevent setting negative stock values in `CatalogItem` model, `CatalogController`, and `CatalogService`. * **CatalogItem Model:** - Add validation attribute to `AvailableStock` property to ensure it cannot be set to negative values. * **CatalogController:** - Add validation in `Create` action to check for negative stock values and add error message to the frontend. - Add validation in `Edit` action to check for negative stock values and add error message to the frontend. * **CatalogService:** - Add validation in `CreateCatalogItem` method to check for negative stock values and throw an exception if the value is negative. - Add validation in `UpdateCatalogItem` method to check for negative stock values and throw an exception if the value is negative. * **Views:** - Add error message display for negative stock values in `Create.cshtml`. - Add error message display for negative stock values in `Edit.cshtml`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/GoatSwitch/dotnet-demo-projects/issues/3?shareId=XXXX-XXXX-XXXX-XXXX).
|
PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here. PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here. PR Code Suggestions ✨Explore these optional code suggestions:
|
| if (catalogItem.AvailableStock < 0) | ||
| { | ||
| throw new ArgumentException("Stock value cannot be negative."); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Remove duplicate validation logic to maintain single source of truth for business rules [General, importance: 8]
| if (catalogItem.AvailableStock < 0) | |
| { | |
| throw new ArgumentException("Stock value cannot be negative."); | |
| } | |
| // Remove validation check as it's handled by model validation |
User description
Fixes #3
Add validation to prevent setting negative stock values in
CatalogItemmodel,CatalogController, andCatalogService.CatalogItem Model:
AvailableStockproperty to ensure it cannot be set to negative values.CatalogController:
Createaction to check for negative stock values and add error message to the frontend.Editaction to check for negative stock values and add error message to the frontend.CatalogService:
CreateCatalogItemmethod to check for negative stock values and throw an exception if the value is negative.UpdateCatalogItemmethod to check for negative stock values and throw an exception if the value is negative.Views:
Create.cshtml.Edit.cshtml.For more details, open the Copilot Workspace session.
PR Type
Bug fix, Enhancement
Description
CatalogControllerto prevent setting negative stock values in bothCreateandEditactions.CatalogItemmodel with range validation to ensureAvailableStockcannot be negative.CatalogServiceto throw exceptions for negative stock values inCreateCatalogItemandUpdateCatalogItemmethods.Create.cshtmlandEdit.cshtmlviews.Changes walkthrough 📝
CatalogController.cs
Add validation for negative stock values in CatalogControllereShopOnWeb/eShop.MVC/Controllers/CatalogController.cs
Createaction.Editaction.CatalogService.cs
Add exception handling for negative stock in CatalogServiceeShopOnWeb/eShop.MVC/Services/CatalogService.cs
CreateCatalogItem.UpdateCatalogItem.CatalogItem.cs
Add range validation to AvailableStock in CatalogItem modeleShopOnWeb/eShop.MVC/Models/CatalogItem.cs
AvailableStockto prevent negative values.Create.cshtml
Display validation message for negative stock in Create vieweShopOnWeb/eShop.MVC/Views/Catalog/Create.cshtml
Edit.cshtml
Display validation message for negative stock in Edit vieweShopOnWeb/eShop.MVC/Views/Catalog/Edit.cshtml