Implemented GetIndicatorByIdEndpoint
This commit is contained in:
@@ -230,4 +230,27 @@ public sealed class EvidenceService(IDbContextFactory<ApplicationDbContext> cont
|
||||
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Result<Indicator>> GetIndicatorAsync(string indicatorId, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var decodeResult = hashService.DecodeLongIdHash(indicatorId);
|
||||
|
||||
if (decodeResult.IsFailed)
|
||||
return Result.Fail(decodeResult.Errors);
|
||||
|
||||
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||
|
||||
var indicator = await context.Indicators.AsNoTracking().FirstOrDefaultAsync(i => i.Id == decodeResult.Value, cancellationToken);
|
||||
|
||||
return indicator is not null
|
||||
? Result.Ok(indicator.Map())
|
||||
: Result.Fail("Failed to find specific indicator.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user