Skip to content

Commit

Permalink
Chore: User type changed to user role.
Browse files Browse the repository at this point in the history
  • Loading branch information
LibardiFelipe committed Dec 30, 2022
1 parent f711e8f commit 74f1716
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 50 deletions.
26 changes: 2 additions & 24 deletions TemplateBase.Domain/Entities/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public User(string firebaseId, string name, string email, string? profilePicture
ChangeProfilePictureUrl(profilePictureUrl, true);
ChangeType(EUserType.Basic, true);
ChangeIsLocked(false, true);
Role = EUserRole.Customer;
}
#endregion

Expand All @@ -31,7 +32,7 @@ public User(string firebaseId, string name, string email, string? profilePicture
public string Name { get; private set; }
public string Email { get; private set; }
public string? ProfilePictureUrl { get; private set; }
public EUserType Type { get; private set; }
public EUserRole Role { get; private set; }
public bool IsLocked { get; private set; }
public string? LockReason { get; private set; }
#endregion
Expand All @@ -58,29 +59,6 @@ public User ChangeName(string value, bool fromConstructor = false)
return this;
}

public User ChangeIsLocked(bool value, bool fromConstructor = false)
{
if (!fromConstructor && IsLocked.Equals(value))
return this;

IsLocked = value;

return this;
}

public User ChangeLockReason(string value, bool fromConstructor = false)
{
if (!fromConstructor && (LockReason?.Equals(value) ?? false))
return this;

LockReason = value;
AddNotifications(new Contract<Notification>()
.Requires()
.IsNotNullOrWhiteSpace(LockReason, "LockReason", string.Format(Mensagens.CampoObrigatorio, "Motivo")));

return this;
}

public User ChangeEmail(string value, bool fromConstructor = false)
{
if (!fromConstructor && (Email?.Equals(value) ?? false))
Expand Down
9 changes: 9 additions & 0 deletions TemplateBase.Domain/Enumerators/EUserRole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TemplateBase.Domain.Enumerators
{
public enum EUserRole : byte
{
Customer = 1,
Moderator = 2,
Admin = 3,
}
}
10 changes: 0 additions & 10 deletions TemplateBase.Domain/Enumerators/EUserType.cs

This file was deleted.

4 changes: 2 additions & 2 deletions TemplateBase.Domain/Specifications/UserSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public UserSpec FilterByEmail(string value)
return this;
}

public UserSpec FilterByType(EUserType value)
public UserSpec FilterByRole(EUserRole value)
{
CriteriaAnd(x => x.Type == value);
CriteriaAnd(x => x.Role == value);
return this;
}

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 @@ -6,7 +6,7 @@
namespace TemplateBase.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class InitialMigration : Migration
public partial class Initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
Expand All @@ -15,7 +15,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
.Annotation("MySql:CharSet", "utf8mb4");

migrationBuilder.CreateTable(
name: "User",
name: "Users",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
Expand All @@ -27,7 +27,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
.Annotation("MySql:CharSet", "utf8mb4"),
ProfilePictureUrl = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Type = table.Column<byte>(type: "tinyint unsigned", nullable: false),
Role = table.Column<byte>(type: "tinyint unsigned", nullable: false),
IsLocked = table.Column<bool>(type: "tinyint(1)", nullable: false),
LockReason = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Expand All @@ -36,7 +36,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
},
constraints: table =>
{
table.PrimaryKey("PK_User", x => x.Id);
table.PrimaryKey("PK_Users", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
}
Expand All @@ -45,7 +45,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "User");
name: "Users");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("ProfilePictureUrl")
.HasColumnType("longtext");
b.Property<byte>("Type")
b.Property<byte>("Role")
.HasColumnType("tinyint unsigned");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("datetime(6)");
b.HasKey("Id");
b.ToTable("User", (string)null);
b.ToTable("Users", (string)null);
});
#pragma warning restore 612, 618
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class UserConfig : EntityConfig<User>
{
public override void Configure(EntityTypeBuilder<User> builder)
{
builder.ToTable("User");
builder.ToTable("Users");
}
}
}
2 changes: 1 addition & 1 deletion TemplateBase.WebAPI/AutoMapper/RequestsToQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public RequestsToQueries()
return new UserQuery()
.FilterByName(src.Name)
.FilterByEmail(src.Email)
.FilterByType(src.Type)
.FilterByRole(src.Role)
.FilterByCreationRange(src.CreatedAtStart, src.CreatedAtEnd)
.FilterByUpdateRange(src.UpdatedAtStart, src.UpdatedAtEnd);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public class UserFilterRequest : FilterBase
{
public string? Name { get; set; }
public string? Email { get; set; }
public EUserType? Type { get; set; }
public EUserRole? Role { get; set; }
}
}

0 comments on commit 74f1716

Please sign in to comment.