Skip to content

Joel Will Belmiro #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin
obj
9 changes: 9 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM gitpod/workspace-dotnet

USER gitpod

RUN curl https://cli-assets.heroku.com/install.sh | sh
RUN curl -sSL https://get.docker.com/rootless | sh
RUN npm install -g --silent @angular/cli
RUN dotnet tool install --global dotnet-ef

7 changes: 7 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
image:
file: .gitpod.Dockerfile

vscode:
extensions:
- [email protected]:P2IAAqkG33Qk7a8Z/Ip6eg==
- [email protected]:7oR3tO6ugyY+mWGZtMigtg==
7 changes: 7 additions & 0 deletions ApiAlunos/ApiAlunos.Domain/ApiAlunos.Domain.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using ApiAlunos.Domain.Models;

namespace ApiAlunos.Domain.Interfaces.Repository
{
public interface IAlunoRepository : IBaseRepository<Aluno>
{
bool AlunoExists(int id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;

namespace ApiAlunos.Domain.Interfaces.Repository
{
public interface IBaseRepository<T> where T : class
{
IEnumerable<T> GetAll();

T Get(int id);

T Add(T entity);

void Update(T entity);

T Remove(T entity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using ApiAlunos.Domain.Models;

namespace ApiAlunos.Domain.Interfaces.Service
{
public interface IAlunoService : IBaseService<Aluno>
{
bool AlunoExists(int id);
}
}
17 changes: 17 additions & 0 deletions ApiAlunos/ApiAlunos.Domain/Interfaces/Service/IBaseService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;

namespace ApiAlunos.Domain.Interfaces.Service
{
public interface IBaseService<T> where T : class
{
IEnumerable<T> GetAll();

T Get(int id);

T Add(T entity);

void Update(T entity);

T Remove(T entity);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ApiAlunos.Models
{
public class Aluno
{
public int AlunoId { get; set; }
public string Nome { get; set; }
public string Email { get; set; }

}
}
namespace ApiAlunos.Domain.Models
{
public class Aluno
{
public int AlunoId { get; set; }
public string Nome { get; set; }
public string Email { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\ApiAlunos.Infra.Data\ApiAlunos.Infra.Data.csproj" />
<ProjectReference Include="..\..\ApiAlunos.Domain\ApiAlunos.Domain.csproj" />
<ProjectReference Include="..\..\ApiAlunos.Service\ApiAlunos.Service.csproj" />
</ItemGroup>

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
19 changes: 19 additions & 0 deletions ApiAlunos/ApiAlunos.Infra/ApiAlunos.Infra.Crosscutting/IoC.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using ApiAlunos.Domain.Interfaces.Repository;
using ApiAlunos.Domain.Interfaces.Service;
using ApiAlunos.Infra.Data.Repository;
using ApiAlunos.Infra.Data.Context;
using ApiAlunos.Service;
using Microsoft.Extensions.DependencyInjection;

namespace ApiAlunos.Infra.Crosscutting
{
public static class IoC
{
public static void RegisterServices(IServiceCollection services)
{
services.AddScoped<IAlunoRepository, AlunoRepository>();
services.AddScoped<IAlunoService, AlunoService>();
services.AddDbContext<AppDbContext>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\..\ApiAlunos.Domain\ApiAlunos.Domain.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
</ItemGroup>

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using ApiAlunos.Domain.Models;
using Microsoft.EntityFrameworkCore;
using ApiAlunos.Infra.Data;
using Microsoft.Extensions.Configuration;

namespace ApiAlunos.Infra.Data.Context
{
public class AppDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder dbContextOptionsBuilder)
{
if (!dbContextOptionsBuilder.IsConfigured)
{
var connectionString = DatabaseConnection.ConnectionConfiguration.GetValue<string>("Default") ?? DatabaseConnection.ConnectionConfiguration.GetConnectionString("Default");
dbContextOptionsBuilder.UseNpgsql(connectionString);
}
}

public AppDbContext()
{
}

public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
}

public DbSet<Aluno> Alunos { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.EnvironmentVariables;
using System.IO;


namespace ApiAlunos.Infra.Data
{
public class DatabaseConnection
{
public static IConfiguration ConnectionConfiguration
{
get
{
IConfigurationRoot Configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddJsonFile("appsettings.Development.json")
.AddEnvironmentVariables()
.Build();
return Configuration;
}
}
}
}

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

namespace ApiAlunos.Migrations
namespace ApiAlunos.Infra.Data.Migrations
{
public partial class inicial : Migration
{
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
@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

namespace ApiAlunos.Infra.Data.Migrations
{
public partial class AlterAlunoId : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "AlunoId",
table: "Alunos",
nullable: false,
oldClrType: typeof(int),
oldType: "integer")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "AlunoId",
table: "Alunos",
type: "integer",
nullable: false,
oldClrType: typeof(int))
.OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// <auto-generated />
using ApiAlunos.Context;
using ApiAlunos.Infra.Data.Context;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

namespace ApiAlunos.Migrations
namespace ApiAlunos.Infra.Data.Migrations
{
[DbContext(typeof(AppDbContext))]
partial class AppDbContextModelSnapshot : ModelSnapshot
Expand All @@ -14,19 +14,22 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.6-servicing-10079")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "3.1.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

modelBuilder.Entity("ApiAlunos.Models.Aluno", b =>
{
b.Property<int>("AlunoId")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);

b.Property<string>("Email");
b.Property<string>("Email")
.HasColumnType("text");

b.Property<string>("Nome");
b.Property<string>("Nome")
.HasColumnType("text");

b.HasKey("AlunoId");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using ApiAlunos.Domain.Models;
using ApiAlunos.Domain.Interfaces.Repository;
using ApiAlunos.Infra.Data.Context;
using System.Linq;

namespace ApiAlunos.Infra.Data.Repository
{
public class AlunoRepository : BaseRepository<Aluno>, IAlunoRepository
{
public AlunoRepository(AppDbContext dbContext) : base(dbContext)
{
}

public bool AlunoExists(int id)
{
return DbSet.Any(e => e.AlunoId == id);
}
}
}
Loading