Skip to content

Create fuel efficincy#11

Open
ThishaniDissanayake wants to merge 2 commits intodevfrom
features/fuel_efficency
Open

Create fuel efficincy#11
ThishaniDissanayake wants to merge 2 commits intodevfrom
features/fuel_efficency

Conversation

@ThishaniDissanayake
Copy link
Copy Markdown
Contributor

No description provided.

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

This PR adds comprehensive fuel efficiency tracking to the backend by introducing a new FuelEfficiency entity, its database mappings, service layer, API endpoints, and example frontend/integration guides.

  • Add FuelEfficiency model, DbSet, and EF Core migrations to support fuel record storage
  • Implement IFuelEfficiencyService and FuelEfficiencyService with CRUD and summary operations
  • Expose endpoints in FuelEfficiencyController and provide DTOs, example scripts, and frontend integration

Reviewed Changes

Copilot reviewed 23 out of 36 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Models/FuelEfficiency.cs Define FuelEfficiency entity and properties
Data/ApplicationDbContext.cs Register FuelEfficiencies DbSet and relations
Migrations/20250712144500_InitialCreateWithFuelEfficiency.cs Create FuelEfficiencies table and indexes
Migrations/ApplicationDbContextModelSnapshot.cs Snapshot updated with FuelEfficiency mapping
Services/FuelEfficiencyService.cs Business logic for fuel record operations
Controllers/FuelEfficiencyController.cs API endpoints for fuel efficiency
DTOs/FuelEfficiencyDTO.cs Request/response DTOs for fuel efficiency API
Program.cs Register IFuelEfficiencyService in DI container
appsettings.json Update connection string for development
Examples/… Frontend integration and API guide documentation
Files not reviewed (1)
  • Vpassbackend/Migrations/20250712144500_InitialCreateWithFuelEfficiency.Designer.cs: Language not supported
Comments suppressed due to low confidence (3)

Vpassbackend/Controllers/FuelEfficiencyController.cs:167

  • Method signature declares ActionResult<decimal> but returns an anonymous object; update the return type or wrap the decimal appropriately in a DTO.
                return Ok(new { AverageMonthlyFuel = averageFuel, Year = year });

Vpassbackend/Controllers/FuelEfficiencyController.cs:75

  • [nitpick] Using GetFuelEfficienciesByVehicle for CreatedAtAction may generate an unexpected Location header; consider creating a GetById endpoint or adjusting route values to point to the newly created record.
                return CreatedAtAction(nameof(GetFuelEfficienciesByVehicle), 

Vpassbackend/obj/project.nuget.cache:3

  • Auto-generated files under obj/ (and nuget cache) should not be committed; consider adding them to .gitignore or removing from the PR.
  "dgSpecHash": "YOzTrqfKGUY=",

Comment on lines +257 to +263
.Select(g => g.Sum(fe => fe.FuelAmount))
.ToListAsync();

if (!monthlyTotals.Any())
return 0;

return monthlyTotals.Average();
Copy link

Copilot AI Jul 13, 2025

Choose a reason for hiding this comment

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

Averaging only months with records skews the yearly average; include zero‐fuel months in the calculation or average over all 12 months to reflect actual monthly average.

Suggested change
.Select(g => g.Sum(fe => fe.FuelAmount))
.ToListAsync();
if (!monthlyTotals.Any())
return 0;
return monthlyTotals.Average();
.Select(g => new { Month = g.Key, TotalFuel = g.Sum(fe => fe.FuelAmount) })
.ToListAsync();
// Initialize an array for all 12 months with zero values
var allMonths = Enumerable.Range(1, 12)
.Select(month => new { Month = month, TotalFuel = 0m })
.ToList();
// Merge the actual monthly totals with the zero-initialized months
foreach (var monthlyTotal in monthlyTotals)
{
allMonths[monthlyTotal.Month - 1] = monthlyTotal;
}
// Calculate the average over all 12 months
return allMonths.Average(m => m.TotalFuel);

Copilot uses AI. Check for mistakes.
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