diff --git a/backend/LeedsBeerQuest.API/LeedsBeerQuest.API.Tests/Data/Services/VenueServiceTests.cs b/backend/LeedsBeerQuest.API/LeedsBeerQuest.API.Tests/Data/Services/VenueServiceTests.cs index 0c99a40..08b1d17 100644 --- a/backend/LeedsBeerQuest.API/LeedsBeerQuest.API.Tests/Data/Services/VenueServiceTests.cs +++ b/backend/LeedsBeerQuest.API/LeedsBeerQuest.API.Tests/Data/Services/VenueServiceTests.cs @@ -2,6 +2,7 @@ using System; using System.Linq; using System.Threading.Tasks; using LeedsBeerQuest.API.Data.Contexts; +using LeedsBeerQuest.API.Data.Models; using LeedsBeerQuest.API.Data.Services; using Microsoft.EntityFrameworkCore; using NUnit.Framework; @@ -27,9 +28,7 @@ public class VenueServiceTests [Test] public async Task GetAllVenues_ReturnsAllVenues_WhenAllVenuesArePresentInDatabase() { - var venueTestData = TestData.VenueTestData.ToArray(); - _context.Venues.AddRange(venueTestData); - await _context.SaveChangesAsync(); + var venueTestData = await seedVenueTestData(); var result = await _venueService.GetAllVenues(); var resultArray = result.ToArray(); @@ -47,4 +46,35 @@ public class VenueServiceTests Assert.AreEqual(0, result.Count()); } + + [Test] + public async Task GetVenue_ReturnsVenue_WhenRequestedVenueExists() + { + var venueTestData = await seedVenueTestData(); + var expectedVenueId = venueTestData[0].Id; + var expectedVenueName = venueTestData[0].Name; + + var result = await _venueService.GetVenue(expectedVenueId);; + + Assert.NotNull(result); + Assert.AreEqual(expectedVenueId, result.Id); + Assert.AreEqual(expectedVenueName, result.Name); + } + + [Test] + public async Task GetVenue_ReturnsNull_WhenRequestedVenueDoesNotExist() + { + var result = await _venueService.GetVenue(1); + + Assert.Null(result); + } + + private async Task seedVenueTestData() + { + var venueTestData = TestData.VenueTestData.ToArray(); + _context.Venues.AddRange(venueTestData); + await _context.SaveChangesAsync(); + + return venueTestData; + } } \ No newline at end of file diff --git a/backend/LeedsBeerQuest.API/LeedsBeerQuest.API/Controllers/VenueController.cs b/backend/LeedsBeerQuest.API/LeedsBeerQuest.API/Controllers/VenueController.cs index 4a54567..216a117 100644 --- a/backend/LeedsBeerQuest.API/LeedsBeerQuest.API/Controllers/VenueController.cs +++ b/backend/LeedsBeerQuest.API/LeedsBeerQuest.API/Controllers/VenueController.cs @@ -23,4 +23,17 @@ public class VenueController : ControllerBase var venues = await _venueService.GetAllVenues(); return Ok(venues); } + + [HttpGet("{venueId:int}")] + public async Task Get(int venueId) + { + if (venueId < 1) + { + return BadRequest("Requested venue ID must be more than zero"); + } + + var venue = await _venueService.GetVenue(venueId); + + return venue == null ? NotFound() : Ok(venue); + } } \ No newline at end of file diff --git a/backend/LeedsBeerQuest.API/LeedsBeerQuest.API/Data/Services/Interfaces/IVenueService.cs b/backend/LeedsBeerQuest.API/LeedsBeerQuest.API/Data/Services/Interfaces/IVenueService.cs index 017d5f7..66b0d88 100644 --- a/backend/LeedsBeerQuest.API/LeedsBeerQuest.API/Data/Services/Interfaces/IVenueService.cs +++ b/backend/LeedsBeerQuest.API/LeedsBeerQuest.API/Data/Services/Interfaces/IVenueService.cs @@ -5,4 +5,5 @@ namespace LeedsBeerQuest.API.Data.Services.Interfaces; public interface IVenueService { public Task> GetAllVenues(); + public Task GetVenue(int venueId); } \ No newline at end of file diff --git a/backend/LeedsBeerQuest.API/LeedsBeerQuest.API/Data/Services/VenueService.cs b/backend/LeedsBeerQuest.API/LeedsBeerQuest.API/Data/Services/VenueService.cs index 283414d..64e2a18 100644 --- a/backend/LeedsBeerQuest.API/LeedsBeerQuest.API/Data/Services/VenueService.cs +++ b/backend/LeedsBeerQuest.API/LeedsBeerQuest.API/Data/Services/VenueService.cs @@ -21,4 +21,12 @@ public class VenueService : IVenueService .Include(v => v.Tags) .ToListAsync(); } + + public async Task GetVenue(int venueId) + { + return await _context.Venues + .Include(v => v.Category) + .Include(v => v.Tags) + .SingleOrDefaultAsync(v => v.Id == venueId); + } } \ No newline at end of file