begin implementing episodes
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
[*.cs]
|
||||||
|
|
||||||
|
# CS0472: The result of the expression is always the same since a value of this type is never equal to 'null'
|
||||||
|
dotnet_diagnostic.CS0472.severity = none
|
||||||
@@ -8,7 +8,12 @@ Project("{54A90642-561A-4BB1-A94E-469ADEE60C69}") = "client", "client\client.esp
|
|||||||
{1EF6EB3C-FCA0-4FF6-8A99-373AFAC6E4EC} = {1EF6EB3C-FCA0-4FF6-8A99-373AFAC6E4EC}
|
{1EF6EB3C-FCA0-4FF6-8A99-373AFAC6E4EC} = {1EF6EB3C-FCA0-4FF6-8A99-373AFAC6E4EC}
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "server", "server\server.csproj", "{1EF6EB3C-FCA0-4FF6-8A99-373AFAC6E4EC}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "server", "server\server.csproj", "{1EF6EB3C-FCA0-4FF6-8A99-373AFAC6E4EC}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2FE01B2A-2F23-477B-BC6A-1E71781A61DB}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
.editorconfig = .editorconfig
|
||||||
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using server.Models;
|
||||||
|
using server.Persistence.Repositories;
|
||||||
|
|
||||||
|
namespace server.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("/api/episodes")]
|
||||||
|
[Produces("application/json")]
|
||||||
|
public class EpisodesController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IEpisodeRepository _episodeRepository;
|
||||||
|
|
||||||
|
public EpisodesController(IEpisodeRepository episodeRepository)
|
||||||
|
{
|
||||||
|
_episodeRepository = episodeRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType(typeof(List<Episode>), 200)]
|
||||||
|
[ProducesResponseType(500)]
|
||||||
|
public async Task<ActionResult<List<Episode>>> GetEpisodesAsync([FromQuery]EpisodeFilter? filter)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
#pragma warning disable CS8604 // Possible null reference argument.
|
||||||
|
var seasons = await _episodeRepository.GetEpisodesAsync(filter);
|
||||||
|
#pragma warning restore CS8604 // Possible null reference argument.
|
||||||
|
return Ok(seasons);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError, "Failed to get episodes");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ using server.Persistence.Repositories;
|
|||||||
namespace server.Controllers
|
namespace server.Controllers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/seasons")]
|
[Route("/api/seasons")]
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
public class SeasonsController : ControllerBase
|
public class SeasonsController : ControllerBase
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace server.Models
|
||||||
|
{
|
||||||
|
public class EpisodeFilter
|
||||||
|
{
|
||||||
|
public int? Season { get; set; } = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using MongoDB.Driver;
|
||||||
|
using MongoDB.Driver.Linq;
|
||||||
|
using server.Models;
|
||||||
|
|
||||||
|
namespace server.Persistence.Repositories
|
||||||
|
{
|
||||||
|
public class EpisodeRepository : IEpisodeRepository
|
||||||
|
{
|
||||||
|
private readonly IDbContext _context;
|
||||||
|
|
||||||
|
public EpisodeRepository(IDbContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<Episode>> GetEpisodesAsync(EpisodeFilter? filter)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var query = _context.Episodes.AsQueryable();
|
||||||
|
|
||||||
|
if (filter?.Season != null)
|
||||||
|
{
|
||||||
|
query = query.Where(episode => episode.Season == filter.Season);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await query.ToListAsync();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using server.Models;
|
||||||
|
|
||||||
|
namespace server.Persistence.Repositories
|
||||||
|
{
|
||||||
|
public interface IEpisodeRepository
|
||||||
|
{
|
||||||
|
Task<List<Episode>> GetEpisodesAsync(EpisodeFilter filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,8 @@ builder.Services.AddSingleton<IDbContext, DbContext>();
|
|||||||
|
|
||||||
builder.Services.AddScoped<ISeasonRepository, SeasonRepository>();
|
builder.Services.AddScoped<ISeasonRepository, SeasonRepository>();
|
||||||
|
|
||||||
|
builder.Services.AddScoped<IEpisodeRepository, EpisodeRepository>();
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\.editorconfig" Link=".editorconfig" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MongoDB.Driver" Version="2.16.0" />
|
<PackageReference Include="MongoDB.Driver" Version="2.16.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
|
||||||
|
|||||||
Reference in New Issue
Block a user