https://github.com/hobaama/to-do-list-web-api
A RESTful ASP.NET Core Web API for managing to-do items, demonstrating CRUD operations, filtering by date, and JSON Patch support.
https://github.com/hobaama/to-do-list-web-api
api api-rest api-restful asp-net-core aspnetcore csharp dotnet-core dotnetcore serilog web-api webapi
Last synced: about 2 months ago
JSON representation
A RESTful ASP.NET Core Web API for managing to-do items, demonstrating CRUD operations, filtering by date, and JSON Patch support.
- Host: GitHub
- URL: https://github.com/hobaama/to-do-list-web-api
- Owner: HoBaaMa
- License: mit
- Created: 2025-07-26T23:03:05.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-08-29T00:47:13.000Z (10 months ago)
- Last Synced: 2025-08-29T05:07:26.014Z (10 months ago)
- Topics: api, api-rest, api-restful, asp-net-core, aspnetcore, csharp, dotnet-core, dotnetcore, serilog, web-api, webapi
- Language: C#
- Homepage:
- Size: 56.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
๏ปฟ# ๐ To-Do List Web API
A simple ASP.NET Core Web API for managing to-do items. This project demonstrates CRUD operations, filtering by date, and supports JSON Patch for partial updates.
---
## ๐ Table of Contents
- [โจ Features](#-features)
- [๐งฐ Technologies Used](#-technologies-used)
- [๐ Getting Started](#-getting-started)
- [๐ง Prerequisites](#-prerequisites)
- [โ๏ธ Setup](#setup)
- [๐ API Endpoints](#-api-endpoints)
- [๐ Example To-Do Item JSON](#-example-to-do-item-json)
- [๐ฉน JSON Patch Example](#-json-patch-example)
- [๐งฑ Model](#-model)
- [โ Error Handling](#-error-handling)
- [๐ฆ Required NuGet Packages](#-required-nuget-packages)
- [๐ Quick Install All](#-quick-install-all)
- [๐ What's New](#-whats-new)
- [๐ Version 1.2.0 โ 29 July 2025](#-version-120--29-july-2025)
- [โ
Version 1.1.0 โ 28 July 2025](#-version-110--28-july-2025)
- [๐ชช License](#-license)
---
## โจ Features
- Create, read, update, and delete to-do items
- Filter to-do items by creation date
- Partial updates using JSON Patch
- Entity Framework Core with SQL Server
- Serilog-based structured logging
---
## ๐งฐ Technologies Used








---
## ๐ Getting Started
### ๐ง Prerequisites
- [.NET 8 SDK](https://dotnet.microsoft.com/download)
- [SQL Server](https://www.microsoft.com/en-us/sql-server/sql-server-downloads)
### โ๏ธ Setup
1. **Clone the repository:**
```bash
git clone https://github.com/HoBaaMa/To-Do-List-Web-API.git
```
2. **Configure the database connection:**
Update the `DefaultConnection` string in `appsettings.json` with your SQL Server details.
3. **Apply migrations:**
```bash
dotnet ef database update
```
4. **Run the application:**
```bash
dotnet run
```
5. **Access Swagger UI:**
Navigate to `https://localhost:{port}/swagger` in your browser.
---
## ๐ API Endpoints
| ๐ Method | ๐ Endpoint | ๐ Description |
|----------|----------------------------|--------------------------------------|
| ๐ข GET | `/api/todo` | Get all to-do items |
| ๐ GET | `/api/todo/{id}` | Get a to-do item by ID |
| ๐
GET | `/api/todo/date/{date}` | Get to-do items by creation date |
| โ POST | `/api/todo` | Create a new to-do item |
| โป๏ธ PUT | `/api/todo/{id}` | Update an existing to-do item |
| ๐ฉน PATCH | `/api/todo/{id}` | Partially update a to-do item |
| โ DELETE| `/api/todo/{id}` | Delete a to-do item |
---
### ๐ Example To-Do Item JSON
```json
{
"id": 1,
"title": "Sample To-Do Item",
"isCompleted": false,
"createdAt": "2023-10-01T12:00:00Z",
"completedAt": "2023-10-10T12:00:00Z"
}
```
---
## ๐ฉน JSON Patch Example
```json
[
{
"op": "replace",
"path": "/isCompleted",
"value": true
},
{
"op": "replace",
"path": "/completedAt",
"value": "2023-10-01T12:00:00Z"
}
]
```
---
## ๐งฑ Model
```csharp
public class TodoItem
{
public int Id { get; set; }
public required string Title { get; set; }
public string? Description { get; set; }
public bool? IsCompleted { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime? CompletedAt { get; set; }
}
```
---
## โ Error Handling
- Returns `400 Bad Request` for invalid input or out-of-range IDs.
- Returns `404 Not Found` if the item does not exist.
---
## ๐ฆ Required NuGet Packages
| ๐ฆ Package Name | ๐ Description |
|---------------------------------------------|--------------------------------------------|
| ๐ Microsoft.EntityFrameworkCore | Entity Framework Core ORM |
| ๐ข๏ธ Microsoft.EntityFrameworkCore.SqlServer | SQL Server provider for EF Core |
| ๐ ๏ธ Microsoft.EntityFrameworkCore.Tools | EF Core CLI tools |
| ๐ฉน Microsoft.AspNetCore.JsonPatch | JSON Patch support |
| ๐งฉ Microsoft.AspNetCore.Mvc.NewtonsoftJson | Newtonsoft.Json support |
| ๐ Swashbuckle.AspNetCore | Swagger / OpenAPI support |
| ๐งพ Serilog.AspNetCore | Serilog logging |
| ๐ค Serilog.Sinks.Console | Serilog console sink |
| ๐ Serilog.Sinks.File | Serilog file sink |
| โ๏ธ Serilog.Settings.Configuration | Serilog configuration from appsettings.json |
### ๐ Quick Install All
```bash
dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.EntityFrameworkCore.Tools
dotnet add package Microsoft.AspNetCore.JsonPatch
dotnet add package Microsoft.AspNetCore.Mvc.NewtonsoftJson
dotnet add package Swashbuckle.AspNetCore
dotnet add package Serilog.AspNetCore
dotnet add package Serilog.Sinks.Console
dotnet add package Serilog.Sinks.File
```
---
## ๐ What's New
### ๐ Version 1.2.0 โ 29 July 2025
- โ
**Improved validation logic and code structure**
- โ Added `CompletedCreationDatesValidationAttribute.cs` and `CompletedStateValidationAttribute.cs` to enforce business rules between `IsCompleted` and `CompletedAt`.
- ๐ ๏ธ Updated `TodoItem.cs` to apply the new validation attributes and removed unnecessary usings.
- ๐งน Cleaned up `TodoRepository.cs` with better ID validation and cleaner code.
- ๐ Enhanced `README.md` with clearer API documentation.
---
### โ
Version 1.1.0 โ 28 July 2025
- โ
**Added logging with Serilog to Todo API**
- ๐ง Configured Serilog in `Program.cs` for structured logging to console and file.
- ๐ Installed and configured Serilog packages in `appsettings.json`.
- ๐ฌ Integrated `ILogger` into `TodoController` for consistent logging.
---
## ๐ชช License
This project is licensed under the [MIT License](LICENSE.txt).