Seguindo os passos da aula 5 do modulo 3 do curso, no final ocorreu um erro ao realizar o get de projetos para ver se vinha as informações de Especialidades, segue a baixo imagem do erro.
Olhei no Program.cs do projeto API achando que era algo a registro da classe e ele está assim:
using Freelando.Api.Endpoints;
using Freelando.Dados;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<FreelandoContext>((options) =>
{
options.UseSqlServer(builder.Configuration["ConnectionStrings:DefaultConnection"]);
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.AddEndPointEspecialidades();
app.AddEndPointProjeto();
app.AddEndPointCandidatura();
app.AddEndPointClientes();
app.AddEndPointContrato();
app.AddEndPointProfissional();
app.AddEndPointServico();
app.UseHttpsRedirection();
app.Run();
Meu ProjetoConverter.cs está assim:
using Freelando.Api.Converters;
using Freelando.Api.Requests;
using Freelando.Api.Responses;
using Freelando.Modelos;
public class ProjetoConverter
{
private ClienteConverter? _clienteConverter;
private EspecialidadeConverter? _especialidadeConverter;
public ProjetoResponse EntityToResponse(Projeto projeto)
{
_clienteConverter = new ClienteConverter();
_especialidadeConverter = new EspecialidadeConverter();
return (projeto is null)
? new ProjetoResponse(Guid.Empty, "", "", StatusProjeto.Disponivel.ToString(), null, new List<EspecialidadeResponse>())
: new ProjetoResponse(projeto.Id, projeto.Titulo, projeto.Descricao, projeto.Status.ToString(), _clienteConverter.EntityToResponse(projeto.Cliente), _especialidadeConverter.EntityListToResponseList(projeto.Especialidades!));
}
public Projeto RequestToEntity(ProjetoRequest projetoRequest)
{
_especialidadeConverter = new EspecialidadeConverter();
return (projetoRequest is null)
? new Projeto(Guid.Empty, "", "", StatusProjeto.Disponivel, new Cliente(Guid.Empty, "", "", "", "", new List<Projeto>()), new List<Especialidade>())
: new Projeto(projetoRequest.Id, projetoRequest.Titulo!, projetoRequest.Descricao!, projetoRequest.Status, new Cliente(), _especialidadeConverter.RequestListToEntityList(projetoRequest.Especialidades));
}
public ICollection<ProjetoResponse> EntityListToResponseList(IEnumerable<Projeto>? projetos)
{
return (projetos is null)
? new List<ProjetoResponse>()
: projetos.Select(p => EntityToResponse(p)).ToList();
}
public ICollection<Projeto> RequestListToEntityList(IEnumerable<ProjetoRequest>? projetos)
{
return (projetos is null)
? new List<Projeto>()
: projetos.Select(a => RequestToEntity(a)).ToList();
}
}