Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions apps/APTrackerAPI/Controllers/AttractionController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using APTrackerAPI.Data;
using APTrackerAPI.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace APTrackerAPI.Controllers
{
/// <summary>
/// Controller for managing attractions.
/// </summary>
[ApiController]
[Route("[controller]")]
public class AttractionController : ControllerBase
{
private readonly ILogger<AttractionController> _logger;
private readonly APTrackerDbContext _dbContext;

public AttractionController(ILogger<AttractionController> logger, APTrackerDbContext dbContext)
{
_logger = logger;
_dbContext = dbContext;
}

/// <summary>
/// Retrieves all attractions.
/// </summary>
/// <returns>A list of all attractions.</returns>
/// <response code="200">Returns the list of attractions</response>
[HttpGet("GetAttraction")]
public async Task<ActionResult<IEnumerable<Attraction>>> GetAttraction()
{
return await _dbContext.Attractions.ToListAsync();
}

/// <summary>
/// Retrieves a specific attraction by a given ID.
/// </summary>
/// <param name="id">The ID of the attraction to retrieve.</param>
/// <returns>The attraction specified by the ID.</returns>
/// <response code="200">Returns the requested attraction</response>
/// <response code="404">If the attraction was not found</response>
[HttpGet("GetAttraction/{id}")]
public async Task<ActionResult<Attraction>> 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;
}
}
}

Loading