Skip to content

Commit

Permalink
In dup-check, only get words w/ same vern from db (#2738)
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored Oct 30, 2023
1 parent bf5b4e9 commit cc7f7a9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Backend.Tests/Mocks/WordRepositoryMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public Task<List<Word>> GetFrontier(string projectId)
return Task.FromResult(_frontier.Where(w => w.ProjectId == projectId).Select(w => w.Clone()).ToList());
}

public Task<List<Word>> GetFrontierWithVernacular(string projectId, string vernacular)
{
return Task.FromResult(_frontier.Where(
w => w.ProjectId == projectId && w.Vernacular == vernacular).Select(w => w.Clone()).ToList());
}

public Task<Word> AddFrontier(Word word)
{
_frontier.Add(word.Clone());
Expand Down
1 change: 1 addition & 0 deletions Backend/Interfaces/IWordRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface IWordRepository
Task<bool> IsFrontierNonempty(string projectId);
Task<bool> IsInFrontier(string projectId, string wordId);
Task<List<Word>> GetFrontier(string projectId);
Task<List<Word>> GetFrontierWithVernacular(string projectId, string vernacular);
Task<Word> AddFrontier(Word word);
Task<List<Word>> AddFrontier(List<Word> words);
Task<bool> DeleteFrontier(string projectId, string wordId);
Expand Down
7 changes: 7 additions & 0 deletions Backend/Repositories/WordRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ public async Task<List<Word>> GetFrontier(string projectId)
return await _wordDatabase.Frontier.Find(w => w.ProjectId == projectId).ToListAsync();
}

/// <summary> Finds all <see cref="Word"/>s in Frontier of specified project with specified vern </summary>
public async Task<List<Word>> GetFrontierWithVernacular(string projectId, string vernacular)
{
return await _wordDatabase.Frontier.Find(
w => w.ProjectId == projectId && w.Vernacular == vernacular).ToListAsync();
}

/// <summary> Adds a <see cref="Word"/> only to the Frontier </summary>
/// <param name="word"></param>
/// <returns> The word created </returns>
Expand Down
4 changes: 2 additions & 2 deletions Backend/Services/WordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ public async Task<bool> Update(string projectId, string userId, string wordId, W
/// <returns> The id string of the existing word, or null if none. </returns>
public async Task<string?> FindContainingWord(Word word)
{
var frontier = await _wordRepo.GetFrontier(word.ProjectId);
var duplicatedWord = frontier.Find(w => w.Contains(word));
var wordsWithVern = await _wordRepo.GetFrontierWithVernacular(word.ProjectId, word.Vernacular);
var duplicatedWord = wordsWithVern.Find(w => w.Contains(word));
return duplicatedWord?.Id;
}
}
Expand Down

0 comments on commit cc7f7a9

Please sign in to comment.