Created
December 29, 2019 05:13
-
-
Save hadoan/3344e90632cbcf03f5976b5800d3cf1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TodoQueryController : ControllerBase | |
{ | |
private readonly TodoDbContext _db; | |
public TodoQueryController(TodoDbContext db) | |
{ | |
_db = db; | |
} | |
[HttpGet] | |
public async Task<ActionResult<List<Todo>>> GetAll() | |
{ | |
return await _db.Todoes.ToListAsync(); | |
} | |
[HttpGet] | |
public async Task<ActionResult<TodaySummary>> GetSummary() | |
{ | |
var summary = await _db.TodoSummaries.FirstOrDefaultAsync(x => x.Date == DateTime.Today); | |
if (summary == null) return new TodaySummary(); | |
else return new TodaySummary | |
{ | |
AddedCount = summary.AddedCount, | |
CompletedCount = summary.CompletedCount | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment