Skip to content

Commit

Permalink
Correctly enforce game create rules
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-bstein committed Sep 13, 2024
1 parent 98f92a1 commit eb8466d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
7 changes: 5 additions & 2 deletions src/Gameboard.Api/Features/Game/GameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ IUserRolePermissionsService permissionsService
/// <param name="model"></param>
/// <returns></returns>
[HttpPost("api/game")]
public Task<Game> Create([FromBody] NewGame model)
=> GameService.Create(model);
public async Task<Game> Create([FromBody] NewGame model)
{
await Authorize(_permissionsService.Can(PermissionKey.Games_CreateEditDelete));
return await GameService.Create(model);
}

/// <summary>
/// Retrieve game
Expand Down
39 changes: 15 additions & 24 deletions src/Gameboard.Api/Features/Game/GameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,22 @@ public interface IGameService
Task<bool> UserIsTeamPlayer(string uid, string gid, string tid);
}

public class GameService : _Service, IGameService
public class GameService(
IGuidService guids,
ILogger<GameService> logger,
IMapper mapper,
CoreOptions options,
Defaults defaults,
INowService nowService,
IUserRolePermissionsService permissionsService,
IStore store
) : _Service(logger, mapper, options), IGameService
{
private readonly Defaults _defaults;
private readonly IGuidService _guids;
private readonly INowService _now;
private readonly IUserRolePermissionsService _permissionsService;
private readonly IStore _store;

public GameService(
IGuidService guids,
ILogger<GameService> logger,
IMapper mapper,
CoreOptions options,
Defaults defaults,
INowService nowService,
IUserRolePermissionsService permissionsService,
IStore store
) : base(logger, mapper, options)
{
_guids = guids;
_defaults = defaults;
_now = nowService;
_permissionsService = permissionsService;
_store = store;
}
private readonly Defaults _defaults = defaults;
private readonly IGuidService _guids = guids;
private readonly INowService _now = nowService;
private readonly IUserRolePermissionsService _permissionsService = permissionsService;
private readonly IStore _store = store;

public async Task<Game> Create(NewGame model)
{
Expand Down

0 comments on commit eb8466d

Please sign in to comment.