Created
October 18, 2025 15:37
-
-
Save wullemsb/92eb9ca58711247b7eff15892142e082 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Microsoft.AspNetCore.Mvc; | |
| using System.Collections.Concurrent; | |
| namespace HTTPFileTryOut.Controllers | |
| { | |
| [ApiController] | |
| [Route("api/[controller]")] | |
| public class ProjectsController : ControllerBase | |
| { | |
| private static readonly ConcurrentDictionary<Guid, Project> Projects = new(); | |
| [HttpPost] | |
| public IActionResult CreateProject([FromBody] CreateProjectRequest request) | |
| { | |
| var project = new Project | |
| { | |
| Id = Guid.NewGuid(), | |
| Name = request.Name, | |
| Tasks = new List<ProjectTask>() | |
| }; | |
| Projects[project.Id] = project; | |
| return CreatedAtAction(nameof(GetProject), new { id = project.Id }, project); | |
| } | |
| [HttpGet("{id}")] | |
| public IActionResult GetProject(Guid id) | |
| { | |
| if (Projects.TryGetValue(id, out var project)) | |
| return Ok(project); | |
| return NotFound(); | |
| } | |
| [HttpPost("{projectId}/tasks")] | |
| public IActionResult AddTask(Guid projectId, [FromBody] AddTaskRequest request) | |
| { | |
| if (!Projects.TryGetValue(projectId, out var project)) | |
| return NotFound(); | |
| var task = new ProjectTask | |
| { | |
| Id = Guid.NewGuid(), | |
| Title = request.Title, | |
| Description = request.Description | |
| }; | |
| project.Tasks.Add(task); | |
| return Created($"api/projects/{projectId}/tasks/{task.Id}", task); | |
| } | |
| } | |
| public class Project | |
| { | |
| public Guid Id { get; set; } | |
| public string Name { get; set; } | |
| public List<ProjectTask> Tasks { get; set; } | |
| } | |
| public class ProjectTask | |
| { | |
| public Guid Id { get; set; } | |
| public string Title { get; set; } | |
| public string Description { get; set; } | |
| } | |
| public class CreateProjectRequest | |
| { | |
| public string Name { get; set; } | |
| } | |
| public class AddTaskRequest | |
| { | |
| public string Title { get; set; } | |
| public string Description { get; set; } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment