This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Faculdade.Api.Model; | |
using Microsoft.EntityFrameworkCore; | |
namespace Faculdade.Api.Data | |
{ | |
public class DataContext: DbContext | |
{ | |
public DataContext(DbContextOptions<DataContext> options) : base(options) | |
{} | |
public DbSet<Autor> Autores {get;set;} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Faculdade.Api.Model | |
{ | |
public class Autor | |
{ | |
public int Id { get; set; } | |
public string Nome { get; set; } | |
public string Curso { get; set; } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
database: | |
image: 'mongo' | |
container_name: 'mongoDbDocker' | |
environment: | |
- MONGO_INITDB_DATABASE=demo | |
- MONGO_INITTB_ROOT_USERNAME=root | |
- MONGO_INITDB_RIIT_PASSWORD=root2020 | |
volumes: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.3' | |
volumes: | |
data: | |
services: | |
db: | |
image: mysql:latest | |
ports: | |
- "3306:3306" | |
volumes: | |
- data:/var/lib/mysql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.3' | |
volumes: | |
data: | |
services: | |
db: | |
image: mysql:latest | |
ports: | |
- "3306:3306" | |
volumes: | |
- data:/var/lib/mysql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ApiController] | |
[Route("api/[controller]")] | |
public class AutorController : ControllerBase |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddDbContext<DataContext>(opt => opt.UseInMemoryDatabase("InMemory")); | |
services.AddTransient<DataContext, DataContext>(); | |
services.AddControllers(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpGet("{id}")] | |
public IActionResult RetornarClientePorId(int id) | |
{ | |
_context.Autores.ToList(); | |
return Ok (_context.Autores.Where(x => x.Id == id)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpGet] | |
public IActionResult RetornarTodosClientes() | |
{ | |
_context.Autores.ToList(); | |
return Ok (_context.Autores.ToList()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
public IActionResult AdicionarAutor(Autor autor) | |
{ | |
if(autor == null) | |
{ | |
return BadRequest("Autor não foi informado no body da request"); | |
} | |
_context.Add(autor); | |
_context.SaveChanges(); | |
return Created($"api/autor/id",new {autor = autor}); |