Skip to content
This repository has been archived by the owner on Feb 17, 2025. It is now read-only.

fix: task routes and models #26

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
using DotnetFoundation.Application.Models.Common;
using DotnetFoundation.Application.Models.DTOs.TaskDetailsDTO;
using DotnetFoundation.Application.Models.Enums;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace DotnetFoundation.Api.Controllers;

[ApiController]
[Route("api/tasks")]
[Route("api")]
public class TaskController : ControllerBase
{
private readonly ITaskDetailsService _taskDetailsService;
Expand All @@ -20,7 +19,7 @@ public TaskController(ITaskDetailsService TaskDetailsService)
/// <summary>
/// Get all tasks.
/// </summary>
[HttpGet]
[HttpGet("tasks")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<BaseResponse<List<TaskDetailsResponse>>>> GetAllTasksAsync()
Expand All @@ -36,7 +35,7 @@ public async Task<ActionResult<BaseResponse<List<TaskDetailsResponse>>>> GetAllT
/// <summary>
/// Get all active tasks.
/// </summary>
[HttpGet("active")]
[HttpGet("tasks/active")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<BaseResponse<List<TaskDetailsResponse>>>> GetActiveTasksAsync()
Expand All @@ -53,7 +52,7 @@ public async Task<ActionResult<BaseResponse<List<TaskDetailsResponse>>>> GetActi
/// Get task details by Id.
/// </summary>
/// <param name="taskId">Id of task record</param>
[HttpGet("{taskId}")]
[HttpGet("tasks/{taskId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
Expand All @@ -72,7 +71,7 @@ public async Task<ActionResult<BaseResponse<TaskDetailsResponse>>> GetTaskByIdAs
/// Add new task.
/// </summary>
/// <param name="detailRequest">Role request details</param>
[HttpPost]
[HttpPost("task")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task endpoint for adding a new task is correctly implemented as a POST operation, which aligns with RESTful design principles for creating resources. However, it's worth noting that the singular form task is used here, whereas other endpoints use the plural form tasks. While this is not incorrect, it's generally a good practice to maintain consistency in naming conventions across the API. Consider aligning this endpoint with others by using the plural form tasks for consistency.

- [HttpPost("task")]
+ [HttpPost("tasks")]

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
[HttpPost("task")]
[HttpPost("tasks")]

[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
Expand All @@ -91,7 +90,7 @@ public async Task<ActionResult<BaseResponse<TaskDetailsResponse>>> InsertTaskAsy
/// </summary>
/// <param name="taskId">Id of task record</param>
/// <param name="modifiedDetails">Modified details for task record</param>
[HttpPut("{taskId}")]
[HttpPut("tasks/{taskId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<BaseResponse<TaskDetailsResponse>>> UpdateTaskAsync(int taskId, TaskDetailsRequest modifiedDetails)
Expand All @@ -108,7 +107,7 @@ public async Task<ActionResult<BaseResponse<TaskDetailsResponse>>> UpdateTaskAsy
/// Change status of task to inactive.
/// </summary>
/// <param name="taskId">Id of task record</param>
[HttpDelete("{taskId}")]
[HttpDelete("tasks/{taskId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<BaseResponse<TaskDetailsResponse>>> InactiveTaskAsync(int taskId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public record TaskDetailsRequest
/// Gets the Description of the task.
/// </summary>
[Required(ErrorMessage = "Description is required")]
[StringLength(100, ErrorMessage = "Description Max Length is 100")]
public string Description { get; init; } = string.Empty;
/// <summary>
/// Gets the Budgeted Hours of the task.
Expand All @@ -23,5 +24,6 @@ public record TaskDetailsRequest
/// <summary>
/// Gets the Category of the task.
/// </summary>
[StringLength(100, ErrorMessage = "Category Max Length is 100")]
public string? Category { get; init; }
}
Loading