Skip to content

Commit a4f0933

Browse files
authored
Merge pull request #4 from DevComputaria/develop
Develop Merge Update
2 parents 993e409 + 446258d commit a4f0933

File tree

20 files changed

+365
-10
lines changed

20 files changed

+365
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace API.Boilerplate.Domain.Arguments.Base
6+
{
7+
public class Response
8+
{
9+
public string Message { get; set; }
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace API.Boilerplate.Domain.Arguments.Usuario
6+
{
7+
public class AdicionarUsuarioRequest
8+
{
9+
public string PrimeiroNome { get; set; }
10+
11+
public string UltimoNome { get; set; }
12+
13+
public string Email { get; set; }
14+
15+
public string Senha { get; set; }
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace API.Boilerplate.Domain.Arguments.Usuario
6+
{
7+
public class AdicionarUsuarioResponse
8+
{
9+
private Guid id;
10+
11+
public AdicionarUsuarioResponse(Guid id)
12+
{
13+
this.id = id;
14+
}
15+
}
16+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using API.Boilerplate.Domain.Entities.Base;
2+
using API.Boilerplate.Domain.ValueObjects;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
7+
namespace API.Boilerplate.Domain.Entities
8+
{
9+
public class Usuario : EntityBase
10+
{
11+
public Usuario()
12+
{
13+
14+
}
15+
16+
public Usuario(Nome nome, Email email, string senha)
17+
{
18+
Nome = nome;
19+
Email = email;
20+
Senha = senha;
21+
}
22+
23+
public Nome Nome { get; private set; }
24+
25+
public Email Email { get; private set; }
26+
27+
public string Senha { get; private set; }
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using API.Boilerplate.Domain.Entities;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace API.Boilerplate.Domain.Interfaces.Repositories
7+
{
8+
public interface IRepositoryUsuario
9+
{
10+
Usuario Obter(Guid id);
11+
12+
Usuario Obter(string email, string senha);
13+
14+
void Salvar(Usuario usuario);
15+
16+
bool Existe(string email);
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace API.Boilerplate.Domain.Interfaces.Services.Base
6+
{
7+
public interface IServiceBase
8+
{
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using API.Boilerplate.Domain.Arguments.Usuario;
2+
using API.Boilerplate.Domain.Interfaces.Services.Base;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
7+
namespace API.Boilerplate.Domain.Interfaces.Services
8+
{
9+
public interface IServiceUsuario : IServiceBase
10+
{
11+
AdicionarUsuarioResponse AdicionarUsuario(AdicionarUsuarioRequest request);
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using API.Boilerplate.Domain.Arguments.Usuario;
2+
using API.Boilerplate.Domain.Entities;
3+
using API.Boilerplate.Domain.Interfaces.Repositories;
4+
using API.Boilerplate.Domain.Interfaces.Services;
5+
using API.Boilerplate.Domain.ValueObjects;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Text;
9+
10+
namespace API.Boilerplate.Domain.Services
11+
{
12+
public class ServiceUsuario : IServiceUsuario
13+
{
14+
//Dependências do serviço
15+
private readonly IRepositoryUsuario _repositoryUsuario;
16+
17+
//Construtor
18+
public ServiceUsuario(IRepositoryUsuario repositoryUsuario)
19+
{
20+
_repositoryUsuario = repositoryUsuario;
21+
}
22+
23+
public AdicionarUsuarioResponse AdicionarUsuario(AdicionarUsuarioRequest request)
24+
{
25+
26+
//Cria value objects
27+
Nome nome = new Nome(request.PrimeiroNome, request.UltimoNome);
28+
29+
30+
Email email = new Email(request.Email);
31+
32+
33+
Usuario usuario = new Usuario(nome, email, request.Senha);
34+
35+
36+
//persistir no banco de dados
37+
_repositoryUsuario.Salvar(usuario);
38+
39+
return new AdicionarUsuarioResponse(usuario.Id);
40+
}
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace API.Boilerplate.Domain.ValueObjects
6+
{
7+
public class Email
8+
{
9+
private string email;
10+
11+
public Email(string email)
12+
{
13+
this.email = email;
14+
}
15+
16+
public string Endereco { get; private set; }
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace API.Boilerplate.Domain.ValueObjects
6+
{
7+
public class Nome
8+
{
9+
public Nome(string primeiroNome, string ultimoNome)
10+
{
11+
PrimeiroNome = primeiroNome;
12+
UltimoNome = ultimoNome;
13+
}
14+
15+
public string PrimeiroNome { get; private set; }
16+
17+
public string UltimoNome { get; set; }
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>

API.Boilerplate.Shared/Settings.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace API.Boilerplate.Shared
6+
{
7+
public class Settings
8+
{
9+
private static string connectionString = "Data Source=.;Initial Catalog=YouLearnCurso; persist security info=True;Integrated Security=SSPI;";
10+
11+
public static string ConnectionString
12+
{
13+
get { return connectionString; }
14+
set { connectionString = value; }
15+
}
16+
}
17+
}

API.Solution.sln

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API.Boilerplate.Domain", "A
1313
EndProject
1414
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API.boilerpalte.Infra", "API.boilerpalte.Infra\API.boilerpalte.Infra.csproj", "{8976419F-6A1D-4555-9938-BA833F40337D}"
1515
EndProject
16-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API.Boilerplate.Api", "API.Boilerplate.Api\API.Boilerplate.Api.csproj", "{4BEC351F-C1F5-4546-B8B7-50F4BC53DF4D}"
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API.Boilerplate.Api", "API.Boilerplate.Api\API.Boilerplate.Api.csproj", "{4BEC351F-C1F5-4546-B8B7-50F4BC53DF4D}"
17+
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API.Boilerplate.Shared", "API.Boilerplate.Shared\API.Boilerplate.Shared.csproj", "{37726F11-E9F7-4BBC-9570-18CDFCB83FBD}"
1719
EndProject
1820
Global
1921
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -33,6 +35,10 @@ Global
3335
{4BEC351F-C1F5-4546-B8B7-50F4BC53DF4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
3436
{4BEC351F-C1F5-4546-B8B7-50F4BC53DF4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
3537
{4BEC351F-C1F5-4546-B8B7-50F4BC53DF4D}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{37726F11-E9F7-4BBC-9570-18CDFCB83FBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{37726F11-E9F7-4BBC-9570-18CDFCB83FBD}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{37726F11-E9F7-4BBC-9570-18CDFCB83FBD}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{37726F11-E9F7-4BBC-9570-18CDFCB83FBD}.Release|Any CPU.Build.0 = Release|Any CPU
3642
EndGlobalSection
3743
GlobalSection(SolutionProperties) = preSolution
3844
HideSolutionNode = FALSE
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.4" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.4" />
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.4" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\API.Boilerplate.Domain\API.Boilerplate.Domain.csproj" />
15+
<ProjectReference Include="..\API.Boilerplate.Shared\API.Boilerplate.Shared.csproj" />
16+
</ItemGroup>
17+
718
</Project>

API.boilerpalte.Infra/Class1.cs

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using API.Boilerplate.Domain.Entities;
2+
using API.Boilerplate.Shared;
3+
using Microsoft.EntityFrameworkCore;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Text;
7+
8+
namespace API.boilerpalte.Infra.Persistence.EF
9+
{
10+
public class ApiBoilerplateContext : DbContext
11+
{
12+
public DbSet<Usuario> Usuarios { get; set; }
13+
14+
public ApiBoilerplateContext()
15+
{
16+
17+
}
18+
19+
protected override void OnConfiguring(DbContextOptionsBuilder oprtionsBuilder)
20+
{
21+
oprtionsBuilder.UseSqlServer(Settings.ConnectionString);
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using API.Boilerplate.Domain.Entities;
2+
using API.Boilerplate.Domain.ValueObjects;
3+
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Text;
8+
9+
namespace API.boilerpalte.Infra.Persistence.EF.Map
10+
{
11+
public class MapUsuario : IEntityTypeConfiguration<Usuario>
12+
{
13+
public void Configure(EntityTypeBuilder<Usuario> builder)
14+
{
15+
//Tabela
16+
builder.ToTable("Usuario");
17+
18+
//Chave primaria
19+
builder.HasKey(x => x.Id);
20+
21+
builder.Property(x => x.Senha).HasMaxLength(36).IsRequired();
22+
23+
//Mapeamento objetos de valor
24+
Action<OwnedNavigationBuilder<Usuario, Nome>> p = cb =>
25+
{
26+
cb.Property(x => x.PrimeiroNome).HasMaxLength(50);
27+
cb.Property(x => x.UltimoNome).HasMaxLength(50);
28+
};
29+
builder.OwnsOne<Nome>(x => x.Nome, p);
30+
31+
builder.OwnsOne<Email>(x => x.Email, cb => cb.Property(x => x.Endereco).HasMaxLength(200));
32+
}
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using API.boilerpalte.Infra.Persistence.EF;
2+
using API.Boilerplate.Domain.Entities;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
8+
namespace API.boilerpalte.Infra.Persistence.Repositories
9+
{
10+
public class RepositoryUsuario
11+
{
12+
private readonly ApiBoilerplateContext _context;
13+
14+
public RepositoryUsuario(ApiBoilerplateContext context)
15+
{
16+
context = _context;
17+
}
18+
19+
public bool Existe(string email)
20+
{
21+
return _context.Usuarios.Any(x => x.Email.Endereco == email);
22+
}
23+
24+
public Usuario Obter(Guid id)
25+
{
26+
return _context.Usuarios.FirstOrDefault(x => x.Id == id);
27+
}
28+
29+
public Usuario Obter(string email, string senha)
30+
{
31+
return _context.Usuarios.FirstOrDefault(x => x.Email.Endereco == email && x.Senha == senha);
32+
}
33+
34+
public void Salvar(Usuario usuario)
35+
{
36+
_context.Usuarios.Add(usuario);
37+
}
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace API.boilerpalte.Infra.Transactions
6+
{
7+
public class IUnitOfWork
8+
{
9+
}
10+
}

0 commit comments

Comments
 (0)