add random candidato
This commit is contained in:
parent
23b1f0f14e
commit
226d819909
@ -30,6 +30,15 @@ namespace OpenCand.API.Controllers
|
||||
return await openCandService.SearchCandidatosAsync(q);
|
||||
}
|
||||
|
||||
[HttpGet("random")]
|
||||
public async Task<object> GetRandomCandidatoId()
|
||||
{
|
||||
return new
|
||||
{
|
||||
idCandidato = await openCandService.GetRandomCandidato()
|
||||
};
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<Candidato> GetCandidatoById([FromRoute] Guid id)
|
||||
{
|
||||
|
@ -101,5 +101,16 @@ namespace OpenCand.Repository
|
||||
return (await connection.QueryAsync<CandidatoExt>(query, new { idcandidato })).AsList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Guid?> GetRandomCandidatoIdAsync()
|
||||
{
|
||||
using var connection = new NpgsqlConnection(ConnectionString);
|
||||
return await connection.QueryFirstOrDefaultAsync<Guid?>(@"
|
||||
SELECT idcandidato
|
||||
FROM candidato
|
||||
ORDER BY RANDOM()
|
||||
LIMIT 1;
|
||||
");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,11 @@ namespace OpenCand.API.Services
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<Guid?> GetRandomCandidato()
|
||||
{
|
||||
return await candidatoRepository.GetRandomCandidatoIdAsync();
|
||||
}
|
||||
|
||||
public async Task<Candidato> GetCandidatoAsync(Guid idcandidato)
|
||||
{
|
||||
var result = await candidatoRepository.GetCandidatoAsync(idcandidato);
|
||||
|
Loading…
x
Reference in New Issue
Block a user