diff --git a/code/server/ApiLeapHit/ApiLeapHit.csproj b/code/server/ApiLeapHit/ApiLeapHit.csproj new file mode 100644 index 0000000..56b0e8b --- /dev/null +++ b/code/server/ApiLeapHit/ApiLeapHit.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + diff --git a/code/server/ApiLeapHit/Controllers/ChatController.cs b/code/server/ApiLeapHit/Controllers/ChatController.cs new file mode 100644 index 0000000..3bc0b15 --- /dev/null +++ b/code/server/ApiLeapHit/Controllers/ChatController.cs @@ -0,0 +1,203 @@ +using ApiLeapHit.Mapper; +using DataBase.DataManager; +using DataBase.Entity; +using DTO; +using DTO.Factory; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace ApiLeapHit.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ChatController : Controller + { + + private readonly DbDataManager _dataManager; + private readonly ILogger _logger; + + public ChatController(DbDataManager dataManager, ILogger logger) + { + _dataManager = dataManager; + _logger = logger; + } + + [HttpPost] + public async Task AddChat([FromBody] DTOChat dtoChat) + { + try + { + var player1 = await _dataManager.GetPlayer(dtoChat.PlayerId1); + var player2 = await _dataManager.GetPlayer(dtoChat.PlayerId2); + + await _dataManager.AddChat(dtoChat.ToChat()); + + var success_message = $"Le chat entre {player1.name} et {player2.name} a été ajouté avec succès."; + _logger.LogInformation(success_message); + return Ok(new ApiResponse(success_message)); + } + catch (Exception ex) + { + var error_message = $"Une erreur est survenue lors de l'ajout du chat : {ex.Message}"; + _logger.LogError(ex, error_message); + return StatusCode(500, new ApiResponse(error_message)); + } + } + + [HttpGet] + public async Task>> GetChats() + { + try + { + var chats = await _dataManager.GetChats(); + if (chats == null) + { + var message = "Aucun chat n'a été trouvé."; + _logger.LogWarning(message); + return NotFound(new ApiResponse(message)); + } + + var dtoChats = new List(); + foreach (var chat in chats) + { + //var player1 = await _dataManager.GetPlayer(chat.player1); + //var player2 = await _dataManager.GetPlayer(chat.player2); + + var dtoChat = chat.ToDto(); + + dtoChats.Add(dtoChat); + } + + var success_message = $"La récupération des chats a réussi. Nombre de chats : {dtoChats.Count}"; + _logger.LogInformation(success_message); + return Ok(new ApiResponse>(success_message,dtoChats)); + } + catch (Exception ex) + { + var error_message = $"Une erreur est survenue lors de la récupération des chats : {ex.Message}"; + _logger.LogError(ex, error_message); + return StatusCode(500, new ApiResponse(error_message)); + } + } + + [HttpGet("{id}")] + public async Task>> GetChatById(int id) + { + try + { + var chat = await _dataManager.GetChat(id); + if (chat == null) + { + var message = "Aucun chat n'a été trouvé."; + _logger.LogWarning(message); + return NotFound(new ApiResponse(message)); + } + + //var player1 = await _dataManager.GetPlayer(chat.player1); + //var player2 = await _dataManager.GetPlayer(chat.player2); + + var dtoChat = chat.ToDto(); + + var success_message = $"La récupération du chat a réussi pour le chat {id}."; + _logger.LogInformation(success_message); + return Ok(new ApiResponse(success_message, dtoChat)); + } + catch (Exception ex) + { + var error_message = $"Une erreur est survenue lors de la récupération du chat {id} : {ex.Message}"; + _logger.LogError(ex, error_message); + return StatusCode(500, new ApiResponse(error_message)); + } + } + + [HttpGet("byPlayer/{id}")] + public async Task>> GetChatsByIdPlayer(int id) + { + try + { + var chats = await _dataManager.GetChatsByIdPlayer(id); + if (chats == null || chats.Count() == 0) + { + var message = "Aucun chat n'a été trouvé pour l'id : {id}."; + _logger.LogWarning(message); + return NotFound(new ApiResponse(message)); + } + + var dtoChats = new List(); + foreach (var chat in chats) + { + dtoChats.Add(chat.ToDto()); + } + + var success_message = $"La récupération des chats a réussi pour l'id : {id}. Nombre de chats : {dtoChats.Count}"; + _logger.LogInformation(success_message); + return Ok(new ApiResponse>(success_message, dtoChats)); + } + catch (Exception ex) + { + var error_message = $"Une erreur est survenue lors de la récupération des chats de l'utilisateur {id} : {ex.Message}"; + _logger.LogError(ex, error_message); + return StatusCode(500, new ApiResponse(error_message)); + } + } + + [HttpGet("players/{idPlayer1}/{idPlayer2}")] + public async Task>> GetChatsByIdPlayers(int idPlayer1, int idPlayer2) + { + try + { + var chats = await _dataManager.GetChatsByIdPlayers(idPlayer1,idPlayer2); + if (chats == null ||chats.Count() == 0) + { + var message = $"Aucun chat n'a été trouvé pour les joueurs {idPlayer1} et {idPlayer2}."; + _logger.LogWarning(message); + return NotFound(new ApiResponse(message)); + } + + var dtoChats = new List(); + foreach (var chat in chats) + { + //var player1 = await _dataManager.GetPlayer(chat.player1); + //var player2 = await _dataManager.GetPlayer(chat.player2); + + dtoChats.Add(chat.ToDto()); + } + + var success_message = $"La récupération des chats a réussi pour les joueurs {idPlayer1} et {idPlayer2}. Nombre de chats : {dtoChats.Count}"; + _logger.LogInformation(success_message); + return Ok(new ApiResponse>(success_message, dtoChats)); + } + catch (Exception ex) + { + var error_message = $"Une erreur est survenue lors de la récupération des chats pour les joueurs {idPlayer1} et {idPlayer2} : {ex.Message}"; + _logger.LogError(ex, error_message); + return StatusCode(500, new ApiResponse(error_message)); + } + } + + [HttpDelete("{id}")] + public async Task RemoveChat(int id) + { + try + { + var result = await _dataManager.RemoveChat(id); + if (result) + { + var success_message = $"Le chat avec l'identifiant {id} a été supprimé avec succès."; + _logger.LogInformation(success_message); + return Ok(new ApiResponse(success_message)); + } + + var warning_message = $"Le chat avec l'identifiant {id} n'a pas été trouvé."; + _logger.LogWarning(warning_message); + return NotFound(new ApiResponse(warning_message)); + } + catch (Exception ex) + { + var error_message = $"Une erreur est survenue lors de la suppression du chat : {ex.Message}"; + _logger.LogError(ex, error_message); + return StatusCode(500, new ApiResponse(error_message)); + } + } + } +} diff --git a/code/server/ApiLeapHit/Controllers/GameController.cs b/code/server/ApiLeapHit/Controllers/GameController.cs new file mode 100644 index 0000000..9dc5947 --- /dev/null +++ b/code/server/ApiLeapHit/Controllers/GameController.cs @@ -0,0 +1,194 @@ +using ApiLeapHit.Mapper; +using DataBase.DataManager; +using DataBase.Entity; +using DTO; +using DTO.Factory; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System.Diagnostics; +using System.Net; +using System.Text; + +namespace ApiLeapHit.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class GameController : ControllerBase + { + private readonly DbDataManager _dataManager; + + private readonly ILogger _logger; + + public GameController(DbDataManager dataManager, ILogger logger) + { + _dataManager = dataManager; + _logger = logger; + } + + [HttpGet("{id}")] + public async Task> GetGame(int id) + { + try + { + _logger.LogInformation("Récupération de la game avec l'identifiant {id}", id); + + var game = await _dataManager.GetGame(id); + if (game == null) + { + var message = $"La game avec l'identifiant {id} n'existe pas"; + _logger.LogWarning(message); + return NotFound(new ApiResponse(message)); + } + + _logger.LogInformation("Récupération des joueurs pour la game avec l'identifiant {id}", id); + + return Ok(new ApiResponse("Récupération de la game réussie.", game.ToDto())); + } + catch (Exception ex) + { + _logger.LogError(ex, $"Une erreur est survenue lors de la récupération des données pour la game avec l'identifiant {id}"); + return StatusCode(500, new ApiResponse($"Une erreur est survenue lors de la récupération des données : {ex.Message}")); + } + } + + [HttpGet] + public async Task>> GetGames() + { + try + { + _logger.LogInformation("Récupération de toutes les games."); + + var games = await _dataManager.GetGames(); + if (games == null) + { + var message = "Aucune game n'a été trouvée."; + _logger.LogWarning(message); + return NotFound(new ApiResponse(message)); + } + + var dtoGames = new List(); + + foreach (var game in games) + { + var winner = await _dataManager.GetPlayer(game.winner); + var loser = await _dataManager.GetPlayer(game.loser); + + //ce cas n'est jamais censé arrivé + if (winner == null || loser == null) + { + _logger.LogError($"Le joueur gagnant ou le joueur perdant n'existe pas pour le jeu avec l'identifiant {game.gameId}."); + continue; + } + + dtoGames.Add(game.ToDto()); + } + + _logger.LogInformation("{Count} games ont été récupérées.", dtoGames.Count); + return Ok(new ApiResponse>("La récupération des games a réussi.", dtoGames)); + } + catch (Exception ex) + { + var message = "Une erreur est survenue lors de la récupération des données."; + _logger.LogError(ex, message); + return StatusCode(500, new ApiResponse($"{message} {ex.Message}")); + } + } + + [HttpGet("byPlayer/{id}")] + public async Task>> GetGameByIdPlayer(int id) + { + try + { + var games = await _dataManager.GetGameById(id); + + if (games == null || games.Count == 0) + { + var message = $"Aucune game trouvée pour le joueur avec l'id {id}."; + _logger.LogInformation(message); + return NotFound(new ApiResponse(message)); + } + + var dtoGames = new List(); + + foreach (var game in games) + { + var winner = await _dataManager.GetPlayer(game.winner); + var loser = await _dataManager.GetPlayer(game.loser); + + //ce cas n'est jamais censé arrivé + if (winner == null || loser == null) + { + _logger.LogError($"Le joueur gagnant ou le joueur perdant n'existe pas pour le jeu avec l'identifiant {game.gameId}."); + continue; + } + dtoGames.Add(game.ToDto()); + } + + var successMessage = $"Récupération réussie des games pour le joueur avec l'id {id}."; + _logger.LogInformation(successMessage); + return Ok(new ApiResponse>(successMessage, dtoGames)); + } + catch (Exception ex) + { + var errorMessage = $"Une erreur est survenue lors de la récupération des games pour le joueur avec l'id {id}."; + _logger.LogError(errorMessage + " Error message: " + ex.Message); + return StatusCode(500, new ApiResponse(errorMessage)); + } + } + + [HttpPost] + public async Task AddGame([FromBody] DTOGame dtoGame) + { + try + { + var winner = await _dataManager.GetPlayer(dtoGame.playerWinner); + var loser = await _dataManager.GetPlayer(dtoGame.playerLoser); + + //if (winner == null || loser == null) + //{ + // var errorMessage = "Le joueur gagnant ou le joueur perdant n'existe pas pour la partie avec l'identifiant " + dtoGame.gameId + "."; + // _logger.LogError(errorMessage); + // return NotFound(new ApiResponse(errorMessage)); + //} + + var game = dtoGame.ToGame(); + await _dataManager.AddGame(game); + + var successMessage = "La partie avec l'identifiant " + game.gameId + " a été ajoutée avec succès."; + _logger.LogInformation(successMessage); + return Ok(new ApiResponse(successMessage, game)); + } + catch (Exception ex) + { + var errorMessage = "Une erreur est survenue lors de l'ajout de la partie : " + ex.Message; + _logger.LogError(errorMessage); + return StatusCode(500, new ApiResponse(errorMessage)); + } + } + + [HttpDelete("{id}")] + public async Task RemoveGame(int id) + { + try + { + var result = await _dataManager.RemoveGame(id); + if (result) + { + var successMessage = $"La game avec l'identifiant {id} a été supprimée avec succès."; + _logger.LogInformation(successMessage); + return Ok(new ApiResponse(successMessage)); + } + + var notFoundMessage = $"La game avec l'identifiant {id} n'existe pas."; + _logger.LogInformation(notFoundMessage); + return NotFound(new ApiResponse(notFoundMessage)); + } + catch (Exception ex) + { + var errorMessage = $"Une erreur est survenue lors de la suppression de la game avec l'identifiant {id} : {ex.Message}"; + _logger.LogError(errorMessage); + return StatusCode(500, new ApiResponse(errorMessage)); + } + } + } +} diff --git a/code/server/ApiLeapHit/Controllers/MessageController.cs b/code/server/ApiLeapHit/Controllers/MessageController.cs new file mode 100644 index 0000000..097fe5b --- /dev/null +++ b/code/server/ApiLeapHit/Controllers/MessageController.cs @@ -0,0 +1,123 @@ +using ApiLeapHit.Mapper; +using DataBase.DataManager; +using DataBase.Entity; +using DTO; +using DTO.Factory; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System.Net; + +namespace ApiLeapHit.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class MessageController : Controller + { + + private readonly DbDataManager _dataManager; + private readonly ILogger _logger; + + public MessageController(DbDataManager dataManager, ILogger logger) + { + _dataManager = dataManager; + _logger = logger; + } + + [HttpPost] + public async Task SendMessage([FromBody] DTOMessage dtoMessage) + { + try + { + var player = await _dataManager.GetPlayer(dtoMessage.PlayerId); + if (player == null) + { + _logger.LogWarning($"Le joueur avec l'identifiant {dtoMessage.PlayerId} n'existe pas."); + return NotFound(new ApiResponse($"Le joueur avec l'identifiant {dtoMessage.PlayerId} n'existe pas.")); + } + + await _dataManager.SendMessage(dtoMessage.ToMessage()); + + _logger.LogInformation($"Le message avec l'identifiant {dtoMessage.messageId} a été envoyé avec succès."); + return Ok(new ApiResponse($"Le message avec l'identifiant {dtoMessage.messageId} a été envoyé avec succès.")); + } + catch (Exception ex) + { + _logger.LogError($"Une erreur est survenue lors de l'envoi du message : {ex.Message}"); + return StatusCode(500, new ApiResponse($"Une erreur est survenue lors de l'envoi du message : {ex.Message}")); + } + } + + [HttpDelete("{id}")] + public async Task RemoveMessage(int id) + { + try + { + var result = await _dataManager.RemoveMessage(id); + if (result) + { + _logger.LogInformation($"Le message avec l'identifiant {id} a été supprimé avec succès."); + return Ok(new ApiResponse($"Le message avec l'identifiant {id} a été supprimé avec succès.")); + } + else + { + _logger.LogWarning($"Le message avec l'identifiant {id} n'existe pas."); + return NotFound(new ApiResponse($"Le message avec l'identifiant {id} n'existe pas.")); + } + } + catch (Exception ex) + { + _logger.LogError($"Une erreur est survenue lors de la suppression du message avec l'identifiant {id} : {ex.Message}"); + return StatusCode(500, new ApiResponse($"Une erreur est survenue lors de la suppression du message avec l'identifiant {id} : {ex.Message}")); + } + } + + [HttpGet("{id}")] + public async Task> ReceiveMessage(int id) + { + try + { + var message = await _dataManager.ReceiveMessage(id); + + if (message == null) + { + _logger.LogWarning($"Aucun message avec l'idée {id} n'a été trouvé."); + return NotFound(new ApiResponse("Le message n'a pas été trouvé.")); + } + + _logger.LogInformation($"Le message avec l'identifiant {id} a été reçu avec succès."); + return Ok(new ApiResponse("Message reçu avec succès.", message.ToDto())); + } + catch (Exception ex) + { + _logger.LogError(ex, $"Une erreur est survenue lors de la récupération du message avec l'id {id}."); + return StatusCode((int)HttpStatusCode.InternalServerError, new ApiResponse($"Une erreur est survenue lors de la récupération du message. : {ex.Message}")); + } + } + + [HttpGet] + public async Task> ReceiveAllMessages() + { + try + { + var messages = await _dataManager.ReceiveAllMessages(); + + if (messages == null || messages.Count() == 0) + { + _logger.LogWarning($"Aucun message n'a été trouvé."); + return NotFound(new ApiResponse("Aucun message n'a pas été trouvé.")); + } + + var dtosMessages = messages.Select(message => message.ToDto()).ToList(); + + _logger.LogInformation($"Les messages ont été reçus avec succès."); + return Ok(new ApiResponse>("Messages reçus avec succès.", dtosMessages)); + } + catch (Exception ex) + { + _logger.LogError(ex, $"Une erreur est survenue lors de la récupération des messages."); + return StatusCode((int)HttpStatusCode.InternalServerError, new ApiResponse($"Une erreur est survenue lors de la récupération des messages. : {ex.Message}")); + } + } + + } +} diff --git a/code/server/ApiLeapHit/Controllers/PlayerController.cs b/code/server/ApiLeapHit/Controllers/PlayerController.cs new file mode 100644 index 0000000..346902b --- /dev/null +++ b/code/server/ApiLeapHit/Controllers/PlayerController.cs @@ -0,0 +1,215 @@ +using ApiLeapHit.Mapper; +using DataBase.DataManager; +using DataBase.Entity; +using DTO; +using DTO.Factory; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System.Net; + +namespace ApiLeapHit.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class PlayerController : ControllerBase + { + private readonly DbDataManager _dataManager; + private readonly ILogger _logger; + + public PlayerController(DbDataManager dataManager, ILogger logger) + { + _dataManager = dataManager; + _logger = logger; + } + + [HttpGet("{id}")] + public async Task> GetPlayer(int id) + { + try + { + var player = await _dataManager.GetPlayer(id); + if (player == null) + { + return NotFound(new ApiResponse("Joueur non trouvé.")); + } + + var response = new ApiResponse($"Le joueur avec l'id {id} a été récupéré avec succès.", player.ToDto()); + + // Ajout des liens HATEOAS + response.Links.Add(new ApiLink( + Url.Action("GetPlayer", "Player", new { id }), + "self", + "GET" + )); + response.Links.Add(new ApiLink( + Url.Action("RemovePlayer", "Player", new { id }), + "delete", + "DELETE" + )); + response.Links.Add(new ApiLink( + Url.Action("Put", "Player", new { id }), + "update", + "PUT" + )); + + return Ok(response); + } + catch (Exception ex) + { + _logger.LogError(ex, $"Une erreur est survenue lors de la récupération du joueur avec l'id {id}."); + return StatusCode((int)HttpStatusCode.InternalServerError, new ApiResponse("Une erreur est survenue lors de la récupération du joueur.")); + } + } + + [HttpPost] + public async Task AddPlayer([FromBody] DTOPlayer dtoPlayer) + { + try + { + var player = dtoPlayer.ToPlayer(); + + await _dataManager.AddPlayer(player); + + // Ajout des liens HATEOAS + var response = new ApiResponse("Joueur ajouté avec succès."); + response.Links.Add(new ApiLink( + Url.Action("GetPlayer", "Player", new { id = player.playerId }), + "self", + "GET" + )); + + return Ok(response); + } + catch (Exception ex) + { + _logger.LogError(ex, "Une erreur est survenue lors de l'ajout du joueur."); + return StatusCode((int)HttpStatusCode.InternalServerError, new ApiResponse("Une erreur est survenue lors de l'ajout du joueur.")); + } + } + + [HttpGet] + public async Task>> GetPlayers() + { + try + { + var players = await _dataManager.GetPlayers(); + if (players == null || players.Count() == 0) + { + return NotFound(new ApiResponse>("Aucun joueur trouvé.")); + } + + var dtoPlayers = players.Select(p => p.ToDto()).ToList(); + + var response = new ApiResponse>($"La récupération des players a réussi. Nombre de players : {dtoPlayers.Count}", dtoPlayers); + + // Ajout des liens HATEOAS + response.Links.Add(new ApiLink( + Url.Action("GetPlayers", "Player"), + "self", + "GET" + )); + response.Links.Add(new ApiLink( + Url.Action("AddPlayer", "Player"), + "create", + "POST" + )); + + foreach (var player in dtoPlayers) + { + response.Links.Add(new ApiLink( + Url.Action("GetPlayer", "Player", new { id = player.playerId }), + "get_player", + "GET" + )); + response.Links.Add(new ApiLink( + Url.Action("RemovePlayer", "Player", new { id = player.playerId }), + "delete_player", + "DELETE" + )); + response.Links.Add(new ApiLink( + Url.Action("Put", "Player", new { id = player.playerId }), + "update_player", + "PUT" + )); + } + + return Ok(response); + } + catch (Exception ex) + { + _logger.LogError(ex, "Une erreur est survenue lors de la récupération des joueurs."); + return StatusCode((int)HttpStatusCode.InternalServerError, new ApiResponse("Une erreur est survenue lors de la récupération des joueurs.")); + } + } + + [HttpDelete("{id}")] + public async Task RemovePlayer(int id) + { + try + { + var result = await _dataManager.RemovePlayer(id); + if (result) + { + // Ajout des liens HATEOAS + var response = new ApiResponse("Joueur supprimé avec succès."); + response.Links.Add(new ApiLink( + Url.Action("GetPlayers", "Player"), + "self", + "GET" + )); + + return Ok(response); + } + return NotFound(new ApiResponse("Joueur non trouvé.")); + } + catch (Exception ex) + { + _logger.LogError(ex, $"Une erreur est survenue lors de la suppression du joueur avec l'id {id}."); + return StatusCode((int)HttpStatusCode.InternalServerError, new ApiResponse("Une erreur est survenue lors de la suppression du joueur.")); + } + } + [HttpPut("{id}")] + public async Task Put(int id, [FromBody] DTOPlayer dtoPlayer) + { + try + { + if (!ModelState.IsValid) + { + return BadRequest(new ApiResponse("Les données du joueur sont invalides.")); + } + + var player = dtoPlayer.ToPlayer(); + + var playerTest = await _dataManager.GetPlayer(id); + if (playerTest == null) + { + return NotFound(new ApiResponse("Joueur non trouvé.")); + } + + await _dataManager.UpdatePlayer(id, player.name); + + // Ajout des liens HATEOAS + var response = new ApiResponse("Joueur mis à jour avec succès."); + response.Links.Add(new ApiLink( + Url.Action("GetPlayer", "Player", new { id }), + "self", + "GET" + )); + response.Links.Add(new ApiLink( + Url.Action ("RemovePlayer", "Player", new { id }), + "delete", + "DELETE" + )); + + + return Ok(response); + } + catch (Exception ex) + { + _logger.LogError(ex, $"Une erreur est survenue lors de la modification du joueur avec l'id {id}."); + return StatusCode((int)HttpStatusCode.InternalServerError, new ApiResponse("Une erreur est survenue lors de la modification du joueur.")); + } + + } + } +} diff --git a/code/server/ApiLeapHit/IDataManager.cs b/code/server/ApiLeapHit/IDataManager.cs new file mode 100644 index 0000000..827c6d4 --- /dev/null +++ b/code/server/ApiLeapHit/IDataManager.cs @@ -0,0 +1,3 @@ +internal interface IDataManager +{ +} \ No newline at end of file diff --git a/code/server/ApiLeapHit/Mapper/ChatMapper.cs b/code/server/ApiLeapHit/Mapper/ChatMapper.cs new file mode 100644 index 0000000..220daa4 --- /dev/null +++ b/code/server/ApiLeapHit/Mapper/ChatMapper.cs @@ -0,0 +1,29 @@ +using DataBase.Entity; +using DTO; + +namespace ApiLeapHit.Mapper +{ + public static class ChatMapper + { + public static DTOChat ToDto(this Chat chat) + { + DTOChat dtoChat = new DTOChat() + { + chatId = chat.chatId, + PlayerId1 = chat.player1, + PlayerId2 = chat.player2 + }; + return dtoChat; + } + + public static Chat ToChat(this DTOChat dtoChat) + { + return new Chat + { + chatId = dtoChat.chatId, + player1 = dtoChat.PlayerId1, + player2 = dtoChat.PlayerId2 + }; + } + } +} diff --git a/code/server/ApiLeapHit/Mapper/GameMapper.cs b/code/server/ApiLeapHit/Mapper/GameMapper.cs new file mode 100644 index 0000000..fa7d34a --- /dev/null +++ b/code/server/ApiLeapHit/Mapper/GameMapper.cs @@ -0,0 +1,32 @@ +using DataBase.Entity; +using DTO; + +namespace ApiLeapHit.Mapper +{ + public static class GameMapper + { + public static DTOGame ToDto(this Game game) + { + DTOGame dtoGame = new DTOGame() + { + gameId = game.gameId, + durationGame = game.durationGame, + nbMaxEchanges = game.nbMaxEchanges, + playerWinner = game.winner, + playerLoser = game.loser + }; + return dtoGame; + } + + public static Game ToGame(this DTOGame dtoGame) + { + return new Game + { + durationGame = dtoGame.durationGame, + nbMaxEchanges = dtoGame.nbMaxEchanges, + winner = dtoGame.playerWinner, + loser = dtoGame.playerLoser + }; + } + } +} diff --git a/code/server/ApiLeapHit/Mapper/GameWithIdPlayerMapper.cs b/code/server/ApiLeapHit/Mapper/GameWithIdPlayerMapper.cs new file mode 100644 index 0000000..33fa3d2 --- /dev/null +++ b/code/server/ApiLeapHit/Mapper/GameWithIdPlayerMapper.cs @@ -0,0 +1,19 @@ +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 + }; + } + } +} diff --git a/code/server/ApiLeapHit/Mapper/MessageMapper.cs b/code/server/ApiLeapHit/Mapper/MessageMapper.cs new file mode 100644 index 0000000..f354d04 --- /dev/null +++ b/code/server/ApiLeapHit/Mapper/MessageMapper.cs @@ -0,0 +1,34 @@ +using DataBase.Entity; +using DTO; + +namespace ApiLeapHit.Mapper +{ + public static class MessageMapper + { + public static DTOMessage ToDto(this Message message) + { + DTOMessage dtoMessage = new DTOMessage() + { + messageId = message.messageId, + message = message.message, + timestamp = message.timestamp, + PlayerId = message.player, + ChatId = message.chat + }; + return dtoMessage; + } + + public static Message ToMessage(this DTOMessage dtoMessage) + { + Message message = new Message() + { + messageId = dtoMessage.messageId, + message = dtoMessage.message, + timestamp = dtoMessage.timestamp, + player = dtoMessage.PlayerId, + chat = dtoMessage.ChatId + }; + return message; + } + } +} diff --git a/code/server/ApiLeapHit/Mapper/PlayerMapper.cs b/code/server/ApiLeapHit/Mapper/PlayerMapper.cs new file mode 100644 index 0000000..b8d2d07 --- /dev/null +++ b/code/server/ApiLeapHit/Mapper/PlayerMapper.cs @@ -0,0 +1,31 @@ +using DataBase.Entity; +using DTO; + +namespace ApiLeapHit.Mapper +{ + public static class PlayerMapper + { + public static DTOPlayer ToDto(this Player player) + { + DTOPlayer dtoPlayer = new DTOPlayer() + { + playerId = player.playerId, + name = player.name, + nbBallTouchTotal = player.nbBallTouchTotal, + timePlayed = player.timePlayed + }; + return dtoPlayer; + } + + public static Player ToPlayer(this DTOPlayer dtoPlayer) + { + return new Player + { + playerId = dtoPlayer.playerId, + name = dtoPlayer.name, + nbBallTouchTotal = dtoPlayer.nbBallTouchTotal, + timePlayed = dtoPlayer.timePlayed + }; + } + } +} diff --git a/code/server/ApiLeapHit/Program.cs b/code/server/ApiLeapHit/Program.cs new file mode 100644 index 0000000..8df64de --- /dev/null +++ b/code/server/ApiLeapHit/Program.cs @@ -0,0 +1,32 @@ +using DataBase.DataManager; +using Microsoft.Extensions.Logging; + +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(); +//builder.Services.AddSingleton(); + +// Add logging +builder.Logging.AddConsole(); + +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(); \ No newline at end of file diff --git a/code/server/ApiLeapHit/Properties/launchSettings.json b/code/server/ApiLeapHit/Properties/launchSettings.json new file mode 100644 index 0000000..eaba764 --- /dev/null +++ b/code/server/ApiLeapHit/Properties/launchSettings.json @@ -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" + } + } + } +} diff --git a/code/server/ApiLeapHit/appsettings.Development.json b/code/server/ApiLeapHit/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/code/server/ApiLeapHit/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/code/server/ApiLeapHit/appsettings.json b/code/server/ApiLeapHit/appsettings.json new file mode 100644 index 0000000..7300b2a --- /dev/null +++ b/code/server/ApiLeapHit/appsettings.json @@ -0,0 +1,18 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + }, + "Console": { + "IncludeScopes": true, + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } + }, + "AllowedHosts": "*" +} diff --git a/code/server/DTO/DTO.csproj b/code/server/DTO/DTO.csproj new file mode 100644 index 0000000..74abf5c --- /dev/null +++ b/code/server/DTO/DTO.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/code/server/DTO/DTOChat.cs b/code/server/DTO/DTOChat.cs new file mode 100644 index 0000000..1765d3e --- /dev/null +++ b/code/server/DTO/DTOChat.cs @@ -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 int PlayerId1 { get; set; } + public int PlayerId2 { get; set; } + } +} diff --git a/code/server/DTO/DTOGame.cs b/code/server/DTO/DTOGame.cs new file mode 100644 index 0000000..ff430e8 --- /dev/null +++ b/code/server/DTO/DTOGame.cs @@ -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 int playerWinner { get; set; } + public int playerLoser { get; set; } + } +} diff --git a/code/server/DTO/DTOGameWithIdPlayer.cs b/code/server/DTO/DTOGameWithIdPlayer.cs new file mode 100644 index 0000000..a586a0b --- /dev/null +++ b/code/server/DTO/DTOGameWithIdPlayer.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class DTOGameWithIdPlayer + { + public int gameId { get; set; } + public int durationGame { get; set; } + public int nbMaxEchanges { get; set; } + public int playerWinner { get; set; } + public int playerLoser { get; set; } + } +} diff --git a/code/server/DTO/DTOMessage.cs b/code/server/DTO/DTOMessage.cs new file mode 100644 index 0000000..df21cde --- /dev/null +++ b/code/server/DTO/DTOMessage.cs @@ -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 int PlayerId { get; set; } + public int ChatId { get; set; } + } +} diff --git a/code/server/DTO/DTOPlayer.cs b/code/server/DTO/DTOPlayer.cs new file mode 100644 index 0000000..1ec7dbb --- /dev/null +++ b/code/server/DTO/DTOPlayer.cs @@ -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; } + } +} diff --git a/code/server/DTO/Factory/ApiLink.cs b/code/server/DTO/Factory/ApiLink.cs new file mode 100644 index 0000000..c9ea3ec --- /dev/null +++ b/code/server/DTO/Factory/ApiLink.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO.Factory +{ + public class ApiLink + { + public string Href { get; set; } + public string Rel { get; set; } + public string Method { get; set; } + + public ApiLink(string href, string rel, string method) + { + Href = href; + Rel = rel; + Method = method; + } + } +} diff --git a/code/server/DTO/Factory/ApiResponse.cs b/code/server/DTO/Factory/ApiResponse.cs new file mode 100644 index 0000000..1cf32a6 --- /dev/null +++ b/code/server/DTO/Factory/ApiResponse.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO.Factory +{ + public class ApiResponse + { + public string Message { get; set; } + public T Data { get; set; } + public List Links { get; set; } = new List(); + + + public ApiResponse(string message, T data = default) + { + Message = message; + Data = data; + } + } +} diff --git a/code/server/DTO/Program.cs b/code/server/DTO/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/code/server/DTO/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/code/server/DataBase/Context/PongDbContext.cs b/code/server/DataBase/Context/PongDbContext.cs index 6bf8ec2..17bad66 100644 --- a/code/server/DataBase/Context/PongDbContext.cs +++ b/code/server/DataBase/Context/PongDbContext.cs @@ -19,7 +19,7 @@ namespace DataBase.Context if (!optionsBuilder.IsConfigured) { - optionsBuilder.UseSqlite($"Data Source=PongDB.db"); + optionsBuilder.UseSqlite($"Data Source=../DataBase/PongDB.db"); } } } diff --git a/code/server/DataBase/DataBase.csproj b/code/server/DataBase/DataBase.csproj index 32c23d2..f523208 100644 --- a/code/server/DataBase/DataBase.csproj +++ b/code/server/DataBase/DataBase.csproj @@ -5,6 +5,7 @@ net6.0 enable enable + $(MSBuildProjectDirectory) diff --git a/code/server/DataBase/DataManager/DbDataManager.Chat.cs b/code/server/DataBase/DataManager/DbDataManager.Chat.cs index 955e082..b15c133 100644 --- a/code/server/DataBase/DataManager/DbDataManager.Chat.cs +++ b/code/server/DataBase/DataManager/DbDataManager.Chat.cs @@ -15,10 +15,11 @@ namespace DataBase.DataManager using (var context = new PongDbContext()) { await context.Chats.AddAsync(chat); + await context.SaveChangesAsync(); } } - public Task RemoveChat(int id) + public async Task RemoveChat(int id) { using (var context = new PongDbContext()) { @@ -26,10 +27,47 @@ namespace DataBase.DataManager if (chat != null) { var result = context.Chats.Remove(chat); - return Task.FromResult(result != null); + await context.SaveChangesAsync(); + return result != null; } - return Task.FromResult(false); + return false; } } + + public Task> GetChats() + { + using (var context = new PongDbContext()) + { + var chats = context.Chats.ToList(); + return Task.FromResult(chats); + } + } + public Task GetChat(int id) + { + using (var context = new PongDbContext()) + { + var chat = context.Chats.Where(g => g.chatId == id).ToList().FirstOrDefault(); + return Task.FromResult(chat); + } + } + + public Task> GetChatsByIdPlayer(int id) + { + using (var context = new PongDbContext()) + { + var chats = context.Chats.Where(g => g.player1 == id || g.player2 == id).ToList(); + return Task.FromResult(chats); + } + } + + public Task> GetChatsByIdPlayers(int idPlayer1, int idPlayer2) + { + using (var context = new PongDbContext()) + { + var chats = context.Chats.Where(g => (g.player1 == idPlayer1 && g.player2 == idPlayer2) || (g.player1 == idPlayer2 && g.player2 == idPlayer1)).ToList(); + return Task.FromResult(chats); + } + } + } } diff --git a/code/server/DataBase/DataManager/DbDataManager.Game.cs b/code/server/DataBase/DataManager/DbDataManager.Game.cs index 1663856..0b72229 100644 --- a/code/server/DataBase/DataManager/DbDataManager.Game.cs +++ b/code/server/DataBase/DataManager/DbDataManager.Game.cs @@ -15,10 +15,11 @@ namespace DataBase.DataManager using (var context = new PongDbContext()) { await context.Games.AddAsync(game); + await context.SaveChangesAsync(); } } - public Task RemoveGame(int id) + public async Task 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; } } @@ -40,5 +42,32 @@ namespace DataBase.DataManager return Task.FromResult(game); } } + + public Task> GetGameById(int id) + { + using (var context = new PongDbContext()) + { + var games = context.Games.Where(g => g.winner == id || g.loser == id).ToList(); + return Task.FromResult(games); + } + } + + public Task> GetGames() + { + using (var context = new PongDbContext()) + { + var games = context.Games.ToList(); + return Task.FromResult(games); + } + } + + public Task GetNbGames() + { + using (var context = new PongDbContext()) + { + var nbgames = context.Games.ToList().Count(); + return Task.FromResult(nbgames); + } + } } } diff --git a/code/server/DataBase/DataManager/DbDataManager.Message.cs b/code/server/DataBase/DataManager/DbDataManager.Message.cs index 137ba69..ef18a47 100644 --- a/code/server/DataBase/DataManager/DbDataManager.Message.cs +++ b/code/server/DataBase/DataManager/DbDataManager.Message.cs @@ -16,6 +16,7 @@ namespace DataBase.DataManager using (var context = new PongDbContext()) { await context.Messages.AddAsync(message); + await context.SaveChangesAsync(); } } @@ -28,7 +29,7 @@ namespace DataBase.DataManager } } - public Task RemoveMessage(int id) + public async Task RemoveMessage(int id) { using (var context = new PongDbContext()) { @@ -36,9 +37,19 @@ namespace DataBase.DataManager if (message != null) { var result = context.Messages.Remove(message); - return Task.FromResult(result != null); + await context.SaveChangesAsync(); + return result != null; } - return Task.FromResult(false); + return false; + } + } + + public Task> ReceiveAllMessages() + { + using (var context = new PongDbContext()) + { + var messages = context.Messages.ToList(); + return Task.FromResult(messages); } } } diff --git a/code/server/DataBase/DataManager/DbDataManager.Player.cs b/code/server/DataBase/DataManager/DbDataManager.Player.cs index a6a7842..6ed56a6 100644 --- a/code/server/DataBase/DataManager/DbDataManager.Player.cs +++ b/code/server/DataBase/DataManager/DbDataManager.Player.cs @@ -17,10 +17,11 @@ namespace DataBase.DataManager using (var context = new PongDbContext()) { await context.Players.AddAsync(player); + await context.SaveChangesAsync(); } } - public Task RemovePlayer(int id) + public async Task RemovePlayer(int id) { using (var context = new PongDbContext()) { @@ -28,13 +29,14 @@ namespace DataBase.DataManager if (player != null) { var result = context.Players.Remove(player); - return Task.FromResult(result != null); + await context.SaveChangesAsync(); + return result != null; } - return Task.FromResult(false); + return false; } } - public Task UpdatePlayer(int id, string newName) + public async Task UpdatePlayer(int id, string newName) { using (var context = new PongDbContext()) { @@ -43,7 +45,8 @@ namespace DataBase.DataManager { player.name = newName; } - return Task.FromResult(player); + await context.SaveChangesAsync(); + return player; } } @@ -55,5 +58,14 @@ namespace DataBase.DataManager return Task.FromResult(player); } } + + public Task> GetPlayers() + { + using (var context = new PongDbContext()) + { + var players = context.Players.ToList(); + return Task.FromResult(players); + } + } } } diff --git a/code/server/DataBase/Migrations/20230216161314_initMigration.Designer.cs b/code/server/DataBase/Migrations/20230222115848_mymigration.Designer.cs similarity index 96% rename from code/server/DataBase/Migrations/20230216161314_initMigration.Designer.cs rename to code/server/DataBase/Migrations/20230222115848_mymigration.Designer.cs index 810a199..6865b45 100644 --- a/code/server/DataBase/Migrations/20230216161314_initMigration.Designer.cs +++ b/code/server/DataBase/Migrations/20230222115848_mymigration.Designer.cs @@ -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 { /// 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 diff --git a/code/server/DataBase/Migrations/20230216161314_initMigration.cs b/code/server/DataBase/Migrations/20230222115848_mymigration.cs similarity index 76% rename from code/server/DataBase/Migrations/20230216161314_initMigration.cs rename to code/server/DataBase/Migrations/20230222115848_mymigration.cs index cb3f6a6..0ea0e72 100644 --- a/code/server/DataBase/Migrations/20230216161314_initMigration.cs +++ b/code/server/DataBase/Migrations/20230222115848_mymigration.cs @@ -8,13 +8,13 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace DataBase.Migrations { /// - public partial class initMigration : Migration + public partial class mymigration : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( - name: "Player", + name: "Players", columns: table => new { playerId = table.Column(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(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(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(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"); } } } diff --git a/code/server/DataBase/Migrations/PongDbContextWithStubModelSnapshot.cs b/code/server/DataBase/Migrations/PongDbContextWithStubModelSnapshot.cs index 7e3f4a3..5abba79 100644 --- a/code/server/DataBase/Migrations/PongDbContextWithStubModelSnapshot.cs +++ b/code/server/DataBase/Migrations/PongDbContextWithStubModelSnapshot.cs @@ -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 diff --git a/code/server/DataBase/PongDB.db b/code/server/DataBase/PongDB.db index 2ebe421..4d4ba40 100644 Binary files a/code/server/DataBase/PongDB.db and b/code/server/DataBase/PongDB.db differ diff --git a/code/server/DataBase/PongDB.db-shm b/code/server/DataBase/PongDB.db-shm new file mode 100644 index 0000000..fe9ac28 Binary files /dev/null and b/code/server/DataBase/PongDB.db-shm differ diff --git a/code/server/DataBase/PongDB.db-wal b/code/server/DataBase/PongDB.db-wal new file mode 100644 index 0000000..e69de29 diff --git a/code/server/DataBase/Program.cs b/code/server/DataBase/Program.cs index 667c92e..e000096 100644 --- a/code/server/DataBase/Program.cs +++ b/code/server/DataBase/Program.cs @@ -1,2 +1 @@ - -Console.WriteLine("Hello world !"); \ No newline at end of file +Console.WriteLine("Hello world !"); \ No newline at end of file diff --git a/code/server/Server.sln b/code/server/Server.sln index 5bbce65..14b6b0a 100644 --- a/code/server/Server.sln +++ b/code/server/Server.sln @@ -3,9 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.2.32526.322 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataBase", "DataBase\DataBase.csproj", "{240EEEA0-7EFB-4919-A5C9-584DC6505C58}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "Server\Server.csproj", "{95CCBA12-CAB4-4574-A91C-77844E5C2C10}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{95CCBA12-CAB4-4574-A91C-77844E5C2C10}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiLeapHit", "ApiLeapHit\ApiLeapHit.csproj", "{693F37D1-B10C-45B2-A180-24D26B5A4841}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{BDA37278-912D-47E9-BD69-47A924A69004}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataBase", "DataBase\DataBase.csproj", "{FCCE7DEC-1F7B-4C66-8C61-3FCB668F9008}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -13,14 +17,22 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {240EEEA0-7EFB-4919-A5C9-584DC6505C58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {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 {95CCBA12-CAB4-4574-A91C-77844E5C2C10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {95CCBA12-CAB4-4574-A91C-77844E5C2C10}.Debug|Any CPU.Build.0 = Debug|Any CPU {95CCBA12-CAB4-4574-A91C-77844E5C2C10}.Release|Any CPU.ActiveCfg = Release|Any CPU {95CCBA12-CAB4-4574-A91C-77844E5C2C10}.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 + {FCCE7DEC-1F7B-4C66-8C61-3FCB668F9008}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FCCE7DEC-1F7B-4C66-8C61-3FCB668F9008}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FCCE7DEC-1F7B-4C66-8C61-3FCB668F9008}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FCCE7DEC-1F7B-4C66-8C61-3FCB668F9008}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE