Fix Restsharp / Move to Postgresql

This commit is contained in:
2023-07-12 05:06:18 +02:00
parent d379a43eb4
commit 99257c3422
19 changed files with 206 additions and 144 deletions

View File

@@ -0,0 +1,17 @@
using System.Text;
using Microsoft.EntityFrameworkCore.Storage;
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal;
namespace LaDOSE.Api;
public class NpgsqlSqlGenerationLowercaseHelper : NpgsqlSqlGenerationHelper
{
static string ToLowerCase(string input) => input.ToLower();
public NpgsqlSqlGenerationLowercaseHelper(RelationalSqlGenerationHelperDependencies dependencies)
: base(dependencies) { }
public override string DelimitIdentifier(string identifier)
=> base.DelimitIdentifier(ToLowerCase(identifier));
public override void DelimitIdentifier(StringBuilder builder, string identifier)
=> base.DelimitIdentifier(builder, ToLowerCase(identifier));
}

View File

@@ -15,8 +15,8 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.8" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.8" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -1,28 +1,19 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using LaDOSE.Business.Interface; using LaDOSE.Business.Interface;
using LaDOSE.Business.Provider;
using LaDOSE.Business.Service; using LaDOSE.Business.Service;
using LaDOSE.Entity; using LaDOSE.Entity;
using LaDOSE.Entity.Context; using LaDOSE.Entity.Context;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
//using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using Pomelo.EntityFrameworkCore.MySql;
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
using AutoMapper; using AutoMapper;
using LaDOSE.Api.Helpers; using LaDOSE.Api.Helpers;
using LaDOSE.Business.Helper; using LaDOSE.Business.Helper;
@@ -32,6 +23,7 @@ using LaDOSE.Entity.Challonge;
using LaDOSE.Entity.Wordpress; 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;
namespace LaDOSE.Api namespace LaDOSE.Api
{ {
@@ -82,9 +74,7 @@ namespace LaDOSE.Api
// )); // ));
services.AddDbContextPool<LaDOSEDbContext>(options => services.AddDbContextPool<LaDOSEDbContext>(options =>
{ {
options.UseMySql( options.UseNpgsql(Configuration.GetConnectionString("DbContext")).ReplaceService<ISqlGenerationHelper,NpgsqlSqlGenerationLowercaseHelper>();
$"Server={MySqlServer};Database={MySqlDatabase};User={MySqlUser};Password={MySqlPassword};",
new MariaDbServerVersion(new Version(10, 1)));
}); });
var key = Encoding.ASCII.GetBytes(this.Configuration["JWTTokenSecret"]); var key = Encoding.ASCII.GetBytes(this.Configuration["JWTTokenSecret"]);

View File

@@ -4,20 +4,24 @@
"Default": "Warning" "Default": "Warning"
} }
}, },
"ConnectionStrings": {
"DbContext":"Host=descartes.local;Username=tom;Password=tom;Database=ladoseapi"
},
"CertificateSettings": { "CertificateSettings": {
"fileName": "localhost.pfx", "fileName": "localhost.pfx",
"password": "YourSecurePassword" "password": "YourSecurePassword"
}, },
"MySql": { "MySql": {
"Server": "host", "Server": "localhost",
"Database": "database", "Database": "ladoseapi",
"User": "User", "User": "dev",
"Password": "Password" "Password": "dev"
}, },
"ApiKey": { "ApiKey": {
"ChallongeApiKey": "Challonge ApiKey" "ChallongeApiKey": "Challonge ApiKey",
"SmashApiKey": "Smash"
}, },
"AllowedHosts": "*", "AllowedHosts": "0.0.0.0",
"Port": 5000, "Port": 5000,
"JWTTokenSecret": "here goes the custom Secret key for authnetication" "JWTTokenSecret": "here goes the custom Secret key for authnetication"
} }

View File

@@ -5,4 +5,8 @@
<Platforms>AnyCPU;x64</Platforms> <Platforms>AnyCPU;x64</Platforms>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project> </Project>

View File

@@ -12,6 +12,7 @@
<PackageReference Include="DSharpPlus.Interactivity" Version="4.2.0" /> <PackageReference Include="DSharpPlus.Interactivity" Version="4.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.8" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.8" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.8" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -34,13 +34,6 @@ namespace LaDOSE.DiscordBot.Service
} }
private void CheckToken()
{
}
public String GetInscrits() public String GetInscrits()
{ {

View File

@@ -40,6 +40,8 @@ namespace LaDOSE.Entity.Context
{ {
} }
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {

View File

@@ -6,6 +6,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.2" /> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.2" />
</ItemGroup> </ItemGroup>

View File

@@ -6,7 +6,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="RestSharp" Version="106.11.4" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RestSharp" Version="110.2.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -2,9 +2,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using LaDOSE.DTO; using LaDOSE.DTO;
using LaDOSE.REST.Event; using LaDOSE.REST.Event;
using Newtonsoft.Json;
using RestSharp; using RestSharp;
using RestSharp.Authenticators; using RestSharp.Authenticators;
using RestSharp.Serialization.Json;
namespace LaDOSE.REST namespace LaDOSE.REST
{ {
@@ -29,33 +30,29 @@ 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);
Client = new RestClient(url, options =>
{
#if DEBUG #if DEBUG
Client.Timeout = 999*1000; options.MaxTimeout = Int32.MaxValue;
#endif #endif
options.Authenticator = new JwtAuthenticator("token");
});
this.username = user; this.username = user;
this.password = password; this.password = password;
GetToken(user, password);
} }
private void GetToken(string user, string password) private string GetToken(string user, string password)
{ {
var restRequest = new RestRequest("users/auth", Method.POST); var restRequest = new RestRequest("users/auth", Method.Post);
restRequest.AddJsonBody(new {username = user, password = password}); restRequest.AddJsonBody(new {username = user, password = password});
var response = Client.Post(restRequest); var response = Client.Post<ApplicationUserDTO>(restRequest);
if (response.IsSuccessful) //var applicationUser = JsonConvert.DeserializeObject<ApplicationUserDTO>(response.Content);
{ this.Auth = response;
JsonDeserializer d = new JsonDeserializer(); return response.Token;
var applicationUser = d.Deserialize<ApplicationUserDTO>(response);
this.Auth = applicationUser;
Client.Authenticator = new JwtAuthenticator($"{applicationUser.Token}");
RaiseUpdatedJwtEvent(new UpdatedJwtEventHandler(this.Auth));
}
else
{
throw new Exception("unable to contact services");
}
} }
private void RaiseUpdatedJwtEvent(UpdatedJwtEventHandler auth) private void RaiseUpdatedJwtEvent(UpdatedJwtEventHandler auth)
@@ -75,120 +72,122 @@ namespace LaDOSE.REST
} }
} }
#region PostFix // #region PostFix
//
private T Post<T>(string resource,T entity) // private T Post<T>(string resource,T entity)
{ // {
var json = new RestSharp.Serialization.Json.JsonSerializer(); // var json = new RestSharp.Serialization.Json.JsonSerializer();
var jsonD = new RestSharp.Serialization.Json.JsonDeserializer(); // var jsonD = new RestSharp.Serialization.Json.JsonDeserializer();
var request = new RestRequest(); // var request = new RestRequest();
request.Method = Method.POST; // request.Method = Method.Post;
request.Resource = resource; // request.Resource = resource;
request.AddHeader("Accept", "application/json"); // request.AddHeader("Accept", "application/json");
request.AddHeader("Content-type", "application/json"); // request.AddHeader("Content-type", "application/json");
request.Parameters.Clear(); // request.Parameters.Clear();
request.AddParameter("application/json; charset=utf-8", json.Serialize(entity), ParameterType.RequestBody); // request.AddParameter("application/json; charset=utf-8", json.Serialize(entity), ParameterType.RequestBody);
request.AddObject(entity);
var response = Client.Execute(request);
//var content = response.Content; // raw content as string
try
{
return jsonD.Deserialize<T>(response);
}
catch (Exception)
{
return default(T);
}
}
private R Post<P,R>(string resource, P entity)
{
var json = new RestSharp.Serialization.Json.JsonSerializer();
var jsonD = new RestSharp.Serialization.Json.JsonDeserializer();
var request = new RestRequest();
request.Method = Method.POST;
request.Resource = resource;
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-type", "application/json");
request.Parameters.Clear();
request.AddParameter("application/json; charset=utf-8", json.Serialize(entity), ParameterType.RequestBody);
// request.AddObject(entity); // request.AddObject(entity);
var response = Client.Execute(request); // var response = Client.Execute(request);
//var content = response.Content; // raw content as string // //var content = response.Content; // raw content as string
try // try
{ // {
return jsonD.Deserialize<R>(response); // return jsonD.Deserialize<T>(response);
} // }
catch (Exception) // catch (Exception)
{ // {
return default(R); // return default(T);
} // }
//
//
} // }
// private R Post<P,R>(string resource, P entity)
#endregion // {
// var json = new RestSharp.Serialization.Json.JsonSerializer();
// var jsonD = new RestSharp.Serialization.Json.JsonDeserializer();
// var request = new RestRequest();
// request.Method = Method.Post;
// request.Resource = resource;
// request.AddHeader("Accept", "application/json");
// request.AddHeader("Content-type", "application/json");
// request.Parameters.Clear();
// request.AddParameter("application/json; charset=utf-8", json.Serialize(entity), ParameterType.RequestBody);
// //request.AddObject(entity);
// var response = Client.Execute(request);
// //var content = response.Content; // raw content as string
// try
// {
// return jsonD.Deserialize<R>(response);
// }
// catch (Exception)
// {
// return default(R);
// }
//
//
// }
//
// #endregion
#region WordPress #region WordPress
public List<WPEventDTO> GetEvents() public List<WPEventDTO> GetEvents()
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest("/api/wordpress/WPEvent", Method.GET); var restRequest = new RestRequest("/api/wordpress/WPEvent", Method.Get);
var restResponse = Client.Get<List<WPEventDTO>>(restRequest); var restResponse = Client.Get<List<WPEventDTO>>(restRequest);
return restResponse.Data; return restResponse;
} }
public WPEventDTO GetNextEvent() public WPEventDTO GetNextEvent()
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest("/api/wordpress/NextEvent", Method.GET); var restRequest = new RestRequest("/api/wordpress/NextEvent", Method.Get);
var restResponse = Client.Get<WPEventDTO>(restRequest); var restResponse = Client.Get<WPEventDTO>(restRequest);
return restResponse.Data; return restResponse;
} }
public string GetLastChallonge() public string GetLastChallonge()
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest($"/api/wordpress/GetLastChallonge/", Method.GET); var restRequest = new RestRequest($"/api/wordpress/GetLastChallonge/", Method.Get);
var restResponse = Client.Get(restRequest); var restResponse = Client.Get(restRequest);
return restResponse.Content; return restResponse.Content;
} }
public string CreateChallonge(int gameId, int eventId) public string CreateChallonge(int gameId, int eventId)
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest($"/api/wordpress/CreateChallonge/{gameId}/{eventId}", Method.GET); var restRequest = new RestRequest($"/api/wordpress/CreateChallonge/{gameId}/{eventId}", Method.Get);
var restResponse = Client.Get(restRequest); var restResponse = Client.Get(restRequest);
return restResponse.Content; return restResponse.Content;
} }
public string CreateChallonge2(int gameId, int eventId, List<WPUserDTO> optionalPlayers) public string CreateChallonge2(int gameId, int eventId, List<WPUserDTO> optionalPlayers)
{ {
CheckToken(); CheckToken();
var restResponse = Post<List<WPUserDTO>,string>($"/api/wordpress/CreateChallonge/{gameId}/{eventId}",optionalPlayers); RestRequest r =
new RestRequest($"/api/wordpress/CreateChallonge/{gameId}/{eventId}").AddJsonBody(optionalPlayers);
var restResponse = Client.Post<string>(r);
return restResponse; return restResponse;
} }
public bool RefreshDb() public bool RefreshDb()
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest("/api/Wordpress/UpdateDb", Method.GET); var restRequest = new RestRequest("/api/Wordpress/UpdateDb", Method.Get);
var restResponse = Client.Get<bool>(restRequest); var restResponse = Client.Get<bool>(restRequest);
return restResponse.Data; return restResponse;
} }
public List<WPUserDTO> GetUsers(int wpEventId, int gameId) public List<WPUserDTO> GetUsers(int wpEventId, int gameId)
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest($"/api/Wordpress/GetUsers/{wpEventId}/{gameId}", Method.GET); var restRequest = new RestRequest($"/api/Wordpress/GetUsers/{wpEventId}/{gameId}", Method.Get);
var restResponse = Client.Get<List<WPUserDTO>>(restRequest); var restResponse = Client.Get<List<WPUserDTO>>(restRequest);
return restResponse.Data; return restResponse;
} }
public List<WPUserDTO> GetUsersOptions(int wpEventId, int gameId) public List<WPUserDTO> GetUsersOptions(int wpEventId, int gameId)
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest($"/api/Wordpress/GetUsersOptions/{wpEventId}/{gameId}", Method.GET); var restRequest = new RestRequest($"/api/Wordpress/GetUsersOptions/{wpEventId}/{gameId}", Method.Get);
var restResponse = Client.Get<List<WPUserDTO>>(restRequest); var restResponse = Client.Get<List<WPUserDTO>>(restRequest);
return restResponse.Data; return restResponse;
} }
@@ -198,20 +197,21 @@ namespace LaDOSE.REST
public List<GameDTO> GetGames() public List<GameDTO> GetGames()
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest("/api/Game", Method.GET); var restRequest = new RestRequest("/api/Game", Method.Get);
var restResponse = Client.Get<List<GameDTO>>(restRequest); var restResponse = Client.Get<List<GameDTO>>(restRequest);
return restResponse.Data; return restResponse;
} }
public GameDTO UpdateGame(GameDTO game) public GameDTO UpdateGame(GameDTO game)
{ {
CheckToken(); CheckToken();
return Post("Api/Game", game); RestRequest r = new RestRequest("Api/Game").AddJsonBody(game);
return Client.Post<GameDTO>(r);
} }
public bool DeleteGame(int gameId) public bool DeleteGame(int gameId)
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest($"/api/Game/{gameId}", Method.DELETE); var restRequest = new RestRequest($"/api/Game/{gameId}", Method.Delete);
var restResponse = Client.Execute(restRequest); var restResponse = Client.Execute(restRequest);
return restResponse.IsSuccessful; return restResponse.IsSuccessful;
} }
@@ -227,26 +227,27 @@ namespace LaDOSE.REST
public List<TodoDTO> GetTodos() public List<TodoDTO> GetTodos()
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest("/api/Todo", Method.GET); var restRequest = new RestRequest("/api/Todo", Method.Get);
var restResponse = Client.Get<List<TodoDTO>>(restRequest); var restResponse = Client.Get<List<TodoDTO>>(restRequest);
return restResponse.Data; return restResponse;
} }
public TodoDTO GetTodoById(int id) public TodoDTO GetTodoById(int id)
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest($"/api/Todo/{id}", Method.GET); var restRequest = new RestRequest($"/api/Todo/{id}", Method.Get);
var restResponse = Client.Get<TodoDTO>(restRequest); var restResponse = Client.Get<TodoDTO>(restRequest);
return restResponse.Data; return restResponse;
} }
public TodoDTO UpdateTodo(TodoDTO Todo) public TodoDTO UpdateTodo(TodoDTO Todo)
{ {
CheckToken(); CheckToken();
return Post("Api/Todo", Todo); var restRequest = new RestRequest($"/api/Todo/", Method.Post).AddJsonBody(Todo);
return Client.Post<TodoDTO>(restRequest);
} }
public bool DeleteTodo(int todoId) public bool DeleteTodo(int todoId)
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest($"/api/Todo/{todoId}", Method.DELETE); var restRequest = new RestRequest($"/api/Todo/{todoId}", Method.Delete);
var restResponse = Client.Execute(restRequest); var restResponse = Client.Execute(restRequest);
return restResponse.IsSuccessful; return restResponse.IsSuccessful;
} }
@@ -258,9 +259,9 @@ namespace LaDOSE.REST
public TournamentsResultDTO Test(string test) public TournamentsResultDTO Test(string test)
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest($"Api/Test/Test/{test}", Method.GET); var restRequest = new RestRequest($"Api/Test/Test/{test}", Method.Get);
var restResponse = Client.Get<TournamentsResultDTO>(restRequest); var restResponse = Client.Get<TournamentsResultDTO>(restRequest);
return restResponse.Data; return restResponse;
} }
@@ -270,14 +271,17 @@ namespace LaDOSE.REST
public List<TournamentDTO> GetTournaments(TimeRangeDTO timeRange) public List<TournamentDTO> GetTournaments(TimeRangeDTO timeRange)
{ {
CheckToken(); CheckToken();
List<TournamentDTO> tournamentDtos = Post<TimeRangeDTO, List<TournamentDTO>>("/api/Tournament/GetTournaments",timeRange); RestRequest r = new RestRequest("/api/Tournament/GetTournaments").AddJsonBody(timeRange);
List<TournamentDTO> tournamentDtos = Client.Post<List<TournamentDTO>>(r);
return tournamentDtos; return tournamentDtos;
} }
public TournamentsResultDTO GetResults(List<int> ids) public TournamentsResultDTO GetResults(List<int> ids)
{ {
CheckToken(); CheckToken();
return Post<List<int>,TournamentsResultDTO>("Api/Tournament/GetResults", ids); var restRequest = new RestRequest("Api/Tournament/GetResults", Method.Post).AddJsonBody(ids);
return Client.Post<TournamentsResultDTO>(restRequest);
} }
@@ -285,33 +289,34 @@ namespace LaDOSE.REST
public bool ParseSmash(string slug) public bool ParseSmash(string slug)
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest($"Api/Tournament/ParseSmash/{slug}", Method.GET); var restRequest = new RestRequest($"Api/Tournament/ParseSmash/{slug}", Method.Get);
var restResponse = Client.Get<bool>(restRequest); var restResponse = Client.Get<bool>(restRequest);
return restResponse.Data; return restResponse;
} }
public bool ParseChallonge(List<int> ids) public bool ParseChallonge(List<int> ids)
{ {
CheckToken(); CheckToken();
return Post<List<int>, bool>("Api/Tournament/ParseChallonge", ids); var restRequest = new RestRequest("Api/Tournament/ParseChallonge", Method.Post).AddJsonBody(ids);
return Client.Post<bool>(restRequest);
} }
#endregion #endregion
#region Tournamenet Event / Player #region Tournamenet Event / Player
public List<EventDTO> GetAllEvents() public List<EventDTO> GetAllEvents()
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest("/api/Event", Method.GET); var restRequest = new RestRequest("/api/Event", Method.Get);
var restResponse = Client.Get<List<EventDTO>>(restRequest); var restResponse = Client.Get<List<EventDTO>>(restRequest);
return restResponse.Data; return restResponse;
} }
public List<string> GetPlayers(string slug) public List<string> GetPlayers(string slug)
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest($"/api/Tournament/GetPLayers/{slug}", Method.GET); var restRequest = new RestRequest($"/api/Tournament/GetPLayers/{slug}", Method.Get);
var restResponse = Client.Get<List<string>>(restRequest); var restResponse = Client.Get<List<string>>(restRequest);
return restResponse.Data; return restResponse;
} }
#endregion #endregion
@@ -321,23 +326,24 @@ namespace LaDOSE.REST
public bool CreateBotEvent(string eventName) public bool CreateBotEvent(string eventName)
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest($"/api/BotEvent/CreateBotEvent/{eventName}", Method.GET); var restRequest = new RestRequest($"/api/BotEvent/CreateBotEvent/{eventName}", Method.Get);
var restResponse = Client.Get<bool>(restRequest); var restResponse = Client.Get<bool>(restRequest);
return restResponse.Data; return restResponse;
} }
public BotEventDTO GetLastBotEvent() public BotEventDTO GetLastBotEvent()
{ {
CheckToken(); CheckToken();
var restRequest = new RestRequest($"/api/BotEvent/GetLastBotEvent/", Method.GET); var restRequest = new RestRequest($"/api/BotEvent/GetLastBotEvent/", Method.Get);
var restResponse = Client.Post<BotEventDTO>(restRequest); var restResponse = Client.Post<BotEventDTO>(restRequest);
return restResponse.Data; return restResponse;
} }
public bool ResultBotEvent(BotEventSendDTO result) public bool ResultBotEvent(BotEventSendDTO result)
{ {
CheckToken(); CheckToken();
return Post<BotEventSendDTO,bool>("/api/BotEvent/ResultBotEvent", result); var restRequest = new RestRequest("/api/BotEvent/ResultBotEvent", Method.Post).AddJsonBody(result);
return Client.Post<bool>(restRequest);
} }
#endregion #endregion

View File

@@ -10,6 +10,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="GraphQL.Client" Version="4.0.2" /> <PackageReference Include="GraphQL.Client" Version="4.0.2" />
<PackageReference Include="GraphQL.Client.Serializer.Newtonsoft" Version="4.0.2" /> <PackageReference Include="GraphQL.Client.Serializer.Newtonsoft" Version="4.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -1,4 +1,5 @@
using System; #nullable enable
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;

View File

@@ -96,7 +96,7 @@ namespace LaDOSE.Business.Service
//POKEMON. //POKEMON.
catch (Exception e) catch (Exception e)
{ {
throw new Exception("FUCK !"); throw new Exception($"FUCK ! {e.Message}");
} }
return currentEvent; return currentEvent;
} }

View File

@@ -20,6 +20,7 @@ namespace LaDOSE.Business.Service
{ {
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
return null; return null;
var p = _context.ApplicationUser.ToList();
var user = _context.ApplicationUser.SingleOrDefault(x => x.Username == username); var user = _context.ApplicationUser.SingleOrDefault(x => x.Username == username);
// check if username exists // check if username exists

View File

@@ -46,7 +46,7 @@ namespace LaDOSE.Business.Service
public bool UpdateBooking() public bool UpdateBooking()
{ {
_context.Database.SetCommandTimeout(60); _context.Database.SetCommandTimeout(60);
_context.Database.ExecuteSqlCommand("call ladoseapi.ImportEvent();"); _context.Database.ExecuteSqlRaw("call ladoseapi.ImportEvent();");
_context.Database.SetCommandTimeout(30); _context.Database.SetCommandTimeout(30);
return true; return true;
} }

View File

@@ -21,6 +21,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Utils", "Utils", "{2A0E1491
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaDOSE.REST", "LaDOSE.REST\LaDOSE.REST.csproj", "{692C2A72-AB7E-4502-BED8-AA2AFA1761CB}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaDOSE.REST", "LaDOSE.REST\LaDOSE.REST.csproj", "{692C2A72-AB7E-4502-BED8-AA2AFA1761CB}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinuxTest", "LinuxTest\LinuxTest.csproj", "{0EFA533F-9657-40CE-A3A5-F4E3C6E649B1}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -51,6 +53,10 @@ Global
{692C2A72-AB7E-4502-BED8-AA2AFA1761CB}.Debug|Any CPU.Build.0 = Debug|Any CPU {692C2A72-AB7E-4502-BED8-AA2AFA1761CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{692C2A72-AB7E-4502-BED8-AA2AFA1761CB}.Release|Any CPU.ActiveCfg = Release|Any CPU {692C2A72-AB7E-4502-BED8-AA2AFA1761CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{692C2A72-AB7E-4502-BED8-AA2AFA1761CB}.Release|Any CPU.Build.0 = Release|Any CPU {692C2A72-AB7E-4502-BED8-AA2AFA1761CB}.Release|Any CPU.Build.0 = Release|Any CPU
{0EFA533F-9657-40CE-A3A5-F4E3C6E649B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0EFA533F-9657-40CE-A3A5-F4E3C6E649B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0EFA533F-9657-40CE-A3A5-F4E3C6E649B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0EFA533F-9657-40CE-A3A5-F4E3C6E649B1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@@ -62,6 +68,7 @@ Global
{952DE665-70B5-492B-BE91-D0111E3BD907} = {6FC9438E-D93E-4E63-9342-F8A966EE2D06} {952DE665-70B5-492B-BE91-D0111E3BD907} = {6FC9438E-D93E-4E63-9342-F8A966EE2D06}
{61201DA6-1BC9-4BA1-AC45-70104D391ECD} = {6FC9438E-D93E-4E63-9342-F8A966EE2D06} {61201DA6-1BC9-4BA1-AC45-70104D391ECD} = {6FC9438E-D93E-4E63-9342-F8A966EE2D06}
{692C2A72-AB7E-4502-BED8-AA2AFA1761CB} = {2A0E1491-8E15-4062-ABE7-C04AE9655515} {692C2A72-AB7E-4502-BED8-AA2AFA1761CB} = {2A0E1491-8E15-4062-ABE7-C04AE9655515}
{0EFA533F-9657-40CE-A3A5-F4E3C6E649B1} = {2A0E1491-8E15-4062-ABE7-C04AE9655515}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D47DEDD0-C906-439D-81E4-D86BBE723B8C} SolutionGuid = {D47DEDD0-C906-439D-81E4-D86BBE723B8C}

View File

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\LaDOSE.REST\LaDOSE.REST.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,19 @@
using LaDOSE.REST;
internal class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Rest Test");
var p = new LaDOSE.REST.RestService();
Console.WriteLine("[+] Connect");
p.Connect(new Uri("http://localhost:5000/"),"dev","dev");
Console.WriteLine("[+] Test");
var games = p.GetGames();
foreach (var ga in games)
{
Console.WriteLine(ga.Name);
}
}
}