Skip to content

feat: add recipe entities + refactor codebase#113

Merged
kevbang merged 17 commits intomainfrom
CC-111/recipe-logic
Mar 10, 2026
Merged

feat: add recipe entities + refactor codebase#113
kevbang merged 17 commits intomainfrom
CC-111/recipe-logic

Conversation

@kevbang
Copy link
Copy Markdown
Collaborator

@kevbang kevbang commented Feb 27, 2026

No description provided.

@kevbang kevbang marked this pull request as draft February 27, 2026 19:12

This comment was marked as resolved.

This comment was marked as outdated.

This comment was marked as outdated.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 67 out of 70 changed files in this pull request and generated 6 comments.

Files not reviewed (3)
  • CulinaryCommandApp/Migrations/20260227192322_RecipeAndLocationUnitSupport.Designer.cs: Language not supported
  • CulinaryCommandApp/Migrations/20260305191150_AddRecipeRowVersion.Designer.cs: Language not supported
  • CulinaryCommandApp/Migrations/20260306015138_SeedUnits.Designer.cs: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread CulinaryCommandApp/Recipe/Services/RecipeService.cs
Comment thread CulinaryCommandApp/Inventory/Pages/Inventory/InventoryCatalog.razor
Comment thread CulinaryCommandApp/Inventory/Pages/Inventory/InventoryCatalog.razor Outdated
Comment thread CulinaryCommandApp/Recipe/Services/Interfaces/IRecipeService.cs
Comment thread CulinaryCommandApp/Inventory/Pages/Inventory/InventoryCatalog.razor
@kevbang kevbang requested a review from Copilot March 10, 2026 02:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 68 out of 71 changed files in this pull request and generated 3 comments.

Files not reviewed (3)
  • CulinaryCommandApp/Migrations/20260227192322_RecipeAndLocationUnitSupport.Designer.cs: Language not supported
  • CulinaryCommandApp/Migrations/20260305191150_AddRecipeRowVersion.Designer.cs: Language not supported
  • CulinaryCommandApp/Migrations/20260306015138_SeedUnits.Designer.cs: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +86 to +93
public async Task<DateTime?> GetRowVersionAsync(int id)
{
return await _db.Recipes
.AsNoTracking()
.Where(r => r.RecipeId == id)
.Select(r => r.RowVersion)
.FirstOrDefaultAsync();
}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

GetRowVersionAsync() projects a non-nullable DateTime and uses FirstOrDefaultAsync; when the recipe isn’t found this returns default(DateTime) (0001-01-01) rather than null, which contradicts the method’s contract and breaks callers that check for null (e.g., ForceOverwrite). Project RowVersion as nullable (cast to DateTime?) and use SingleOrDefault/FirstOrDefault on the nullable projection so missing recipes return null.

Copilot uses AI. Check for mistakes.
Comment on lines +596 to +618
// Validate all lines: UnitId is non-nullable in the schema and required
// for inventory transactions, so every line (ingredient or sub-recipe) must
// have a unit selected before saving. Also ensure each line has exactly one
// of IngredientId / SubRecipeId set so no orphaned lines reach the database.
var missingUnit = _ingredientLines
.Where(l => l.Source.UnitId == 0)
.ToList();
if (missingUnit.Any())
{
_errorMessage = $"{missingUnit.Count} line(s) are missing a unit. Please select a unit for every ingredient and sub-recipe line.";
_saving = false;
return;
}

var missingReference = _ingredientLines
.Where(l => l.Source.IngredientId is null && l.Source.SubRecipeId is null)
.ToList();
if (missingReference.Any())
{
_errorMessage = $"{missingReference.Count} line(s) have no ingredient or sub-recipe selected. Please complete or remove them before saving.";
_saving = false;
return;
}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

RecipeForm’s save validation checks for lines where both IngredientId and SubRecipeId are null, but it doesn’t enforce the “exactly one” requirement described in the comment. A line with both fields set would pass validation and persist an ambiguous reference. Add a validation that rejects lines where both IngredientId and SubRecipeId are set (and ideally ensure the UI clears the other field whenever one is chosen).

Copilot uses AI. Check for mistakes.
Comment on lines +254 to +265
<div class="col-md-2">
<label class="form-label form-label-sm">Unit</label>
<select class="form-select form-select-sm"
value="@line.UnitId"
@onchange="(e) => OnLineUnitChanged(line, e.Value?.ToString())">
<option value="0">-- Unit --</option>
@foreach (var unit in _locationUnits)
{
<option value="@unit.Id">@unit.Abbreviation</option>
}
</select>
</div>
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

For ingredient lines, the Unit dropdown is populated from all location units, allowing users to pick a unit that differs from the ingredient’s stock unit. InventoryTransactionService updates Ingredients.StockQuantity by adding StockChange without any unit conversion, so permitting arbitrary units here can lead to incorrect inventory deductions. Either constrain the selectable units to the ingredient’s unit (or a known convertible set) and normalize StockChange, or implement conversion before recording transactions.

Copilot uses AI. Check for mistakes.
@kevbang kevbang marked this pull request as ready for review March 10, 2026 02:36
Copy link
Copy Markdown
Collaborator

@antphan12 antphan12 left a comment

Choose a reason for hiding this comment

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

A lot of changes and looks good, will take a look at prod in the morning!

@kevbang kevbang merged commit e6f164a into main Mar 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants