Skip to content

Commit

Permalink
Fix 2 for #595 - make sure Name field is always there.
Browse files Browse the repository at this point in the history
* The "OK" is not needed but will be auto-added.
* If "Name" is not there, it will crash when trying to get the fields.
  • Loading branch information
johnml1135 committed Jan 21, 2025
1 parent f5f4244 commit da134f7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ public static IMongoDataAccessConfigurator AddDataFilesRepositories(this IMongoD
);
configurator.AddRepository<Corpus>(
"corpora.corpus",
init: c =>
c.Indexes.CreateOrUpdateAsync(
init: async c =>
{
await c.Indexes.CreateOrUpdateAsync(
new CreateIndexModel<Corpus>(Builders<Corpus>.IndexKeys.Ascending(p => p.Owner))
)
);
// migrate by adding Name field
await c.UpdateManyAsync(
Builders<Corpus>.Filter.Exists(b => b.Name, false),
Builders<Corpus>.Update.Set(b => b.Name, "")
);
}
);
return configurator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ IDataFileService dataFileService
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(void), StatusCodes.Status503ServiceUnavailable)]
public async Task<ActionResult<IEnumerable<CorpusDto>>> GetAllAsync(CancellationToken cancellationToken)
public async Task<IEnumerable<CorpusDto>> GetAllAsync(CancellationToken cancellationToken)
{
return Ok((await _corpusService.GetAllAsync(Owner, cancellationToken)).Select(Map));
return (await _corpusService.GetAllAsync(Owner, cancellationToken)).Select(Map);
}

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions src/Serval/test/Serval.E2ETests/ServalApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ public async Task NmtQueueMultiple()
"en",
true
);
// Verify the corpora are readable
var allCorpora = await _helperClient.CorporaClient.GetAllAsync();
Assert.That(allCorpora, Has.Count.GreaterThan(0));

for (int i = 0; i < NUM_ENGINES; i++)
{
_helperClient.InitTranslationBuildConfig();
Expand Down

0 comments on commit da134f7

Please sign in to comment.