Compare commits

...

6 Commits

Author SHA1 Message Date
96b0fb986f Merge pull request 'campaign' (#4) from campaign into master
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #4
2021-09-24 10:29:48 +00:00
a664d09065 Merge branch 'master' into campaign
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2021-09-24 10:09:23 +00:00
Michele Scandura
099fca8ceb small fixes
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2021-09-24 11:02:22 +01:00
Michele Scandura
5276055c4d fix player invitation 2021-09-24 11:00:24 +01:00
Michele Scandura
85e2f699bf general fixes
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2021-09-24 10:21:44 +01:00
3e1acd26f2 invite player fixes
All checks were successful
continuous-integration/drone/push Build is passing
2021-09-23 22:15:15 +01:00
15 changed files with 99 additions and 50 deletions

View File

@ -6,13 +6,13 @@ namespace Sledgemapper.Api.Commands
public class InvitePlayerToCampaignCommand : IRequest<bool>
{
public double Timestamp { get; private set; }
public string CampaignName { get; private set; }
public Guid CampaignId { get; private set; }
public string Email { get; private set; }
public string UserId { get; private set; }
public InvitePlayerToCampaignCommand(string campaingName, string email, string userId)
public InvitePlayerToCampaignCommand(Guid campaignId, string email, string userId)
{
Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
CampaignName = campaingName;
CampaignId = campaignId;
UserId = userId;
Email = email;
}

View File

@ -48,10 +48,10 @@ namespace Sledgemapper.Api.Controllers
}
[HttpPost]
[Route("{campaignName}/players/{email}")]
public async Task<bool> Invite(string campaignName, string email)
[Route("{campaignId}/players/{email}")]
public async Task<bool> Invite(Guid campaignId, string email)
{
var result = await _mediator.Send(new InvitePlayerToCampaignCommand(campaignName, email, UserId));
var result = await _mediator.Send(new InvitePlayerToCampaignCommand(campaignId, email, UserId));
return result;
}

View File

@ -29,7 +29,18 @@ namespace Sledgemapper.Api.Handlers
var user = await _dbcontext.Users.FindAsync(command.UserId);
_dbcontext.Attach(user);
var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignId == command.CampaignId && campaign.OwnerId == command.UserId).Include(campaign => campaign.InvitedUsers).FirstAsync();
var campaign = await _dbcontext
.Campaigns
.Where(campaign => campaign.CampaignId == command.CampaignId)
.Include(c => c.InvitedUsers)
.Include(c => c.Owner)
.Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user)).FirstAsync();
//var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignId == command.CampaignId && campaign.OwnerId == command.UserId).Include(campaign => campaign.InvitedUsers).FirstAsync();
var players = campaign.InvitedUsers.Select(user => new Player { Initials = user.Initials, UserName = user.UserName , UserId = new Guid(user.Id)}).ToList();
return players;

View File

@ -1,43 +1,53 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Infrastructure.Data;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Infrastructure.Data;
namespace Sledgemapper.Api.Handlers
{
public class InvitePlayerToCampaignCommandHandler : IRequestHandler<InvitePlayerToCampaignCommand, bool>
{
private readonly SledgemapperDbContext _dbContext;
private readonly IMediator _mediator;
private readonly SledgemapperDbContext _dbcontext;
public InvitePlayerToCampaignCommandHandler(IMediator mediator, SledgemapperDbContext dbcontext)
public InvitePlayerToCampaignCommandHandler(IMediator mediator, SledgemapperDbContext dbContext)
{
_mediator = mediator;
_dbcontext = dbcontext;
_dbContext = dbContext;
}
public async Task<bool> Handle(InvitePlayerToCampaignCommand command, CancellationToken cancellationToken)
{
try
{
var user = await _dbcontext.Users.FindAsync(command.UserId);
var user = await _dbContext.Users.FindAsync(command.UserId);
var campaign = await _dbcontext.Campaigns.Where(campaign=>campaign.CampaignName==command.CampaignName && campaign.OwnerId==command.UserId).Include(campaign=>campaign.InvitedUsers).FirstAsync();
var invitedUser = await _dbcontext.Users.FirstOrDefaultAsync(user=>user.Email==command.Email);
_dbcontext.Attach(invitedUser);
_dbcontext.Attach(campaign);
var campaign = await _dbContext
.Campaigns
.Where(campaign => campaign.CampaignId == command.CampaignId)
.Include(c => c.InvitedUsers)
.Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user))
.FirstAsync(cancellationToken);
var invitedUser =
await _dbContext.Users.FirstOrDefaultAsync(iUser => iUser.Email == command.Email,
cancellationToken);
_dbContext.Attach(invitedUser);
_dbContext.Attach(campaign);
campaign.InvitedUsers.Add(invitedUser);
_dbcontext.Campaigns.Update(campaign);
await _dbcontext.SaveChangesAsync();
await _dbContext.SaveChangesAsync(cancellationToken);
return true;
}
catch (Exception ex)
{
}
return false;
}
}

View File

@ -23,7 +23,7 @@ namespace Sledgemapper.Api.Handlers
{
try
{
var user = await _dbcontext.Users.FindAsync(notification.UserId, cancellationToken);
var user = await _dbcontext.Users.FindAsync(new object[] { notification.UserId }, cancellationToken);
_dbcontext.Attach(user);
var campaign = new Core.Entities.Campaign
{

View File

@ -9,19 +9,19 @@
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
<PackageReference Include="mediatr" Version="9.0.0" />
<PackageReference Include="mediatr.extensions.microsoft.dependencyinjection" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.6">
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.10">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.10" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.11.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.2" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.12.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.10" />
</ItemGroup>
<PropertyGroup>

View File

@ -301,7 +301,16 @@ namespace Sledgemapper
Program.helper.SaveUnencryptedTokenCache(JsonSerializer.SerializeToUtf8Bytes(_authenticateResponse));
await Connection.StopAsync();
State.Instance.CampaignId=Guid.Empty;
State.Instance.CampaignName = string.Empty;
State.Instance.SessionId = Guid.Empty;
State.Instance.MapId = Guid.Empty;
State.Instance.MapName = string.Empty;
SessionData.SessionId = Guid.Empty;
SessionData.SessionName = string.Empty;
SessionData.Players.Clear();
return _authenticateResponse;
}

View File

@ -42,15 +42,15 @@ namespace Sledgemapper
Task<List<Player>> GetPlayers(Guid campaignName);
[Get("/campaign/{campaignName}/maps")]
Task<List<Session>> GetMaps(Guid campaignName);
[Get("/campaign/{campaignId}/maps")]
Task<List<Session>> GetMaps(Guid campaignId);
[Get("/map/{campaignName}/{mapName}")]
Task<Session> GetMap(Guid campaignName, Guid mapName);
[Get("/map/{campaignId}/{mapId}")]
Task<Session> GetMap(Guid campaignId, Guid mapId);
[Post("/campaign/{campaignName}/players/{email}")]
Task InvitePlayer(string campaignName, string email);
[Post("/campaign/{campaignId}/players/{email}")]
Task InvitePlayer(Guid campaignId, string email);

View File

@ -57,6 +57,7 @@ namespace Sledgemapper
MyraEnvironment.Game = this;
_sessionData = new Session();
IsFixedTimeStep = true;
TargetElapsedTime = TimeSpan.FromSeconds(1d / 30d);

View File

@ -58,7 +58,7 @@
<PackageReference Include="polly" Version="7.2.2" />
<PackageReference Include="polly.extensions.http" Version="3.0.0" />
<PackageReference Include="Refit.HttpClientFactory" Version="6.0.94" />
<PackageReference Include="Sentry" Version="3.9.2" />
<PackageReference Include="Sentry" Version="3.9.3" />
<PackageReference Include="TinyMessenger" Version="1.4.0-alpha3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>

View File

@ -100,6 +100,7 @@ namespace Sledgemapper.UI
_authResponse = await CommunicationManager.Login(new AuthenticateModel
{
Username = TxtEmail.Text,
Email = TxtEmail.Text,
Password = TxtPassword.Text
});
successful = true;

View File

@ -229,7 +229,13 @@ namespace Sledgemapper.UI
//MenuConnectJoin.Enabled = true;
MenuCampaignOpen.Enabled = true;
MenuCampaingNew.Enabled = true;
MenuMapNew.Enabled = false;
MenuMapOpen.Enabled = false;
MenuCampaignPlayers.Enabled = false;
lblCampaign.Text = "n/a";
lblMap.Text = "n/a";
CommunicationManager.SessionData.MapEntityAdded -= OnMapEntityAdded;
CommunicationManager.SessionData.MapEntityDeleted -= OnMapEntityDeleted;
lblUsername.Text = $"{obj.Initials}";
}
@ -297,7 +303,7 @@ namespace Sledgemapper.UI
{
if (!((MenuItem)sender).Enabled) return;
var content = new PlayerList(CommunicationManager);
var content = new PlayerList(CommunicationManager, Messenger);
if (await content.LoadPlayers())
{
content.ShowInModalWindow(Desktop, "Players");

View File

@ -1,15 +1,20 @@
/* Generated by MyraPad at 28/08/2021 19:49:08 */
using System.Threading.Tasks;
using TinyMessenger;
namespace Sledgemapper.UI
{
public partial class PlayerList
{
protected readonly CommunicationManager CommunicationManager;
protected CommunicationManager CommunicationManager { get; }
protected TinyMessengerHub Messenger { get; }
public PlayerList(CommunicationManager communicationManager)
public PlayerList(CommunicationManager communicationManager, TinyMessenger.TinyMessengerHub messenger)
{
CommunicationManager = communicationManager;
Messenger = messenger;
BuildUI();
CommunicationManager = communicationManager;
BtnInvitePlayer.Click += (s, e) =>
@ -38,7 +43,7 @@ namespace Sledgemapper.UI
private void ShowAddPLayerWindow()
{
new PlayerWindow(CommunicationManager).ShowInModalWindow(Desktop, "Invite player");
new PlayerWindow(CommunicationManager, Messenger).ShowInModalWindow(Desktop, "Invite player");
}
}
}

View File

@ -1,17 +1,21 @@
/* Generated by MyraPad at 28/08/2021 22:04:11 */
using Myra.Graphics2D.UI;
using Sentry;
using Sledgemapper.Messages;
using System;
using TinyMessenger;
namespace Sledgemapper.UI
{
public partial class PlayerWindow
{
protected readonly CommunicationManager CommunicationManager;
protected CommunicationManager CommunicationManager { get; }
protected TinyMessengerHub Messenger { get; }
public PlayerWindow(CommunicationManager communicationManager)
public PlayerWindow(CommunicationManager communicationManager, TinyMessenger.TinyMessengerHub messenger)
{
CommunicationManager = communicationManager;
Messenger = messenger;
BuildUI();
BtnNewCampaign.Click += OnButtonInvitePlayerClicked;
@ -29,11 +33,13 @@ namespace Sledgemapper.UI
var successful = false;
try
{
await CommunicationManager.Api.InvitePlayer(State.Instance.CampaignName, localContent.Content.TxtCampaign.Text);
await CommunicationManager.Api.InvitePlayer(State.Instance.CampaignId, localContent.Content.TxtCampaign.Text);
}
catch (Exception ex)
{
Messenger.Publish(new ErrorMessage(this, "Error inviting player"));
SentrySdk.CaptureException(ex);
}
this.GetContainingWindow().Close();
}

View File

@ -45,7 +45,7 @@ namespace Sledgemapper.UI
grid1.Widgets.Add(TxtCampaign);
BtnNewCampaign = new TextButton();
BtnNewCampaign.Text = "New";
BtnNewCampaign.Text = "Invite";
BtnNewCampaign.Padding = new Thickness(10, 5);
BtnNewCampaign.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center;
BtnNewCampaign.Id = "BtnNewCampaign";