CommitteeController

Namespace:
Assembly: backend.dll

Controller for managing committees. This controller provides endpoints to create, delete, and rename committees, as well as to retrieve a list of all committees. It requires the user to be authenticated and authorized as an admin to perform create, delete, or rename operations on committees. The controller interacts with the AppDbContext to perform database operations related to committees.

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

Inheritance

objectControllerBaseControllerCommitteeController


Implements

IActionFilter, IAsyncActionFilter, IFilterMetadata,

IDisposable

Constructors


CommitteeController(AppDbContext, ILogger<CommitteeController>)

Constructor for CommitteeController. 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 committee data and log information or errors during operations.

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

Parameters

NameTypeDescription
contextAppDbContextThe database context to be used for accessing committee data.
loggerILogger<CommitteeController>The logger to be used for logging information and errors.

Methods


CreateCommittee(string)

Creates a new committee with the specified name. This endpoint allows an admin user to create a new committee.

[HttpPost("CreateCommittee")]
[SwaggerOperation(null, null, Summary = "Create Committee", Description = "This endpoint allows an admin user to create a new committee with a specified name.")]
[SwaggerResponse(201, "Returns the created committee if successful.", null)]
[ProducesResponseType(typeof(Committee), 201)]
[SwaggerResponse(400, "BadRequest if the name is empty or already exists.", null)]
[SwaggerResponse(401, "Unauthorized if the user is not an admin.", null)]
[SwaggerResponse(500, "Internal server error if there is an issue creating the committee.", null)]
public Task<IActionResult> CreateCommittee(string Name)

Parameters

NameTypeDescription
NamestringThe name of the committee to be created.

This parameter is required and must not be empty. If the name is already taken, an error will be returned.

Returns

TypeDescription
TaskAn IActionResult indicating the result of the operation.

If successful, it returns the created committee. If the user is not an admin, it returns an Unauthorized response. If the name is empty or already exists, it returns a BadRequest response.


DeleteCommittee(string)

Deletes a committee with the specified name. This endpoint allows an admin user to delete a committee.

[HttpDelete("DeleteCommittee")]
[SwaggerOperation(null, null, Summary = "Delete Committee", Description = "This endpoint allows an admin user to delete a committee with a specified name.")]
[SwaggerResponse(200, "Returns a success message if the committee is deleted successfully.", null)]
[ProducesResponseType(typeof(string), 200)]
[SwaggerResponse(401, "Unauthorized if the user is not an admin.", null)]
[SwaggerResponse(404, "NotFound if the committee does not exist.", null)]
[SwaggerResponse(500, "Internal server error if there is an issue deleting the committee.", null)]
public Task<IActionResult> DeleteCommittee(string name)

Parameters

NameTypeDescription
namestringThe name of the committee to be deleted.

This parameter is required and must not be empty. If the committee does not exist, an error will be returned.

Returns

TypeDescription
TaskAn IActionResult indicating the result of the operation.

If successful, it returns a success message. If the user is not an admin, it returns an Unauthorized response. If the committee does not exist, it returns a NotFound response.


GetCommittees()

Retrieves a list of all committees. This endpoint returns a list of committees ordered by their names. It does not require any parameters and is accessible to all authenticated users. Returns a JSON response containing the list of committees.

[HttpGet("GetCommittees")]
[ProducesResponseType(typeof(List<Committee>), 200)]
[SwaggerOperation(null, null, Summary = "Get Committees", Description = "This endpoint returns a list of committees ordered by their names. It does not require any parameters and is accessible to all authenticated users. Returns a JSON response containing the list of committees.")]
public IActionResult GetCommittees()

Returns

TypeDescription
IActionResultAn IActionResult containing the list of committees in JSON format.

RenameCommittee(string, string)

Renames a committee from the specified name to a new name. This endpoint allows an admin user to rename a committee.

[HttpPut("RenameCommittee")]
[SwaggerOperation(null, null, Summary = "Rename Committee", Description = "This endpoint allows an admin user to rename a committee.")]
[SwaggerResponse(200, "Returns the new name of the committee if renamed successfully.", null)]
[ProducesResponseType(typeof(string), 200)]
[SwaggerResponse(400, "BadRequest if the new name is empty or already exists.", null)]
[SwaggerResponse(401, "Unauthorized if the user is not an admin.", null)]
[SwaggerResponse(404, "NotFound if the committee does not exist.", null)]
[SwaggerResponse(500, "Internal server error if there is an issue renaming the committee.", null)]
public Task<IActionResult> RenameCommittee(string name, string newName)

Parameters

NameTypeDescription
namestringThe current name of the committee to be renamed.

This parameter is required and must not be empty. If the committee does not exist, an error will be returned.

newName string

The new name for the committee. This parameter is required and must not be empty. If the new name is already taken, an error will be returned.

Returns

TypeDescription
TaskAn IActionResult indicating the result of the operation.

If successful, it returns the new name of the committee. If the user is not an admin, it returns an Unauthorized response. If the committee does not exist, it returns a NotFound response. If the new name is already taken, it returns a BadRequest response.