mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-19 17:41:37 -04:00
feat(server): version guarded metadata edits
This commit is contained in:
1 parent
11471e3c71
commit
d216bcd406
8 files changed
+122
-6
No files matched your search
@@ -129,8 +129,7 @@ public sealed class RemoteNestRepository : INestRepository, IDisposable
|
||||
public async Task<NestRecord> UpdateMetadataAsync(
|
||||
Guid id, NestRecord record, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
throw new IOException("Metadata updates require guarded revision support and are not available yet. Upgrade the client before editing server metadata.");
|
||||
return await UpdateMetadataAsync(id, record, record.Revision, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(Guid id, CancellationToken cancellationToken = default)
|
||||
@@ -193,6 +192,20 @@ public sealed class RemoteNestRepository : INestRepository, IDisposable
|
||||
return saved;
|
||||
}
|
||||
|
||||
public async Task<NestRecord> UpdateMetadataAsync(Guid id, NestRecord record, int expectedRevision,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
ValidateId(id);
|
||||
ValidateRevision(expectedRevision);
|
||||
await GetRevisionsAsync(id, limit: 1, cancellationToken: cancellationToken);
|
||||
using var request = new HttpRequestMessage(HttpMethod.Put, Url($"api/nests/{id}/metadata"));
|
||||
request.Headers.IfMatch.Add(new EntityTagHeaderValue($"\"{expectedRevision.ToString(CultureInfo.InvariantCulture)}\""));
|
||||
request.Content = JsonContent.Create(record, options: JsonOptions);
|
||||
using var response = await _httpClient.SendAsync(request, cancellationToken);
|
||||
await EnsureSuccess(response, $"edit nest {id}; reload after a conflict", cancellationToken);
|
||||
return await ReadRecord(response, cancellationToken);
|
||||
}
|
||||
|
||||
private static void ValidateId(Guid id)
|
||||
{
|
||||
if (id == Guid.Empty) throw new ArgumentException("A nest id is required.", nameof(id));
|
||||
|
||||
Reference in new issue
Block a user