diff --git a/taskmaster-api/Data/DTOs/TaskDto.cs b/taskmaster-api/Data/DTOs/TaskDto.cs index a73fa3c..2f42828 100644 --- a/taskmaster-api/Data/DTOs/TaskDto.cs +++ b/taskmaster-api/Data/DTOs/TaskDto.cs @@ -6,11 +6,27 @@ namespace taskmaster_api.Data.DTOs { public class TaskDto : IDto { - public int Id { get; set; } + public int? Id { get; set; } public string Title { get; set; } - public string Description { get; set; } - public DateTime DueDate { get; set; } + public string? Description { get; set; } + public DateTime? DueDate { get; set; } public string Status { get; set; } + public DateTime CreatedAt { get; set; } + public DateTime UpdatedAt { get; set; } + + public TaskDto() + { + Status = Models.TaskStatus.Pending; + if (Id.HasValue) + { + UpdatedAt = DateTime.UtcNow; + } + else + { + CreatedAt = DateTime.UtcNow; + UpdatedAt = DateTime.UtcNow; + } + } public TaskEntity ToEntity() { diff --git a/taskmaster-api/Data/Entities/TaskEntity.cs b/taskmaster-api/Data/Entities/TaskEntity.cs index b9e69c2..8a54c76 100644 --- a/taskmaster-api/Data/Entities/TaskEntity.cs +++ b/taskmaster-api/Data/Entities/TaskEntity.cs @@ -1,24 +1,36 @@ -using System.ComponentModel.DataAnnotations; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Microsoft.EntityFrameworkCore; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using taskmaster_api.Data.DTOs; using taskmaster_api.Data.Entities.Interface; using taskmaster_api.Utilities; +using System.Runtime.Serialization; namespace taskmaster_api.Data.Entities { public class TaskEntity : IEntity { [Key] - public int Id { get; set; } + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int? Id { get; set; } [Required] public string Title { get; set; } - public string Description { get; set; } + public string? Description { get; set; } - public DateTime DueDate { get; set; } + public DateTime? DueDate { get; set; } + [StringLength(50)] public string Status { get; set; } + public DateTime CreatedAt { get; set; } + + public DateTime UpdatedAt { get; set; } + public TaskDto ToDto() { return EntityHelpers.ToDto(this); diff --git a/taskmaster-api/Data/Models/TaskStatus.cs b/taskmaster-api/Data/Models/TaskStatus.cs index f71d39c..a22ea8f 100644 --- a/taskmaster-api/Data/Models/TaskStatus.cs +++ b/taskmaster-api/Data/Models/TaskStatus.cs @@ -2,6 +2,7 @@ { public static class TaskStatus { + public const string Pending = "Pending"; public const string Open = "Open"; public const string InProgress = "InProgress"; public const string Completed = "Complete"; diff --git a/taskmaster-api/Migrations/20231208193605_InitialCreate.Designer.cs b/taskmaster-api/Migrations/20231211053644_InitialCreate.Designer.cs similarity index 92% rename from taskmaster-api/Migrations/20231208193605_InitialCreate.Designer.cs rename to taskmaster-api/Migrations/20231211053644_InitialCreate.Designer.cs index 403e300..c2225c3 100644 --- a/taskmaster-api/Migrations/20231208193605_InitialCreate.Designer.cs +++ b/taskmaster-api/Migrations/20231211053644_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ namespace taskmaster_api.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20231208193605_InitialCreate")] + [Migration("20231211053644_InitialCreate")] partial class InitialCreate { /// @@ -225,47 +225,36 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) modelBuilder.Entity("taskmaster_api.Data.Entities.TaskEntity", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); b.Property("Description") - .IsRequired() .HasColumnType("nvarchar(max)"); - b.Property("DueDate") + b.Property("DueDate") .HasColumnType("datetime2"); - b.Property("Title") + b.Property("Status") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); - b.HasKey("Id"); - - b.ToTable("Tasks"); - }); - - modelBuilder.Entity("taskmaster_api.Data.Entities.UserEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Email") + b.Property("Title") .IsRequired() .HasColumnType("nvarchar(max)"); - b.Property("Username") - .IsRequired() - .HasColumnType("nvarchar(max)"); + b.Property("UpdatedAt") + .HasColumnType("datetime2"); b.HasKey("Id"); - b.ToTable("Users"); + b.ToTable("Tasks"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => diff --git a/taskmaster-api/Migrations/20231208193605_InitialCreate.cs b/taskmaster-api/Migrations/20231211053644_InitialCreate.cs similarity index 93% rename from taskmaster-api/Migrations/20231208193605_InitialCreate.cs rename to taskmaster-api/Migrations/20231211053644_InitialCreate.cs index 2ff02d2..df85bb3 100644 --- a/taskmaster-api/Migrations/20231208193605_InitialCreate.cs +++ b/taskmaster-api/Migrations/20231211053644_InitialCreate.cs @@ -57,28 +57,17 @@ protected override void Up(MigrationBuilder migrationBuilder) Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Title = table.Column(type: "nvarchar(max)", nullable: false), - Description = table.Column(type: "nvarchar(max)", nullable: false), - DueDate = table.Column(type: "datetime2", nullable: false) + Description = table.Column(type: "nvarchar(max)", nullable: true), + DueDate = table.Column(type: "datetime2", nullable: true), + Status = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false), + UpdatedAt = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Tasks", x => x.Id); }); - migrationBuilder.CreateTable( - name: "Users", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Username = table.Column(type: "nvarchar(max)", nullable: false), - Email = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Users", x => x.Id); - }); - migrationBuilder.CreateTable( name: "AspNetRoleClaims", columns: table => new @@ -246,9 +235,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "Tasks"); - migrationBuilder.DropTable( - name: "Users"); - migrationBuilder.DropTable( name: "AspNetRoles"); diff --git a/taskmaster-api/Migrations/ApplicationDbContextModelSnapshot.cs b/taskmaster-api/Migrations/ApplicationDbContextModelSnapshot.cs index d3637dc..df2fd24 100644 --- a/taskmaster-api/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/taskmaster-api/Migrations/ApplicationDbContextModelSnapshot.cs @@ -222,47 +222,36 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("taskmaster_api.Data.Entities.TaskEntity", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); b.Property("Description") - .IsRequired() .HasColumnType("nvarchar(max)"); - b.Property("DueDate") + b.Property("DueDate") .HasColumnType("datetime2"); - b.Property("Title") + b.Property("Status") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); - b.HasKey("Id"); - - b.ToTable("Tasks"); - }); - - modelBuilder.Entity("taskmaster_api.Data.Entities.UserEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Email") + b.Property("Title") .IsRequired() .HasColumnType("nvarchar(max)"); - b.Property("Username") - .IsRequired() - .HasColumnType("nvarchar(max)"); + b.Property("UpdatedAt") + .HasColumnType("datetime2"); b.HasKey("Id"); - b.ToTable("Users"); + b.ToTable("Tasks"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b =>