Skip to content

Commit

Permalink
Merge pull request #13 from romandykyi/todo-lists-and-items-ownerships
Browse files Browse the repository at this point in the history
To-do Lists and Items Ownerships
  • Loading branch information
romandykyi authored Mar 3, 2024
2 parents 883fa87 + c8509b2 commit 8fcd950
Show file tree
Hide file tree
Showing 25 changed files with 1,080 additions and 65 deletions.
2 changes: 1 addition & 1 deletion AdvancedTodoList.Core/Dtos/TodoListDtos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public record TodoListCreateDto(string Name, string Description);
/// <summary>
/// DTO for a full view of a to-do list.
/// </summary>
public record TodoListGetByIdDto(string Id, string Name, string Description);
public record TodoListGetByIdDto(string Id, string Name, string Description, ApplicationUserPreviewDto Owner);
2 changes: 1 addition & 1 deletion AdvancedTodoList.Core/Dtos/TodoListItemDtos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public record TodoItemUpdateStateDto(TodoItemState State);
public record TodoItemGetByIdDto(
int Id, string TodoListId, string Name,
string Description, DateTime? DeadlineDate,
TodoItemState State
TodoItemState State, ApplicationUserPreviewDto Owner
);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ public record struct RolePermissions(
bool RemoveMembers = false,
bool AssignRoles = false,
bool EditRoles = false
);
)
{
/// <summary>
/// Instance of a structure with all permissions.
/// </summary>
public static readonly RolePermissions All = new(true, true, true, true, true, true, true, true);
}
22 changes: 16 additions & 6 deletions AdvancedTodoList.Core/Models/TodoLists/TodoItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using AdvancedTodoList.Core.Models.Auth;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace AdvancedTodoList.Core.Models.TodoLists;
Expand Down Expand Up @@ -37,6 +38,20 @@ public class TodoItem : IEntity<int>, ITodoListDependant
/// </summary>
[ForeignKey(nameof(TodoList))]
public required string TodoListId { get; set; }
/// <summary>
/// Navigation property to the to-do list associated with this to-do item.
/// </summary>
public TodoList TodoList { get; set; } = null!;

/// <summary>
/// Foreign key referencing the user who created this item.
/// </summary>
[ForeignKey(nameof(Owner))]
public required string? OwnerId { get; set; } = null!;
/// <summary>
/// Navigation property to the user who created this item.
/// </summary>
public ApplicationUser? Owner { get; set; }

/// <summary>
/// Maximum allowed length of <see cref="Name"/>.
Expand All @@ -46,11 +61,6 @@ public class TodoItem : IEntity<int>, ITodoListDependant
/// Maximum allowed length of <see cref="Description"/>.
/// </summary>
public const int DescriptionMaxLength = 10_000;

/// <summary>
/// To-do list associated with this to-do item.
/// </summary>
public TodoList TodoList { get; set; } = null!;
}

/// <summary>
Expand Down
13 changes: 12 additions & 1 deletion AdvancedTodoList.Core/Models/TodoLists/TodoList.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using AdvancedTodoList.Core.Models.Auth;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace AdvancedTodoList.Core.Models.TodoLists;
Expand Down Expand Up @@ -26,6 +27,16 @@ public class TodoList : IEntity<string>
[MaxLength(DescriptionMaxLength)]
public required string Description { get; set; } = null!;

/// <summary>
/// Foreign key referencing the user who created this to-do list.
/// </summary>
[ForeignKey(nameof(Owner))]
public required string? OwnerId { get; set; } = null!;
/// <summary>
/// Navigation property to the user who created this to-do list.
/// </summary>
public ApplicationUser? Owner { get; set; }

/// <summary>
/// Maximum allowed length of <see cref="Name"/>.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion AdvancedTodoList.Core/Services/ITodoItemsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ public interface ITodoItemsService
/// </summary>
/// <param name="todoListId">The ID of the to-do list to associate the item with.</param>
/// <param name="dto">The DTO containing information for creating the to-do list item.</param>
/// <param name="callerId">ID of the user who creates the to-do list item.</param>
/// <returns>
/// A task representing the asynchronous operation.
/// The task result contains the created <see cref="TodoItem"/> mapped to
/// <see cref="TodoItemGetByIdDto"/> or <see langword="null" /> if to-do list with ID
/// <paramref name="todoListId"/> does not exist.
/// </returns>
public Task<TodoItemGetByIdDto?> CreateAsync(string todoListId, TodoItemCreateDto dto);
public Task<TodoItemGetByIdDto?> CreateAsync(string todoListId, TodoItemCreateDto dto, string callerId);

/// <summary>
/// Edits a to-do list item asynchronously.
Expand Down
6 changes: 5 additions & 1 deletion AdvancedTodoList.Core/Services/ITodoListsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ public interface ITodoListsService
/// <summary>
/// Creates a new to-do list asynchronously.
/// </summary>
/// <remarks>
/// This method should also create an "Owner" role with all permissions and assign the caller to it.
/// </remarks>
/// <param name="dto">The DTO containing information for creating the to-do list.</param>
/// <param name="callerId">ID of the user who creates the to-do list.</param>
/// <returns>
/// A task representing the asynchronous operation.
/// The task result contains the created <see cref="TodoList"/> mapped to
/// <see cref="TodoListGetByIdDto"/>.
/// </returns>
public Task<TodoListGetByIdDto> CreateAsync(TodoListCreateDto dto);
public Task<TodoListGetByIdDto> CreateAsync(TodoListCreateDto dto, string callerId);

/// <summary>
/// Edits a to-do list asynchronously.
Expand Down
Loading

0 comments on commit 8fcd950

Please sign in to comment.