Skip to content

Commit

Permalink
Add models for basic to-do list management
Browse files Browse the repository at this point in the history
  • Loading branch information
romandykyi committed Feb 9, 2024
1 parent 48d0480 commit c82ed0c
Show file tree
Hide file tree
Showing 12 changed files with 602 additions and 43 deletions.
16 changes: 0 additions & 16 deletions AdvancedTodoList.Core/Models/TodoItem.cs

This file was deleted.

15 changes: 0 additions & 15 deletions AdvancedTodoList.Core/Models/TodoList.cs

This file was deleted.

73 changes: 73 additions & 0 deletions AdvancedTodoList.Core/Models/TodoLists/TodoItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace AdvancedTodoList.Core.Models.TodoLists;

/// <summary>
/// Represents a to-do list item entity.
/// </summary>
public class TodoItem
{
/// <summary>
/// An unique identifier for the to-do list item.
/// </summary>
[Key]
public int Id { get; set; }
/// <summary>
/// Name (title) of the to-do item.
/// </summary>
[MaxLength(NameMaxLength)]
public string Name { get; set; } = null!;
/// <summary>
/// Description of the to-do item.
/// </summary>
[MaxLength(DescriptionMaxLength)]
public string Description { get; set; } = null!;
/// <summary>
/// Current state of the to-do item.
/// </summary>
public TodoItemState State { get; set; }
/// <summary>
/// Deadline date for the todo item. Can be null.
/// </summary>
public DateTime? DeadlineDate { get; set; }

/// <summary>
/// Foreign key referencing the associated to-do list.
/// </summary>
[ForeignKey(nameof(TodoList))]
public string TodoListId { get; set; } = null!;

/// <summary>
/// Maximum allowed length of <see cref="Name"/>.
/// </summary>
public const int NameMaxLength = 100;
/// <summary>
/// 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>
/// An enum that represents the possible states of a to-do list item.
/// </summary>
public enum TodoItemState : byte
{
/// <summary>
/// The task is active (default state).
/// </summary>
Active = 0,
/// <summary>
/// The task has been completed.
/// </summary>
Completed,
/// <summary>
/// The task has been skipped.
/// </summary>
Skipped
}
42 changes: 42 additions & 0 deletions AdvancedTodoList.Core/Models/TodoLists/TodoList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace AdvancedTodoList.Core.Models.TodoLists;

/// <summary>
/// Represents a to-do list entity.
/// </summary>
public class TodoList
{
/// <summary>
/// An unique identifier for the to-do list.
/// </summary>
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public string Id { get; set; } = null!;

/// <summary>
/// Name (title) of the to-do list.
/// </summary>
[MaxLength(NameMaxLength)]
public string Name { get; set; } = null!;
/// <summary>
/// Description of the to-do list.
/// </summary>
[MaxLength(DescriptionMaxLength)]
public string Description { get; set; } = null!;

/// <summary>
/// Maximum allowed length of <see cref="Name"/>.
/// </summary>
public const int NameMaxLength = 100;
/// <summary>
/// Maximum allowed length of <see cref="Description"/>.
/// </summary>
public const int DescriptionMaxLength = 25_000;

/// <summary>
/// Collection of to-do items associated with this todo list.
/// </summary>
public virtual IEnumerable<TodoItem> TodoItems { get; set; } = null!;
}
2 changes: 1 addition & 1 deletion AdvancedTodoList.Core/Services/ITodoListsService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using AdvancedTodoList.Core.Dtos;
using AdvancedTodoList.Core.Models;
using AdvancedTodoList.Core.Models.TodoLists;

namespace AdvancedTodoList.Core.Services;

Expand Down
2 changes: 2 additions & 0 deletions AdvancedTodoList.Infrastructure/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using AdvancedTodoList.Core.Models;
using AdvancedTodoList.Core.Models.TodoLists;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace AdvancedTodoList.Infrastructure.Data;

public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) :
Expand Down
Loading

0 comments on commit c82ed0c

Please sign in to comment.