Skip to content

Commit

Permalink
Feature: Entidade de template para emails adicionada.
Browse files Browse the repository at this point in the history
  • Loading branch information
LibardiFelipe committed Oct 9, 2022
1 parent 7455db5 commit 4c8ef1f
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 0 deletions.
48 changes: 48 additions & 0 deletions TemplateBase.Domain/Entities/TemplateEmail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Flunt.Notifications;
using Flunt.Validations;
using TemplateBase.Domain.Entities.Base;
using TemplateBase.Domain.Resources;

namespace TemplateBase.Domain.Entities
{
public class TemplateEmail : Entity
{
public TemplateEmail() { }
public TemplateEmail(string name, string body)
{
ChangeName(name, true);
ChangeBody(body, true);
}

public string Name { get; private set; }
public string Body { get; private set; }

public TemplateEmail ChangeName(string value, bool fromConstructor = false)
{
if (!fromConstructor && (Name?.Equals(value) ?? false))
return this;

Name = value;
AddNotifications(new Contract<Notification>()
.Requires()
.IsNotNullOrWhiteSpace(Name, "Name", string.Format(DefaultMessages.CampoObrigatorio, "Nome")));

FlagAsChanged();
return this;
}

public TemplateEmail ChangeBody(string value, bool fromConstructor = false)
{
if (!fromConstructor && (Body?.Equals(value) ?? false))
return this;

Body = value;
AddNotifications(new Contract<Notification>()
.Requires()
.IsNotNullOrWhiteSpace(Body, "Body", string.Format(DefaultMessages.CampoObrigatorio, "Corpo")));

FlagAsChanged();
return this;
}
}
}

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
@@ -0,0 +1,34 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TemplateBase.Infrastructure.Migrations
{
public partial class TemplateEmailAdded : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "TemplateEmail",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: true),
Body = table.Column<string>(type: "TEXT", nullable: true),
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_TemplateEmail", x => x.Id);
});
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "TemplateEmail");
}
}
}
23 changes: 23 additions & 0 deletions TemplateBase.Infrastructure/Migrations/DataContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ protected override void BuildModel(ModelBuilder modelBuilder)
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "6.0.9");

modelBuilder.Entity("TemplateBase.Domain.Entities.TemplateEmail", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Body")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("TemplateEmail", (string)null);
});

modelBuilder.Entity("TemplateBase.Domain.Entities.User", b =>
{
b.Property<Guid>("Id")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using TemplateBase.Domain.Entities;

namespace TemplateBase.Infrastructure.Persistence.Contexts.DataConfig
{
internal class TemplateEmailConfig : EntityConfig<TemplateEmail>
{
public override void Configure(EntityTypeBuilder<TemplateEmail> builder)
{
builder.ToTable("TemplateEmail");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class DataContext : DbContext
public DataContext(DbContextOptions<DataContext> options) : base(options) { }

public DbSet<User> Users { get; set; }
public DbSet<TemplateEmail> EmailTemplates { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down

0 comments on commit 4c8ef1f

Please sign in to comment.