Problem statement
Use everything from this module in one API: map the five task endpoints in a route group, with typed results, the right status codes, an id constraint and query filters with defaults.
Requirements
The task store, the TaskItem model and the request contracts are already provided and registered. Your task has one part: map the task endpoints in MapTaskEndpoints in TaskTrackerApi/Endpoints/TaskEndpoints.cs.
A route group, made with MapGroup(prefix), gives several endpoints one shared prefix: each endpoint mapped on the group adds only the rest of its path. TypedResults work like Results, and when a handler's return type names its results, such as Results<Ok<TaskItem>, NotFound>, the endpoint also declares the status codes it can answer with.
ITaskStore (provided)
- GetTasks(status, minPriority) returns the matching tasks ordered by Id. The status all keeps every status
- Find(id), Add(request), Update(id, request) and Remove(id). Update and Remove return false when no task has that id
TaskEndpoints
- MapTaskEndpoints returns the route group for /api/v1/tasks, and all five endpoints are mapped on it, so no route repeats the prefix
- GET /api/v1/tasks answers 200 with the tasks. status (default all) and minPriority (an int, default 1) come from the query string, and a minPriority that is not a whole number is answered with 400
- GET /api/v1/tasks/{id} answers 200 with the task
- POST /api/v1/tasks takes a CreateTaskRequest and answers 201 with the new task. Its Location header is the task's detail path, such as /api/v1/tasks/6
- PUT /api/v1/tasks/{id} takes an UpdateTaskRequest, replaces the task and answers 204 with no body
- DELETE /api/v1/tasks/{id} removes the task and answers 204 with no body
- GET, PUT and DELETE answer 404 for an id that no task has
- {id} only matches a whole number that fits in an int, so /api/v1/tasks/abc gets a 404 from routing
- Each handler's return type names its typed results, so every endpoint declares its status codes
Sample Requests & Responses
GET /api/v1/tasks?status=open&minPriority=3
Response (200 OK):
[
{ "id": 3, "title": "Update onboarding guide", "status": "open", "priority": 4 },
{ "id": 5, "title": "Plan sprint retro", "status": "open", "priority": 5 }
]
GET /api/v1/tasks/2
Response (200 OK):
{ "id": 2, "title": "Review pull request", "status": "done", "priority": 1 }
POST /api/v1/tasks
Request body:
{ "title": "Book the venue", "status": "open", "priority": 3 }
Response (201 Created), with the header Location: /api/v1/tasks/6:
{ "id": 6, "title": "Book the venue", "status": "open", "priority": 3 }
PUT /api/v1/tasks/2 with { "title": "Review pull request feedback", "status": "open", "priority": 4 }
Response (204 No Content).
DELETE /api/v1/tasks/3
Response (204 No Content).
GET /api/v1/tasks/99 and GET /api/v1/tasks/abc
Response (404 Not Found) for each.
GET /api/v1/tasks?minPriority=abc
Response (400 Bad Request).
