Test tournament result.

This commit is contained in:
2019-05-29 02:15:31 +02:00
parent 1f5961cdd0
commit 959b3e922a
11 changed files with 124 additions and 20 deletions

View File

@@ -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<List<TournamentDTO>> GetChallonges()
{
var tournaments = await _service.GetTournaments(DateTime.Now.AddMonths(-2), null);
return AutoMapper.Mapper.Map<List<TournamentDTO>>(tournaments);
}
}
}

View File

@@ -1,6 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using AutoMapper; using AutoMapper;
using LaDOSE.Business.Interface; using LaDOSE.Business.Interface;
using LaDOSE.DTO; using LaDOSE.DTO;
@@ -92,12 +90,6 @@ namespace LaDOSE.Api.Controllers
return _service.CreateChallonge(gameId, wpEventId, additionalPlayer); return _service.CreateChallonge(gameId, wpEventId, additionalPlayer);
} }
[HttpGet("GetTournaments")]
public async Task<List<Tuple<int, string, string>>> GetChallonge()
{
var game = await _service.GetTournaments(DateTime.Now.AddMonths(-2), null);
return game;
}
} }
} }

View File

@@ -24,7 +24,7 @@
<ItemGroup> <ItemGroup>
<Reference Include="ChallongeCSharpDriver"> <Reference Include="ChallongeCSharpDriver">
<HintPath>..\Libraries\ChallongeCSharpDriver.dll</HintPath> <HintPath>..\..\..\..\..\Project\LaDOSE\LaDOSE\Library\ChallongeCSharpDriver.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>

View File

@@ -26,6 +26,7 @@ using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
using AutoMapper; using AutoMapper;
using LaDOSE.Api.Helpers; using LaDOSE.Api.Helpers;
using LaDOSE.Business.Helper; using LaDOSE.Business.Helper;
using LaDOSE.Entity.Challonge;
using LaDOSE.Entity.Wordpress; using LaDOSE.Entity.Wordpress;
namespace LaDOSE.Api namespace LaDOSE.Api
@@ -121,6 +122,8 @@ namespace LaDOSE.Api
cfg.CreateMap<ApplicationUser, LaDOSE.DTO.ApplicationUserDTO>(); cfg.CreateMap<ApplicationUser, LaDOSE.DTO.ApplicationUserDTO>();
cfg.CreateMap<WPBooking, LaDOSE.DTO.WPBookingDTO>().ForMember(e=>e.Meta,opt=>opt.MapFrom(s=>s.Meta.CleanWpMeta())); cfg.CreateMap<WPBooking, LaDOSE.DTO.WPBookingDTO>().ForMember(e=>e.Meta,opt=>opt.MapFrom(s=>s.Meta.CleanWpMeta()));
cfg.CreateMapTwoWay<Game, LaDOSE.DTO.GameDTO>(); cfg.CreateMapTwoWay<Game, LaDOSE.DTO.GameDTO>();
cfg.CreateMapTwoWay<Participent, LaDOSE.DTO.ParticipentDTO>();
cfg.CreateMapTwoWay<Tournament, LaDOSE.DTO.TournamentDTO>();
cfg.CreateMapTwoWay<Todo, LaDOSE.DTO.TodoDTO>(); cfg.CreateMapTwoWay<Todo, LaDOSE.DTO.TodoDTO>();
}); });

View File

@@ -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<ParticipentDTO> 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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -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<Participent> Participents { get; set; }
}
}

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using ChallongeCSharpDriver.Core.Results; using ChallongeCSharpDriver.Core.Results;
using LaDOSE.Entity.Challonge;
namespace LaDOSE.Business.Interface namespace LaDOSE.Business.Interface
{ {
@@ -12,6 +13,7 @@ namespace LaDOSE.Business.Interface
Task<TournamentResult> CreateTournament(string name, string url); Task<TournamentResult> CreateTournament(string name, string url);
Task<ParticipantResult> AddPlayer(int tournamentId, string userName); Task<ParticipantResult> AddPlayer(int tournamentId, string userName);
Task<List<TournamentResult>> GetTournaments(DateTime? start, DateTime? end); Task<List<Tournament>> GetTournaments(DateTime? start, DateTime? end);
Task<List<Participent>> GetParticipents(int tournamentId);
} }
} }

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using LaDOSE.Entity; using LaDOSE.Entity;
using LaDOSE.Entity.Challonge;
using LaDOSE.Entity.Wordpress; using LaDOSE.Entity.Wordpress;
namespace LaDOSE.Business.Interface namespace LaDOSE.Business.Interface
@@ -17,6 +18,6 @@ namespace LaDOSE.Business.Interface
Task<string> GetLastChallonge(); Task<string> GetLastChallonge();
Task<List<Tuple<int, string, string>>> GetTournaments(DateTime? start, DateTime? end); Task<List<Tournament>> GetTournaments(DateTime? start, DateTime? end);
} }
} }

View File

@@ -8,6 +8,7 @@ using ChallongeCSharpDriver.Core.Objects;
using ChallongeCSharpDriver.Core.Queries; using ChallongeCSharpDriver.Core.Queries;
using ChallongeCSharpDriver.Core.Results; using ChallongeCSharpDriver.Core.Results;
using LaDOSE.Business.Interface; using LaDOSE.Business.Interface;
using LaDOSE.Entity.Challonge;
namespace LaDOSE.Business.Provider namespace LaDOSE.Business.Provider
{ {
@@ -45,7 +46,7 @@ namespace LaDOSE.Business.Provider
} }
public async Task<List<TournamentResult>> GetTournaments(DateTime? start, DateTime? end) public async Task<List<Tournament>> GetTournaments(DateTime? start, DateTime? end)
{ {
List<TournamentResult> tournamentResultList = await new TournamentsQuery() List<TournamentResult> tournamentResultList = await new TournamentsQuery()
@@ -57,7 +58,29 @@ namespace LaDOSE.Business.Provider
} }
.call(this.ApiCaller); .call(this.ApiCaller);
return tournamentResultList; List<Tournament> tournaments = new List<Tournament>();
tournamentResultList.ForEach(w => tournaments.Add(new Tournament()
{
Id = w.id,
Name = w.name,
Participents = new List<Participent>()
}));
return tournaments;
}
public async Task<List<Participent>> GetParticipents(int tournamentId)
{
var participentResults = new ParticipantsQuery().call(ApiCaller);
List<Participent> participants = new List<Participent>();
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<string> GetLastTournament() public async Task<string> GetLastTournament()

View File

@@ -10,6 +10,7 @@ using ChallongeCSharpDriver.Core.Results;
using LaDOSE.Business.Helper; using LaDOSE.Business.Helper;
using LaDOSE.Business.Interface; using LaDOSE.Business.Interface;
using LaDOSE.Entity; using LaDOSE.Entity;
using LaDOSE.Entity.Challonge;
using LaDOSE.Entity.Context; using LaDOSE.Entity.Context;
using LaDOSE.Entity.Wordpress; using LaDOSE.Entity.Wordpress;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@@ -164,12 +165,18 @@ namespace LaDOSE.Business.Service
var lastTournament = await _challongeProvider.GetLastTournament(); var lastTournament = await _challongeProvider.GetLastTournament();
return lastTournament; return lastTournament;
} }
public async Task<List<Tuple<int, string, string>>> GetTournaments(DateTime? start, DateTime? end) public async Task<List<Tournament>> GetTournaments(DateTime? start, DateTime? end)
{ {
var tournamentResults = await _challongeProvider.GetTournaments(start,end); var tournaments = await _challongeProvider.GetTournaments(start,end);
List<Tuple<int,string,string>> ret = new List<Tuple<int, string,string>>();
tournamentResults.ForEach(w =>ret.Add(new Tuple<int, string,string>(w.id,w.name,w.url))); foreach (var tournament in tournaments)
return ret; {
List<Participent> participents = await _challongeProvider.GetParticipents(tournament.Id);
tournament.Participents = participents;
}
return tournaments;
} }
private string FormatCurrentEventName(string currentEventName) private string FormatCurrentEventName(string currentEventName)
{ {