Feat Gestion de Fuentes URLs
This commit is contained in:
@@ -86,5 +86,65 @@ namespace ChatbotApi.Controllers
|
||||
.ToListAsync();
|
||||
return Ok(logs);
|
||||
}
|
||||
|
||||
// ENDPOINTS PARA FUENTES DE CONTEXTO (URLs)
|
||||
[HttpGet("fuentes")]
|
||||
public async Task<IActionResult> GetAllFuentes()
|
||||
{
|
||||
var fuentes = await _context.FuentesDeContexto.OrderBy(f => f.Nombre).ToListAsync();
|
||||
return Ok(fuentes);
|
||||
}
|
||||
|
||||
[HttpPost("fuentes")]
|
||||
public async Task<IActionResult> CreateFuente([FromBody] FuenteContexto fuente)
|
||||
{
|
||||
_context.FuentesDeContexto.Add(fuente);
|
||||
await _context.SaveChangesAsync();
|
||||
return CreatedAtAction(nameof(GetAllFuentes), new { id = fuente.Id }, fuente);
|
||||
}
|
||||
|
||||
[HttpPut("fuentes/{id}")]
|
||||
public async Task<IActionResult> UpdateFuente(int id, [FromBody] FuenteContexto fuente)
|
||||
{
|
||||
if (id != fuente.Id)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
_context.Entry(fuente).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!_context.FuentesDeContexto.Any(e => e.Id == id))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("fuentes/{id}")]
|
||||
public async Task<IActionResult> DeleteFuente(int id)
|
||||
{
|
||||
var fuente = await _context.FuentesDeContexto.FindAsync(id);
|
||||
if (fuente == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
_context.FuentesDeContexto.Remove(fuente);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user