Skip to content
Merged
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
22 changes: 19 additions & 3 deletions taskmaster-api/Data/DTOs/TaskDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,27 @@ namespace taskmaster_api.Data.DTOs
{
public class TaskDto : IDto<TaskEntity>
{
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()
{
Expand Down
20 changes: 16 additions & 4 deletions taskmaster-api/Data/Entities/TaskEntity.cs
Original file line number Diff line number Diff line change
@@ -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<TaskDto>
{
[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<TaskEntity, TaskDto>(this);
Expand Down
1 change: 1 addition & 0 deletions taskmaster-api/Data/Models/TaskStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,17 @@ protected override void Up(MigrationBuilder migrationBuilder)
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column<string>(type: "nvarchar(max)", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
DueDate = table.Column<DateTime>(type: "datetime2", nullable: false)
Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
DueDate = table.Column<DateTime>(type: "datetime2", nullable: true),
Status = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Tasks", x => x.Id);
});

migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Username = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});

migrationBuilder.CreateTable(
name: "AspNetRoleClaims",
columns: table => new
Expand Down Expand Up @@ -246,9 +235,6 @@ protected override void Down(MigrationBuilder migrationBuilder)
migrationBuilder.DropTable(
name: "Tasks");

migrationBuilder.DropTable(
name: "Users");

migrationBuilder.DropTable(
name: "AspNetRoles");

Expand Down
37 changes: 13 additions & 24 deletions taskmaster-api/Migrations/ApplicationDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,47 +222,36 @@ protected override void BuildModel(ModelBuilder modelBuilder)

modelBuilder.Entity("taskmaster_api.Data.Entities.TaskEntity", b =>
{
b.Property<int>("Id")
b.Property<int?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");

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

b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");

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

b.Property<DateTime>("DueDate")
b.Property<DateTime?>("DueDate")
.HasColumnType("datetime2");

b.Property<string>("Title")
b.Property<string>("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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");

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

b.Property<string>("Email")
b.Property<string>("Title")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("Username")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("datetime2");

b.HasKey("Id");

b.ToTable("Users");
b.ToTable("Tasks");
});

modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
Expand Down