LeaderboardController
Namespace: Commissiestrijd.Controllers
Assembly: backend.dll
Controller for handling leaderboard operations. This controller allows users to retrieve the leaderboard based on submitted tasks within a specified date range. It checks if the user is authorized before allowing access to the leaderboard. The leaderboard is generated by summing the points of approved tasks grouped by committee.
[ApiController]
[Route("[controller]")]
public class LeaderboardController : Controller, IActionFilter, IAsyncActionFilter, IFilterMetadata, IDisposable
Inheritance
object
← ControllerBase
← Controller
← LeaderboardController
Implements
IActionFilter
,
IAsyncActionFilter
,
IFilterMetadata
,
IDisposable
Show Inherited Members (204)
Constructors
LeaderboardController(AppDbContext, ILogger<LeaderboardController>)
Constructor for the LeaderboardController. Initializes the controller with the provided database context and logger. This constructor is used to set up the necessary dependencies for the controller, allowing it to access submitted task data and log information or errors during operations.
public LeaderboardController(AppDbContext context, ILogger<LeaderboardController> logger)
Parameters
Name | Type | Description |
---|---|---|
context | AppDbContext | The database context used to access the application's data. |
logger | ILogger<LeaderboardController> | The logger used for logging information or errors during operations. |
Methods
GetLeaderboard(DateTime, DateTime)
Retrieves the leaderboard based on submitted tasks within a specified date range. This method allows users to get the leaderboard by providing a start date and an end date for the period they want to analyze. The leaderboard is generated by summing the points of approved tasks grouped by committee, and ordered by points in descending order. The method validates the date range to ensure the start date is not after the end date and that the dates are treated as UTC dates. If the date range is valid, it retrieves all approved tasks within that range, filters out tasks that exceed the MaxPerPeriod limit, and then groups the tasks by committee to calculate the total points for each committee.
[Authorize]
[HttpGet("GetLeaderboard")]
[SwaggerOperation(null, null, Summary = "Get Leaderboard", Description = "This endpoint allows users to get the leaderboard by providing a start and end date for the period they want to analyze.")]
[SwaggerResponse(200, "Returns the leaderboard data as a list of anonymous objects containing committee names and their total points within the specified date range.", null)]
[ProducesResponseType(typeof(List<object>), 200)]
[SwaggerResponse(400, "BadRequest if the start date is after the end date.", null)]
[SwaggerResponse(500, "Internal Server Error if an error occurs while processing the request.", null)]
public IActionResult GetLeaderboard(DateTime StartDate, DateTime EndDate)
Parameters
Name | Type | Description |
---|---|---|
StartDate | DateTime | The start date of the period for which to retrieve the leaderboard. |
EndDate | DateTime | The end date of the period for which to retrieve the leaderboard. |
Returns
Type | Description |
---|---|
IActionResult | An IActionResult containing the leaderboard data or a BadRequest result if the date range is |
invalid.
GetLeaderboardByPeriodName(string)
Get the leaderboard for a specific period by its name. This endpoint can be accessed without authentication.
[HttpGet("GetLeaderboardByPeriodName")]
[SwaggerOperation(null, null, Summary = "Get Leaderboard by Period Name", Description = "This endpoint allows users to get the leaderboard by providing a period name.")]
[SwaggerResponse(200, "Returns the leaderboard data as a list of anonymous objects containing committee names and their total points for the specified period.", null)]
[ProducesResponseType(typeof(List<object>), 200)]
[SwaggerResponse(400, "BadRequest if the period name is invalid.", null)]
[SwaggerResponse(404, "NotFound if no periods are found with the specified name.", null)]
[SwaggerResponse(500, "Internal Server Error if an error occurs while processing the request.", null)]
public IActionResult GetLeaderboardByPeriodName(string periodName)
Parameters
Name | Type | Description |
---|---|---|
periodName | string | The name of the period to retrieve the leaderboard for. |
Returns
Type | Description |
---|---|
IActionResult | The leaderboard data for the specified period. |