From 0173070ba4dca0f17138345c36a486f2590d91b2 Mon Sep 17 00:00:00 2001 From: Darkstack <1835601+darkstack@users.noreply.github.com> Date: Sat, 30 Jul 2022 20:00:31 +0200 Subject: [PATCH] Fix challonge event Fix GenericController Fix ChallongeSave. Fix RestAPI in prod mode. --- .../LaDOSE.Api/Controllers/EventController.cs | 15 +++++-- .../Controllers/GenericController.cs | 10 ++--- .../Controllers/GenericControllerDTO.cs | 10 ++--- .../Controllers/TournamentController.cs | 2 +- LaDOSE.Src/LaDOSE.REST/RestService.cs | 40 +++++++++---------- .../Interface/IExternalProviderService.cs | 2 +- .../ChallongProvider/ChallongeProvider.cs | 6 +-- .../Provider/SmashProvider/SmashProvider.cs | 5 ++- .../Service/ExternalProviderService.cs | 10 +++-- 9 files changed, 56 insertions(+), 44 deletions(-) diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/EventController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/EventController.cs index a2aae4b..3207fca 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/EventController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/EventController.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using AutoMapper; using LaDOSE.Business.Interface; +using LaDOSE.DTO; using LaDOSE.Entity; using LaDOSE.Entity.Wordpress; using Microsoft.AspNetCore.Authorization; @@ -11,19 +13,24 @@ using Microsoft.AspNetCore.Mvc; namespace LaDOSE.Api.Controllers { - [AllowAnonymous] + //[Authorize] [Produces("application/json")] [Route("api/[controller]")] - public class EventController : GenericController + public class EventController : GenericControllerDTO { private IGameService _gameService; - public EventController(IEventService service,IGameService gameService) : base(service) + public EventController(IMapper mapper, IEventService service,IGameService gameService) : base(mapper,service) { this._gameService = gameService; } - + + public override List Get() + { + return this._mapper.Map>(_service.GetAll().OrderByDescending(e=>e.Date).ToList()); + } + } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs index 96890d3..dc42710 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Mvc; namespace LaDOSE.Api.Controllers { - public class GenericController : Controller where TU : Entity.Context.Entity where T : IBaseService + public abstract class GenericController : Controller where TU : Entity.Context.Entity where T : IBaseService { protected T _service; @@ -18,13 +18,13 @@ namespace LaDOSE.Api.Controllers } [HttpPost] - public TU Post([FromBody] TU dto) + public virtual TU Post([FromBody] TU dto) { return _service.AddOrUpdate(dto); } [HttpGet] - public List Get() + public virtual List Get() { return _service.GetAll().ToList(); @@ -32,14 +32,14 @@ namespace LaDOSE.Api.Controllers } [HttpGet("{id}")] - public TU Get(int id) + public virtual TU Get(int id) { return _service.GetById(id); } [HttpDelete("{id}")] - public IActionResult Delete(int id) + public virtual IActionResult Delete(int id) { try { diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs index 98e7715..dbd8e8b 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Mvc; namespace LaDOSE.Api.Controllers { - public class GenericControllerDTO : Controller where TU : Entity.Context.Entity where T : IBaseService + public abstract class GenericControllerDTO : Controller where TU : Entity.Context.Entity where T : IBaseService { protected IMapper _mapper; protected T _service; @@ -19,26 +19,26 @@ namespace LaDOSE.Api.Controllers } [HttpPost] - public D Post([FromBody]D dto) + public virtual D Post([FromBody]D dto) { TU entity = _mapper.Map(dto); return _mapper.Map(_service.AddOrUpdate(entity)); } [HttpGet] - public List Get() + public virtual List Get() { return _mapper.Map>(_service.GetAll().ToList()); } [HttpGet("{id}")] - public D Get(int id) + public virtual D Get(int id) { return _mapper.Map(_service.GetById(id)); } [HttpDelete("{id}")] - public IActionResult Delete(int id) + public virtual IActionResult Delete(int id) { try { diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs index c4840c4..13413a9 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs @@ -74,7 +74,7 @@ namespace LaDOSE.Api.Controllers { if (ids != null) { - var tournaments = await _service.ParseChallonge(ids); + var tournaments = await _service.GetChallongeEvents(ids); return tournaments.Count>0; } return false; diff --git a/LaDOSE.Src/LaDOSE.REST/RestService.cs b/LaDOSE.Src/LaDOSE.REST/RestService.cs index e64e5e7..d2e9118 100644 --- a/LaDOSE.Src/LaDOSE.REST/RestService.cs +++ b/LaDOSE.Src/LaDOSE.REST/RestService.cs @@ -29,9 +29,9 @@ namespace LaDOSE.REST public void Connect(Uri url, string user, string password) { Client = new RestClient(url); - +#if DEBUG Client.Timeout = 999*1000; - +#endif this.username = user; this.password = password; GetToken(user, password); @@ -75,7 +75,7 @@ namespace LaDOSE.REST } } - #region PostFix +#region PostFix private T Post(string resource,T entity) { @@ -128,9 +128,9 @@ namespace LaDOSE.REST } - #endregion +#endregion - #region WordPress +#region WordPress public List GetEvents() { CheckToken(); @@ -192,9 +192,9 @@ namespace LaDOSE.REST } - #endregion +#endregion - #region Games +#region Games public List GetGames() { CheckToken(); @@ -215,14 +215,14 @@ namespace LaDOSE.REST var restResponse = Client.Execute(restRequest); return restResponse.IsSuccessful; } - #endregion +#endregion - #region Events +#region Events - #endregion +#endregion - #region Todo +#region Todo public List GetTodos() { @@ -252,8 +252,8 @@ namespace LaDOSE.REST } - #endregion - #region Tournaments +#endregion +#region Tournaments public TournamentsResultDTO Test(string test) { @@ -264,8 +264,8 @@ namespace LaDOSE.REST } - #endregion - #region Tournaments +#endregion +#region Tournaments public List GetTournaments(TimeRangeDTO timeRange) { @@ -296,8 +296,8 @@ namespace LaDOSE.REST CheckToken(); return Post, bool>("Api/Tournament/ParseChallonge", ids); } - #endregion - #region Tournamenet Event / Player +#endregion +#region Tournamenet Event / Player public List GetAllEvents() { CheckToken(); @@ -313,10 +313,10 @@ namespace LaDOSE.REST var restResponse = Client.Get>(restRequest); return restResponse.Data; } - #endregion +#endregion - #region Bot Command +#region Bot Command public bool CreateBotEvent(string eventName) { @@ -340,6 +340,6 @@ namespace LaDOSE.REST return Post("/api/BotEvent/ResultBotEvent", result); } - #endregion +#endregion } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs b/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs index 986a0c4..a46c34e 100644 --- a/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs +++ b/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs @@ -10,7 +10,7 @@ namespace LaDOSE.Business.Interface { Task> GetTournaments(DateTime? start, DateTime? end); Task ParseSmash(string tournamentSlug); - Task> ParseChallonge(List ids); + //Task> ParseChallonge(List ids); //Task GetChallongeTournamentsResult(List ids); //Task GetSmashResult(string tournamentSlug); diff --git a/LaDOSE.Src/LaDOSE.Service/Provider/ChallongProvider/ChallongeProvider.cs b/LaDOSE.Src/LaDOSE.Service/Provider/ChallongProvider/ChallongeProvider.cs index 2465792..38ef07a 100644 --- a/LaDOSE.Src/LaDOSE.Service/Provider/ChallongProvider/ChallongeProvider.cs +++ b/LaDOSE.Src/LaDOSE.Service/Provider/ChallongProvider/ChallongeProvider.cs @@ -197,14 +197,14 @@ namespace LaDOSE.Business.Provider.ChallongProvider Name = eventName, Date = Date, }; - this.EventService.AddOrUpdate(currentevent); + //this.EventService.AddOrUpdate(currentevent); return currentevent; } - private const string RegexRanking = @"[R|r]anking.?#\w{3}"; + private const string RegexRanking = @"[R|r]anking.?#\d{1,3}"; private const string DateRanking = @"^\[(\d{2}\/\d{2}\/\d{2})\]"; - private const string GameRanking = @"\-.(\w*)$"; + private const string GameRanking = @"\-.((\w|\.|\s)*)$"; public async Task> ParseEvent(List idTournaments) { var result = new List(); diff --git a/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs b/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs index fc2420b..0106340 100644 --- a/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs +++ b/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs @@ -85,7 +85,10 @@ namespace LaDOSE.Business.Provider.SmashProvider Game = games.FirstOrDefault(g => g.SmashId == e.videogame.id) }).ToList(); - + if (tournaments.Any(e => !e.Finish)) + { + throw new Exception("Tournament not finished."); + } return new Event { SmashSlug = slug, diff --git a/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs b/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs index eb33aa5..4ac6b09 100644 --- a/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs +++ b/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs @@ -192,10 +192,11 @@ namespace LaDOSE.Business.Service } - public Task> ParseChallonge(List ids) - { - return _challongeProvider.ParseEvent(ids); - } + //public Task> ParseChallonge(List ids) + //{ + // return GetChallongeEvents(ids); + // //return _challongeProvider.Get(ids); + //} private Event GetBySlug(string tournamentSlug) { @@ -220,6 +221,7 @@ namespace LaDOSE.Business.Service { var events = await this._challongeProvider.ParseEvent(ids); this._context.Event.AddRange(events); + this._context.SaveChanges(); return events; }