diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/EventController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/EventController.cs index be79699..1c2686f 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/EventController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/EventController.cs @@ -11,32 +11,17 @@ namespace LaDOSE.Api.Controllers { [Produces("application/json")] [Route("api/[controller]")] - public class EventController : Controller + public class EventController : GenericController { - 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); } } diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs index 8321a2d..58398cf 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs @@ -13,36 +13,10 @@ namespace LaDOSE.Api.Controllers [Authorize] [Route("api/[controller]")] [Produces("application/json")] - public class GameController : ControllerBase + public class GameController : GenericController { - - private readonly IGameService _gameService; - - public GameController(IGameService gameService) + public GameController(IGameService service) : base(service) { - _gameService = gameService; } - // GET api/Game - [HttpGet] - public List 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); - } - } } diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs new file mode 100644 index 0000000..3b3dad9 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs @@ -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 :Controller where TU : Entity.Context.Entity where T : IBaseService + { + protected T _service; + + public GenericController(T service) + { + _service = service; + } + + [HttpPost] + public TU Post([FromBody]TU dto) + { + return _service.Create(dto); + } + [HttpGet] + public List Get() + { + + return _service.GetAll().ToList(); + + } + [HttpGet("{id}")] + public TU Get(int id) + { + return _service.GetById(id); + + } + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/SeasonController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/SeasonController.cs new file mode 100644 index 0000000..d24b430 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/SeasonController.cs @@ -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 + { + public SeasonController(ISeasonService service) : base(service) + { + } + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Api/Startup.cs b/LaDOSE.Src/LaDOSE.Api/Startup.cs index 51b151f..3fbefeb 100644 --- a/LaDOSE.Src/LaDOSE.Api/Startup.cs +++ b/LaDOSE.Src/LaDOSE.Api/Startup.cs @@ -97,6 +97,7 @@ namespace LaDOSE.Api services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddTransient(p => new ChallongeProvider(this.Configuration["ApiKey:ChallongeApiKey"])); } diff --git a/LaDOSE.Src/LaDOSE.Entity/Context/Entity.cs b/LaDOSE.Src/LaDOSE.Entity/Context/Entity.cs new file mode 100644 index 0000000..d47bc2e --- /dev/null +++ b/LaDOSE.Src/LaDOSE.Entity/Context/Entity.cs @@ -0,0 +1,10 @@ +using System.ComponentModel.DataAnnotations; + +namespace LaDOSE.Entity.Context +{ + public class Entity + { + [Key] + public int Id { get; set; } + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Entity/Event.cs b/LaDOSE.Src/LaDOSE.Entity/Event.cs index 0d55573..86126b2 100644 --- a/LaDOSE.Src/LaDOSE.Entity/Event.cs +++ b/LaDOSE.Src/LaDOSE.Entity/Event.cs @@ -4,10 +4,10 @@ using System.ComponentModel.DataAnnotations; namespace LaDOSE.Entity { - public class Event + public class Event : Context.Entity { - [Key] - public int Id { get; set; } + //[Key] + //public int Id { get; set; } public string Name { get; set; } public DateTime Date { get; set; } public int SeasonId { get; set; } diff --git a/LaDOSE.Src/LaDOSE.Entity/EventGame.cs b/LaDOSE.Src/LaDOSE.Entity/EventGame.cs index 0238a74..afce7a1 100644 --- a/LaDOSE.Src/LaDOSE.Entity/EventGame.cs +++ b/LaDOSE.Src/LaDOSE.Entity/EventGame.cs @@ -1,6 +1,6 @@ namespace LaDOSE.Entity { - public class EventGame + public class EventGame { public int EventId { get; set; } diff --git a/LaDOSE.Src/LaDOSE.Entity/Game.cs b/LaDOSE.Src/LaDOSE.Entity/Game.cs index 8180f14..b4b0d92 100644 --- a/LaDOSE.Src/LaDOSE.Entity/Game.cs +++ b/LaDOSE.Src/LaDOSE.Entity/Game.cs @@ -4,10 +4,8 @@ using System.ComponentModel.DataAnnotations; namespace LaDOSE.Entity { - public class Game + public class Game : Context.Entity { - [Key] - public int Id { get; set; } public string Name { get; set; } public string ImgUrl { get; set; } diff --git a/LaDOSE.Src/LaDOSE.Entity/Season.cs b/LaDOSE.Src/LaDOSE.Entity/Season.cs index 551bea1..0261d98 100644 --- a/LaDOSE.Src/LaDOSE.Entity/Season.cs +++ b/LaDOSE.Src/LaDOSE.Entity/Season.cs @@ -4,10 +4,9 @@ using System.ComponentModel.DataAnnotations; namespace LaDOSE.Entity { - public class Season + public class Season : Context.Entity { - [Key] - public int Id { get; set; } + public string Name { get; set; } public DateTime StartDate { get; set; } diff --git a/LaDOSE.Src/LaDOSE.Service/Interface/ISeasonService.cs b/LaDOSE.Src/LaDOSE.Service/Interface/ISeasonService.cs new file mode 100644 index 0000000..3feaecc --- /dev/null +++ b/LaDOSE.Src/LaDOSE.Service/Interface/ISeasonService.cs @@ -0,0 +1,9 @@ +using LaDOSE.Entity; + +namespace LaDOSE.Business.Interface +{ + public interface ISeasonService : IBaseService + { + + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Service/Service/SeasonService.cs b/LaDOSE.Src/LaDOSE.Service/Service/SeasonService.cs new file mode 100644 index 0000000..ca8307f --- /dev/null +++ b/LaDOSE.Src/LaDOSE.Service/Service/SeasonService.cs @@ -0,0 +1,13 @@ +using LaDOSE.Business.Interface; +using LaDOSE.Entity; +using LaDOSE.Entity.Context; + +namespace LaDOSE.Business.Service +{ + public class SeasonService : BaseService, ISeasonService + { + public SeasonService(LaDOSEDbContext context) : base(context) + { + } + } +} \ No newline at end of file