using Microsoft.AspNetCore.Mvc; using TaskTracker.Core.DTOs; using TaskTracker.Core.Entities; using TaskTracker.Core.Interfaces; namespace TaskTracker.Api.Controllers; [ApiController] [Route("api/tasks/{taskId:int}/notes")] public class NotesController(ITaskRepository taskRepo) : ControllerBase { [HttpGet] public async Task GetNotes(int taskId) { var task = await taskRepo.GetByIdAsync(taskId); if (task is null) return NotFound(ApiResponse.Fail("Task not found")); return Ok(ApiResponse>.Ok(task.Notes)); } [HttpPost] public async Task AddNote(int taskId, [FromBody] CreateNoteRequest request) { var task = await taskRepo.GetByIdAsync(taskId); if (task is null) return NotFound(ApiResponse.Fail("Task not found")); var note = new TaskNote { Content = request.Content, Type = request.Type, CreatedAt = DateTime.UtcNow }; task.Notes.Add(note); await taskRepo.UpdateAsync(task); return Ok(ApiResponse.Ok(note)); } }