Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In dup-check, only get words with same vernacular from db #2738

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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