Skip to content

Commit

Permalink
Add GetPartOfSpeech(Guid) to IMiniLcmReadApi
Browse files Browse the repository at this point in the history
  • Loading branch information
rmunn committed Nov 6, 2024
1 parent 9680e53 commit 0013457
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
8 changes: 8 additions & 0 deletions backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ public IAsyncEnumerable<PartOfSpeech> GetPartsOfSpeech()
.Select(FromLcmPartOfSpeech);
}

public Task<PartOfSpeech?> GetPartOfSpeech(Guid id)
{
return Task.FromResult(
PartOfSpeechRepository
.TryGetObject(id, out var partOfSpeech)
? FromLcmPartOfSpeech(partOfSpeech) : null);
}

public Task<PartOfSpeech> CreatePartOfSpeech(PartOfSpeech partOfSpeech)
{
IPartOfSpeech? lcmPartOfSpeech = null;
Expand Down
10 changes: 4 additions & 6 deletions backend/FwLite/FwLiteProjectSync/DryRunMiniLcmApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@ public IAsyncEnumerable<PartOfSpeech> GetPartsOfSpeech()
return api.GetPartsOfSpeech();
}

public async Task<PartOfSpeech?> GetPartOfSpeech(Guid id)
public Task<PartOfSpeech?> GetPartOfSpeech(Guid id)
{
// TODO: Should we add GetPartOfSpeech to the read API? Then we could just do this:
// return api.GetPartOfSpeech(id);
return await GetPartsOfSpeech().Where(pos => pos.Id == id).FirstOrDefaultAsync();
return api.GetPartOfSpeech(id);
}

public Task<PartOfSpeech> CreatePartOfSpeech(PartOfSpeech partOfSpeech)
public async Task<PartOfSpeech> CreatePartOfSpeech(PartOfSpeech partOfSpeech)
{
DryRunRecords.Add(new DryRunRecord(nameof(CreatePartOfSpeech), $"Create part of speech {partOfSpeech.Name}"));
return Task.FromResult(partOfSpeech); // Or maybe GetPartOfSpeech(partOfSpeech.Id)!;
return partOfSpeech; // Since this is a dry run, api.GetPartOfSpeech would return null
}
public Task<PartOfSpeech> UpdatePartOfSpeech(Guid id, UpdateObjectInput<PartOfSpeech> update)
{
Expand Down
1 change: 1 addition & 0 deletions backend/FwLite/MiniLcm/IMiniLcmReadApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface IMiniLcmReadApi
IAsyncEnumerable<Entry> GetEntries(QueryOptions? options = null);
IAsyncEnumerable<Entry> SearchEntries(string query, QueryOptions? options = null);
Task<Entry?> GetEntry(Guid id);
Task<PartOfSpeech?> GetPartOfSpeech(Guid id);
}

public record QueryOptions(
Expand Down
5 changes: 5 additions & 0 deletions backend/FwLite/MiniLcm/InMemoryApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ public async Task<PartOfSpeech> CreatePartOfSpeech(PartOfSpeech partOfSpeech)
throw new NotImplementedException();
}

public Task<PartOfSpeech?> GetPartOfSpeech(Guid id)
{
throw new NotImplementedException();
}

public Task<PartOfSpeech> UpdatePartOfSpeech(Guid id, UpdateObjectInput<PartOfSpeech> update)
{
throw new NotImplementedException();
Expand Down

0 comments on commit 0013457

Please sign in to comment.