diff --git a/apps/APTrackerAPI/Controllers/AttractionController.cs b/apps/APTrackerAPI/Controllers/AttractionController.cs new file mode 100644 index 0000000..a457214 --- /dev/null +++ b/apps/APTrackerAPI/Controllers/AttractionController.cs @@ -0,0 +1,57 @@ +using APTrackerAPI.Data; +using APTrackerAPI.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace APTrackerAPI.Controllers +{ + /// + /// Controller for managing attractions. + /// + [ApiController] + [Route("[controller]")] + public class AttractionController : ControllerBase + { + private readonly ILogger _logger; + private readonly APTrackerDbContext _dbContext; + + public AttractionController(ILogger logger, APTrackerDbContext dbContext) + { + _logger = logger; + _dbContext = dbContext; + } + + /// + /// Retrieves all attractions. + /// + /// A list of all attractions. + /// Returns the list of attractions + [HttpGet("GetAttraction")] + public async Task>> GetAttraction() + { + return await _dbContext.Attractions.ToListAsync(); + } + + /// + /// Retrieves a specific attraction by a given ID. + /// + /// The ID of the attraction to retrieve. + /// The attraction specified by the ID. + /// Returns the requested attraction + /// If the attraction was not found + [HttpGet("GetAttraction/{id}")] + public async Task> GetAttraction(int id) + { + var attraction = await _dbContext.Attractions.FindAsync(id); + + if (attraction == null) + { + _logger.LogWarning("Attraction with id {Id} does not exist", id); + return NotFound(); + } + + return attraction; + } + } +} +