Skip to content

Conversation

@jchindev1
Copy link
Owner

This pull request introduces a significant update to the web-api.web project, transitioning the ToDo functionality to use Entity Framework Core with a SQL Server database. The changes include the addition of a database context, repository pattern implementation, migration files, and updates to the application configuration and endpoints.

Database Integration and Configuration:

  • Added ToDoContext class to define the Entity Framework Core database context for managing ToDo entities. Includes entity configuration for properties such as Title, Description, and IsCompleted. (src/web-api.web/Data/ToDoContext.cs, src/web-api.web/Data/ToDoContext.csR1-R29)
  • Introduced connection string for SQL Server in appsettings.json to enable database connectivity. (src/web-api.web/appsettings.json, src/web-api.web/appsettings.jsonR2-R4)
  • Updated web-api.web.csproj to include necessary Entity Framework Core packages (Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameworkCore.Tools). (src/web-api.web/web-api.web.csproj, src/web-api.web/web-api.web.csprojR12-R16)

Repository Pattern Implementation:

Migration and Database Schema:

Service and Endpoint Updates:

  • Refactored ToDoSvc to use IToDoRepository for database operations instead of in-memory storage. (src/web-api.web/Services/ToDoSvc.cs, src/web-api.web/Services/ToDoSvc.csR2-R60)
  • Updated API endpoints in Program.cs to align with RESTful conventions (/todos instead of /todo) and ensure proper integration with the database-backed service. (src/web-api.web/Program.cs, src/web-api.web/Program.csL36-R86)

These changes collectively enhance the scalability and maintainability of the ToDo functionality by leveraging Entity Framework Core and adhering to best practices such as the repository pattern.

Copilot AI review requested due to automatic review settings June 5, 2025 17:14
Copy link

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 transitions the ToDo functionality to use Entity Framework Core with SQL Server by introducing a DbContext, repository pattern, migrations, and updating service registrations and endpoints.

  • Added EF Core SQL Server packages and connection string
  • Implemented IToDoRepository/ToDoRepository and wired up DI
  • Refactored ToDoSvc and API endpoints to use the database-backed service

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/web-api.web/web-api.web.csproj Added EF Core SQL Server & Tools package references
src/web-api.web/appsettings.json Introduced SQL Server connection string
src/web-api.web/Services/ToDoSvc.cs Refactored service to use repository for CRUD
src/web-api.web/Repositories/ToDoRepository.cs Implemented EF Core repository methods
src/web-api.web/Repositories/IToDoRepository.cs Defined repository interface for ToDo
src/web-api.web/Program.cs Configured DbContext, registered services, updated endpoints
src/web-api.web/Data/ToDoContext.cs Added EF Core DbContext with entity configuration
src/web-api.web/Migrations/20250604210641_InitialCreate.cs Added initial migration for ToDos table
src/web-api.web/Migrations/ToDoContextModelSnapshot.cs Generated model snapshot for current schema
Files not reviewed (1)
  • src/web-api.web/Migrations/20250604210641_InitialCreate.Designer.cs: Language not supported
Comments suppressed due to low confidence (3)

src/web-api.web/Program.cs:1

  • Remove the unused using directive as it's not referenced in this file.
using System.Reflection.Metadata.Ecma335;

.WithOpenApi();

app.MapGet("/todo/{id:int}", async (int id, ToDoSvc svc) =>
app.MapGet("/todos/{id}", async (int id, ToDoSvc toDoSvc) =>
Copy link

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

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

Add an explicit route constraint ({id:int}) to ensure the id parameter is parsed as an integer and avoid unintended route matches.

Suggested change
app.MapGet("/todos/{id}", async (int id, ToDoSvc toDoSvc) =>
app.MapGet("/todos/{id:int}", async (int id, ToDoSvc toDoSvc) =>

Copilot uses AI. Check for mistakes.
public async Task<IReadOnlyList<ToDo>> GetAllAsync()
{
_logger.LogDebug("Fetching all ToDo items from database.");
var toDos = await _context.ToDos.ToListAsync();
Copy link

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

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

Consider using AsNoTracking() (e.g., _context.ToDos.AsNoTracking().ToListAsync()) for read-only queries to reduce change tracking overhead.

Suggested change
var toDos = await _context.ToDos.ToListAsync();
var toDos = await _context.ToDos.AsNoTracking().ToListAsync();

Copilot uses AI. Check for mistakes.
public async Task<ToDo?> GetByIdAsync(int id)
{
_logger.LogDebug("Fetching ToDo item with Id {Id} from database.", id);
return await _context.ToDos.FirstOrDefaultAsync(t => t.Id == id);
Copy link

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

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

For read-only fetch, consider using AsNoTracking() before the query (e.g., _context.ToDos.AsNoTracking().FirstOrDefaultAsync(...)).

Suggested change
return await _context.ToDos.FirstOrDefaultAsync(t => t.Id == id);
return await _context.ToDos.AsNoTracking().FirstOrDefaultAsync(t => t.Id == id);

Copilot uses AI. Check for mistakes.
jchindev added 4 commits June 5, 2025 14:00
This commit removes a line containing multiple `using` directives from the `Program.cs` file. This change helps to clean up the code by reducing unnecessary dependencies and reorganizing the namespaces used in the file.
feat(api): add Coinbase exchange rate response models
feat(api): update endpoints for currency and rate retrieval
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