Merge pull request 'Api' (#2) from Api into master
continuous-integration/drone/push Build is failing Details

Reviewed-on: #2
Server
Noan RANDON 2 years ago
commit 4efea53f29

@ -1,12 +1,30 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /app
# Première étape de la construction
WORKDIR /app/server
RUN dotnet new console RUN dotnet new console
COPY server/Server/Program.cs Program.cs COPY Server/Program.cs Program.cs
RUN dotnet publish -c Release -o out RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/runtime:6.0 # Deuxième étape de la construction
WORKDIR /app/api
COPY ApiLeapHit/ApiLeapHit.csproj .
COPY DTO/DTO.csproj DTO/
COPY DataBase/DataBase.csproj DataBase/
RUN dotnet restore
COPY . .
WORKDIR /app/api/ApiLeapHit
RUN dotnet build -c Release -o /app/build
# Troisième étape de la construction
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS final
WORKDIR /app WORKDIR /app
COPY --from=build /app/out . COPY --from=build /app/server/out .
ENTRYPOINT ["dotnet", "app.dll"] COPY --from=build /app/api/build .
# Configuration de l'application
EXPOSE 80
EXPOSE 443
EXPOSE 3131 EXPOSE 3131
ENTRYPOINT ["dotnet", "ApiLeapHit.dll"]

@ -84,6 +84,13 @@ namespace ApiLeapHit.Controllers
return NotFound(new ApiResponse<object>("Le message n'a pas été trouvé.")); return NotFound(new ApiResponse<object>("Le message n'a pas été trouvé."));
} }
var response = new ApiResponse<DTOMessage>("Joueur ajouté avec succès.");
response.Links.Add(new ApiLink(
Url.Action("GetPlayer", "Player", new { id = player.playerId }),
"self",
"GET"
));
_logger.LogInformation($"Le message avec l'identifiant {id} a été reçu avec succès."); _logger.LogInformation($"Le message avec l'identifiant {id} a été reçu avec succès.");
return Ok(new ApiResponse<DTOMessage>("Message reçu avec succès.", message.ToDto())); return Ok(new ApiResponse<DTOMessage>("Message reçu avec succès.", message.ToDto()));
} }

@ -23,7 +23,7 @@ namespace ApiLeapHit.Controllers
} }
[HttpGet("{id}")] [HttpGet("{id}")]
public async Task<ActionResult<DTOPlayer>> GetPlayer(int id) public async Task<ActionResult<ApiResponse<DTOPlayer>>> GetPlayer(int id)
{ {
try try
{ {
@ -66,24 +66,25 @@ namespace ApiLeapHit.Controllers
{ {
try try
{ {
var player = dtoPlayer.ToPlayer(); var player = dtoPlayer.ToPlayer();
await _dataManager.AddPlayer(player); await _dataManager.AddPlayer(player);
// Ajout des liens HATEOAS // Ajout des liens HATEOAS
var response = new ApiResponse<object>("Joueur ajouté avec succès."); var response = new ApiResponse<DTOPlayer>("Joueur ajouté avec succès.");
response.Links.Add(new ApiLink( response.Links.Add(new ApiLink(
Url.Action("GetPlayer", "Player", new { id = player.playerId }), Url.Action("GetPlayer", "Player", new { id = player.playerId }),
"self", "self",
"GET" "GET"
)); ));
var response2 = new ApiResponse<object>("Joueur ajouté avec succès.");
return Ok(response); return Ok(response);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Une erreur est survenue lors de l'ajout du joueur."); _logger.LogError(ex, "Une erreur est survenue lors de l'ajout du joueur.");
return StatusCode((int)HttpStatusCode.InternalServerError, new ApiResponse<object>("Une erreur est survenue lors de l'ajout du joueur.")); return StatusCode((int)HttpStatusCode.InternalServerError, new ApiResponse<object>($"Une erreur est survenue lors de l'ajout du joueur. {ex.Message}"));
} }
} }
@ -103,35 +104,35 @@ namespace ApiLeapHit.Controllers
var response = new ApiResponse<IEnumerable<DTOPlayer>>($"La récupération des players a réussi. Nombre de players : {dtoPlayers.Count}", dtoPlayers); var response = new ApiResponse<IEnumerable<DTOPlayer>>($"La récupération des players a réussi. Nombre de players : {dtoPlayers.Count}", dtoPlayers);
// Ajout des liens HATEOAS // Ajout des liens HATEOAS
response.Links.Add(new ApiLink( //response.Links.Add(new ApiLink(
Url.Action("GetPlayers", "Player"), // Url.Action("GetPlayers", "Player"),
"self", // "self",
"GET" // "GET"
)); //));
response.Links.Add(new ApiLink( //response.Links.Add(new ApiLink(
Url.Action("AddPlayer", "Player"), // Url.Action("AddPlayer", "Player"),
"create", // "create",
"POST" // "POST"
)); //));
foreach (var player in dtoPlayers) //foreach (var player in dtoPlayers)
{ //{
response.Links.Add(new ApiLink( // response.Links.Add(new ApiLink(
Url.Action("GetPlayer", "Player", new { id = player.playerId }), // Url.Action("GetPlayer", "Player", new { id = player.playerId }),
"get_player", // "get_player",
"GET" // "GET"
)); // ));
response.Links.Add(new ApiLink( // response.Links.Add(new ApiLink(
Url.Action("RemovePlayer", "Player", new { id = player.playerId }), // Url.Action("RemovePlayer", "Player", new { id = player.playerId }),
"delete_player", // "delete_player",
"DELETE" // "DELETE"
)); // ));
response.Links.Add(new ApiLink( // response.Links.Add(new ApiLink(
Url.Action("Put", "Player", new { id = player.playerId }), // Url.Action("Put", "Player", new { id = player.playerId }),
"update_player", // "update_player",
"PUT" // "PUT"
)); // ));
} //}
return Ok(response); return Ok(response);
} }

@ -13,7 +13,9 @@ namespace ApiLeapHit.Mapper
durationGame = game.durationGame, durationGame = game.durationGame,
nbMaxEchanges = game.nbMaxEchanges, nbMaxEchanges = game.nbMaxEchanges,
playerWinner = game.winner, playerWinner = game.winner,
playerLoser = game.loser playerLoser = game.loser,
scoreLoser = game.loser,
scoreWinner = game.winner
}; };
return dtoGame; return dtoGame;
} }
@ -25,7 +27,9 @@ namespace ApiLeapHit.Mapper
durationGame = dtoGame.durationGame, durationGame = dtoGame.durationGame,
nbMaxEchanges = dtoGame.nbMaxEchanges, nbMaxEchanges = dtoGame.nbMaxEchanges,
winner = dtoGame.playerWinner, winner = dtoGame.playerWinner,
loser = dtoGame.playerLoser loser = dtoGame.playerLoser,
scoreLoser = dtoGame.scoreLoser,
scoreWinner = dtoGame.scoreWinner
}; };
} }
} }

@ -1,19 +0,0 @@
using DataBase.Entity;
using DTO;
namespace ApiLeapHit.Mapper
{
public static class GameWithIdPlayerMapper
{
public static Game ToGame(this DTOGameWithIdPlayer dtoGame, Player winner, Player loser)
{
return new Game
{
durationGame = dtoGame.durationGame,
nbMaxEchanges = dtoGame.nbMaxEchanges,
winner = winner.playerId,
loser = loser.playerId
};
}
}
}

@ -13,5 +13,7 @@ namespace DTO
public int nbMaxEchanges { get; set; } public int nbMaxEchanges { get; set; }
public int playerWinner { get; set; } public int playerWinner { get; set; }
public int playerLoser { get; set; } public int playerLoser { get; set; }
public int scoreWinner { get; set; }
public int scoreLoser { get; set; }
} }
} }

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -10,7 +11,8 @@ namespace DTO.Factory
{ {
public string Message { get; set; } public string Message { get; set; }
public T Data { get; set; } public T Data { get; set; }
public List<ApiLink> Links { get; set; } = new List<ApiLink>(); public List<ApiLink> Links { get; set; }
private List<ApiLink> links = new();
public ApiResponse(string message, T data = default) public ApiResponse(string message, T data = default)

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

@ -17,7 +17,7 @@ namespace DataBase.DataManager
using (var context = new PongDbContext()) using (var context = new PongDbContext())
{ {
await context.Players.AddAsync(player); await context.Players.AddAsync(player);
await context.SaveChangesAsync(); context.SaveChangesAsync();
} }
} }

@ -11,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace DataBase.Migrations namespace DataBase.Migrations
{ {
[DbContext(typeof(PongDbContextWithStub))] [DbContext(typeof(PongDbContextWithStub))]
[Migration("20230222115848_mymigration")] [Migration("20230228121953_Migrations")]
partial class mymigration partial class Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -64,6 +64,12 @@ namespace DataBase.Migrations
b.Property<int>("nbMaxEchanges") b.Property<int>("nbMaxEchanges")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("scoreLoser")
.HasColumnType("INTEGER");
b.Property<int>("scoreWinner")
.HasColumnType("INTEGER");
b.Property<int>("winner") b.Property<int>("winner")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
@ -82,6 +88,8 @@ namespace DataBase.Migrations
durationGame = 65, durationGame = 65,
loser = 2, loser = 2,
nbMaxEchanges = 5, nbMaxEchanges = 5,
scoreLoser = 2,
scoreWinner = 6,
winner = 1 winner = 1
}); });
}); });

@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace DataBase.Migrations namespace DataBase.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class mymigration : Migration public partial class Migrations : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
@ -63,7 +63,9 @@ namespace DataBase.Migrations
durationGame = table.Column<int>(type: "INTEGER", nullable: false), durationGame = table.Column<int>(type: "INTEGER", nullable: false),
nbMaxEchanges = table.Column<int>(type: "INTEGER", nullable: false), nbMaxEchanges = table.Column<int>(type: "INTEGER", nullable: false),
winner = table.Column<int>(type: "INTEGER", nullable: false), winner = table.Column<int>(type: "INTEGER", nullable: false),
loser = table.Column<int>(type: "INTEGER", nullable: false) loser = table.Column<int>(type: "INTEGER", nullable: false),
scoreWinner = table.Column<int>(type: "INTEGER", nullable: false),
scoreLoser = table.Column<int>(type: "INTEGER", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
@ -126,8 +128,8 @@ namespace DataBase.Migrations
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "Games", table: "Games",
columns: new[] { "gameId", "durationGame", "loser", "nbMaxEchanges", "winner" }, columns: new[] { "gameId", "durationGame", "loser", "nbMaxEchanges", "scoreLoser", "scoreWinner", "winner" },
values: new object[] { 1, 65, 2, 5, 1 }); values: new object[] { 1, 65, 2, 5, 2, 6, 1 });
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "Messages", table: "Messages",

@ -61,6 +61,12 @@ namespace DataBase.Migrations
b.Property<int>("nbMaxEchanges") b.Property<int>("nbMaxEchanges")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("scoreLoser")
.HasColumnType("INTEGER");
b.Property<int>("scoreWinner")
.HasColumnType("INTEGER");
b.Property<int>("winner") b.Property<int>("winner")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
@ -79,6 +85,8 @@ namespace DataBase.Migrations
durationGame = 65, durationGame = 65,
loser = 2, loser = 2,
nbMaxEchanges = 5, nbMaxEchanges = 5,
scoreLoser = 2,
scoreWinner = 6,
winner = 1 winner = 1
}); });
}); });

Binary file not shown.
Loading…
Cancel
Save