Fix challonge event
Fix GenericController Fix ChallongeSave. Fix RestAPI in prod mode.
This commit is contained in:
@@ -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<IEventService, Event>
|
||||
public class EventController : GenericControllerDTO<IEventService, Event, EventDTO>
|
||||
{
|
||||
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<EventDTO> Get()
|
||||
{
|
||||
return this._mapper.Map<List<EventDTO>>(_service.GetAll().OrderByDescending(e=>e.Date).ToList());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LaDOSE.Api.Controllers
|
||||
{
|
||||
public class GenericController<T, TU> : Controller where TU : Entity.Context.Entity where T : IBaseService<TU>
|
||||
public abstract class GenericController<T, TU> : Controller where TU : Entity.Context.Entity where T : IBaseService<TU>
|
||||
{
|
||||
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<TU> Get()
|
||||
public virtual List<TU> 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
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LaDOSE.Api.Controllers
|
||||
{
|
||||
public class GenericControllerDTO<T, TU, D> : Controller where TU : Entity.Context.Entity where T : IBaseService<TU>
|
||||
public abstract class GenericControllerDTO<T, TU, D> : Controller where TU : Entity.Context.Entity where T : IBaseService<TU>
|
||||
{
|
||||
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<TU>(dto);
|
||||
return _mapper.Map<D>(_service.AddOrUpdate(entity));
|
||||
}
|
||||
[HttpGet]
|
||||
public List<D> Get()
|
||||
public virtual List<D> Get()
|
||||
{
|
||||
|
||||
return _mapper.Map<List<D>>(_service.GetAll().ToList());
|
||||
|
||||
}
|
||||
[HttpGet("{id}")]
|
||||
public D Get(int id)
|
||||
public virtual D Get(int id)
|
||||
{
|
||||
return _mapper.Map<D>(_service.GetById(id));
|
||||
|
||||
}
|
||||
[HttpDelete("{id}")]
|
||||
public IActionResult Delete(int id)
|
||||
public virtual IActionResult Delete(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace LaDOSE.Business.Interface
|
||||
{
|
||||
Task<List<ChallongeTournament>> GetTournaments(DateTime? start, DateTime? end);
|
||||
Task<Event> ParseSmash(string tournamentSlug);
|
||||
Task<List<Event>> ParseChallonge(List<int> ids);
|
||||
//Task<List<Event>> ParseChallonge(List<int> ids);
|
||||
|
||||
//Task<TournamentsResult> GetChallongeTournamentsResult(List<int> ids);
|
||||
//Task<TournamentsResult> GetSmashResult(string tournamentSlug);
|
||||
|
||||
@@ -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<List<Event>> ParseEvent(List<int> idTournaments)
|
||||
{
|
||||
var result = new List<Event>();
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -192,10 +192,11 @@ namespace LaDOSE.Business.Service
|
||||
|
||||
}
|
||||
|
||||
public Task<List<Event>> ParseChallonge(List<int> ids)
|
||||
{
|
||||
return _challongeProvider.ParseEvent(ids);
|
||||
}
|
||||
//public Task<List<Event>> ParseChallonge(List<int> 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user