using Microsoft.AspNetCore.Mvc; using TaskTracker.Core.DTOs; using TaskTracker.Core.Entities; using TaskTracker.Core.Interfaces; namespace TaskTracker.Api.Controllers; [ApiController] [Route("api/[controller]")] public class MappingsController(IAppMappingRepository mappingRepo) : ControllerBase { [HttpGet] public async Task GetAll() { var mappings = await mappingRepo.GetAllAsync(); return Ok(ApiResponse>.Ok(mappings)); } [HttpPost] public async Task Create([FromBody] CreateAppMappingRequest request) { var mapping = new AppMapping { Pattern = request.Pattern, MatchType = request.MatchType, Category = request.Category, FriendlyName = request.FriendlyName }; var created = await mappingRepo.CreateAsync(mapping); return Ok(ApiResponse.Ok(created)); } [HttpPut("{id:int}")] public async Task Update(int id, [FromBody] CreateAppMappingRequest request) { var mapping = await mappingRepo.GetByIdAsync(id); if (mapping is null) return NotFound(ApiResponse.Fail("Mapping not found")); mapping.Pattern = request.Pattern; mapping.MatchType = request.MatchType; mapping.Category = request.Category; mapping.FriendlyName = request.FriendlyName; await mappingRepo.UpdateAsync(mapping); return Ok(ApiResponse.Ok(mapping)); } [HttpDelete("{id:int}")] public async Task Delete(int id) { await mappingRepo.DeleteAsync(id); return Ok(ApiResponse.Ok()); } }