| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using Application.Abstractions.Data;
- using Domain.Entities.Developers;
- using Domain.Entities.Developers.ValueObject;
- using Application.Abstractions.Messaging;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.RazorPages;
- using Microsoft.EntityFrameworkCore;
- namespace Admin.Pages.Developers.Apps;
- public class DetailModel(IMediator mediator, IAppDbContext db) : PageModel
- {
- [BindProperty(SupportsGet = true)]
- public int ID { get; set; }
- public ApiApplication? App { get; set; }
- public List<ApiCredential> Credentials { get; set; } = [];
- public List<string> Scopes { get; set; } = [];
- public int? RateLimitOverride { get; set; }
- [BindProperty]
- public int LimitPerMinute { get; set; }
- public async Task<IActionResult> OnGetAsync(CancellationToken ct)
- {
- App = await db.ApiApplication
- .Include(c => c.Owner)
- .FirstOrDefaultAsync(c => c.ID == ID, ct);
- if (App is null)
- {
- return NotFound();
- }
- Credentials = await db.ApiCredential
- .Where(c => c.ApplicationID == ID)
- .OrderByDescending(c => c.CreatedAt)
- .ToListAsync(ct);
- Scopes = await db.ApiApplicationScope
- .Where(c => c.ApplicationID == ID)
- .Select(c => c.Scope)
- .ToListAsync(ct);
- RateLimitOverride = await db.ApiRateLimit
- .Where(c => c.ApplicationID == ID)
- .Select(c => (int?)c.LimitPerMinute)
- .FirstOrDefaultAsync(ct);
- LimitPerMinute = RateLimitOverride ?? 60;
- return Page();
- }
- public async Task<IActionResult> OnPostApproveAsync(CancellationToken ct)
- {
- try
- {
- await mediator.Send(new Application.Features.Admin.Developers.ApproveApp.Command([ID]), ct);
- TempData["SuccessMessage"] = "앱이 승인되었습니다.";
- }
- catch (Exception e)
- {
- TempData["ErrorMessages"] = e.Message;
- }
- return RedirectToPage("/Developers/Apps/Detail", new { ID });
- }
- public async Task<IActionResult> OnPostSuspendAsync(CancellationToken ct)
- {
- try
- {
- await mediator.Send(new Application.Features.Admin.Developers.SuspendApp.Command([ID]), ct);
- TempData["SuccessMessage"] = "앱이 정지되었습니다.";
- }
- catch (Exception e)
- {
- TempData["ErrorMessages"] = e.Message;
- }
- return RedirectToPage("/Developers/Apps/Detail", new { ID });
- }
- public async Task<IActionResult> OnPostOverrideRateLimitAsync(CancellationToken ct)
- {
- var result = await mediator.Send(new Application.Features.Admin.Developers.OverrideRateLimit.Command(ID, LimitPerMinute), ct);
- if (result.IsSuccess)
- {
- TempData["SuccessMessage"] = $"Rate limit 를 {LimitPerMinute}/min 으로 설정했습니다.";
- }
- else
- {
- TempData["ErrorMessages"] = result.Error.Description;
- }
- return RedirectToPage("/Developers/Apps/Detail", new { ID });
- }
- }
|