Generic Controller Test
This commit is contained in:
@@ -11,32 +11,17 @@ namespace LaDOSE.Api.Controllers
|
|||||||
{
|
{
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
public class EventController : Controller
|
public class EventController : GenericController<IEventService, Event>
|
||||||
{
|
{
|
||||||
private IEventService _eventService;
|
public EventController(IEventService service) : base(service)
|
||||||
|
|
||||||
public EventController(IEventService eventService)
|
|
||||||
{
|
{
|
||||||
_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}")]
|
[HttpGet("Generate/{eventId}/{wpEventId}")]
|
||||||
public bool GenerateChallonge(int eventId, int 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]
|
[Authorize]
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
public class GameController : ControllerBase
|
public class GameController : GenericController<IGameService, Game>
|
||||||
{
|
{
|
||||||
|
public GameController(IGameService service) : base(service)
|
||||||
private readonly IGameService _gameService;
|
|
||||||
|
|
||||||
public GameController(IGameService gameService)
|
|
||||||
{
|
{
|
||||||
_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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -97,6 +97,7 @@ namespace LaDOSE.Api
|
|||||||
services.AddScoped<IUserService, UserService>();
|
services.AddScoped<IUserService, UserService>();
|
||||||
services.AddScoped<IGameService, GameService>();
|
services.AddScoped<IGameService, GameService>();
|
||||||
services.AddScoped<IEventService, EventService>();
|
services.AddScoped<IEventService, EventService>();
|
||||||
|
services.AddScoped<ISeasonService, SeasonService>();
|
||||||
services.AddTransient<IChallongeProvider>(p => new ChallongeProvider(this.Configuration["ApiKey:ChallongeApiKey"]));
|
services.AddTransient<IChallongeProvider>(p => new ChallongeProvider(this.Configuration["ApiKey:ChallongeApiKey"]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
LaDOSE.Src/LaDOSE.Entity/Context/Entity.cs
Normal file
10
LaDOSE.Src/LaDOSE.Entity/Context/Entity.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace LaDOSE.Entity.Context
|
||||||
|
{
|
||||||
|
public class Entity
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,10 +4,10 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
|
|
||||||
namespace LaDOSE.Entity
|
namespace LaDOSE.Entity
|
||||||
{
|
{
|
||||||
public class Event
|
public class Event : Context.Entity
|
||||||
{
|
{
|
||||||
[Key]
|
//[Key]
|
||||||
public int Id { get; set; }
|
//public int Id { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public DateTime Date { get; set; }
|
public DateTime Date { get; set; }
|
||||||
public int SeasonId { get; set; }
|
public int SeasonId { get; set; }
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
|
|
||||||
namespace LaDOSE.Entity
|
namespace LaDOSE.Entity
|
||||||
{
|
{
|
||||||
public class Game
|
public class Game : Context.Entity
|
||||||
{
|
{
|
||||||
[Key]
|
|
||||||
public int Id { get; set; }
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string ImgUrl { get; set; }
|
public string ImgUrl { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,9 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
|
|
||||||
namespace LaDOSE.Entity
|
namespace LaDOSE.Entity
|
||||||
{
|
{
|
||||||
public class Season
|
public class Season : Context.Entity
|
||||||
{
|
{
|
||||||
[Key]
|
|
||||||
public int Id { get; set; }
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public DateTime StartDate { get; set; }
|
public DateTime StartDate { get; set; }
|
||||||
|
|||||||
9
LaDOSE.Src/LaDOSE.Service/Interface/ISeasonService.cs
Normal file
9
LaDOSE.Src/LaDOSE.Service/Interface/ISeasonService.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using LaDOSE.Entity;
|
||||||
|
|
||||||
|
namespace LaDOSE.Business.Interface
|
||||||
|
{
|
||||||
|
public interface ISeasonService : IBaseService<Season>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
13
LaDOSE.Src/LaDOSE.Service/Service/SeasonService.cs
Normal file
13
LaDOSE.Src/LaDOSE.Service/Service/SeasonService.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using LaDOSE.Business.Interface;
|
||||||
|
using LaDOSE.Entity;
|
||||||
|
using LaDOSE.Entity.Context;
|
||||||
|
|
||||||
|
namespace LaDOSE.Business.Service
|
||||||
|
{
|
||||||
|
public class SeasonService : BaseService<Season>, ISeasonService
|
||||||
|
{
|
||||||
|
public SeasonService(LaDOSEDbContext context) : base(context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user