Skip to content
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet.defaultSolution": "TodoApiDTO.sln"
}
116 changes: 0 additions & 116 deletions Controllers/TodoItemsController.cs

This file was deleted.

14 changes: 0 additions & 14 deletions Models/TodoContext.cs

This file was deleted.

55 changes: 0 additions & 55 deletions Startup.cs

This file was deleted.

18 changes: 0 additions & 18 deletions TodoApiDTO.csproj

This file was deleted.

13 changes: 12 additions & 1 deletion TodoApiDTO.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30002.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodoApiDTO", "TodoApiDTO.csproj", "{623124F9-F5BA-42DD-BC26-A1720774229C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodoApiDTO", ".\src\TodoApi\TodoApiDTO.csproj", "{623124F9-F5BA-42DD-BC26-A1720774229C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,11 +15,22 @@ Global
{623124F9-F5BA-42DD-BC26-A1720774229C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{623124F9-F5BA-42DD-BC26-A1720774229C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{623124F9-F5BA-42DD-BC26-A1720774229C}.Release|Any CPU.Build.0 = Release|Any CPU
{0FAF1E6A-594A-4FDA-9F8D-B32AD299F808}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0FAF1E6A-594A-4FDA-9F8D-B32AD299F808}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FAF1E6A-594A-4FDA-9F8D-B32AD299F808}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FAF1E6A-594A-4FDA-9F8D-B32AD299F808}.Release|Any CPU.Build.0 = Release|Any CPU
{ED312825-6F90-4170-A494-1AEFC4ACBAED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED312825-6F90-4170-A494-1AEFC4ACBAED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED312825-6F90-4170-A494-1AEFC4ACBAED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED312825-6F90-4170-A494-1AEFC4ACBAED}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {60984BC9-01D1-4B40-9733-E459B1231F96}
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{ED312825-6F90-4170-A494-1AEFC4ACBAED} = {E0EE6CC2-8FCD-43B4-BAA1-E8A578F48AB0}
EndGlobalSection
EndGlobal
10 changes: 0 additions & 10 deletions appsettings.json

This file was deleted.

33 changes: 33 additions & 0 deletions deployments/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3.7'
services:
api:
build:
context: ../src/
dockerfile: dockerfile
ports:
- 9000:80
depends_on:
- db
networks:
- mynetwork

db:
image: mcr.microsoft.com/mssql/server:2019-latest
ports:
- 1433:1433
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=Pass44w0rd
- MSSQL_TCP_ENABLED=1
- MSSQL_TCP_PORT=1433
- MSSQLNP_ENABLED=1
volumes:
- dbdata:/var/opt/mssql
networks:
- mynetwork

networks:
mynetwork:

volumes:
dbdata:
3 changes: 3 additions & 0 deletions src/TodoApi/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet.defaultSolution": "TodoApiDTO.sln"
}
78 changes: 78 additions & 0 deletions src/TodoApi/Controllers/TodoItemsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TodoApi.Data;
using TodoApi.Models;
using TodoApi.Services.Interfaces;

namespace TodoApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class TodoItemsController : ControllerBase
{
private ITodoService _todoService;

public TodoItemsController(ITodoService todoService)
{
_todoService = todoService;
}

[HttpGet]
public async Task<ActionResult<IEnumerable<TodoItemDTO>>> GetTodoItems()
{
var todoItems = await _todoService.GetTodoItems();
return Ok(todoItems.Select(item => item.AsDto()));
}

[HttpGet("{id}")]
public async Task<ActionResult<TodoItemDTO>> GetTodoItem(long id)
{
var todoItem = await _todoService.GetTodoItem(id);

if (todoItem == null)
{
return NotFound();
}

return Ok(todoItem.AsDto());
}

[HttpPut("{id}")]
public async Task<IActionResult> UpdateTodoItem(long id, TodoItemDTO todoItemDTO)
{
if (id != todoItemDTO.Id)
{
return BadRequest();
}

var todoItem = await _todoService.GetTodoItem(id);
if (todoItem == null)
{
return NotFound();
}
await _todoService.UpdateTodoItem(id, todoItemDTO);
return NoContent();
}

[HttpPost]
public async Task<ActionResult<TodoItemDTO>> CreateTodoItem(TodoItemDTO todoItemDTO)
{
await _todoService.CreateTodoItem(todoItemDTO);
return Ok(todoItemDTO);
}

[HttpDelete("{id}")]
public async Task<IActionResult> DeleteTodoItem(long id)
{
if (!await _todoService.TodoItemExists(id))
{
return NotFound();
}
await _todoService.DeleteTodoItem(id);
return NoContent();
}
}
}
Loading