From 167f9574d20e77c248a0da78797351b136c312f7 Mon Sep 17 00:00:00 2001 From: CaptaiNiveau Date: Sat, 6 Aug 2022 01:03:45 +0200 Subject: [PATCH] Created backend --- .idea/.idea.leaky-ships.dir/.idea/.gitignore | 13 + .../.idea.leaky-ships.dir/.idea/encodings.xml | 4 + .../.idea/indexLayout.xml | 8 + .idea/.idea.leaky-ships.dir/.idea/misc.xml | 6 + .idea/.idea.leaky-ships.dir/.idea/vcs.xml | 6 + backend/.gitignore | 234 ++++++++++++++++++ .../.idea.SinkyShipsAPI/.idea/.gitignore | 13 + backend/.idea/.idea.SinkyShipsAPI/.idea/.name | 1 + .../.idea.SinkyShipsAPI/.idea/encodings.xml | 4 + .../.idea.SinkyShipsAPI/.idea/indexLayout.xml | 8 + .../.idea/.idea.SinkyShipsAPI/.idea/misc.xml | 6 + .../.idea/.idea.SinkyShipsAPI/.idea/vcs.xml | 6 + backend/SinkyShipsAPI.sln | 16 ++ backend/SinkyShipsAPI/.dockerignore | 25 ++ backend/SinkyShipsAPI/Dockerfile | 20 ++ backend/SinkyShipsAPI/Hubs/GameHub.cs | 8 + backend/SinkyShipsAPI/Model/Board.cs | 3 + backend/SinkyShipsAPI/Model/Player.cs | 3 + backend/SinkyShipsAPI/Model/Session.cs | 3 + backend/SinkyShipsAPI/Program.cs | 41 +++ .../Properties/launchSettings.json | 28 +++ .../SinkyShipsAPI/Repositories/IRepository.cs | 14 ++ .../Repositories/PlayerRepository.cs | 6 + .../Repositories/SessionRepository.cs | 26 ++ backend/SinkyShipsAPI/SinkyShipsAPI.csproj | 15 ++ .../appsettings.Development.json | 8 + backend/SinkyShipsAPI/appsettings.json | 9 + 27 files changed, 534 insertions(+) create mode 100644 .idea/.idea.leaky-ships.dir/.idea/.gitignore create mode 100644 .idea/.idea.leaky-ships.dir/.idea/encodings.xml create mode 100644 .idea/.idea.leaky-ships.dir/.idea/indexLayout.xml create mode 100644 .idea/.idea.leaky-ships.dir/.idea/misc.xml create mode 100644 .idea/.idea.leaky-ships.dir/.idea/vcs.xml create mode 100644 backend/.gitignore create mode 100644 backend/.idea/.idea.SinkyShipsAPI/.idea/.gitignore create mode 100644 backend/.idea/.idea.SinkyShipsAPI/.idea/.name create mode 100644 backend/.idea/.idea.SinkyShipsAPI/.idea/encodings.xml create mode 100644 backend/.idea/.idea.SinkyShipsAPI/.idea/indexLayout.xml create mode 100644 backend/.idea/.idea.SinkyShipsAPI/.idea/misc.xml create mode 100644 backend/.idea/.idea.SinkyShipsAPI/.idea/vcs.xml create mode 100644 backend/SinkyShipsAPI.sln create mode 100644 backend/SinkyShipsAPI/.dockerignore create mode 100644 backend/SinkyShipsAPI/Dockerfile create mode 100644 backend/SinkyShipsAPI/Hubs/GameHub.cs create mode 100644 backend/SinkyShipsAPI/Model/Board.cs create mode 100644 backend/SinkyShipsAPI/Model/Player.cs create mode 100644 backend/SinkyShipsAPI/Model/Session.cs create mode 100644 backend/SinkyShipsAPI/Program.cs create mode 100644 backend/SinkyShipsAPI/Properties/launchSettings.json create mode 100644 backend/SinkyShipsAPI/Repositories/IRepository.cs create mode 100644 backend/SinkyShipsAPI/Repositories/PlayerRepository.cs create mode 100644 backend/SinkyShipsAPI/Repositories/SessionRepository.cs create mode 100644 backend/SinkyShipsAPI/SinkyShipsAPI.csproj create mode 100644 backend/SinkyShipsAPI/appsettings.Development.json create mode 100644 backend/SinkyShipsAPI/appsettings.json diff --git a/.idea/.idea.leaky-ships.dir/.idea/.gitignore b/.idea/.idea.leaky-ships.dir/.idea/.gitignore new file mode 100644 index 0000000..7106cb5 --- /dev/null +++ b/.idea/.idea.leaky-ships.dir/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/modules.xml +/projectSettingsUpdater.xml +/.idea.leaky-ships.iml +/contentModel.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.leaky-ships.dir/.idea/encodings.xml b/.idea/.idea.leaky-ships.dir/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.leaky-ships.dir/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.leaky-ships.dir/.idea/indexLayout.xml b/.idea/.idea.leaky-ships.dir/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.leaky-ships.dir/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.leaky-ships.dir/.idea/misc.xml b/.idea/.idea.leaky-ships.dir/.idea/misc.xml new file mode 100644 index 0000000..1d8c84d --- /dev/null +++ b/.idea/.idea.leaky-ships.dir/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/.idea.leaky-ships.dir/.idea/vcs.xml b/.idea/.idea.leaky-ships.dir/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.leaky-ships.dir/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 0000000..9b3a78d --- /dev/null +++ b/backend/.gitignore @@ -0,0 +1,234 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Microsoft Azure ApplicationInsights config file +ApplicationInsights.config + +# Windows Store app package directory +AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ \ No newline at end of file diff --git a/backend/.idea/.idea.SinkyShipsAPI/.idea/.gitignore b/backend/.idea/.idea.SinkyShipsAPI/.idea/.gitignore new file mode 100644 index 0000000..432b119 --- /dev/null +++ b/backend/.idea/.idea.SinkyShipsAPI/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/modules.xml +/contentModel.xml +/projectSettingsUpdater.xml +/.idea.SinkyShipsAPI.iml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/backend/.idea/.idea.SinkyShipsAPI/.idea/.name b/backend/.idea/.idea.SinkyShipsAPI/.idea/.name new file mode 100644 index 0000000..526bd0f --- /dev/null +++ b/backend/.idea/.idea.SinkyShipsAPI/.idea/.name @@ -0,0 +1 @@ +SinkyShipsAPI \ No newline at end of file diff --git a/backend/.idea/.idea.SinkyShipsAPI/.idea/encodings.xml b/backend/.idea/.idea.SinkyShipsAPI/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/backend/.idea/.idea.SinkyShipsAPI/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/backend/.idea/.idea.SinkyShipsAPI/.idea/indexLayout.xml b/backend/.idea/.idea.SinkyShipsAPI/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/backend/.idea/.idea.SinkyShipsAPI/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/backend/.idea/.idea.SinkyShipsAPI/.idea/misc.xml b/backend/.idea/.idea.SinkyShipsAPI/.idea/misc.xml new file mode 100644 index 0000000..1d8c84d --- /dev/null +++ b/backend/.idea/.idea.SinkyShipsAPI/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/backend/.idea/.idea.SinkyShipsAPI/.idea/vcs.xml b/backend/.idea/.idea.SinkyShipsAPI/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/backend/.idea/.idea.SinkyShipsAPI/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/backend/SinkyShipsAPI.sln b/backend/SinkyShipsAPI.sln new file mode 100644 index 0000000..eed50ed --- /dev/null +++ b/backend/SinkyShipsAPI.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SinkyShipsAPI", "SinkyShipsAPI\SinkyShipsAPI.csproj", "{FB7A524F-B0C9-44DB-B1D9-776E01B28D93}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FB7A524F-B0C9-44DB-B1D9-776E01B28D93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB7A524F-B0C9-44DB-B1D9-776E01B28D93}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB7A524F-B0C9-44DB-B1D9-776E01B28D93}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB7A524F-B0C9-44DB-B1D9-776E01B28D93}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/backend/SinkyShipsAPI/.dockerignore b/backend/SinkyShipsAPI/.dockerignore new file mode 100644 index 0000000..cd967fc --- /dev/null +++ b/backend/SinkyShipsAPI/.dockerignore @@ -0,0 +1,25 @@ +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.idea +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/backend/SinkyShipsAPI/Dockerfile b/backend/SinkyShipsAPI/Dockerfile new file mode 100644 index 0000000..da2ae4b --- /dev/null +++ b/backend/SinkyShipsAPI/Dockerfile @@ -0,0 +1,20 @@ +FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +WORKDIR /src +COPY ["SinkyShipsAPI/SinkyShipsAPI.csproj", "SinkyShipsAPI/"] +RUN dotnet restore "SinkyShipsAPI/SinkyShipsAPI.csproj" +COPY . . +WORKDIR "/src/SinkyShipsAPI" +RUN dotnet build "SinkyShipsAPI.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "SinkyShipsAPI.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "SinkyShipsAPI.dll"] diff --git a/backend/SinkyShipsAPI/Hubs/GameHub.cs b/backend/SinkyShipsAPI/Hubs/GameHub.cs new file mode 100644 index 0000000..e85a8b6 --- /dev/null +++ b/backend/SinkyShipsAPI/Hubs/GameHub.cs @@ -0,0 +1,8 @@ +using Microsoft.AspNetCore.SignalR; + +namespace SinkyShipsAPI.Hubs; + +public class GameHub : Hub +{ + +} \ No newline at end of file diff --git a/backend/SinkyShipsAPI/Model/Board.cs b/backend/SinkyShipsAPI/Model/Board.cs new file mode 100644 index 0000000..0385f96 --- /dev/null +++ b/backend/SinkyShipsAPI/Model/Board.cs @@ -0,0 +1,3 @@ +namespace SinkyShipsAPI.Model; + +public record Board(Guid Id); \ No newline at end of file diff --git a/backend/SinkyShipsAPI/Model/Player.cs b/backend/SinkyShipsAPI/Model/Player.cs new file mode 100644 index 0000000..260436f --- /dev/null +++ b/backend/SinkyShipsAPI/Model/Player.cs @@ -0,0 +1,3 @@ +namespace SinkyShipsAPI.Model; + +public record Player(Guid Id, string Name); \ No newline at end of file diff --git a/backend/SinkyShipsAPI/Model/Session.cs b/backend/SinkyShipsAPI/Model/Session.cs new file mode 100644 index 0000000..97c5ee7 --- /dev/null +++ b/backend/SinkyShipsAPI/Model/Session.cs @@ -0,0 +1,3 @@ +namespace SinkyShipsAPI.Model; + +public record Session(Guid Id, Player PlayerOne, Player PlayerTwo); \ No newline at end of file diff --git a/backend/SinkyShipsAPI/Program.cs b/backend/SinkyShipsAPI/Program.cs new file mode 100644 index 0000000..f3e8107 --- /dev/null +++ b/backend/SinkyShipsAPI/Program.cs @@ -0,0 +1,41 @@ +using SinkyShipsAPI.Hubs; + +var builder = WebApplication.CreateBuilder(args); +builder.Services.AddControllers(); +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSignalR(); +builder.Services.AddSwaggerGen(); +builder.Services.AddCors(); + +var app = builder.Build(); +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); + app.UseCors(policyBuilder => policyBuilder + .AllowAnyHeader() + .AllowAnyMethod() + .AllowAnyOrigin() + .AllowCredentials() + ); +} +app.UseHttpsRedirection(); +app.UseRouting(); +app.UseAuthorization(); +app.UseEndpoints(endpoints => +{ + endpoints.MapHub("/hub"); +}); + +app.MapGet("/", () => "Hello World!"); + +//Websocket functions + +//SessionStart name -> sessionId +//SessionJoin sessionCode, name -> sessionId +//StartGame sessionId, settings +//SubmitBoard shipPositions[] -> +// + +app.Run(); \ No newline at end of file diff --git a/backend/SinkyShipsAPI/Properties/launchSettings.json b/backend/SinkyShipsAPI/Properties/launchSettings.json new file mode 100644 index 0000000..7b5d3e5 --- /dev/null +++ b/backend/SinkyShipsAPI/Properties/launchSettings.json @@ -0,0 +1,28 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:9968", + "sslPort": 44374 + } + }, + "profiles": { + "SinkyShipsAPI": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7036;http://localhost:5045", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/backend/SinkyShipsAPI/Repositories/IRepository.cs b/backend/SinkyShipsAPI/Repositories/IRepository.cs new file mode 100644 index 0000000..cb719a2 --- /dev/null +++ b/backend/SinkyShipsAPI/Repositories/IRepository.cs @@ -0,0 +1,14 @@ +using System.Dynamic; + +namespace SinkyShipsAPI.Repositories; + +public interface IRepository +{ + ValueTask GetById(Guid id); + + bool Create(T entity); + + bool Update(T entity); + + bool Delete(T entity); +} \ No newline at end of file diff --git a/backend/SinkyShipsAPI/Repositories/PlayerRepository.cs b/backend/SinkyShipsAPI/Repositories/PlayerRepository.cs new file mode 100644 index 0000000..300e355 --- /dev/null +++ b/backend/SinkyShipsAPI/Repositories/PlayerRepository.cs @@ -0,0 +1,6 @@ +namespace SinkyShipsAPI.Repositories; + +public class PlayerRepository +{ + +} \ No newline at end of file diff --git a/backend/SinkyShipsAPI/Repositories/SessionRepository.cs b/backend/SinkyShipsAPI/Repositories/SessionRepository.cs new file mode 100644 index 0000000..a713f52 --- /dev/null +++ b/backend/SinkyShipsAPI/Repositories/SessionRepository.cs @@ -0,0 +1,26 @@ +using SinkyShipsAPI.Model; + +namespace SinkyShipsAPI.Repositories; + +public class SessionRepository : IRepository +{ + public ValueTask GetById(Guid id) + { + throw new NotImplementedException(); + } + + public bool Create(Session entity) + { + throw new NotImplementedException(); + } + + public bool Update(Session entity) + { + throw new NotImplementedException(); + } + + public bool Delete(Session entity) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/backend/SinkyShipsAPI/SinkyShipsAPI.csproj b/backend/SinkyShipsAPI/SinkyShipsAPI.csproj new file mode 100644 index 0000000..e606255 --- /dev/null +++ b/backend/SinkyShipsAPI/SinkyShipsAPI.csproj @@ -0,0 +1,15 @@ + + + + net6.0 + enable + enable + Linux + + + + + + + + diff --git a/backend/SinkyShipsAPI/appsettings.Development.json b/backend/SinkyShipsAPI/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/backend/SinkyShipsAPI/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/backend/SinkyShipsAPI/appsettings.json b/backend/SinkyShipsAPI/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/backend/SinkyShipsAPI/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}