🔨 Réalisation du controlleur game + modif dbGame
continuous-integration/drone/push Build is passing Details

pull/1/head
Noan07 2 years ago
parent 85bd82a182
commit 089b169e32

@ -0,0 +1,18 @@
<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>
<ItemGroup>
<ProjectReference Include="..\DataBase\DataBase.csproj" />
<ProjectReference Include="..\DTO\DTO.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,83 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace ApiLeapHit.Controllers
{
public class ChatController : Controller
{
// GET: ChatController
public ActionResult Index()
{
return View();
}
// GET: ChatController/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: ChatController/Create
public ActionResult Create()
{
return View();
}
// POST: ChatController/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: ChatController/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: ChatController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: ChatController/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: ChatController/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
}
}

@ -0,0 +1,89 @@
using DataBase.DataManager;
using DataBase.Entity;
using DTO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.Net;
namespace ApiLeapHit.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class GameController : ControllerBase
{
private readonly DbDataManager _dataManager;
public GameController(DbDataManager dataManager)
{
_dataManager = dataManager;
}
[HttpGet("{id}")]
public async Task<ActionResult<DTOGame>> GetGame(int id)
{
var game = await _dataManager.GetGame(id);
if (game == null)
{
return NotFound();
}
var winner = await _dataManager.GetPlayer(game.winner);
var loser = await _dataManager.GetPlayer(game.loser);
var dtoGame = new DTOGame
{
gameId = game.gameId,
durationGame = game.durationGame,
nbMaxEchanges = game.nbMaxEchanges,
playerWinner = new DTOPlayer { playerId = winner.playerId, name = winner.name, nbBallTouchTotal = winner.nbBallTouchTotal, timePlayed = winner.timePlayed },
playerLoser = new DTOPlayer
{
playerId = loser.playerId,
name = loser.name,
nbBallTouchTotal = loser.nbBallTouchTotal,
timePlayed = loser.timePlayed
}
};
return Ok(dtoGame);
}
[HttpPost]
public async Task<ActionResult> AddGame([FromBody] DTOGame dtoGame)
{
var winner = await _dataManager.GetPlayer(dtoGame.playerWinner.playerId);
var loser = await _dataManager.GetPlayer(dtoGame.playerLoser.playerId);
var game = new Game
{
durationGame = dtoGame.durationGame,
nbMaxEchanges = dtoGame.nbMaxEchanges,
winner = winner.playerId,
loser = loser.playerId
};
await _dataManager.AddGame(game);
return Ok();
}
[HttpDelete("{id}")]
public async Task<ActionResult> RemoveGame(int id)
{
try
{
var result = await _dataManager.RemoveGame(id);
if (result)
{
return Ok();
}
return NotFound();
}
catch (Exception ex)
{
return StatusCode((int)HttpStatusCode.InternalServerError, FactoryMessage.MessageCreate("Une erreur est survenue lors de la récupération des champions"));
}
}
}
}

@ -0,0 +1,83 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace ApiLeapHit.Controllers
{
public class MessageController : Controller
{
// GET: MessageController
public ActionResult Index()
{
return View();
}
// GET: MessageController/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: MessageController/Create
public ActionResult Create()
{
return View();
}
// POST: MessageController/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: MessageController/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: MessageController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: MessageController/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: MessageController/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
}
}

@ -0,0 +1,83 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace ApiLeapHit.Controllers
{
public class PlayerController : Controller
{
// GET: PlayerController
public ActionResult Index()
{
return View();
}
// GET: PlayerController/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: PlayerController/Create
public ActionResult Create()
{
return View();
}
// POST: PlayerController/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: PlayerController/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: PlayerController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: PlayerController/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: PlayerController/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
}
}

@ -0,0 +1,3 @@
internal interface IDataManager
{
}

@ -0,0 +1,28 @@
using DataBase.DataManager;
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();
builder.Services.AddScoped<DbDataManager>();
//builder.Services.AddSingleton<IDataManager, StubData>();
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();

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

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

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

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

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class DTOChat
{
public int chatId { get; set; }
public DTOPlayer PlayerId1 { get; set; }
public DTOPlayer PlayerId2 { get; set; }
}
}

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class DTOGame
{
public int gameId { get; set; }
public int durationGame { get; set; }
public int nbMaxEchanges { get; set; }
public DTOPlayer playerWinner { get; set; }
public DTOPlayer playerLoser { get; set; }
}
}

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class DTOMessage
{
public int messageId { get; set; }
public string message { get; set; }
public DateTime timestamp { get; set; }
public DTOPlayer PlayerId { get; set; }
public DTOChat ChatId { get; set; }
}
}

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class DTOPlayer
{
public int playerId { get; set; }
public string name { get; set; }
public int nbBallTouchTotal { get; set; }
public int timePlayed { get; set; }
}
}

@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

@ -19,7 +19,7 @@ namespace DataBase.Context
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlite($"Data Source=PongDB.db");
optionsBuilder.UseSqlite($"Data Source=C:\\Users\\noanr\\source\\repos\\leap-hit-server\\code\\server\\DataBase\\PongDB.db");
}
}
}

@ -5,6 +5,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
</PropertyGroup>
<ItemGroup>

@ -15,10 +15,11 @@ namespace DataBase.DataManager
using (var context = new PongDbContext())
{
await context.Games.AddAsync(game);
await context.SaveChangesAsync();
}
}
public Task<bool> RemoveGame(int id)
public async Task<bool> RemoveGame(int id)
{
using (var context = new PongDbContext())
{
@ -26,9 +27,10 @@ namespace DataBase.DataManager
if (game != null)
{
var result = context.Games.Remove(game);
return Task.FromResult(result != null);
await context.SaveChangesAsync();
return result != null;
}
return Task.FromResult(false);
return false;
}
}

@ -11,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace DataBase.Migrations
{
[DbContext(typeof(PongDbContextWithStub))]
[Migration("20230216161314_initMigration")]
partial class initMigration
[Migration("20230222115848_mymigration")]
partial class mymigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -38,7 +38,7 @@ namespace DataBase.Migrations
b.HasIndex("player2");
b.ToTable("Chat");
b.ToTable("Chats");
b.HasData(
new
@ -73,7 +73,7 @@ namespace DataBase.Migrations
b.HasIndex("winner");
b.ToTable("Game");
b.ToTable("Games");
b.HasData(
new
@ -111,7 +111,7 @@ namespace DataBase.Migrations
b.HasIndex("player");
b.ToTable("Message");
b.ToTable("Messages");
b.HasData(
new
@ -150,7 +150,7 @@ namespace DataBase.Migrations
b.HasKey("playerId");
b.ToTable("Player");
b.ToTable("Players");
b.HasData(
new

@ -8,13 +8,13 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace DataBase.Migrations
{
/// <inheritdoc />
public partial class initMigration : Migration
public partial class mymigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Player",
name: "Players",
columns: table => new
{
playerId = table.Column<int>(type: "INTEGER", nullable: false)
@ -25,11 +25,11 @@ namespace DataBase.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Player", x => x.playerId);
table.PrimaryKey("PK_Players", x => x.playerId);
});
migrationBuilder.CreateTable(
name: "Chat",
name: "Chats",
columns: table => new
{
chatId = table.Column<int>(type: "INTEGER", nullable: false)
@ -39,23 +39,23 @@ namespace DataBase.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Chat", x => x.chatId);
table.PrimaryKey("PK_Chats", x => x.chatId);
table.ForeignKey(
name: "FK_Chat_Player_player1",
name: "FK_Chats_Players_player1",
column: x => x.player1,
principalTable: "Player",
principalTable: "Players",
principalColumn: "playerId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Chat_Player_player2",
name: "FK_Chats_Players_player2",
column: x => x.player2,
principalTable: "Player",
principalTable: "Players",
principalColumn: "playerId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Game",
name: "Games",
columns: table => new
{
gameId = table.Column<int>(type: "INTEGER", nullable: false)
@ -67,23 +67,23 @@ namespace DataBase.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Game", x => x.gameId);
table.PrimaryKey("PK_Games", x => x.gameId);
table.ForeignKey(
name: "FK_Game_Player_loser",
name: "FK_Games_Players_loser",
column: x => x.loser,
principalTable: "Player",
principalTable: "Players",
principalColumn: "playerId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Game_Player_winner",
name: "FK_Games_Players_winner",
column: x => x.winner,
principalTable: "Player",
principalTable: "Players",
principalColumn: "playerId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Message",
name: "Messages",
columns: table => new
{
messageId = table.Column<int>(type: "INTEGER", nullable: false)
@ -95,23 +95,23 @@ namespace DataBase.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Message", x => x.messageId);
table.PrimaryKey("PK_Messages", x => x.messageId);
table.ForeignKey(
name: "FK_Message_Chat_chat",
name: "FK_Messages_Chats_chat",
column: x => x.chat,
principalTable: "Chat",
principalTable: "Chats",
principalColumn: "chatId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Message_Player_player",
name: "FK_Messages_Players_player",
column: x => x.player,
principalTable: "Player",
principalTable: "Players",
principalColumn: "playerId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "Player",
table: "Players",
columns: new[] { "playerId", "name", "nbBallTouchTotal", "timePlayed" },
values: new object[,]
{
@ -120,17 +120,17 @@ namespace DataBase.Migrations
});
migrationBuilder.InsertData(
table: "Chat",
table: "Chats",
columns: new[] { "chatId", "player1", "player2" },
values: new object[] { 1, 1, 2 });
migrationBuilder.InsertData(
table: "Game",
table: "Games",
columns: new[] { "gameId", "durationGame", "loser", "nbMaxEchanges", "winner" },
values: new object[] { 1, 65, 2, 5, 1 });
migrationBuilder.InsertData(
table: "Message",
table: "Messages",
columns: new[] { "messageId", "chat", "message", "player", "timestamp" },
values: new object[,]
{
@ -139,33 +139,33 @@ namespace DataBase.Migrations
});
migrationBuilder.CreateIndex(
name: "IX_Chat_player1",
table: "Chat",
name: "IX_Chats_player1",
table: "Chats",
column: "player1");
migrationBuilder.CreateIndex(
name: "IX_Chat_player2",
table: "Chat",
name: "IX_Chats_player2",
table: "Chats",
column: "player2");
migrationBuilder.CreateIndex(
name: "IX_Game_loser",
table: "Game",
name: "IX_Games_loser",
table: "Games",
column: "loser");
migrationBuilder.CreateIndex(
name: "IX_Game_winner",
table: "Game",
name: "IX_Games_winner",
table: "Games",
column: "winner");
migrationBuilder.CreateIndex(
name: "IX_Message_chat",
table: "Message",
name: "IX_Messages_chat",
table: "Messages",
column: "chat");
migrationBuilder.CreateIndex(
name: "IX_Message_player",
table: "Message",
name: "IX_Messages_player",
table: "Messages",
column: "player");
}
@ -173,16 +173,16 @@ namespace DataBase.Migrations
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Game");
name: "Games");
migrationBuilder.DropTable(
name: "Message");
name: "Messages");
migrationBuilder.DropTable(
name: "Chat");
name: "Chats");
migrationBuilder.DropTable(
name: "Player");
name: "Players");
}
}
}

@ -35,7 +35,7 @@ namespace DataBase.Migrations
b.HasIndex("player2");
b.ToTable("Chat");
b.ToTable("Chats");
b.HasData(
new
@ -70,7 +70,7 @@ namespace DataBase.Migrations
b.HasIndex("winner");
b.ToTable("Game");
b.ToTable("Games");
b.HasData(
new
@ -108,7 +108,7 @@ namespace DataBase.Migrations
b.HasIndex("player");
b.ToTable("Message");
b.ToTable("Messages");
b.HasData(
new
@ -147,7 +147,7 @@ namespace DataBase.Migrations
b.HasKey("playerId");
b.ToTable("Player");
b.ToTable("Players");
b.HasData(
new

Binary file not shown.

@ -1,2 +1 @@

Console.WriteLine("Hello world !");
Console.WriteLine("Hello world !");

@ -7,7 +7,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "Server\Server.csp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{1D3CF318-8453-4D0C-B11D-2A6B7E44AA47}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataBase", "DataBase\DataBase.csproj", "{240EEEA0-7EFB-4919-A5C9-584DC6505C58}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataBase", "DataBase\DataBase.csproj", "{240EEEA0-7EFB-4919-A5C9-584DC6505C58}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiLeapHit", "ApiLeapHit\ApiLeapHit.csproj", "{693F37D1-B10C-45B2-A180-24D26B5A4841}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTO", "DTO\DTO.csproj", "{BDA37278-912D-47E9-BD69-47A924A69004}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -27,6 +31,14 @@ Global
{240EEEA0-7EFB-4919-A5C9-584DC6505C58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{240EEEA0-7EFB-4919-A5C9-584DC6505C58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{240EEEA0-7EFB-4919-A5C9-584DC6505C58}.Release|Any CPU.Build.0 = Release|Any CPU
{693F37D1-B10C-45B2-A180-24D26B5A4841}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{693F37D1-B10C-45B2-A180-24D26B5A4841}.Debug|Any CPU.Build.0 = Debug|Any CPU
{693F37D1-B10C-45B2-A180-24D26B5A4841}.Release|Any CPU.ActiveCfg = Release|Any CPU
{693F37D1-B10C-45B2-A180-24D26B5A4841}.Release|Any CPU.Build.0 = Release|Any CPU
{BDA37278-912D-47E9-BD69-47A924A69004}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BDA37278-912D-47E9-BD69-47A924A69004}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BDA37278-912D-47E9-BD69-47A924A69004}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BDA37278-912D-47E9-BD69-47A924A69004}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save