Implement step 17 modules: threads/messages, notifications with automation (submission.created, idea.created, grant_call.opened), innovation test feedback, admin panel (submissions, verify, metrics, grant call status), Middleman adaptation and partnerships. Split multi-type files into one type per file and replace object-valued dictionaries with string-valued maps in data contracts (migrations 0006/0007).
90 lines
2.7 KiB
C#
90 lines
2.7 KiB
C#
using SurrealDb.Net;
|
|
using TarninaHub.Application.Abstractions;
|
|
using TarninaHub.Application.Dtos;
|
|
|
|
namespace TarninaHub.Infrastructure.Persistence;
|
|
|
|
public sealed class GrantCallService : IGrantCallService
|
|
{
|
|
private const string SelectFields =
|
|
"type::string(id) AS id, name, opens_at, closes_at, status, external_id";
|
|
|
|
private readonly ISurrealDbClient _client;
|
|
|
|
public GrantCallService(ISurrealDbClient client)
|
|
{
|
|
_client = client;
|
|
}
|
|
|
|
public async Task<IReadOnlyList<GrantCallResponse>> ListAsync(
|
|
string? status,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var parameters = new Dictionary<string, object?>();
|
|
var where = string.Empty;
|
|
|
|
if (!string.IsNullOrWhiteSpace(status))
|
|
{
|
|
where = " WHERE status = $status";
|
|
parameters["status"] = status;
|
|
}
|
|
|
|
var response = await _client.RawQuery(
|
|
$"SELECT {SelectFields} FROM grant_call{where} ORDER BY opens_at DESC;",
|
|
parameters,
|
|
cancellationToken);
|
|
response.EnsureAllOks();
|
|
|
|
var rows = response.GetValue<List<GrantCallRow>>(0) ?? [];
|
|
|
|
return rows.Select(Map).ToList();
|
|
}
|
|
|
|
public async Task<GrantCallResponse?> GetAsync(string grantCallId, CancellationToken cancellationToken)
|
|
{
|
|
var (table, id) = SurrealRecordId.Split(grantCallId);
|
|
|
|
var response = await _client.RawQuery(
|
|
$"SELECT {SelectFields} FROM type::record($table, $id) LIMIT 1;",
|
|
new Dictionary<string, object?> { ["table"] = table, ["id"] = id },
|
|
cancellationToken);
|
|
response.EnsureAllOks();
|
|
|
|
var rows = response.GetValue<List<GrantCallRow>>(0) ?? [];
|
|
|
|
return rows.Count > 0 ? Map(rows[0]) : null;
|
|
}
|
|
|
|
public async Task<GrantCallResponse?> UpdateStatusAsync(
|
|
string grantCallId,
|
|
string status,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var (table, id) = SurrealRecordId.Split(grantCallId);
|
|
|
|
var response = await _client.RawQuery(
|
|
"UPDATE type::record($table, $id) SET status = $status; " +
|
|
$"SELECT {SelectFields} FROM type::record($table, $id) LIMIT 1;",
|
|
new Dictionary<string, object?>
|
|
{
|
|
["table"] = table,
|
|
["id"] = id,
|
|
["status"] = status,
|
|
},
|
|
cancellationToken);
|
|
response.EnsureAllOks();
|
|
|
|
var rows = response.GetValue<List<GrantCallRow>>(1) ?? [];
|
|
|
|
return rows.Count > 0 ? Map(rows[0]) : null;
|
|
}
|
|
|
|
private static GrantCallResponse Map(GrantCallRow row) => new(
|
|
row.Id,
|
|
row.Name,
|
|
row.OpensAt,
|
|
row.ClosesAt,
|
|
row.Status,
|
|
row.ExternalId);
|
|
}
|