SubmittedTaskController
Namespace: Commissiestrijd.Controllers
Assembly: backend.dll
Controller for handling submitted tasks. This controller allows users to submit tasks, approve or reject submitted tasks, and retrieve lists of submitted tasks based on their status. It checks if the user is authorized before allowing access to the endpoints. The submitted tasks are stored in the database and can be filtered by committee or status.
[Authorize]
[ApiController]
[Route("[controller]")]
public class SubmittedTaskController : Controller, IActionFilter, IAsyncActionFilter, IFilterMetadata, IDisposable
Inheritance
object
← ControllerBase
← Controller
← SubmittedTaskController
Implements
IActionFilter
,
IAsyncActionFilter
,
IFilterMetadata
,
IDisposable
Show Inherited Members (204)
Constructors
SubmittedTaskController(AppDbContext, ILogger<SubmittedTaskController>)
Constructor for the SubmittedTaskController. 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 SubmittedTaskController(AppDbContext context, ILogger<SubmittedTaskController> logger)
Parameters
Name | Type | Description |
---|---|---|
context | AppDbContext | The database context used to access the application's data. |
logger | ILogger<SubmittedTaskController> | The logger used for logging information or errors during operations. |
Methods
ApproveTask(Guid, int, int?)
Approves a submitted task. This method allows an admin to approve a submitted task by providing the task ID, points to award, and an optional maximum points per period. It validates the request parameters, checks if the task exists, and updates the task status to approved with the specified points.
[HttpPut("ApproveTask")]
[SwaggerOperation(null, null, Summary = "Approve Task", Description = "This endpoint allows an admin to approve a submitted task.")]
[SwaggerResponse(200, "Returns the approved task with its details if the approval is successful.", null)]
[ProducesResponseType(typeof(SubmittedTask), 200)]
[SwaggerResponse(400, "BadRequest if the request parameters are invalid, such as empty task ID, invalid points value, or points exceeding the maximum limit.", null)]
[SwaggerResponse(401, "Unauthorized if the user is not an admin.", null)]
[SwaggerResponse(404, "NotFound if the specified task does not exist.", null)]
[SwaggerResponse(500, "Internal Server Error if an error occurs while processing the request.", null)]
public Task<IActionResult> ApproveTask(Guid TaskId, int Points, int? MaxPerPeriod = null)
Parameters
Name | Type | Description |
---|---|---|
TaskId | Guid | The ID of the task to approve. |
Points | int | The number of points to award for the approved task. |
MaxPerPeriod | int | The maximum points that can be awarded per period for this task. |
This parameter is optional.
Returns
Type | Description |
---|---|
Task | An IActionResult containing the approved task or an error response if validation fails. |
GetApprovedTasks(int, int, string?)
Retrieves a list of rejected tasks. This method allows users to retrieve a list of tasks that have been rejected, optionally filtered by committee. It returns the rejected tasks ordered by submission date in descending order.
[HttpGet("GetApprovedTasks")]
[SwaggerOperation(null, null, Summary = "Get Approved Tasks", Description = "This endpoint retrieves all approved tasks from the database.")]
[SwaggerResponse(200, "Returns a list of approved tasks.", null)]
[ProducesResponseType(typeof(PageResponse<SubmittedTask>), 200)]
[SwaggerResponse(400, "BadRequest if the request parameters are invalid.", null)]
[SwaggerResponse(500, "Internal Server Error if an error occurs while retrieving the tasks.", null)]
public IActionResult GetApprovedTasks(int page, int pageSize = 5, string? committee = null)
Parameters
Name | Type | Description |
---|---|---|
page | int | The page number to retrieve. |
pageSize | int | The number of items to retrieve per page. |
This parameter is optional and defaults to 5.
committee
string
?
The name of the committee to filter the tasks by. This parameter is optional.
Returns
Type | Description |
---|---|
IActionResult | An IActionResult containing a list of rejected tasks or an empty list if no tasks are |
found.
GetPendingTasks(int, int, string?)
Retrieves a list of submitted tasks. This method allows users to retrieve a list of tasks that have been submitted, optionally filtered by committee. It returns the submitted tasks ordered by submission date in descending order.
[HttpGet("GetPendingTasks")]
[SwaggerOperation(null, null, Summary = "Get Pending Tasks", Description = "This endpoint retrieves all pending tasks from the database.")]
[SwaggerResponse(200, "Returns a list of pending tasks.", null)]
[ProducesResponseType(typeof(PageResponse<SubmittedTask>), 200)]
[SwaggerResponse(400, "BadRequest if the request parameters are invalid.", null)]
[SwaggerResponse(500, "Internal Server Error if an error occurs while retrieving the tasks.", null)]
public IActionResult GetPendingTasks(int page = 1, int pageSize = 5, string? committee = null)
Parameters
Name | Type | Description |
---|---|---|
page | int | The page number to retrieve. |
pageSize | int | The number of items to retrieve per page. |
This parameter is optional and defaults to 5.
committee
string
?
The name of the committee to filter the tasks by. This parameter is optional.
Returns
Type | Description |
---|---|
IActionResult | A list of pending tasks, ordered by submission date in descending order. |
GetRejectedTasks(int, int, string?)
Retrieves a list of rejected tasks. This method allows users to retrieve a list of tasks that have been rejected, optionally filtered by committee. It returns the rejected tasks ordered by submission date in descending order.
[HttpGet("GetRejectedTasks")]
[SwaggerOperation(null, null, Summary = "Get Rejected Tasks", Description = "This endpoint retrieves all rejected tasks from the database.")]
[SwaggerResponse(200, "Returns a list of rejected tasks.", null)]
[ProducesResponseType(typeof(PageResponse<SubmittedTask>), 200)]
[SwaggerResponse(400, "BadRequest if the request parameters are invalid.", null)]
[SwaggerResponse(500, "Internal Server Error if an error occurs while retrieving the tasks.", null)]
public IActionResult GetRejectedTasks(int page, int pageSize = 5, string? committee = null)
Parameters
Name | Type | Description |
---|---|---|
page | int | The page number to retrieve. |
pageSize | int | The number of items to retrieve per page. |
This parameter is optional and defaults to 5.
committee
string
?
The name of the committee to filter the tasks by. This parameter is optional.
Returns
Type | Description |
---|---|
IActionResult | A list of rejected tasks, ordered by submission date in descending order. |
GetSubmittedTask(Guid)
Retrieves a specific submitted task by its ID. This method allows users to retrieve a submitted task by providing the task ID. It returns the task details if found, or a NotFound response if the task does not exist.
[HttpGet("GetSubmittedTask")]
[SwaggerOperation(null, null, Summary = "Get Submitted Task", Description = "This endpoint retrieves a submitted task by its ID.")]
[SwaggerResponse(200, "Returns the submitted task with its details if found.", null)]
[ProducesResponseType(typeof(SubmittedTask), 200)]
[SwaggerResponse(400, "BadRequest if the request parameters are invalid, such as an empty task ID.", null)]
[SwaggerResponse(404, "NotFound if the specified task does not exist.", null)]
[SwaggerResponse(500, "Internal Server Error if an error occurs while processing the request.", null)]
public IActionResult GetSubmittedTask(Guid TaskId)
Parameters
Name | Type | Description |
---|---|---|
TaskId | Guid | The ID of the submitted task to retrieve. |
Returns
Type | Description |
---|---|
IActionResult | An IActionResult containing the submitted task details or a NotFound response if the task does not exist. |
GetSubmittedTasks(int, int, string?)
Retrieves a paginated list of submitted tasks. This method allows users to retrieve a list of tasks that have been submitted, with optional filtering by committee.
[HttpGet("GetSubmittedTasks")]
[SwaggerOperation(null, null, Summary = "Get Submitted Tasks", Description = "This endpoint retrieves all submitted tasks from the database.")]
[SwaggerResponse(200, "Returns a list of submitted tasks.", null)]
[ProducesResponseType(typeof(PageResponse<SubmittedTask>), 200)]
[SwaggerResponse(400, "Bad Request if the request parameters are invalid.", null)]
[SwaggerResponse(500, "Internal Server Error if an error occurs while retrieving the tasks.", null)]
public IActionResult GetSubmittedTasks(int page, int pageSize = 50, string? committee = null)
Parameters
Name | Type | Description |
---|---|---|
page | int | The page number to retrieve. |
pageSize | int | The number of tasks to retrieve per page. |
This parameter is optional and will be defaulted to 50.
committee
string
?
The name of the committee to filter the tasks by. This parameter is optional.
Returns
Type | Description |
---|---|
IActionResult | A paginated list of submitted tasks. |
RejectTask(Guid, string)
Rejects a submitted task. This method allows an admin to reject a submitted task by providing the task ID and a reason for rejection. It validates the request parameters, checks if the task exists, and updates the task status to rejected with the specified reason.
[HttpPut("RejectTask")]
[SwaggerOperation(null, null, Summary = "Reject Task", Description = "This endpoint allows an admin to reject a submitted task.")]
[SwaggerResponse(200, "Returns the rejected task with its details if the rejection is successful.", null)]
[ProducesResponseType(typeof(SubmittedTask), 200)]
[SwaggerResponse(400, "BadRequest if the request parameters are invalid, such as empty task ID or reason.", null)]
[SwaggerResponse(401, "Unauthorized if the user is not an admin.", null)]
[SwaggerResponse(404, "NotFound if the specified task does not exist.", null)]
[SwaggerResponse(500, "Internal Server Error if an error occurs while processing the request.", null)]
public Task<IActionResult> RejectTask(Guid TaskId, string Reason)
Parameters
Name | Type | Description |
---|---|---|
TaskId | Guid | The ID of the task to reject. |
Reason | string | The reason for rejecting the task. |
Returns
Type | Description |
---|---|
Task | An IActionResult containing the rejected task or an error response if validation fails. |
SubmitTask(SubmitTaskRequestDto)
Submits a task for a committee. This method allows users to submit a task by providing the task ID, committee name, and an image file. It validates the request parameters, checks if the task and committee exist, and saves the submitted task to the database.
[HttpPost("SubmitTask")]
[SwaggerOperation(null, null, Summary = "Submit Task", Description = "This endpoint allows users to submit a task for a committee.")]
[SwaggerResponse(200, "Returns the submitted task with its details if the submission is successful.", null)]
[ProducesResponseType(typeof(SubmittedTask), 200)]
[SwaggerResponse(400, "BadRequest if the request parameters are invalid, such as empty task ID, committee name, or missing image file.", null)]
[SwaggerResponse(404, "NotFound if the specified committee or task does not exist.", null)]
[SwaggerResponse(500, "Internal Server Error if an error occurs while processing the request.", null)]
public Task<IActionResult> SubmitTask(SubmitTaskRequestDto SubmitTaskRequestDto)
Parameters
Name | Type | Description |
---|---|---|
SubmitTaskRequestDto | SubmitTaskRequestDto | The request data transfer object containing the task ID, committee name, and image file. |
Returns
Type | Description |
---|---|
Task | An IActionResult containing the submitted task or an error response if validation fails. |