Generic Controller Test
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
37
LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs
Normal file
37
LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs
Normal 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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
18
LaDOSE.Src/LaDOSE.Api/Controllers/SeasonController.cs
Normal file
18
LaDOSE.Src/LaDOSE.Api/Controllers/SeasonController.cs
Normal 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user