namespaces and guest game invitations

This commit is contained in:
2021-01-25 20:41:14 -06:00
parent 495fb288e1
commit 1352d75c6a
38 changed files with 262 additions and 208 deletions

View File

@@ -1,30 +1,61 @@
using AspShogiSockets.ServiceModels.Api.Messages;
using Gameboard.ShogiUI.Sockets.Repositories;
using Gameboard.ShogiUI.Sockets.Repositories.RepositoryManagers;
using Gameboard.ShogiUI.Sockets.ServiceModels.Api.Messages;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;
using Websockets.Repositories;
namespace AspShogiSockets.Controllers
namespace Gameboard.ShogiUI.Sockets.Controllers
{
[Authorize]
[ApiController]
[Route("[controller]")]
public class GameController : ControllerBase
{
private readonly IGameboardRepository gameboardRepository;
private readonly IGameboardRepositoryManager manager;
private readonly IGameboardRepository repository;
public GameController(IGameboardRepository gameboardRepository)
public GameController(
IGameboardRepository repository,
IGameboardRepositoryManager manager)
{
this.gameboardRepository = gameboardRepository;
this.manager = manager;
this.repository = repository;
}
[Route("JoinCode")]
public async Task<IActionResult> PostGameInvitation([FromBody] PostGameInvitation request)
{
var userName = HttpContext.User.Claims.First(c => c.Type == "preferred_username").Value;
var code = (await gameboardRepository.PostJoinCode(request.SessionName, userName)).JoinCode;
return new CreatedResult("", new PostGameInvitationResponse(code));
var isPlayer1 = await manager.IsPlayer1(request.SessionName, userName);
if (isPlayer1)
{
var code = (await repository.PostJoinCode(request.SessionName, userName)).JoinCode;
return new CreatedResult("", new PostGameInvitationResponse(code));
}
else
{
return new UnauthorizedResult();
}
}
[AllowAnonymous]
[Route("GuestJoinCode")]
public async Task<IActionResult> PostGuestGameInvitation([FromBody] PostGuestGameInvitation request)
{
var isGuest = manager.IsGuest(request.GuestId);
var isPlayer1 = manager.IsPlayer1(request.SessionName, request.GuestId);
if (isGuest && await isPlayer1)
{
var code = (await repository.PostJoinCode(request.SessionName, request.GuestId)).JoinCode;
return new CreatedResult("", new PostGameInvitationResponse(code));
}
else
{
return new UnauthorizedResult();
}
}
}
}

View File

@@ -1,15 +1,13 @@
using AspShogiSockets.Repositories.RepositoryManagers;
using AspShogiSockets.ServiceModels.Api.Messages;
using Gameboard.ShogiUI.Sockets.Managers;
using Gameboard.ShogiUI.Sockets.Repositories;
using Gameboard.ShogiUI.Sockets.Repositories.RepositoryManagers;
using Gameboard.ShogiUI.Sockets.ServiceModels.Api.Messages;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Linq;
using System.Threading.Tasks;
using Websockets.Managers;
using Websockets.Repositories;
using Websockets.ServiceModels;
namespace Websockets.Controllers
namespace Gameboard.ShogiUI.Sockets.Controllers
{
[Authorize]
[Route("[controller]")]