0

I am implementing a new API using ARDALIS api endpoints, I just finished the set up for the project, but for some reason the first endpoint implemented always returns empty responses. Although, my database is full of data.

This is the endpoint which gets all the teams available in the database.

public class GetTeams : EndpointBaseAsync.WithoutRequest.WithActionResult<IEnumerable<TeamsResult>>
{

    private readonly ITeamsRepository _teamsRepository;

    public GetTeams(ITeamsRepository teamsRepository)
    {
        _teamsRepository = teamsRepository;
    }

    [HttpGet()]
    [Route("/teams")]
    [SwaggerOperation(
    Summary = "Gets a list of all the available teams",
    Description = "Gets list of all the teams",
    OperationId = "Teams.Get",
    Tags = new[] { "TeamEndpoint" })
    ]
    public override async Task<ActionResult<IEnumerable<TeamsResult>>> HandleAsync(CancellationToken cancellationToken = default)
    {
        var teams = await _teamsRepository.GetAllTeams();

        

        return Ok(teams);
    }
}

This is the Repository:

private readonly string _connectionStringSoccerApi;
    public TeamsRepository(IOptions<ConnectionStringConfig> connectionString)
    {
        _connectionStringSoccerApi = connectionString.Value.SoccerApi;

    }
    public async Task<IEnumerable<TeamsResult>> GetAllTeams()
    {
        using var connection = new SqlConnection(_connectionStringSoccerApi);
        string getAllTeamsQuery = "Select * from Teams";

        return await connection.QueryAsync<TeamsResult>(getAllTeamsQuery);
        
    }
}

And the TeamResult class

public class TeamsResult
{
    public string Name;
}

I debugged it and the values are being returned as they should, but for some reason swagger shows this response:

enter image description here

Any suggestions?

I tried changing the TeamResult class and returning only the first element of the returned list, but I did not work.

Flydog57
  • 6,851
  • 2
  • 17
  • 18
Uribe2304
  • 51
  • 1
  • 8

0 Answers0