Generic Controller Test

This commit is contained in:
2018-10-12 20:52:59 +02:00
parent 39075051b2
commit e47c1ccb5e
12 changed files with 102 additions and 58 deletions

View File

@@ -11,32 +11,17 @@ namespace LaDOSE.Api.Controllers
{
[Produces("application/json")]
[Route("api/[controller]")]
public class EventController : Controller
public class EventController : GenericController<IEventService, Event>
{
private IEventService _eventService;
public EventController(IEventService eventService)
public EventController(IEventService service) : base(service)
{
_eventService = eventService;
}
[HttpPost]
public Event Post([FromBody]Event dto)
{
return _eventService.Create(dto);
}
[HttpGet("{id}")]
public Event Get(int id)
{
return _eventService.GetById(id);
}
[HttpGet("Generate/{eventId}/{wpEventId}")]
public bool GenerateChallonge(int eventId, int wpEventId)
{
return _eventService.CreateChallonge(eventId, wpEventId);
return _service.CreateChallonge(eventId, wpEventId);
}
}

View File

@@ -13,36 +13,10 @@ namespace LaDOSE.Api.Controllers
[Authorize]
[Route("api/[controller]")]
[Produces("application/json")]
public class GameController : ControllerBase
public class GameController : GenericController<IGameService, Game>
{
private readonly IGameService _gameService;
public GameController(IGameService gameService)
public GameController(IGameService service) : base(service)
{
_gameService = gameService;
}
// GET api/Game
[HttpGet]
public List<Game> Get()
{
return _gameService.GetAll().ToList();
}
// GET api/Game/5
[HttpGet("{id}")]
public Game Get(int id)
{
return _gameService.GetById(id);
}
[HttpPut()]
public bool Put(Game game)
{
return _gameService.Update(game);
}
}
}

View File

@@ -0,0 +1,37 @@
using System.Collections.Generic;
using System.Linq;
using LaDOSE.Business.Interface;
using LaDOSE.Entity;
using Microsoft.AspNetCore.Mvc;
namespace LaDOSE.Api.Controllers
{
public class GenericController<T,TU> :Controller where TU : Entity.Context.Entity where T : IBaseService<TU>
{
protected T _service;
public GenericController(T service)
{
_service = service;
}
[HttpPost]
public TU Post([FromBody]TU dto)
{
return _service.Create(dto);
}
[HttpGet]
public List<TU> Get()
{
return _service.GetAll().ToList();
}
[HttpGet("{id}")]
public TU Get(int id)
{
return _service.GetById(id);
}
}
}

View File

@@ -0,0 +1,18 @@
using LaDOSE.Business.Interface;
using LaDOSE.Business.Service;
using LaDOSE.Entity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace LaDOSE.Api.Controllers
{
[Authorize]
[Route("api/[controller]")]
[Produces("application/json")]
public class SeasonController : GenericController<ISeasonService,Season>
{
public SeasonController(ISeasonService service) : base(service)
{
}
}
}