Skip to content

Commit

Permalink
fix caching
Browse files Browse the repository at this point in the history
  • Loading branch information
PHAN Xuan Quang committed Sep 12, 2024
1 parent ab9cca5 commit 35782ba
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions EngAce.Api/Controllers/QuizController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public async Task<ActionResult<List<Quiz>>> Generate([FromBody] GenerateQuizzes
/// <response code="400">The error message if an error occurs during the suggestion process.</response>
/// <response code="401">The error message if the access key is invalid.</response>
[HttpGet("Suggest3Topics")]
[ResponseCache(Duration = ReviewScope.OneHourAsCachingAge, Location = ResponseCacheLocation.Any, NoStore = false)]
public async Task<ActionResult<List<string>>> Suggest3Topics(EnglishLevel englishLevel = EnglishLevel.Intermediate)
{
if (string.IsNullOrEmpty(_accessKey))
Expand Down Expand Up @@ -138,11 +139,10 @@ public async Task<ActionResult<List<string>>> Suggest3Topics(EnglishLevel englis
[ResponseCache(Duration = QuizScope.ThreeDaysAsCachingAge, Location = ResponseCacheLocation.Any, NoStore = false)]
public ActionResult<Dictionary<int, string>> GetEnglishLevels()
{
var levels = Enum.GetValues(typeof(EnglishLevel)).Cast<EnglishLevel>().ToList();

var descriptions = levels.ToDictionary(
level => (int)level,
level => GeneralHelper.GetEnumDescription(level)
var descriptions = Enum
.GetValues(typeof(EnglishLevel))
.Cast<EnglishLevel>()
.ToDictionary(level => (int)level, level => GeneralHelper.GetEnumDescription(level)
);

return Ok(descriptions);
Expand All @@ -156,16 +156,14 @@ public ActionResult<Dictionary<int, string>> GetEnglishLevels()
/// </returns>
/// <response code="200">Returns a dictionary of quiz types and their descriptions.</response>
[HttpGet("GetQuizTypes")]
[ResponseCache(Duration = QuizScope.ThreeDaysAsCachingAge, Location = ResponseCacheLocation.Any, NoStore = false)]
[ResponseCache(Duration = ReviewScope.OneHourAsCachingAge, Location = ResponseCacheLocation.Any, NoStore = false)]
public ActionResult<Dictionary<int, string>> GetQuizTypes()
{
var types = Enum.GetValues(typeof(QuizzType))
var descriptions = Enum
.GetValues(typeof(QuizzType))
.Cast<QuizzType>()
.OrderBy(t => GeneralHelper.GetEnumDescription(t));

var descriptions = types.ToDictionary(
type => (int)type,
type => GeneralHelper.GetEnumDescription(type)
.OrderBy(t => GeneralHelper.GetEnumDescription(t))
.ToDictionary(type => (int)type, type => GeneralHelper.GetEnumDescription(type)
);

return Ok(descriptions);
Expand Down

0 comments on commit 35782ba

Please sign in to comment.