Challonge Provider can create tournament
This commit is contained in:
12
LaDOSE.Src/LaDOSE.Service/Interface/IChallongeProvider.cs
Normal file
12
LaDOSE.Src/LaDOSE.Service/Interface/IChallongeProvider.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LaDOSE.Business.Interface
|
||||
{
|
||||
public interface IChallongeProvider
|
||||
{
|
||||
Task<Boolean> GetLastTournament();
|
||||
string GetLastTournamentMessage();
|
||||
Task<Tuple<int, string>> CreateTournament(string name, string url);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,6 @@ namespace LaDOSE.Business.Interface
|
||||
{
|
||||
public interface IEventService : IBaseService<Event>
|
||||
{
|
||||
|
||||
bool CreateChallonge(int dto);
|
||||
}
|
||||
}
|
||||
@@ -10,4 +10,10 @@
|
||||
<ProjectReference Include="..\LaDOSE.Entity\LaDOSE.Entity.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="ChallongeCSharpDriver">
|
||||
<HintPath>..\..\Library\ChallongeCSharpDriver.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
78
LaDOSE.Src/LaDOSE.Service/Provider/ChallongeProvider.cs
Normal file
78
LaDOSE.Src/LaDOSE.Service/Provider/ChallongeProvider.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ChallongeCSharpDriver;
|
||||
using ChallongeCSharpDriver.Caller;
|
||||
using ChallongeCSharpDriver.Core.Queries;
|
||||
using ChallongeCSharpDriver.Core.Results;
|
||||
using LaDOSE.Business.Interface;
|
||||
|
||||
namespace LaDOSE.Business.Provider
|
||||
{
|
||||
public class ChallongeProvider : IChallongeProvider
|
||||
{
|
||||
private ChallongeConfig Config;
|
||||
public string ApiKey { get; set; }
|
||||
|
||||
public ChallongeHTTPClientAPICaller ApiCaller { get; set; }
|
||||
|
||||
public string DernierTournois { get; set; }
|
||||
|
||||
|
||||
public ChallongeProvider(string apiKey)
|
||||
{
|
||||
this.ApiKey = apiKey;
|
||||
this.Config = new ChallongeConfig(this.ApiKey);
|
||||
this.ApiCaller = new ChallongeHTTPClientAPICaller(Config);
|
||||
DernierTournois = "Aucun tournois.";
|
||||
}
|
||||
|
||||
public async Task<Tuple<int, string>> CreateTournament(string name, string url)
|
||||
{
|
||||
var p = await new CreateTournamentQuery(name, TournamentType.Double_Elimination, url).call(ApiCaller);
|
||||
return new Tuple<int, string>(p.id, p.url);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public async Task<Boolean> GetLastTournament()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
List<TournamentResult> tournamentResultList = await new TournamentsQuery()
|
||||
{
|
||||
state = TournamentState.Ended
|
||||
}
|
||||
.call(this.ApiCaller);
|
||||
|
||||
|
||||
var lastDate = tournamentResultList.Max(e => e.completed_at);
|
||||
if (lastDate.HasValue)
|
||||
{
|
||||
var lastRankingDate = new DateTime(lastDate.Value.Year, lastDate.Value.Month, lastDate.Value.Day);
|
||||
|
||||
var lastTournament = tournamentResultList.Where(e => e.completed_at > lastRankingDate).ToList();
|
||||
string returnValue = "Les derniers tournois : \n";
|
||||
foreach (var tournamentResult in lastTournament)
|
||||
{
|
||||
returnValue += $"{tournamentResult.name} : <https://challonge.com/{tournamentResult.url}> \n";
|
||||
}
|
||||
|
||||
DernierTournois = returnValue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public string GetLastTournamentMessage()
|
||||
{
|
||||
return DernierTournois;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,24 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using LaDOSE.Business.Interface;
|
||||
using LaDOSE.Entity;
|
||||
using LaDOSE.Entity.Context;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LaDOSE.Business.Service
|
||||
{
|
||||
public class EventService : BaseService<Event>, IEventService
|
||||
{
|
||||
public EventService(LaDOSEDbContext context) : base(context)
|
||||
private IChallongeProvider _challongeProvider;
|
||||
|
||||
public EventService(LaDOSEDbContext context,IChallongeProvider challongeProvider) : base(context)
|
||||
{
|
||||
this._challongeProvider = challongeProvider;
|
||||
}
|
||||
|
||||
public override Event GetById(int id)
|
||||
{
|
||||
return _context.Event.Include(e=>e.Season).Include(e=>e.Games).ThenInclude(e=>e.Game).FirstOrDefault(e=>e.Id == id);
|
||||
}
|
||||
|
||||
public override Event Create(Event e)
|
||||
@@ -22,5 +32,25 @@ namespace LaDOSE.Business.Service
|
||||
_context.SaveChanges();
|
||||
return eventAdded.Entity;
|
||||
}
|
||||
|
||||
public bool CreateChallonge(int dto)
|
||||
{
|
||||
var currentEvent = _context.Event.Include(e=>e.Games).ThenInclude(e=>e.Game).FirstOrDefault(e=>e.Id == dto);
|
||||
if (currentEvent != null)
|
||||
{
|
||||
var games = currentEvent.Games.Select(e => e.Game);
|
||||
var s = currentEvent.Date.ToString("MM/dd/yy");
|
||||
foreach (var game in games)
|
||||
{
|
||||
var url = $"TestDev{game.Id}{game.Name}";
|
||||
var name = $"[{s}]Ranking {currentEvent.Name}{game.Name}";
|
||||
_challongeProvider.CreateTournament(name,url);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ namespace LaDOSE.Business.Service
|
||||
|
||||
public override IEnumerable<Game> GetAll()
|
||||
{
|
||||
return _context.Game.Include(e => e.Seasons).ToList();
|
||||
return _context.Game.Include(e => e.Seasons).ThenInclude(e=>e.Season).ToList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user