PossibleTaskController

Namespace: Commissiestrijd.Controllers
Assembly: backend.dll

Controller for handling possible task operations. This controller allows administrators to manage possible tasks, including creating, editing, retrieving, and activating/deactivating tasks. It checks if the user is an admin before allowing access to these operations. The possible tasks are stored in the application's database and can be retrieved or modified as needed.

[Authorize]
[ApiController]
[Route("[controller]")]
public class PossibleTaskController : Controller, IActionFilter, IAsyncActionFilter, IFilterMetadata, IDisposable

Inheritance

objectControllerBaseControllerPossibleTaskController


Implements

IActionFilter, IAsyncActionFilter, IFilterMetadata,

IDisposable

Constructors


PossibleTaskController(AppDbContext, ILogger<PossibleTaskController>)

Constructor for the PossibleTaskController. 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 possible task data and log information or errors during operations.

public PossibleTaskController(AppDbContext context, ILogger<PossibleTaskController> logger)

Parameters

NameTypeDescription
contextAppDbContextThe database context used to access the application's data.
loggerILogger<PossibleTaskController>The logger used for logging information or errors during operations.

Methods


CreateCommitteeTask(string, string, int, int?)

Creates a new possible task. This method allows administrators to create a new possible task by providing a description, short description, points, and an optional maximum number of tasks per period. It checks if the user is an admin before allowing access to this operation. The method validates the input parameters to ensure they meet the required criteria, including non-empty descriptions, valid point values, and character limits. If the input is valid, a new PossibleTask object is created and added to the database.

[HttpPost("CreatePossibleTask")]
[SwaggerOperation(null, null, Summary = "Create Possible Task", Description = "This endpoint allows an admin user to create a new possible task.")]
[SwaggerResponse(201, "Returns the created task.", null)]
[ProducesResponseType(typeof(PossibleTask), 201)]
[SwaggerResponse(400, "BadRequest if the description or short description is empty or longer than the allowed character limits, or if the point value is not between 1 and 100.", null)]
[SwaggerResponse(401, "Unauthorized if the user is not an admin.", null)]
[SwaggerResponse(500, "If an error occurs while creating the task, a 500 Internal Server Error response is returned.", null)]
public Task<IActionResult> CreateCommitteeTask(string Description, string ShortDescription, int Points, int? MaxPerPeriod = null)

Parameters

NameTypeDescription
DescriptionstringThe description of the task, which must not be empty and cannot exceed 500 characters.
ShortDescriptionstringThe short description of the task, which must not be empty and cannot exceed 50 characters.
PointsintThe point value of the task, which must be greater than zero and not exceed 100.
MaxPerPeriodintAn optional parameter specifying the maximum number of tasks that can be completed per period.

If not provided, it defaults to null.

Returns

TypeDescription
TaskAn IActionResult containing the created task or a BadRequest result if the input is invalid.

EditPossibleTask(Guid, string, string, int, bool, int?)

Edits an existing possible task. This method allows administrators to modify the details of an existing possible task by providing the task ID, description, short description, points, active state, and an optional maximum number of tasks per period. It checks if the user is an admin before allowing access to this operation. The method validates the input parameters to ensure they meet the required criteria, including non-empty descriptions, valid point values, and character limits. If the input is valid, the existing PossibleTask object is updated with the new values and saved to the database.

[HttpPut("EditPossibleTask")]
[SwaggerOperation(null, null, Summary = "Edit Possible Task", Description = "This endpoint allows an admin user to edit an existing possible task.")]
[SwaggerResponse(200, "Returns the updated task.", null)]
[ProducesResponseType(typeof(PossibleTask), 200)]
[SwaggerResponse(400, "BadRequest if the task ID is empty, the description or short description is empty or longer than the allowed character limits, or if the point value is not between 1 and 100.", null)]
[SwaggerResponse(401, "Unauthorized if the user is not an admin.", null)]
[SwaggerResponse(404, "NotFound if the task is not found.", null)]
[SwaggerResponse(500, "If an error occurs while editing the task, a 500 Internal Server Error response is returned.", null)]
public Task<IActionResult> EditPossibleTask(Guid TaskId, string Description, string ShortDescription, int Points, bool IsActive, int? MaxPerPeriod = null)

Parameters

NameTypeDescription
TaskIdGuidThe ID of the task to be edited, which must not be empty.
DescriptionstringThe new description of the task, which must not be empty and cannot exceed 500 characters.
ShortDescriptionstringThe new short description of the task, which must not be empty and cannot exceed 50 characters.
PointsintThe new point value of the task, which must be greater than zero and not exceed 100.
IsActiveboolA boolean indicating whether the task is active or not.
MaxPerPeriodintAn optional parameter specifying the maximum number of tasks that can be completed per period.

If not provided, it defaults to null.

Returns

TypeDescription
TaskAn IActionResult containing the updated task or a BadRequest result if the input is invalid

or the task is not found.


GetActivePossibleTasks()

Retrieves a list of active possible tasks. This method allows administrators to get a list of all active possible tasks stored in the database. It checks if the user is an admin before allowing access to the tasks.

[HttpGet("GetActivePossibleTasks")]
[SwaggerOperation(null, null, Summary = "Get Active Possible Tasks", Description = "This endpoint retrieves all active possible tasks from the database.")]
[SwaggerResponse(200, "Returns a list of active possible tasks.", null)]
[ProducesResponseType(typeof(List<PossibleTask>), 200)]
[SwaggerResponse(400, "BadRequest if the description or short description is empty or longer than 500 characters, or if the point value is not between 1 and 100.", null)]
[SwaggerResponse(401, "Unauthorized if the user is not an admin.", null)]
[SwaggerResponse(404, "NotFound if the task is not found.", null)]
[SwaggerResponse(500, "If an error occurs while retrieving the tasks, a 500 Internal Server Error response is returned.", null)]
public IActionResult GetActivePossibleTasks()

Returns

TypeDescription
IActionResultAn IActionResult containing a list of active possible tasks or an Unauthorized result if the user is not an admin.

GetPossibleTask(Guid)

Retrieves a possible task by its ID. This method allows administrators to get the details of a specific possible task by providing the task ID. It checks if the user is an admin before allowing access to this operation. The method validates the task ID to ensure it is not empty, and if the task is found, it returns the task details.

[HttpGet("GetPossibleTask")]
[SwaggerOperation(null, null, Summary = "Get Possible Task", Description = "This endpoint retrieves a possible task by its ID.")]
[SwaggerResponse(200, "Returns the possible task with the specified ID.", null)]
[ProducesResponseType(typeof(PossibleTask), 200)]
[SwaggerResponse(400, "BadRequest if the task ID is empty.", null)]
[SwaggerResponse(401, "Unauthorized if the user is not an admin.", null)]
[SwaggerResponse(404, "NotFound if the task is not found.", null)]
[SwaggerResponse(500, "If an error occurs while retrieving the task, a 500 Internal Server Error response is returned.", null)]
public IActionResult GetPossibleTask(Guid TaskId)

Parameters

NameTypeDescription
TaskIdGuidThe ID of the task to be retrieved, which must not be empty.

Returns

TypeDescription
IActionResultAn IActionResult containing the possible task details or a BadRequest result if the task ID is empty,

or a NotFound result if the task is not found.


GetPossibleTasks()

Retrieves a list of all possible tasks. This method allows users to get a list of all possible tasks stored in the database.

[HttpGet("GetPossibleTasks")]
[SwaggerOperation(null, null, Summary = "Get Possible Tasks", Description = "This endpoint retrieves all possible tasks from the database.")]
[SwaggerResponse(200, "Returns a list of possible tasks.", null)]
[ProducesResponseType(typeof(List<PossibleTask>), 200)]
[SwaggerResponse(500, "If an error occurs while retrieving the tasks, a 500 Internal Server Error response is returned.", null)]
public IActionResult GetPossibleTasks()

Returns

TypeDescription
IActionResultAn IActionResult containing a list of possible tasks or an Unauthorized result if the user is not an admin.

SetPossibleTaskState(Guid, bool)

Sets the active state of a possible task. This method allows administrators to activate or deactivate a possible task by providing the task ID and the desired state (true for active, false for inactive). It checks if the user is an admin before allowing access to this operation. The method validates the task ID to ensure it is not empty, and if the task is found, it updates the IsActive property of the task.

[HttpPost("SetPossibleTaskState")]
[SwaggerOperation(null, null, Summary = "Set Possible Task State", Description = "This endpoint allows an admin user to activate or deactivate a possible task.")]
[SwaggerResponse(204, "NoContent if the task state is successfully updated.", null)]
[ProducesResponseType(typeof(void), 204)]
[SwaggerResponse(400, "BadRequest if the task ID is empty.", null)]
[SwaggerResponse(401, "Unauthorized if the user is not an admin.", null)]
[SwaggerResponse(404, "NotFound if the task is not found.", null)]
[SwaggerResponse(500, "If an error occurs while updating the task state, a 500 Internal Server Error response is returned.", null)]
public Task<IActionResult> SetPossibleTaskState(Guid TaskId, bool State)

Parameters

NameTypeDescription
TaskIdGuidThe ID of the task to be updated, which must not be empty.
StateboolA boolean indicating whether the task should be active (true) or inactive (false).

Returns

TypeDescription
TaskAn IActionResult indicating the result of the operation.