Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ScrumPoker.Business.Interfaces.Interfaces;

public class IRoundStateService
{

}
35 changes: 35 additions & 0 deletions ScrumPoker.Business/RoundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@ public class RoundService : IRoundService
private readonly IGameRoomService _gameRoomService;
private readonly IRoundRepository _roundRepository;
private readonly IUserManager _userManager;

private static readonly IReadOnlyList<RoundState> Grooming = new List<RoundState>
{
RoundState.VoteRegistration
};

private static readonly IReadOnlyList<RoundState> VoteRegistration = new List<RoundState>
{
RoundState.VoteReview
};

private static readonly IReadOnlyList<RoundState> VoteReview = new List<RoundState>
{
RoundState.VoteRegistration,
RoundState.Finished
};

private static readonly IReadOnlyList<RoundState> Finished = new List<RoundState>();

private static IEnumerable<RoundState> CheckRoundStates(Round roundRequest)
{
var result = roundRequest.RoundState switch
{
RoundState.Grooming => Grooming,
RoundState.VoteRegistration => VoteRegistration,
RoundState.VoteReview => VoteReview,
RoundState.Finished => Finished,
_ => throw new ArgumentOutOfRangeException()
};

return result;
}

public RoundService(IRoundRepository roundRepository, IGameRoomService gameRoomService, IUserManager userManager)
{
Expand Down Expand Up @@ -53,6 +85,9 @@ public async Task SetState(Round roundRequest)
if (gameRoomDto.MasterId != currentUserId)
throw new ActionNotAllowedException($"User has not rights to Update game room (ID {gameRoomDto.Id})");

if (!CheckRoundStates(roundDto).Contains(roundRequest.RoundState))
throw new InvalidRoundStateException($"Round state {roundRequest.RoundState.ToString()} is not allowed after {roundDto.RoundState.ToString()}");

await _roundRepository.SetState(roundRequest);
}

Expand Down
25 changes: 25 additions & 0 deletions ScrumPoker.Business/RoundStateService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using ScrumPoker.Business.Interfaces.Interfaces;
using ScrumPoker.Common.Models;

namespace ScrumPoker.Business;

public class RoundStateService : IRoundStateService
{
private static readonly IReadOnlyList<RoundState> Grooming = new List<RoundState>
{
RoundState.VoteRegistration
};

private static readonly IReadOnlyList<RoundState> VoteRegistration = new List<RoundState>
{
RoundState.VoteReview
};

private static readonly IReadOnlyList<RoundState> VoteReview = new List<RoundState>
{
RoundState.VoteRegistration,
RoundState.Finished
};

private static readonly IReadOnlyList<RoundState> Finished = new List<RoundState>();
}
1 change: 0 additions & 1 deletion ScrumPoker.Business/VoteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using ScrumPoker.Common.Models;
using ScrumPoker.Common.NotFoundExceptions;
using ScrumPoker.DataAccess.Interfaces;
using ScrumPoker.DataAccess.Models.Models;

namespace ScrumPoker.Business;

Expand Down
1 change: 1 addition & 0 deletions ScrumPoker.Infrastructure/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public static void Register(this IServiceCollection services)
services.AddTransient<IVoteService, VoteService>();
services.AddHttpContextAccessor();
services.AddTransient<IUserManager, UserManager>();
services.AddTransient<IRoundStateService, RoundStateService>();
}
}