Skip to content
This repository was archived by the owner on Mar 17, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Backend/TodoList.Api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["TodoList.Api/TodoList.Api.csproj", "TodoList.Api/"]
RUN dotnet restore "TodoList.Api/TodoList.Api.csproj"
COPY . .
WORKDIR "/src/TodoList.Api"
RUN dotnet build "TodoList.Api.csproj" -c Release -o /app/build
Expand Down
12 changes: 0 additions & 12 deletions Backend/TodoList.Api/TodoList.Api.UnitTests/DummyTestShould.cs

This file was deleted.

60 changes: 53 additions & 7 deletions Backend/TodoList.Api/TodoList.Api.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31613.86
# Visual Studio Version 17
VisualStudioVersion = 17.7.34018.315
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodoList.Api", "TodoList.Api\TodoList.Api.csproj", "{065CE954-2618-4A24-A613-9C336C2154C6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TodoList.Api.UnitTests", "TodoList.Api.UnitTests\TodoList.Api.UnitTests.csproj", "{2BBBFEED-85B6-4361-85B2-F9E08C86C55B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodoList.Library", "TodoList.Library\TodoList.Library.csproj", "{42D3DAB6-0CB6-4424-8645-4C2796E77FC7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodoList.Core", "TodoList.Core\TodoList.Core.csproj", "{46A7210F-0FE2-4307-A7B1-FFE06D1C92CD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodoList.Infrastructure", "TodoList.Infrastructure\TodoList.Infrastructure.csproj", "{FCB5DEA6-98EA-4357-B98F-C18B880E6F21}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodoList.Service", "TodoList.Service\TodoList.Service.csproj", "{7AEC1BDF-9BCE-455E-8373-5D4E053D147C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodoList.Infrastructure.UnitTests", "TodoList.Infrastructure.UnitTests\TodoList.Infrastructure.UnitTests.csproj", "{BEB07DAC-7C52-4505-BC0E-E825A36DC3C3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodoList.Service.UnitTests", "TodoList.Service.UnitTests\TodoList.Service.UnitTests.csproj", "{6B7B2271-7D87-4924-81D8-05D12DACDC86}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{5BCC6D7E-8246-49A9-8C47-DC1301B5E880}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodoList.Testing", "TodoList.Testing\TodoList.Testing.csproj", "{6F0AE390-BAF4-41C3-9101-8C320959FDA9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Library", "Library", "{FA9E5F6B-3C0D-4B13-9D9B-BB405052B963}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -17,14 +33,44 @@ Global
{065CE954-2618-4A24-A613-9C336C2154C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{065CE954-2618-4A24-A613-9C336C2154C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{065CE954-2618-4A24-A613-9C336C2154C6}.Release|Any CPU.Build.0 = Release|Any CPU
{2BBBFEED-85B6-4361-85B2-F9E08C86C55B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2BBBFEED-85B6-4361-85B2-F9E08C86C55B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2BBBFEED-85B6-4361-85B2-F9E08C86C55B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2BBBFEED-85B6-4361-85B2-F9E08C86C55B}.Release|Any CPU.Build.0 = Release|Any CPU
{42D3DAB6-0CB6-4424-8645-4C2796E77FC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{42D3DAB6-0CB6-4424-8645-4C2796E77FC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{42D3DAB6-0CB6-4424-8645-4C2796E77FC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{42D3DAB6-0CB6-4424-8645-4C2796E77FC7}.Release|Any CPU.Build.0 = Release|Any CPU
{46A7210F-0FE2-4307-A7B1-FFE06D1C92CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46A7210F-0FE2-4307-A7B1-FFE06D1C92CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46A7210F-0FE2-4307-A7B1-FFE06D1C92CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46A7210F-0FE2-4307-A7B1-FFE06D1C92CD}.Release|Any CPU.Build.0 = Release|Any CPU
{FCB5DEA6-98EA-4357-B98F-C18B880E6F21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FCB5DEA6-98EA-4357-B98F-C18B880E6F21}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FCB5DEA6-98EA-4357-B98F-C18B880E6F21}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FCB5DEA6-98EA-4357-B98F-C18B880E6F21}.Release|Any CPU.Build.0 = Release|Any CPU
{7AEC1BDF-9BCE-455E-8373-5D4E053D147C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7AEC1BDF-9BCE-455E-8373-5D4E053D147C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7AEC1BDF-9BCE-455E-8373-5D4E053D147C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7AEC1BDF-9BCE-455E-8373-5D4E053D147C}.Release|Any CPU.Build.0 = Release|Any CPU
{BEB07DAC-7C52-4505-BC0E-E825A36DC3C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BEB07DAC-7C52-4505-BC0E-E825A36DC3C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEB07DAC-7C52-4505-BC0E-E825A36DC3C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEB07DAC-7C52-4505-BC0E-E825A36DC3C3}.Release|Any CPU.Build.0 = Release|Any CPU
{6B7B2271-7D87-4924-81D8-05D12DACDC86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B7B2271-7D87-4924-81D8-05D12DACDC86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B7B2271-7D87-4924-81D8-05D12DACDC86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B7B2271-7D87-4924-81D8-05D12DACDC86}.Release|Any CPU.Build.0 = Release|Any CPU
{6F0AE390-BAF4-41C3-9101-8C320959FDA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F0AE390-BAF4-41C3-9101-8C320959FDA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F0AE390-BAF4-41C3-9101-8C320959FDA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F0AE390-BAF4-41C3-9101-8C320959FDA9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{42D3DAB6-0CB6-4424-8645-4C2796E77FC7} = {FA9E5F6B-3C0D-4B13-9D9B-BB405052B963}
{BEB07DAC-7C52-4505-BC0E-E825A36DC3C3} = {5BCC6D7E-8246-49A9-8C47-DC1301B5E880}
{6B7B2271-7D87-4924-81D8-05D12DACDC86} = {5BCC6D7E-8246-49A9-8C47-DC1301B5E880}
{6F0AE390-BAF4-41C3-9101-8C320959FDA9} = {5BCC6D7E-8246-49A9-8C47-DC1301B5E880}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {061F7879-5D14-4C5E-A4A9-782C6FEB1132}
EndGlobalSection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
using System.Linq;
using System.Data;
using System.Threading.Tasks;

namespace TodoList.Api.Controllers
Expand All @@ -11,28 +11,29 @@ namespace TodoList.Api.Controllers
[ApiController]
public class TodoItemsController : ControllerBase
{
private readonly TodoContext _context;
private readonly ILogger<TodoItemsController> _logger;
private readonly ITodoService _service;

public TodoItemsController(TodoContext context, ILogger<TodoItemsController> logger)
public TodoItemsController(ITodoService service, ILogger<TodoItemsController> logger)
{
_context = context;
_service = service;
_logger = logger;
}

// GET: api/TodoItems
[HttpGet]
public async Task<IActionResult> GetTodoItems()
{
var results = await _context.TodoItems.Where(x => !x.IsCompleted).ToListAsync();
var results = await _service.FetchUncompletedAsync();

return Ok(results);
}

// GET: api/TodoItems/...
[HttpGet("{id}")]
public async Task<IActionResult> GetTodoItem(Guid id)
{
var result = await _context.TodoItems.FindAsync(id);
var result = await _service.FindByIdAsync(id);

if (result == null)
{
Expand All @@ -51,26 +52,17 @@ public async Task<IActionResult> PutTodoItem(Guid id, TodoItem todoItem)
return BadRequest();
}

_context.Entry(todoItem).State = EntityState.Modified;

try
{
await _context.SaveChangesAsync();
await _service.UpdateAsync(todoItem);
}
catch (DbUpdateConcurrencyException)
{
if (!TodoItemIdExists(id))
{
return NotFound();
}
else
{
throw;
}
return NotFound();
}

return NoContent();
}
}

// POST: api/TodoItems
[HttpPost]
Expand All @@ -80,26 +72,17 @@ public async Task<IActionResult> PostTodoItem(TodoItem todoItem)
{
return BadRequest("Description is required");
}
else if (TodoItemDescriptionExists(todoItem.Description))
{
return BadRequest("Description already exists");
}

_context.TodoItems.Add(todoItem);
await _context.SaveChangesAsync();

return CreatedAtAction(nameof(GetTodoItem), new { id = todoItem.Id }, todoItem);
}

private bool TodoItemIdExists(Guid id)
{
return _context.TodoItems.Any(x => x.Id == id);
}
try
{
await _service.CreateAsync(todoItem);

private bool TodoItemDescriptionExists(string description)
{
return _context.TodoItems
.Any(x => x.Description.ToLowerInvariant() == description.ToLowerInvariant() && !x.IsCompleted);
return CreatedAtAction(nameof(GetTodoItem), new { id = todoItem.Id }, todoItem);
}
catch (DuplicateNameException)
{
return BadRequest("Description already exists");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System;
using System.Net;
using System.Net.Mime;
using System.Threading.Tasks;

namespace TodoList.Api;

public class ErrorHandleMiddleware
{
private readonly RequestDelegate _next;
private readonly ILogger<ErrorHandleMiddleware> _logger;

public ErrorHandleMiddleware(RequestDelegate next, ILogger<ErrorHandleMiddleware> logger)
{
_next = next;
_logger = logger;
}

public async Task InvokeAsync(HttpContext context)
{
try
{
await _next.Invoke(context);
}
catch (Exception ex)
{
_logger.LogError(ex.Message);

context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
context.Response.ContentType = MediaTypeNames.Application.Json;

await context.Response.WriteAsync("Internal Server Error");

}
}
}
44 changes: 27 additions & 17 deletions Backend/TodoList.Api/TodoList.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:64463",
"sslPort": 44397
}
},
{
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
//"launchUrl": "swagger",
"launchUrl": "api/todoitems",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"TodoList.Api": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
//"launchUrl": "swagger",
"launchUrl": "api/todoitems",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"dotnetRunMessages": "true",
"applicationUrl": "https://localhost:5001;http://localhost:5000"
},
"WSL": {
"commandName": "WSL2",
"launchBrowser": true,
"launchUrl": "https://localhost:5001/api/todoitems",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "https://localhost:5001;http://localhost:5000"
},
"distributionName": ""
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/api/todoitems",
"environmentVariables": {
"ASPNETCORE_URLS": "https://+:443;http://+:80"
},
"publishAllPorts": true,
"useSSL": true
}
}
}
},
"$schema": "http://json.schemastore.org/launchsettings.json"
}
9 changes: 6 additions & 3 deletions Backend/TodoList.Api/TodoList.Api/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using TodoList.Services;

namespace TodoList.Api
{
Expand All @@ -20,6 +20,9 @@ public Startup(IConfiguration configuration)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddInfrastructure();
services.AddServices();

services.AddCors(options =>
{
options.AddPolicy("AllowAllHeaders",
Expand All @@ -36,8 +39,6 @@ public void ConfigureServices(IServiceCollection services)
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "TodoList.Api", Version = "v1" });
});

services.AddDbContext<TodoContext>(opt => opt.UseInMemoryDatabase("TodoItemsDB"));
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand All @@ -50,6 +51,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "TodoList.Api v1"));
}

app.UseMiddleware<ErrorHandleMiddleware>();

app.UseHttpsRedirection();

app.UseRouting();
Expand Down
14 changes: 0 additions & 14 deletions Backend/TodoList.Api/TodoList.Api/TodoContext.cs

This file was deleted.

13 changes: 0 additions & 13 deletions Backend/TodoList.Api/TodoList.Api/TodoItem.cs

This file was deleted.

Loading