Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aron to do list #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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: 6 additions & 0 deletions Todo.Tests/Todo.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.13" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.13" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions Todo.Tests/WhenTodoItemIsConvertedToEditFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,11 @@ public void EqualImportance()
{
Assert.Equal(srcTodoItem.Importance, resultFields.Importance);
}

[Fact]
public void EqualRank()
{
Assert.Equal(srcTodoItem.Rank, resultFields.Rank);
}
}
}
49 changes: 49 additions & 0 deletions Todo/ApiControllers/TodoItemController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Todo.Data;
using Todo.Services;

namespace Todo.ApiControllers
{
[Route("api/[controller]")]
[ApiController]
public class TodoItemController : ControllerBase
{
private readonly ApplicationDbContext dbContext;

public TodoItemController(ApplicationDbContext dbContext)
{
this.dbContext = dbContext;
}

[HttpPost]
public async Task<IActionResult> SetRank(RankSetModel model)
{
if (model.TodoItemId == 0)
return BadRequest();

var todoItem = dbContext.SingleTodoItem(model.TodoItemId);

if (todoItem != null)
{
todoItem.Rank = model.Rank;
dbContext.Update(todoItem);
await dbContext.SaveChangesAsync();
}
else
return BadRequest();

return Ok();
}

public class RankSetModel
{
public int Rank { get; set; }
public int TodoItemId { get; set; }
}
}
}
3 changes: 2 additions & 1 deletion Todo/Controllers/TodoItemController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Todo.Data;
Expand Down
5 changes: 3 additions & 2 deletions Todo/Data/Entities/TodoItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ public class TodoItem
public IdentityUser ResponsibleParty { get; set; }
public bool IsDone { get; set; }
public Importance Importance { get; set; }

public int Rank { get; set; }
public int TodoListId { get; set; }
public TodoList TodoList { get; set; }

protected TodoItem() { }

public TodoItem(int todoListId, string responsiblePartyId, string title, Importance importance)
public TodoItem(int todoListId, string responsiblePartyId, string title, Importance importance, int rank = 0)
{
TodoListId = todoListId;
ResponsiblePartyId = responsiblePartyId;
Title = title;
Importance = importance;
Rank = rank;
}
}
}
Loading