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 _logger; public OAuthClientsController( ApplicationDbContext context, ILogger logger) { _context = context; _logger = logger; } [HttpGet] public async Task>> GetClients() { return await _context.OAuthApplications.ToListAsync(); } [HttpGet("{id}")] public async Task> GetClient(long id) { var client = await _context.OAuthApplications.FindAsync(id); if (client == null) { return NotFound(); } return client; } [HttpPost] public async Task> CreateClient(OAuthApplication application) { _context.OAuthApplications.Add(application); await _context.SaveChangesAsync(); return CreatedAtAction(nameof(GetClient), new { id = application.Id }, application); } [HttpPut("{id}")] public async Task 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 DeleteClient(long id) { var client = await _context.OAuthApplications.FindAsync(id); if (client == null) { return NotFound(); } _context.OAuthApplications.Remove(client); await _context.SaveChangesAsync(); return NoContent(); } }