75 lines
2.0 KiB
C#
75 lines
2.0 KiB
C#
using Fengling.AuthService.Data;
|
|
using Fengling.AuthService.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Fengling.AuthService.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class OAuthClientsController : ControllerBase
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
private readonly ILogger<OAuthClientsController> _logger;
|
|
|
|
public OAuthClientsController(
|
|
ApplicationDbContext context,
|
|
ILogger<OAuthClientsController> logger)
|
|
{
|
|
_context = context;
|
|
_logger = logger;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<ActionResult<IEnumerable<OAuthApplication>>> GetClients()
|
|
{
|
|
return await _context.OAuthApplications.ToListAsync();
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public async Task<ActionResult<OAuthApplication>> GetClient(long id)
|
|
{
|
|
var client = await _context.OAuthApplications.FindAsync(id);
|
|
if (client == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
return client;
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<ActionResult<OAuthApplication>> CreateClient(OAuthApplication application)
|
|
{
|
|
_context.OAuthApplications.Add(application);
|
|
await _context.SaveChangesAsync();
|
|
return CreatedAtAction(nameof(GetClient), new { id = application.Id }, application);
|
|
}
|
|
|
|
[HttpPut("{id}")]
|
|
public async Task<IActionResult> UpdateClient(long id, OAuthApplication application)
|
|
{
|
|
if (id != application.Id)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
|
|
_context.Entry(application).State = EntityState.Modified;
|
|
await _context.SaveChangesAsync();
|
|
return NoContent();
|
|
}
|
|
|
|
[HttpDelete("{id}")]
|
|
public async Task<IActionResult> DeleteClient(long id)
|
|
{
|
|
var client = await _context.OAuthApplications.FindAsync(id);
|
|
if (client == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
_context.OAuthApplications.Remove(client);
|
|
await _context.SaveChangesAsync();
|
|
return NoContent();
|
|
}
|
|
}
|