Ajout du projet Ktor et de la dépendance à Ktorm

pull/4/head
Lucas EVARD 2 years ago
parent 94d5abb84f
commit e63d4cfb19

36
Sources/.gitignore vendored

@ -0,0 +1,36 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/

@ -1,37 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33424.131
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "Shared\Shared.csproj", "{ACD97125-7DB7-4A05-B9B2-D531D2B08A27}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj", "{94CAC52F-2584-4C8F-85BF-9333FFCE1481}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AllInApi", "AllInApi\AllInApi.csproj", "{3336A244-C3FE-415F-BB19-DDA0DC301524}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ACD97125-7DB7-4A05-B9B2-D531D2B08A27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ACD97125-7DB7-4A05-B9B2-D531D2B08A27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ACD97125-7DB7-4A05-B9B2-D531D2B08A27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ACD97125-7DB7-4A05-B9B2-D531D2B08A27}.Release|Any CPU.Build.0 = Release|Any CPU
{94CAC52F-2584-4C8F-85BF-9333FFCE1481}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94CAC52F-2584-4C8F-85BF-9333FFCE1481}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94CAC52F-2584-4C8F-85BF-9333FFCE1481}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94CAC52F-2584-4C8F-85BF-9333FFCE1481}.Release|Any CPU.Build.0 = Release|Any CPU
{3336A244-C3FE-415F-BB19-DDA0DC301524}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3336A244-C3FE-415F-BB19-DDA0DC301524}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3336A244-C3FE-415F-BB19-DDA0DC301524}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3336A244-C3FE-415F-BB19-DDA0DC301524}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BDB705DC-223D-4FDE-8D00-67929A13F0FD}
EndGlobalSection
EndGlobal

@ -1,13 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
</Project>

@ -1,11 +0,0 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace AllInApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class BetController : ControllerBase
{
}
}

@ -1,11 +0,0 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace AllInApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class GroupController : ControllerBase
{
}
}

@ -1,43 +0,0 @@
using Microsoft.AspNetCore.Mvc;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace AllInApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class UserController : ControllerBase
{
// GET: api/<UserController>
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/<UserController>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/<UserController>
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/<UserController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<UserController>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}

@ -1,12 +0,0 @@
namespace AllInApi.DTO
{
public class BetDTO
{
public string Name { get; set; }
public string Title { get; set; }
public List<string> Choices { get; set; }
public string Themes{ get; set; }
public Dictionary<UserDTO, MiseDTO>? Bets { get; set; }
}
}

@ -1,9 +0,0 @@
namespace AllInApi.DTO
{
public class GroupDTO
{
public string Name { get; set; }
public DateTime CreationDate { get; set; }
public LargeImageDTO Image { get; set; }
}
}

@ -1,7 +0,0 @@
namespace AllInApi.DTO
{
public class LargeImageDTO
{
public string Base64 { get; set; }
}
}

@ -1,8 +0,0 @@
namespace AllInApi.DTO
{
public class MiseDTO
{
public int Cost { get; set; }
public int Choices { get; set; }
}
}

@ -1,12 +0,0 @@
namespace AllInApi.DTO
{
public class UserDTO
{
public string Name { get; set; }
public string Mail { get; set; }
public LargeImageDTO Image { get; set; }
public int NumberOfCoins { get; set; }
public List<GroupDTO> Groups { get; set;}
}
}

@ -1,6 +0,0 @@
namespace AllInApi.Mapper
{
public class BetMapper
{
}
}

@ -1,6 +0,0 @@
namespace AllInApi.Mapper
{
public class GroupMapper
{
}
}

@ -1,6 +0,0 @@
namespace AllInApi.Mapper
{
public class UserMapper
{
}
}

@ -1,25 +0,0 @@
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

@ -1,31 +0,0 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:7156",
"sslPort": 44309
}
},
"profiles": {
"AllInApi": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7065;http://localhost:5238",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

@ -1,8 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

@ -1,9 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

@ -1,102 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public class Bet
{
public string Id
{
get => id;
private init
{
if (string.IsNullOrWhiteSpace(value))
{
id = "Unknown";
return;
}
id = value;
}
}
private readonly string id = null!;
public string Title
{
get => title;
private init
{
if (string.IsNullOrWhiteSpace(value))
{
title = "Unknown";
return;
}
title = value;
}
}
private readonly string title = null!;
public string Name
{
get => name;
private init
{
if (string.IsNullOrWhiteSpace(value))
{
name = "Unknown";
return;
}
name = value;
}
}
private readonly string name = null!;
public ReadOnlyDictionary<User, Mise> Users { get; private set; }
private Dictionary<User, Mise> users = new Dictionary<User, Mise>();
public ReadOnlyCollection<String> Choices { get; private set; }
private List<String> choices = new();
public string Theme
{
get => theme;
private init
{
if (string.IsNullOrWhiteSpace(value))
{
theme = "Unknown";
return;
}
theme = value;
}
}
private readonly string theme = null!;
public bool Status { get; set; }
public string Description { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public Bet(string id, string title, string name, string theme, bool status, string description, DateTime startDate, DateTime endDate)
{
Id = id;
Title = title;
Name = name;
Choices = new ReadOnlyCollection<String>(choices);
Theme = theme;
Status = status;
Description = description;
StartDate = startDate;
EndDate = endDate;
Users = new ReadOnlyDictionary<User, Mise>(users);
}
}
}

@ -1,68 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public class Group
{
public string Id
{
get => id;
private init
{
if (string.IsNullOrWhiteSpace(value))
{
id = "Unknown";
return;
}
id = value;
}
}
private readonly string id = null!;
public string Name
{
get => name;
set
{
if (value == null)
{
name = "";
return;
}
name = value;
}
}
private string name = "";
public LargeImage Image { get; set; }
public DateTime CreationDate { get; set; }
public Group(string id, string name, DateTime creationDate, string image = "")
{
Id = id;
Name = name;
Image = new LargeImage(image);
CreationDate = creationDate;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(obj, null)) return false;
if (ReferenceEquals(obj, this)) return true;
if (GetType() != obj.GetType()) return false;
return Equals(obj as Group);
}
public override int GetHashCode()
=> Id.GetHashCode() % 997;
public bool Equals(Group? other)
=> Id.Equals(other?.Id);
}
}

@ -1,40 +0,0 @@
using Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public interface IDataManager
{
IUsersManager UsersMgr { get; }
IBetsManager BetsMgr { get; }
IRunesManager RunesMgr { get; }
}
public interface IUsersManager : IGenericDataManager<User?>
{
Task<int> GetItemByMail(string mail);
Task<int> GetNbItemsByUser(Group? group);
Task<IEnumerable<User?>> GetItemsByGroup(Group? group, int index, int count, string? orderingPropertyName = null, bool descending = false);
Task<int> GetNbItemsByAllCoins(int allCoins);
Task<IEnumerable<User?>> GetItemsByAllCoins(int allCoins, int index, int count, string? orderingPropertyName = null, bool descending = false);
}
public interface IBetsManager : IGenericDataManager<Bet?>
{
Task<int> GetNbItemsByUser(User? user);
Task<IEnumerable<Bet?>> GetItemsByUser(User? user, int index, int count, string? orderingPropertyName = null, bool descending = false);
Task<int> GetNbItemsByDescription(string description);
Task<IEnumerable<Bet?>> GetItemsByDescription(string description, int index, int count, string? orderingPropertyName = null, bool descending = false);
}
public interface IRunesManager : IGenericDataManager<Rune?>
{
}
}

@ -1,32 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public class LargeImage : IEquatable<LargeImage>
{
public string Base64 { get; set; }
public LargeImage(string base64)
{
Base64 = base64;
}
public bool Equals(LargeImage? other)
=> other != null && other.Base64.Equals(Base64);
public override bool Equals(object? obj)
{
if (ReferenceEquals(obj, null)) return false;
if (ReferenceEquals(obj!, this)) return true;
if (GetType() != obj!.GetType()) return false;
return Equals(obj! as LargeImage);
}
public override int GetHashCode()
=> Base64.Substring(0, 10).GetHashCode();
}
}

@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public class Mise
{
public int Cost { get; set; }
public string Choice { get; set; }
public Mise(int cost, string choice)
{
Cost = cost;
Choice = choice;
}
}
}

@ -1,13 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

@ -1,134 +0,0 @@
using System.Collections.ObjectModel;
using System.Reflection.PortableExecutable;
using System.Security.Claims;
using System.Text;
using System.Xml.Linq;
using static System.Net.Mime.MediaTypeNames;
namespace Model
{
public class User
{
public string Id
{
get => id;
private init
{
if (string.IsNullOrWhiteSpace(value))
{
id = "Unknown";
return;
}
id = value;
}
}
private readonly string id = null!;
public string Pseudo
{
get => pseudo;
set
{
if (value == null)
{
pseudo = "";
return;
}
pseudo = value;
}
}
private string pseudo = "";
public string Mail
{
get => mail;
set
{
if (value == null)
{
mail = "";
return;
}
mail = value;
}
}
private string mail = "";
public string Password
{
get => password;
set
{
if (value == null)
{
password = "";
return;
}
password = value;
}
}
private string password = "";
public DateTime CreationDate { get; set; }
public LargeImage Image { get; set; }
public int AllCoins { get; set; }
public User(string id, string pseudo, string mail, string password, DateTime date, string image = "", int allCoins = 0)
{
Id = id;
Pseudo = pseudo;
Mail = mail;
Password = password;
Image = new LargeImage(image);
AllCoins = allCoins;
Groups = new ReadOnlyCollection<Group>(groups);
}
public ReadOnlyCollection<Group> Groups { get; private set; }
private List<Group> groups = new();
public bool AddGroup(Group group)
{
if (groups.Contains(group))
return false;
groups.Add(group);
return true;
}
public bool RemoveSkin(Group group)
=> groups.Remove(group);
public override bool Equals(object? obj)
{
if (ReferenceEquals(obj, null)) return false;
if (ReferenceEquals(obj, this)) return true;
if (GetType() != obj.GetType()) return false;
return Equals(obj as User);
}
public override int GetHashCode()
=> Id.GetHashCode() % 997;
public bool Equals(User? other)
=> Id.Equals(other?.Id);
public override string ToString()
{
StringBuilder sb = new StringBuilder($"{Id} ({Mail})");
if (!string.IsNullOrWhiteSpace(Image.Base64))
{
sb.AppendLine($"\t{Image.Base64}");
}
if (Groups.Any())
{
sb.AppendLine("\tGroup:");
foreach (var group in Groups)
{
sb.AppendLine($"\t\t{group.Id} - {group.Name}");
}
}
return sb.ToString();
}
}
}

@ -1,12 +0,0 @@
namespace Shared;
public interface IGenericDataManager<T>
{
Task<int> GetNbItems();
Task<IEnumerable<T>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false);
Task<int> GetNbItemsByName(string substring);
Task<IEnumerable<T>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false);
Task<IEnumerable<T>> GetItemByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false);
Task<T> UpdateItem(T oldItem, T newItem);
Task<T> AddItem(T item);
Task<bool> DeleteItem(T item);
}

@ -1,9 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -0,0 +1,143 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>allin</groupId>
<artifactId>allin-api</artifactId>
<version>0.0.1</version>
<name>allin-api</name>
<description>allin-api</description>
<properties>
<ktor_version>2.3.4</ktor_version>
<kotlin.code.style>official</kotlin.code.style>
<kotlin_version>1.9.10</kotlin_version>
<logback_version>1.4.11</logback_version>
<slf4j_version>2.0.9</slf4j_version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
<main.class>allin.ApplicationKt</main.class>
</properties>
<repositories>
</repositories>
<dependencies>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-core-jvm</artifactId>
<version>${ktor_version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-netty-jvm</artifactId>
<version>${ktor_version}</version>
</dependency>
<dependency>
<groupId>org.ktorm</groupId>
<artifactId>ktorm-core</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback_version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j_version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-tests-jvm</artifactId>
<version>${ktor_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${kotlin_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-debug</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin_version}</version>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>${main.class}</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${main.class}</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,15 @@
package allin
import allin.plugins.*
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
fun main() {
embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = Application::module)
.start(wait = true)
}
fun Application.module() {
configureRouting()
}

@ -0,0 +1,13 @@
package allin.plugins
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
fun Application.configureRouting() {
routing {
get("/") {
call.respondText("Hello World!")
}
}
}

@ -0,0 +1,12 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="trace">
<appender-ref ref="STDOUT"/>
</root>
<logger name="org.eclipse.jetty" level="INFO"/>
<logger name="io.netty" level="INFO"/>
</configuration>

@ -0,0 +1,4 @@
package allin
class ApplicationTest {
}

@ -0,0 +1,12 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="trace">
<appender-ref ref="STDOUT"/>
</root>
<logger name="org.eclipse.jetty" level="INFO"/>
<logger name="io.netty" level="INFO"/>
</configuration>
Loading…
Cancel
Save