[HttpGet]
public async Task<List<WordDto>> Get(string? categoryName)
{
var words = _db.Words.AsQueryable();
if (categoryName is not null)
{
words = words
.Where(w => w.Category.Name == categoryName);
}
var wordsList = await words
.Select(w => new WordDto(w.Id, w.Text, w.Length, w.Category))
.ToListAsync();
//Shuffling all words in a category. Horribly ineffcient.
wordsList.Shuffle();
//Return first x words.
return wordsList.Slice(0, 3);
}
[HttpGet]
public async Task<List<WordDto>> Get(string? categoryName)
{
var words = _db.Words.AsQueryable();
if (categoryName is not null)
{
words = words
.Where(w => w.Category.Name == categoryName);
}
var wordsList = await words
.Select(w => new WordDto(w.Id, w.Text, w.Length, w.Category))
.ToListAsync();
//Shuffling all words in a category. Horribly ineffcient.
wordsList.Shuffle();
//Return first x words.
return wordsList.Slice(0, 3);
}