Improved client handling and episode models
This commit is contained in:
@@ -4,7 +4,8 @@ using AutoMapper;
|
||||
using EstusShots.Server.Models;
|
||||
using EstusShots.Server.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Dto = EstusShots.Shared.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Dto = EstusShots.Shared.Dto;
|
||||
|
||||
namespace EstusShots.Server.Controllers
|
||||
{
|
||||
@@ -14,18 +15,20 @@ namespace EstusShots.Server.Controllers
|
||||
{
|
||||
private readonly EstusShotsContext _context;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public SeasonController(EstusShotsContext context, IMapper mapper)
|
||||
public SeasonController(EstusShotsContext context, IMapper mapper, ILogger<SeasonController> logger)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<Dto.Season>> GetSeason(Guid id)
|
||||
{
|
||||
var season = await _context.Seasons.FindAsync(id);
|
||||
if (season == null) return NotFound();
|
||||
if (season == null) {return NotFound();}
|
||||
|
||||
var seasonDto = _mapper.Map<Dto.Season>(season);
|
||||
return seasonDto;
|
||||
@@ -36,7 +39,15 @@ namespace EstusShots.Server.Controllers
|
||||
{
|
||||
var dbSeason = _mapper.Map<Season>(season);
|
||||
_context.Seasons.Add(dbSeason);
|
||||
await _context.SaveChangesAsync();
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
_logger.LogInformation("New season created");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Error while saving Season");
|
||||
}
|
||||
return CreatedAtAction(nameof(GetSeason), new {id = dbSeason.SeasonId}, dbSeason);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user