-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create entities crud operations (#8)
* exclude services in separate project * Revert "exclude services in separate project" This reverts commit 049097a. * Add Player CRUD operations, add automapper nuget to project * add corrected service and repository registration * player mapper registration * add json ignoring cycles service registration * add Game CRUD operations. corrected PLayer Service * Corrected Create/Update Game oprtaions. Deleted sport type table and exchanged for enum type. Updated game mapping profile * renamed class namespaces, correction of CRUD operations, changed Game entity class * created unit tests for player/game repositories and controllers * corrected names in game tests * corrected controllers and services * changed names of particular unit tests * structure fixes, code mistakes fixes * amended status code in controllers * code fixes in player and Game Controllers and tests * replaced unneceaseary property duplication in Response.cs * fixed incorrect response in player and game controllers * Added ServiceResponse class, refactored Game Service and GameController. Updated resources messages * cahnged logic in player service and controller * few minor changes to controller/models. Refactored Controllers unit tests * deleted folder with custom exceptions. Rewrited unit tests for Game and Player service * fixed empty lines * fixed empty line in playerServiceTests * fixed empty lines part 2
- Loading branch information
Showing
62 changed files
with
2,757 additions
and
1,069 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 10 additions & 10 deletions
20
Actively/Actively/ActivelyApp/Controllers/AuthenticationController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
Actively/Actively/ActivelyApp/Controllers/GameController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
using ActivelyApp.Models.Common; | ||
using ActivelyApp.Models.EntityDto; | ||
using ActivelyApp.Services.EntityService; | ||
using ActivelyDomain.Entities; | ||
using AutoMapper; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Resources; | ||
|
||
namespace ActivelyApp.Controllers | ||
{ | ||
[ApiController] | ||
[Authorize] | ||
[Route("[controller]/[action]")] | ||
public class GameController : Controller | ||
{ | ||
private readonly IGameService _gameService; | ||
private readonly IMapper _mapper; | ||
|
||
public GameController(IGameService gameService, IMapper mapper) | ||
{ | ||
_gameService = gameService; | ||
_mapper = mapper; | ||
} | ||
|
||
[HttpGet] | ||
public async Task<IActionResult> GetAllGames() | ||
{ | ||
var serviceResult = await _gameService.GetAllGames(); | ||
if (serviceResult.IsSuccess == true) | ||
{ | ||
var games = _mapper.Map<IEnumerable<GameDto>>(serviceResult.Data); | ||
return StatusCode(StatusCodes.Status200OK, new Response | ||
{ Type = ResponseType.Success, Status = Common.Success, Content = games, Message = serviceResult.Message, IsSuccess = true }); | ||
} | ||
else | ||
{ | ||
return StatusCode(StatusCodes.Status400BadRequest, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
} | ||
|
||
[HttpGet] | ||
public async Task<IActionResult> GetGameById(int id) | ||
{ | ||
var serviceResult = await _gameService.GetGameById(id); | ||
|
||
if (serviceResult.IsSuccess == true) | ||
{ | ||
var game = _mapper.Map<GameDto>(serviceResult.Data); | ||
return StatusCode(StatusCodes.Status200OK, new Response | ||
{ Type = ResponseType.Success, Status = Common.Success, Content = game, Message = serviceResult.Message, IsSuccess = true }); | ||
} | ||
else | ||
{ | ||
if (serviceResult.Message == Common.GameNotExists) | ||
{ | ||
return StatusCode(StatusCodes.Status404NotFound, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
return StatusCode(StatusCodes.Status400BadRequest, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
} | ||
|
||
[HttpPost] | ||
public async Task<IActionResult> CreateGame([FromBody] CreateGameInfoDto newGame) | ||
{ | ||
var entityNewGame = _mapper.Map<Game>(newGame); | ||
var serviceResult = await _gameService.CreateGame(entityNewGame); | ||
if (serviceResult.IsSuccess == true) | ||
{ | ||
return StatusCode(StatusCodes.Status201Created, new Response | ||
{ Type = ResponseType.Success, Status = Common.Success, Content = newGame, Message = serviceResult.Message, IsSuccess = true }); | ||
} | ||
else | ||
{ | ||
return StatusCode(StatusCodes.Status400BadRequest, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
} | ||
|
||
[HttpPatch] | ||
public async Task<IActionResult> UpdateGame([FromBody] UpdateGameInfoDto updateGameInfo, int id) | ||
{ | ||
var entityUpdateGame = _mapper.Map<Game>(updateGameInfo); | ||
var serviceResult = await _gameService.UpdateGame(entityUpdateGame, id); | ||
if (serviceResult.IsSuccess == true) | ||
{ | ||
return StatusCode(StatusCodes.Status200OK, new Response | ||
{ Type = ResponseType.Success, Status = Common.Success, Content = updateGameInfo, Message = serviceResult.Message, IsSuccess = true }); | ||
} | ||
else | ||
{ | ||
if (serviceResult.Message == Common.GameNotExists) | ||
{ | ||
return StatusCode(StatusCodes.Status404NotFound, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
|
||
return StatusCode(StatusCodes.Status400BadRequest, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
} | ||
|
||
[HttpDelete] | ||
public async Task<IActionResult> DeleteGame(int id) | ||
{ | ||
var serviceResult = await _gameService.DeleteGame(id); | ||
if (serviceResult.IsSuccess == true) | ||
{ | ||
return StatusCode(StatusCodes.Status200OK, new Response | ||
{ Type = ResponseType.Success, Status = Common.Success, Message = serviceResult.Message, IsSuccess = true }); | ||
} | ||
else | ||
{ | ||
if (serviceResult.Message == Common.GameNotExists) | ||
{ | ||
return StatusCode(StatusCodes.Status404NotFound, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
|
||
return StatusCode(StatusCodes.Status400BadRequest, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
Actively/Actively/ActivelyApp/Controllers/PlayerController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
using ActivelyApp.Models.Common; | ||
using ActivelyApp.Models.EntityDto; | ||
using ActivelyApp.Services.EntityService; | ||
using ActivelyDomain.Entities; | ||
using AutoMapper; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Resources; | ||
|
||
namespace ActivelyApp.Controllers | ||
{ | ||
[ApiController] | ||
[Authorize] | ||
[Route("[controller]/[action]")] | ||
public class PlayerController : Controller | ||
{ | ||
private readonly IPlayerService _playerService; | ||
private readonly IMapper _mapper; | ||
|
||
public PlayerController(IPlayerService playerService, IMapper mapper) | ||
{ | ||
_playerService = playerService; | ||
_mapper = mapper; | ||
} | ||
|
||
[HttpGet] | ||
public async Task<IActionResult> GetAllPlayers() | ||
{ | ||
var serviceResult = await _playerService.GetAllPlayers(); | ||
if (serviceResult.IsSuccess == true) | ||
{ | ||
var players = _mapper.Map<IEnumerable<PlayerDto>>(serviceResult.Data); | ||
return StatusCode(StatusCodes.Status200OK, new Response | ||
{ Type = ResponseType.Success, Status = Common.Success, Content = players, Message = serviceResult.Message, IsSuccess = true }); | ||
} | ||
else | ||
{ | ||
return StatusCode(StatusCodes.Status400BadRequest, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
} | ||
|
||
[HttpGet] | ||
public async Task<IActionResult> GetPlayerById(int id) | ||
{ | ||
var serviceResult = await _playerService.GetPlayerById(id); | ||
|
||
if (serviceResult.IsSuccess == true) | ||
{ | ||
var player = _mapper.Map<PlayerDto>(serviceResult.Data); | ||
return StatusCode(StatusCodes.Status200OK, new Response | ||
{ Type = ResponseType.Success, Status = Common.Success, Content = player, Message = serviceResult.Message, IsSuccess = true }); | ||
} | ||
else | ||
{ | ||
if (serviceResult.Message == Common.PlayerNotExists) | ||
{ | ||
return StatusCode(StatusCodes.Status404NotFound, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
return StatusCode(StatusCodes.Status400BadRequest, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
} | ||
|
||
[HttpPost] | ||
public async Task<IActionResult> CreatePlayer([FromBody] CreatePlayerInfoDto newPlayer) | ||
{ | ||
var entityNewPlayer = _mapper.Map<Player>(newPlayer); | ||
var serviceResult = await _playerService.CreatePlayer(entityNewPlayer); | ||
if (serviceResult.IsSuccess == true) | ||
{ | ||
return StatusCode(StatusCodes.Status201Created, new Response | ||
{ Type = ResponseType.Success, Status = Common.Success, Content = newPlayer, Message = serviceResult.Message, IsSuccess = true }); | ||
} | ||
else | ||
{ | ||
return StatusCode(StatusCodes.Status400BadRequest, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
} | ||
|
||
[HttpPatch] | ||
public async Task<IActionResult> UpdatePlayer([FromBody] UpdatePlayerInfoDto updatePlayerInfo, int id) | ||
{ | ||
var entityUpdatePlayer = _mapper.Map<Player>(updatePlayerInfo); | ||
var serviceResult = await _playerService.UpdatePlayer(entityUpdatePlayer, id); | ||
if (serviceResult.IsSuccess == true) | ||
{ | ||
return StatusCode(StatusCodes.Status200OK, new Response | ||
{ Type = ResponseType.Success, Status = Common.Success, Content = updatePlayerInfo, Message = serviceResult.Message, IsSuccess = true }); | ||
} | ||
else | ||
{ | ||
if (serviceResult.Message == Common.PlayerNotExists) | ||
{ | ||
return StatusCode(StatusCodes.Status404NotFound, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
|
||
return StatusCode(StatusCodes.Status400BadRequest, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
} | ||
|
||
[HttpDelete] | ||
public async Task<IActionResult> DeletePlayer(int id) | ||
{ | ||
var serviceResult = await _playerService.DeletePlayer(id); | ||
if (serviceResult.IsSuccess == true) | ||
{ | ||
return StatusCode(StatusCodes.Status200OK, new Response | ||
{ Type = ResponseType.Success, Status = Common.Success, Message = serviceResult.Message, IsSuccess = true }); | ||
} | ||
else | ||
{ | ||
if (serviceResult.Message == Common.PlayerNotExists) | ||
{ | ||
return StatusCode(StatusCodes.Status404NotFound, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
|
||
return StatusCode(StatusCodes.Status400BadRequest, new Response | ||
{ Type = ResponseType.Error, Status = Common.Error, Message = serviceResult.Message, IsSuccess = false }); | ||
} | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Actively/Actively/ActivelyApp/Mappings/GameMappingProfile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using ActivelyApp.Models.EntityDto; | ||
using ActivelyDomain.Entities; | ||
using AutoMapper; | ||
|
||
namespace ActivelyApp.Mappings | ||
{ | ||
public class GameMappingProfile : Profile | ||
{ | ||
public GameMappingProfile() | ||
{ | ||
CreateMap<CreateGameInfoDto, Game>(); | ||
CreateMap<UpdateGameInfoDto, Game>(); | ||
CreateMap<Game, GameDto>(); | ||
CreateMap<GameDto, Game>(); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Actively/Actively/ActivelyApp/Mappings/PLayerMappingProfile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using ActivelyApp.Models.EntityDto; | ||
using ActivelyDomain.Entities; | ||
using AutoMapper; | ||
|
||
namespace ActivelyApp.Mappings | ||
{ | ||
public class PlayerMappingProfile : Profile | ||
{ | ||
public PlayerMappingProfile() | ||
{ | ||
CreateMap<CreatePlayerInfoDto, Player>(); | ||
CreateMap<UpdatePlayerInfoDto, Player>(); | ||
CreateMap<Player, PlayerDto>(); | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...uthentication/Email/EmailConfiguration.cs → ...enticationDto/Email/EmailConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...dels/Authentication/Email/EmailMessage.cs → ...s/AuthenticationDto/Email/EmailMessage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...Models/Authentication/Login/LoginModel.cs → ...els/AuthenticationDto/Login/LoginModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.