diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs new file mode 100644 index 0000000..2eafb85 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using LaDOSE.Business.Interface; +using LaDOSE.DTO; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace LaDOSE.Api.Controllers +{ + [Authorize] + [Produces("application/json")] + [Route("api/[controller]")] + public class TournamentController : Controller + { + public IGameService GameService { get; } + + private IWordPressService _service; + // GET + public TournamentController(IWordPressService service, IGameService gameService) + { + GameService = gameService; + _service = service; + } + + [HttpGet("GetTournaments")] + public async Task> GetChallonges() + { + + var tournaments = await _service.GetTournaments(DateTime.Now.AddMonths(-2), null); + return AutoMapper.Mapper.Map>(tournaments); + } + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs index fc3cb72..a9cf763 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; +using System.Collections.Generic; using AutoMapper; using LaDOSE.Business.Interface; using LaDOSE.DTO; @@ -92,12 +90,6 @@ namespace LaDOSE.Api.Controllers return _service.CreateChallonge(gameId, wpEventId, additionalPlayer); } - [HttpGet("GetTournaments")] - public async Task>> GetChallonge() - { - - var game = await _service.GetTournaments(DateTime.Now.AddMonths(-2), null); - return game; - } + } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj b/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj index c99aa87..522da19 100644 --- a/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj +++ b/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj @@ -24,7 +24,7 @@ - ..\Libraries\ChallongeCSharpDriver.dll + ..\..\..\..\..\Project\LaDOSE\LaDOSE\Library\ChallongeCSharpDriver.dll diff --git a/LaDOSE.Src/LaDOSE.Api/Startup.cs b/LaDOSE.Src/LaDOSE.Api/Startup.cs index c94e7cf..04926c8 100644 --- a/LaDOSE.Src/LaDOSE.Api/Startup.cs +++ b/LaDOSE.Src/LaDOSE.Api/Startup.cs @@ -26,6 +26,7 @@ using Pomelo.EntityFrameworkCore.MySql.Infrastructure; using AutoMapper; using LaDOSE.Api.Helpers; using LaDOSE.Business.Helper; +using LaDOSE.Entity.Challonge; using LaDOSE.Entity.Wordpress; namespace LaDOSE.Api @@ -121,6 +122,8 @@ namespace LaDOSE.Api cfg.CreateMap(); cfg.CreateMap().ForMember(e=>e.Meta,opt=>opt.MapFrom(s=>s.Meta.CleanWpMeta())); cfg.CreateMapTwoWay(); + cfg.CreateMapTwoWay(); + cfg.CreateMapTwoWay(); cfg.CreateMapTwoWay(); }); diff --git a/LaDOSE.Src/LaDOSE.DTO/TournamentDTO.cs b/LaDOSE.Src/LaDOSE.DTO/TournamentDTO.cs new file mode 100644 index 0000000..13cc9ef --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DTO/TournamentDTO.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace LaDOSE.DTO +{ + public class TournamentDTO + { + public int Id { get; set; } + public string Name { get; set; } + public string Game { get; set; } + public List Participents {get;set;} + } + + public class ParticipentDTO + { + public int Id { get; set; } + public string Name { get; set; } + public int? Rank { get; set; } + public bool? IsMember{ get; set; } + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Entity/Challonge/Participent.cs b/LaDOSE.Src/LaDOSE.Entity/Challonge/Participent.cs new file mode 100644 index 0000000..7e0c477 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.Entity/Challonge/Participent.cs @@ -0,0 +1,10 @@ +namespace LaDOSE.Entity.Challonge +{ + public class Participent + { + public int Id { get; set; } + public string Name { get; set; } + public int? Rank { get; set; } + public bool? IsMember { get; set; } + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Entity/Challonge/Tournament.cs b/LaDOSE.Src/LaDOSE.Entity/Challonge/Tournament.cs new file mode 100644 index 0000000..7c7ab61 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.Entity/Challonge/Tournament.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace LaDOSE.Entity.Challonge +{ + public class Tournament + { + public int Id { get; set; } + public string Name { get; set; } + public string Game { get; set; } + public List Participents { get; set; } + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Service/Interface/IChallongeProvider.cs b/LaDOSE.Src/LaDOSE.Service/Interface/IChallongeProvider.cs index befd03d..bc9f25c 100644 --- a/LaDOSE.Src/LaDOSE.Service/Interface/IChallongeProvider.cs +++ b/LaDOSE.Src/LaDOSE.Service/Interface/IChallongeProvider.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using ChallongeCSharpDriver.Core.Results; +using LaDOSE.Entity.Challonge; namespace LaDOSE.Business.Interface { @@ -12,6 +13,7 @@ namespace LaDOSE.Business.Interface Task CreateTournament(string name, string url); Task AddPlayer(int tournamentId, string userName); - Task> GetTournaments(DateTime? start, DateTime? end); + Task> GetTournaments(DateTime? start, DateTime? end); + Task> GetParticipents(int tournamentId); } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Service/Interface/IWordPressService.cs b/LaDOSE.Src/LaDOSE.Service/Interface/IWordPressService.cs index 7c3a4b5..82372ce 100644 --- a/LaDOSE.Src/LaDOSE.Service/Interface/IWordPressService.cs +++ b/LaDOSE.Src/LaDOSE.Service/Interface/IWordPressService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using LaDOSE.Entity; +using LaDOSE.Entity.Challonge; using LaDOSE.Entity.Wordpress; namespace LaDOSE.Business.Interface @@ -17,6 +18,6 @@ namespace LaDOSE.Business.Interface Task GetLastChallonge(); - Task>> GetTournaments(DateTime? start, DateTime? end); + Task> GetTournaments(DateTime? start, DateTime? end); } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Service/Provider/ChallongeProvider.cs b/LaDOSE.Src/LaDOSE.Service/Provider/ChallongeProvider.cs index c75fc3c..9754619 100644 --- a/LaDOSE.Src/LaDOSE.Service/Provider/ChallongeProvider.cs +++ b/LaDOSE.Src/LaDOSE.Service/Provider/ChallongeProvider.cs @@ -8,6 +8,7 @@ using ChallongeCSharpDriver.Core.Objects; using ChallongeCSharpDriver.Core.Queries; using ChallongeCSharpDriver.Core.Results; using LaDOSE.Business.Interface; +using LaDOSE.Entity.Challonge; namespace LaDOSE.Business.Provider { @@ -45,7 +46,7 @@ namespace LaDOSE.Business.Provider } - public async Task> GetTournaments(DateTime? start, DateTime? end) + public async Task> GetTournaments(DateTime? start, DateTime? end) { List tournamentResultList = await new TournamentsQuery() @@ -57,7 +58,29 @@ namespace LaDOSE.Business.Provider } .call(this.ApiCaller); - return tournamentResultList; + List tournaments = new List(); + tournamentResultList.ForEach(w => tournaments.Add(new Tournament() + { + Id = w.id, + Name = w.name, + Participents = new List() + })); + return tournaments; + } + + public async Task> GetParticipents(int tournamentId) + { + var participentResults = new ParticipantsQuery().call(ApiCaller); + + List participants = new List(); + participentResults.Result.ForEach(w => participants.Add(new Participent() + { + Id = w.id, + Name = w.name, + Rank = w.final_rank, + IsMember = false, + })); + return participants; } public async Task GetLastTournament() diff --git a/LaDOSE.Src/LaDOSE.Service/Service/WordPressService.cs b/LaDOSE.Src/LaDOSE.Service/Service/WordPressService.cs index 73914bb..49d91ca 100644 --- a/LaDOSE.Src/LaDOSE.Service/Service/WordPressService.cs +++ b/LaDOSE.Src/LaDOSE.Service/Service/WordPressService.cs @@ -10,6 +10,7 @@ using ChallongeCSharpDriver.Core.Results; using LaDOSE.Business.Helper; using LaDOSE.Business.Interface; using LaDOSE.Entity; +using LaDOSE.Entity.Challonge; using LaDOSE.Entity.Context; using LaDOSE.Entity.Wordpress; using Microsoft.EntityFrameworkCore; @@ -164,12 +165,18 @@ namespace LaDOSE.Business.Service var lastTournament = await _challongeProvider.GetLastTournament(); return lastTournament; } - public async Task>> GetTournaments(DateTime? start, DateTime? end) + public async Task> GetTournaments(DateTime? start, DateTime? end) { - var tournamentResults = await _challongeProvider.GetTournaments(start,end); - List> ret = new List>(); - tournamentResults.ForEach(w =>ret.Add(new Tuple(w.id,w.name,w.url))); - return ret; + var tournaments = await _challongeProvider.GetTournaments(start,end); + + foreach (var tournament in tournaments) + { + List participents = await _challongeProvider.GetParticipents(tournament.Id); + tournament.Participents = participents; + } + + + return tournaments; } private string FormatCurrentEventName(string currentEventName) {