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
12 changes: 0 additions & 12 deletions Models/TodoItem.cs

This file was deleted.

1 change: 0 additions & 1 deletion README.md

This file was deleted.

18 changes: 0 additions & 18 deletions TodoApiDTO.csproj

This file was deleted.

20 changes: 13 additions & 7 deletions TodoApiDTO.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30002.166
# Visual Studio Version 17
VisualStudioVersion = 17.6.33815.320
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodoApiDTO", "TodoApiDTO.csproj", "{623124F9-F5BA-42DD-BC26-A1720774229C}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TodoApiDTOTests", "TodoApiDTOTests\TodoApiDTOTests.csproj", "{B16AF459-6CB0-4F47-9040-2BBF1D7E857B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodoApiDTO", "TodoApiDTO\TodoApiDTO.csproj", "{AB010941-7483-4C99-BE32-505E505A154D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{623124F9-F5BA-42DD-BC26-A1720774229C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
{B16AF459-6CB0-4F47-9040-2BBF1D7E857B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B16AF459-6CB0-4F47-9040-2BBF1D7E857B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B16AF459-6CB0-4F47-9040-2BBF1D7E857B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B16AF459-6CB0-4F47-9040-2BBF1D7E857B}.Release|Any CPU.Build.0 = Release|Any CPU
{AB010941-7483-4C99-BE32-505E505A154D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB010941-7483-4C99-BE32-505E505A154D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB010941-7483-4C99-BE32-505E505A154D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB010941-7483-4C99-BE32-505E505A154D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
118 changes: 118 additions & 0 deletions TodoApiDTO/Controllers/TodoItemsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using TodoApi.Models;
using TodoApiDTO.Services;

namespace TodoApi.Controllers
{
[Route("api/[controller]")]
[Produces("application/json")]
[ApiController]
public class TodoItemsController : ControllerBase
{
private readonly ITodoService _service;

public TodoItemsController(ITodoService service)
{
_service = service;
}

/// <summary>
/// Gets ToDoItems.
/// </summary>
/// <returns></returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<TodoItemDTO>))]
public async Task<IActionResult> GetTodoItems()
{
return Ok(await _service.Get());
}

/// <summary>
/// Gets a specific ToDoItem.
/// </summary>
/// <param name="id">Item ID</param>
/// <returns></returns>
[HttpGet("{id}")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(TodoItemDTO))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetTodoItem(long id)
{
var todoItem = await _service.Get(id);

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

return Ok(todoItem);
}

/// <summary>
/// Updates a specific ToDoItem.
/// </summary>
/// <param name="id">Item ID</param>
/// <param name="todoItemDTO">Modified item</param>
/// <returns></returns>
[HttpPut("{id}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> UpdateTodoItem(long id, TodoItemDTO todoItemDTO)
{
if (id != todoItemDTO.Id)
{
return BadRequest();
}

var wasUpdated = await _service.Update(id, todoItemDTO);

if (!wasUpdated)
{
return NotFound();
}

return NoContent();
}

/// <summary>
/// Creates a new ToDoItem.
/// </summary>
/// <param name="todoItemDTO">New item</param>
/// <returns></returns>
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created, Type = typeof(TodoItemDTO))]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> CreateTodoItem(TodoItemDTO todoItemDTO)
{
var todoItem = await _service.Create(todoItemDTO);

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

/// <summary>
/// Deletes a spefific ToDoItem.
/// </summary>
/// <param name="id">Item ID</param>
/// <returns></returns>
[HttpDelete("{id}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> DeleteTodoItem(long id)
{
var wasDeleted = await _service.Delete(id);

if (!wasDeleted)
{
return NotFound();
}

return NoContent();
}
}
}
7 changes: 5 additions & 2 deletions Models/TodoContext.cs → TodoApiDTO/Data/TodoContext.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using Microsoft.EntityFrameworkCore;

namespace TodoApi.Models
namespace TodoApiDTO.Data
{
public class TodoContext : DbContext
{
public TodoContext() { }


public TodoContext(DbContextOptions<TodoContext> options)
: base(options)
{
}

public DbSet<TodoItem> TodoItems { get; set; }
public virtual DbSet<TodoItem> TodoItems { get; set; }
}
}
14 changes: 14 additions & 0 deletions TodoApiDTO/Data/TodoItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;

namespace TodoApiDTO.Data
{
#region snippet
public class TodoItem
{
public long Id { get; set; }
public string? Name { get; set; }
public bool IsComplete { get; set; }
public string? Secret { get; set; }
}
#endregion
}
51 changes: 51 additions & 0 deletions TodoApiDTO/Migrations/20230621182622_InitialCreate.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions TodoApiDTO/Migrations/20230621182622_InitialCreate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TodoApiDTO.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "TodoItems",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
IsComplete = table.Column<bool>(type: "bit", nullable: false),
Secret = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_TodoItems", x => x.Id);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "TodoItems");
}
}
}
48 changes: 48 additions & 0 deletions TodoApiDTO/Migrations/TodoContextModelSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using TodoApiDTO.Data;

#nullable disable

namespace TodoApiDTO.Migrations
{
[DbContext(typeof(TodoContext))]
partial class TodoContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

modelBuilder.Entity("TodoApi.Models.TodoItem", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");

SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));

b.Property<bool>("IsComplete")
.HasColumnType("bit");

b.Property<string>("Name")
.HasColumnType("nvarchar(max)");

b.Property<string>("Secret")
.HasColumnType("nvarchar(max)");

b.HasKey("Id");

b.ToTable("TodoItems");
});
#pragma warning restore 612, 618
}
}
}
2 changes: 1 addition & 1 deletion Models/TodoItemDTO.cs → TodoApiDTO/Models/TodoItemDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
public class TodoItemDTO
{
public long Id { get; set; }
public string Name { get; set; }
public string? Name { get; set; }
public bool IsComplete { get; set; }
}
#endregion
Expand Down
File renamed without changes.
Loading