Modification get smash
All checks were successful
Build App / Build (push) Successful in 1m53s

This commit is contained in:
2024-03-22 23:58:43 +01:00
parent 88fb4935b5
commit 454c12a5a9
19 changed files with 176 additions and 63 deletions

View File

@@ -17,8 +17,17 @@ namespace LaDOSE.Api.Controllers
[Produces("application/json")] [Produces("application/json")]
public class GameController : GenericControllerDTO<IGameService, Game, GameDTO> public class GameController : GenericControllerDTO<IGameService, Game, GameDTO>
{ {
public GameController(IMapper mapper,IGameService service) : base(mapper,service) private IExternalProviderService provider;
public GameController(IMapper mapper,IGameService service, IExternalProviderService service2) : base(mapper,service)
{ {
provider = service2;
}
[HttpGet("smash/{name}")]
public async Task<List<GameDTO>> GetIdFromSmash(string name)
{
var smashGame = await provider.GetSmashGame(name);
return _mapper.Map<List<GameDTO>>(smashGame);;
} }
} }
} }

View File

@@ -19,7 +19,7 @@ namespace LaDOSE.Api.Controllers
private IMapper _mapper; private IMapper _mapper;
// GET // GETawa
public TournamentController(IMapper mapper, IExternalProviderService service) public TournamentController(IMapper mapper, IExternalProviderService service)
{ {
_mapper = mapper; _mapper = mapper;

View File

@@ -24,6 +24,7 @@ using LaDOSE.Entity.Wordpress;
using Result = LaDOSE.Entity.Challonge.Result; using Result = LaDOSE.Entity.Challonge.Result;
using LaDOSE.Entity.BotEvent; using LaDOSE.Entity.BotEvent;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.Hosting;
namespace LaDOSE.Api namespace LaDOSE.Api
{ {
@@ -163,7 +164,7 @@ namespace LaDOSE.Api
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app, IHostEnvironment env, ILoggerFactory loggerFactory)
{ {
//loggerFactory.AddConsole(Configuration.GetSection("Logging")); //loggerFactory.AddConsole(Configuration.GetSection("Logging"));
//loggerFactory.AddDebug(); //loggerFactory.AddDebug();

View File

@@ -3,6 +3,8 @@ using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using LaDOSE.DesktopApp.Avalonia.ViewModels; using LaDOSE.DesktopApp.Avalonia.ViewModels;
using LaDOSE.DesktopApp.Avalonia.Views; using LaDOSE.DesktopApp.Avalonia.Views;
using LaDOSE.REST;
using MsBox.Avalonia;
using ReactiveUI; using ReactiveUI;
using Splat; using Splat;
@@ -10,6 +12,10 @@ namespace LaDOSE.DesktopApp.Avalonia;
public partial class App : Application public partial class App : Application
{ {
public override void Initialize() public override void Initialize()
{ {
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);

View File

@@ -23,6 +23,7 @@
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.--> <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.10"/> <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.10"/>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.10"/> <PackageReference Include="Avalonia.ReactiveUI" Version="11.0.10"/>
<PackageReference Include="MessageBox.Avalonia" Version="3.1.5.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
</ItemGroup> </ItemGroup>

View File

@@ -5,6 +5,8 @@ using System.ComponentModel;
using System.IO; using System.IO;
using LaDOSE.REST; using LaDOSE.REST;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MsBox.Avalonia;
using MsBox.Avalonia.Enums;
using Splat; using Splat;
// using Xilium.CefGlue; // using Xilium.CefGlue;
// using Xilium.CefGlue.Common; // using Xilium.CefGlue.Common;
@@ -22,23 +24,36 @@ sealed class Program
public static void Main(string[] args) public static void Main(string[] args)
{ {
RegisterDependencies(Locator.CurrentMutable, Locator.Current); RegisterDependencies(Locator.CurrentMutable, Locator.Current);
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args); var app = BuildAvaloniaApp();
app.StartWithClassicDesktopLifetime(args);
} }
private static void RegisterDependencies(IMutableDependencyResolver currentMutable, IReadonlyDependencyResolver current) private static void RegisterDependencies(IMutableDependencyResolver currentMutable, IReadonlyDependencyResolver current)
{ {
var builder = new ConfigurationBuilder() var builder = new ConfigurationBuilder()
.AddJsonFile("settings.json", optional: true, reloadOnChange: true).Build(); .AddJsonFile("settings.json", optional: true, reloadOnChange: true).Build();
var restUrl = builder["REST:Url"].ToString(); var restUrl = builder["REST:Url"].ToString();
var restUser = builder["REST:User"].ToString(); var restUser = builder["REST:User"].ToString();
var restPassword = builder["REST:Password"].ToString(); var restPassword = builder["REST:Password"].ToString();
currentMutable.RegisterLazySingleton<RestService>(() => currentMutable.RegisterLazySingleton<RestService>(() =>
{ {
var restService = new RestService(); var restService = new RestService();
try
{
restService.Connect(new Uri(restUrl), restUser, restPassword); restService.Connect(new Uri(restUrl), restUser, restPassword);
}
catch (Exception e)
{
Console.WriteLine(e);
}
return restService; return restService;
}); });
} }
// Avalonia configuration, don't remove; also used by visual designer. // Avalonia configuration, don't remove; also used by visual designer.
@@ -48,13 +63,5 @@ sealed class Program
.UsePlatformDetect() .UsePlatformDetect()
.WithInterFont() .WithInterFont()
.LogToTrace() .LogToTrace()
.AfterSetup(_ =>
{
// CefRuntimeLoader.Initialize(new CefSettings()
// {
// WindowlessRenderingEnabled = true,
// NoSandbox = true,
// });
})
.UseReactiveUI(); .UseReactiveUI();
} }

View File

@@ -14,14 +14,14 @@ namespace LaDOSE.DesktopApp.Avalonia.Utils
_compare = c; _compare = c;
} }
public bool Equals(T x, T y) public bool Equals(T? x, T? y)
{ {
return _compare(x, y); return _compare(x, y);
} }
public int GetHashCode(T obj) public int GetHashCode(T obj)
{ {
return 0; return obj.GetHashCode();
} }
} }
} }

View File

@@ -18,6 +18,7 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
private GameDTO _currentGame; private GameDTO _currentGame;
private List<GameDTO> _games; private List<GameDTO> _games;
private List<GameDTO> _Searchgames;
private RestService RestService { get; set; } private RestService RestService { get; set; }
public GamesViewModel(IScreen screen): base(screen,"Games") public GamesViewModel(IScreen screen): base(screen,"Games")
{ {
@@ -26,6 +27,7 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
OnInitialize(); OnInitialize();
} }
void OnInitialize() void OnInitialize()
{ {
LoadGames(); LoadGames();
@@ -49,6 +51,15 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
} }
} }
public List<GameDTO> SearchGame
{
get => _Searchgames;
set
{
_Searchgames = value;
RaisePropertyChanged(nameof(this.SearchGame));
}
}
public GameDTO CurrentGame public GameDTO CurrentGame
{ {
get => _currentGame; get => _currentGame;
@@ -79,6 +90,10 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
LoadGames(); LoadGames();
} }
public void GetGame()
{
SearchGame = this.RestService.GetSmashGames(this.CurrentGame.LongName);
}
public bool CanDeleteGame => CurrentGame != null; public bool CanDeleteGame => CurrentGame != null;

View File

@@ -10,7 +10,7 @@ public class MainWindowViewModel : Window
public void CloseApp() public void CloseApp()
{ {
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime) if (Application.Current != null && Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime)
((IClassicDesktopStyleApplicationLifetime)Application.Current.ApplicationLifetime).Shutdown(); ((Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)!).Shutdown();
} }
} }

View File

@@ -21,16 +21,16 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
{ {
public string DisplayName => "Tournament Result"; public string DisplayName => "Tournament Result";
private RestService RestService { get; set; } private RestService? RestService { get; set; }
//Dictionary<string, Dictionary<int, int>> _computedResult; //Dictionary<string, Dictionary<int, int>> _computedResult;
#region Properties #region Properties
private string css = string.Empty; private string css = string.Empty;
private String _selectRegex; private string? _selectRegex;
public String SelectRegex public string? SelectRegex
{ {
get { return _selectRegex; } get { return _selectRegex; }
set set
@@ -40,9 +40,9 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
} }
} }
private String _selectEventRegex; private string? _selectEventRegex;
public String SelectEventRegex public string? SelectEventRegex
{ {
get { return _selectEventRegex; } get { return _selectEventRegex; }
set set
@@ -51,8 +51,8 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
RaisePropertyChanged(nameof(SelectEventRegex)); RaisePropertyChanged(nameof(SelectEventRegex));
} }
} }
private string _slug; private string? _slug;
public String Slug public string? Slug
{ {
get { return _slug; } get { return _slug; }
set set
@@ -62,9 +62,9 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
} }
} }
private String _html; private string? _html;
public String Html public string? Html
{ {
get { return $"<html><head><style>{this.css}</style></head><body>{HtmlContent}</body></html>"; } get { return $"<html><head><style>{this.css}</style></head><body>{HtmlContent}</body></html>"; }
set set
@@ -72,9 +72,9 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
_html = value; _html = value;
} }
} }
private String _htmlContent; private string? _htmlContent;
public String HtmlContent public string? HtmlContent
{ {
get { return _htmlContent; } get { return _htmlContent; }
set set
@@ -112,12 +112,12 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
} }
private TournamentsResultDTO _results; private TournamentsResultDTO? _results;
public List<TournamentDTO> Tournaments { get; set; } public List<TournamentDTO> Tournaments { get; set; }
public List<EventDTO> Events { get; set; } public List<EventDTO> Events { get; set; }
public TournamentsResultDTO Results public TournamentsResultDTO? Results
{ {
get => _results; get => _results;
set set
@@ -151,10 +151,10 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
} }
} }
private GameDTO _selectedGame; private GameDTO? _selectedGame;
public GameDTO SelectedGame public GameDTO? SelectedGame
{ {
get { return _selectedGame; } get { return _selectedGame; }
set set
@@ -172,9 +172,9 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
} }
} }
private ObservableCollection<ResultDTO> _selectedGameResult; private ObservableCollection<ResultDTO>? _selectedGameResult;
public ObservableCollection<ResultDTO> SelectedGameResult public ObservableCollection<ResultDTO>? SelectedGameResult
{ {
get { return _selectedGameResult; } get { return _selectedGameResult; }
set set
@@ -184,11 +184,11 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
} }
} }
private String _first; private string? _first;
private DataTable _gridDataTable; private DataTable? _gridDataTable;
private string _error; private string? _error;
public String First public string? First
{ {
get { return _first; } get { return _first; }
set set
@@ -252,7 +252,7 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
} }
public DataTable GridDataTable public DataTable? GridDataTable
{ {
get => _gridDataTable; get => _gridDataTable;
set set
@@ -262,7 +262,7 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
RaisePropertyChanged(nameof(GridDataTableView)); RaisePropertyChanged(nameof(GridDataTableView));
} }
} }
public DataView GridDataTableView public DataView? GridDataTableView
{ {
get get
{ {
@@ -293,7 +293,7 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
} }
public string Error public string? Error
{ {
get => _error; get => _error;
set set
@@ -356,7 +356,7 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
DataTable grid = new DataTable(); DataTable? grid = new DataTable();
var games = Results.Games.Distinct().OrderBy(e => e.Order).ToList(); var games = Results.Games.Distinct().OrderBy(e => e.Order).ToList();
grid.Columns.Add("Players"); grid.Columns.Add("Players");
games.ForEach(e => grid.Columns.Add(e.Name.Replace('.', ' '),typeof(Int32))); games.ForEach(e => grid.Columns.Add(e.Name.Replace('.', ' '),typeof(Int32)));
@@ -468,7 +468,7 @@ namespace LaDOSE.DesktopApp.Avalonia.ViewModels
{ {
sb.AppendLine($"<br> 1/ {top3[0]}<br> 2/ {top3[1]}<br> 3/ {top3[2]} <br>"); sb.AppendLine($"<br> 1/ {top3[0]}<br> 2/ {top3[1]}<br> 3/ {top3[2]} <br>");
//<a href=\"https://challonge.com/fr/{enumerable.First().TournamentUrl}\" target=\"_blank\">https://challonge.com/fr/{enumerable.First().TournamentUrl}</a> //<a href=\"https://challonge.com/fr/{enumerable.First().TournamentUrl}\" target=\"_blank\">https://challonge.com/fr/{enumerable.First().TournamentUrl}</a>
var url = enumerable.FirstOrDefault().TournamentUrl; string url = enumerable.FirstOrDefault()?.TournamentUrl;
url = url.Replace(" ", "-"); url = url.Replace(" ", "-");
url = url.Replace(".", "-"); url = url.Replace(".", "-");
sb.AppendLine($"<a href=\"https://smash.gg/tournament/ranking-1002/event/{url}\" target=\"_blank\">Voir le Bracket</p></td>"); sb.AppendLine($"<a href=\"https://smash.gg/tournament/ranking-1002/event/{url}\" target=\"_blank\">Voir le Bracket</p></td>");

View File

@@ -2,9 +2,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="650"
x:Class="LaDOSE.DesktopApp.Avalonia.Views.GamesView" x:Class="LaDOSE.DesktopApp.Avalonia.Views.GamesView"
xmlns:vm="using:LaDOSE.DesktopApp.Avalonia.ViewModels" xmlns:vm="using:LaDOSE.DesktopApp.Avalonia.ViewModels"
xmlns:dto="clr-namespace:LaDOSE.DTO;assembly=LaDOSE.DTO"
x:DataType="vm:GamesViewModel" x:DataType="vm:GamesViewModel"
> >
<Grid Row="4" Column="1"> <Grid Row="4" Column="1">
@@ -42,6 +43,7 @@
<RowDefinition Height="Auto"></RowDefinition> <RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition> <RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition> <RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition> <RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition> <RowDefinition Height="Auto"></RowDefinition>
@@ -71,11 +73,19 @@
<Label Grid.Row="6" Grid.Column="0">WpTagOs</Label> <Label Grid.Row="6" Grid.Column="0">WpTagOs</Label>
<TextBox Grid.Row="6" Grid.Column="1" Text="{Binding Path=CurrentGame.WordPressTagOs,Mode=TwoWay}" ></TextBox> <TextBox Grid.Row="6" Grid.Column="1" Text="{Binding Path=CurrentGame.WordPressTagOs,Mode=TwoWay}" ></TextBox>
<Label Grid.Row="7" Grid.Column="0">SmashId</Label> <Label Grid.Row="7" Grid.Column="0">SmashId</Label>
<TextBox Grid.Row="7" Grid.Column="1" Text="{Binding Path=CurrentGame.SmashId,Mode=TwoWay}"> <AutoCompleteBox Grid.Row="7" Grid.Column="1" Text="{Binding Path=CurrentGame.SmashId,Mode=TwoWay}" ItemsSource="{Binding Path=SearchGame}">
<AutoCompleteBox.ItemTemplate>
<DataTemplate>
<DockPanel LastChildFill="True" Margin="2" x:DataType="dto:GameDTO">
<TextBox Text="{Binding Id}"></TextBox>
<TextBlock Text="{Binding Name}" DockPanel.Dock="Left"/>
</DockPanel>
</DataTemplate>
</AutoCompleteBox.ItemTemplate>
</AutoCompleteBox>
</TextBox> <Button Grid.Row="9" x:Name="Update" Command="{Binding Update}">Update</Button>
<Button Grid.Row="9" Grid.Column="1" x:Name="SmashGame" Command="{Binding GetGame}">Get Game From Smash</Button>
<Button Grid.Row="9" Grid.ColumnSpan="2" x:Name="Update" Command="{Binding Update}">Update</Button>
</Grid> </Grid>
</Grid> </Grid>

View File

@@ -24,7 +24,7 @@ namespace LaDOSE.DesktopApp.Avalonia.Views
object? IViewFor.ViewModel object? IViewFor.ViewModel
{ {
get => ViewModel; get => ViewModel;
set => ViewModel = (TournamentResultViewModel)value; set => ViewModel = (TournamentResultViewModel)value!;
} }
public TournamentResultViewModel? ViewModel { get; set; } public TournamentResultViewModel? ViewModel { get; set; }

View File

@@ -24,6 +24,7 @@ namespace LaDOSE.REST
public event EventHandler<UpdatedJwtEventHandler> UpdatedJwtEvent; public event EventHandler<UpdatedJwtEventHandler> UpdatedJwtEvent;
public RestService() public RestService()
{ {
@@ -33,7 +34,15 @@ namespace LaDOSE.REST
public void Connect(Uri url, string user, string password) public void Connect(Uri url, string user, string password)
{ {
Client = new RestClient(url); Client = new RestClient(url);
string token = GetToken(user, password); string token;
try
{
token = GetToken(user, password);
}
catch (Exception)
{
return;
}
Client = new RestClient(url, options => Client = new RestClient(url, options =>
{ {
#if DEBUG #if DEBUG
@@ -205,6 +214,14 @@ namespace LaDOSE.REST
return restResponse; return restResponse;
} }
public List<GameDTO> GetSmashGames(string name)
{
CheckToken();
var restRequest = new RestRequest($"/api/Game/Smash/{name}", Method.Get);
var restResponse = Client.Get<List<GameDTO>>(restRequest);
return restResponse;
}
public GameDTO UpdateGame(GameDTO game) public GameDTO UpdateGame(GameDTO game)
{ {
CheckToken(); CheckToken();

View File

@@ -10,6 +10,9 @@ namespace LaDOSE.Business.Interface
{ {
Task<List<ChallongeTournament>> GetTournaments(DateTime? start, DateTime? end); Task<List<ChallongeTournament>> GetTournaments(DateTime? start, DateTime? end);
Task<Event> ParseSmash(string tournamentSlug); Task<Event> ParseSmash(string tournamentSlug);
Task<List<Game>> GetSmashGame(string name);
//Task<List<Event>> ParseChallonge(List<int> ids); //Task<List<Event>> ParseChallonge(List<int> ids);
//Task<TournamentsResult> GetChallongeTournamentsResult(List<int> ids); //Task<TournamentsResult> GetChallongeTournamentsResult(List<int> ids);

View File

@@ -18,6 +18,7 @@ namespace LaDOSE.Business.Interface
Task<TournamentResponse> GetNames(string slug); Task<TournamentResponse> GetNames(string slug);
Task<List<Game>> GetGames(string name);
} }
} }

View File

@@ -47,6 +47,37 @@ namespace LaDOSE.Business.Provider.SmashProvider
return graphQLResponse.Data; return graphQLResponse.Data;
} }
public async Task<List<Game>> GetGames(string game)
{
var query = new GraphQLRequest()
{
Query = @"
query VideogameQuery($name:String) {
videogames(query: { filter: { name: $name }, perPage: 5 }) {
nodes {
id
name
displayName
}
}
}
",
OperationName = "VideogameQuery",
Variables = new
{
name = game,
}
};
VideoGamesResponse querySmash = await QuerySmash<VideoGamesResponse>(query);
if (querySmash.videogames != null)
{
return querySmash.videogames.nodes.Select(e => new Game() { Id = e.id, Name = e.Name }).ToList();
}
return new List<Game>();
}
public async Task<Event> GetEvent(string slug) public async Task<Event> GetEvent(string slug)
{ {

View File

@@ -120,7 +120,10 @@ namespace LaDOSE.Business.Provider.SmashProvider
} }
public class VideoGamesResponse
{
public Node<VideoGameType>? videogames {get; set; }
}
public class TournamentResponse public class TournamentResponse

View File

@@ -78,6 +78,10 @@ namespace LaDOSE.Business.Service
//} //}
} }
public async Task<List<Game>> GetSmashGames(string name)
{
return await _smashProvider.GetGames(name);
}
public async Task<Event> ParseSmash(string tournamentSlug) public async Task<Event> ParseSmash(string tournamentSlug)
{ {
Event eventExist = GetBySlug(tournamentSlug); Event eventExist = GetBySlug(tournamentSlug);
@@ -109,6 +113,11 @@ namespace LaDOSE.Business.Service
} }
public Task<List<Game>> GetSmashGame(string name)
{
return _smashProvider.GetGames(name);
}
private Event GetBySlug(string tournamentSlug) private Event GetBySlug(string tournamentSlug)
{ {
return _context.Event.FirstOrDefault(e => e.SmashSlug == tournamentSlug); return _context.Event.FirstOrDefault(e => e.SmashSlug == tournamentSlug);