Test tournament result.
This commit is contained in:
34
LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs
Normal file
34
LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<List<Tuple<int, string, string>>> GetChallonge()
|
||||
{
|
||||
|
||||
var game = await _service.GetTournaments(DateTime.Now.AddMonths(-2), null);
|
||||
return game;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="ChallongeCSharpDriver">
|
||||
<HintPath>..\Libraries\ChallongeCSharpDriver.dll</HintPath>
|
||||
<HintPath>..\..\..\..\..\Project\LaDOSE\LaDOSE\Library\ChallongeCSharpDriver.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -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<ApplicationUser, LaDOSE.DTO.ApplicationUserDTO>();
|
||||
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<Participent, LaDOSE.DTO.ParticipentDTO>();
|
||||
cfg.CreateMapTwoWay<Tournament, LaDOSE.DTO.TournamentDTO>();
|
||||
cfg.CreateMapTwoWay<Todo, LaDOSE.DTO.TodoDTO>();
|
||||
|
||||
});
|
||||
|
||||
20
LaDOSE.Src/LaDOSE.DTO/TournamentDTO.cs
Normal file
20
LaDOSE.Src/LaDOSE.DTO/TournamentDTO.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
10
LaDOSE.Src/LaDOSE.Entity/Challonge/Participent.cs
Normal file
10
LaDOSE.Src/LaDOSE.Entity/Challonge/Participent.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
12
LaDOSE.Src/LaDOSE.Entity/Challonge/Tournament.cs
Normal file
12
LaDOSE.Src/LaDOSE.Entity/Challonge/Tournament.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
@@ -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<TournamentResult> CreateTournament(string name, string url);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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<string> GetLastChallonge();
|
||||
|
||||
Task<List<Tuple<int, string, string>>> GetTournaments(DateTime? start, DateTime? end);
|
||||
Task<List<Tournament>> GetTournaments(DateTime? start, DateTime? end);
|
||||
}
|
||||
}
|
||||
@@ -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<List<TournamentResult>> GetTournaments(DateTime? start, DateTime? end)
|
||||
public async Task<List<Tournament>> GetTournaments(DateTime? start, DateTime? end)
|
||||
{
|
||||
|
||||
List<TournamentResult> tournamentResultList = await new TournamentsQuery()
|
||||
@@ -57,7 +58,29 @@ namespace LaDOSE.Business.Provider
|
||||
|
||||
}
|
||||
.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()
|
||||
|
||||
@@ -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<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);
|
||||
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)));
|
||||
return ret;
|
||||
var tournaments = await _challongeProvider.GetTournaments(start,end);
|
||||
|
||||
foreach (var tournament in tournaments)
|
||||
{
|
||||
List<Participent> participents = await _challongeProvider.GetParticipents(tournament.Id);
|
||||
tournament.Participents = participents;
|
||||
}
|
||||
|
||||
|
||||
return tournaments;
|
||||
}
|
||||
private string FormatCurrentEventName(string currentEventName)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user