| 12345678910111213141516171819202122232425262728293031323334353637 |
- using Application.Abstractions.Data;
- using Application.Abstractions.Messaging;
- using Microsoft.EntityFrameworkCore;
- using SharedKernel.Results;
- namespace Application.Features.Api.Developers.Apps.GetApp;
- internal sealed class Handler(IAppDbContext db) : IQueryHandler<Query, Result<Response>>
- {
- public async Task<Result<Response>> Handle(Query request, CancellationToken ct)
- {
- var app = await db.ApiApplication
- .Where(c => c.ID == request.AppID && c.OwnerMemberID == request.OwnerMemberID)
- .FirstOrDefaultAsync(ct);
- if (app is null)
- {
- return Result.Failure<Response>(Error.NotFound("App.NotFound", "App not found."));
- }
- var scopes = await db.ApiApplicationScope
- .Where(c => c.ApplicationID == app.ID)
- .Select(c => c.Scope)
- .ToListAsync(ct);
- var credentials = await db.ApiCredential
- .Where(c => c.ApplicationID == app.ID)
- .OrderByDescending(c => c.CreatedAt)
- .Select(c => new CredentialInfo(c.ClientID, c.SecretHint, c.Status, c.CreatedAt, c.LastUsedAt))
- .ToListAsync(ct);
- return Result.Success(new Response(
- app.ID, app.Name, app.Description, app.HomepageUrl, app.LogoPath, app.Status,
- scopes, credentials, app.CreatedAt
- ));
- }
- }
|