Skip to content

Commit

Permalink
Add endpoints for Gamebrain + bugfixes (#61)
Browse files Browse the repository at this point in the history
* Move challenge events endpoint to unity controller (it's only used there anyway)

* Resolved an issue that caused players to be unable to return to a CubeSpace game if they refreshed or otherwise left the page.

* Add Serilog for better log control in Grafana.

* Add admin endpoint to clear out Unity-related challenge data.

* Resolve player presence bugs during team formation.

* Resolve player presence bugs during team formation.

* Fixed a regression in the api/team/:id endpoint

* Fixed a regression in the api/team/:id endpoint

* Enhancements to unity challenges endpoint to accommodate console-related metadata.

* Modified the unity create challenge endpoint to accept calls from each player on the team.

* Add mission update endpoint for Gamebrain.

* Correct an issue where invite code was being deleted by enlistees.

* Corrects an issue where the Unity API was creating state for TopoMojo incorrectly.
  • Loading branch information
sei-bstein authored Nov 4, 2022
1 parent f9d2c15 commit 0404712
Show file tree
Hide file tree
Showing 44 changed files with 797 additions and 556 deletions.
2 changes: 0 additions & 2 deletions src/Gameboard.Api/Data/Entities/User.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Copyright 2021 Carnegie Mellon University. All Rights Reserved.
// Released under a MIT (SEI)-style license. See LICENSE.md in the project root for license information.

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Gameboard.Api.Data
{
Expand Down
7 changes: 0 additions & 7 deletions src/Gameboard.Api/Data/Store/IStore[TEntity].cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,12 @@ public interface IStore<TEntity>
DbSet<TEntity> DbSet { get; }

IQueryable<TEntity> List(string term = null);

Task<TEntity> Create(TEntity entity);

Task<IEnumerable<TEntity>> Create(IEnumerable<TEntity> range);

Task<TEntity> Retrieve(string id, Func<IQueryable<TEntity>, IQueryable<TEntity>> includes = null);

Task Update(TEntity entity);

Task Update(IEnumerable<TEntity> range);

Task Delete(string id);

}

}
9 changes: 8 additions & 1 deletion src/Gameboard.Api/Features/Challenge/Challenge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Released under a MIT (SEI)-style license. See LICENSE.md in the project root for license information.

using System;
using Gameboard.Api.Features.ChallengeEvents;
using TopoMojo.Api.Client;

namespace Gameboard.Api
Expand Down Expand Up @@ -178,6 +177,14 @@ public class ArchivedChallenge
public SectionSubmission[] Submissions { get; set; }
}

public class ChallengeEventSummary
{
public string UserId { get; set; }
public string Text { get; set; }
public ChallengeEventType Type { get; set; }
public DateTimeOffset Timestamp { get; set; }
}

public class ChallengeSearchFilter : SearchFilter
{
public string uid { get; set; } // Used to search for all challenges of a user
Expand Down
3 changes: 2 additions & 1 deletion src/Gameboard.Api/Features/Challenge/ChallengeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using AutoMapper;
using Gameboard.Api.Features.ChallengeEvents;

namespace Gameboard.Api.Services
{
Expand Down Expand Up @@ -115,6 +114,8 @@ public ChallengeMapper()
.ForMember(d => d.SessionId, opt => opt.MapFrom(s => s.IsolationId))
;

CreateMap<Data.ChallengeEvent, ChallengeEventSummary>();

JsonOptions = new JsonSerializerOptions
{
AllowTrailingCommas = true,
Expand Down
6 changes: 1 addition & 5 deletions src/Gameboard.Api/Features/Challenge/ChallengeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,26 +437,22 @@ await Store.Retrieve(model.SessionId)
);

if (!challenge.State.Vms.Any(v => v.Name == model.Name))
throw new ResourceNotFound();
throw new ResourceNotFound<VmState>("n/a", $"VMS for challenge {model.Name}");

switch (model.Action)
{
case ConsoleAction.Ticket:

return Mapper.Map<ConsoleSummary>(
await Mojo.GetVmTicketAsync(model.Id)
);

case ConsoleAction.Reset:

var vm = await Mojo.ChangeVmAsync(
new VmOperation
{
Id = model.Id,
Type = VmOperationType.Reset
}
);

return new ConsoleSummary
{
Id = vm.Id,
Expand Down
10 changes: 5 additions & 5 deletions src/Gameboard.Api/Features/Challenge/ChallengeValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ private Task _validate(PlayerDataFilter model)
private async Task _validate(Entity model)
{
if ((await Exists(model.Id)).Equals(false))
throw new ResourceNotFound();
throw new ResourceNotFound<Challenge>(model.Id);
}

private async Task _validate(NewChallenge model)
{
if ((await PlayerExists(model.PlayerId)).Equals(false))
throw new ResourceNotFound();
throw new ResourceNotFound<Player>(model.PlayerId);

if ((await SpecExists(model.SpecId)).Equals(false))
throw new ResourceNotFound();
throw new ResourceNotFound<ChallengeSpec>(model.SpecId);

var player = await _store.DbContext.Players.FindAsync(model.PlayerId);

if (player.IsLive.Equals(false))
throw new SessionNotActive();
throw new SessionNotActive(player.Id);

var spec = await _store.DbContext.ChallengeSpecs.FindAsync(model.SpecId);

Expand All @@ -68,7 +68,7 @@ private async Task _validate(NewChallenge model)
private async Task _validate(ChangedChallenge model)
{
if ((await Exists(model.Id)).Equals(false))
throw new ResourceNotFound();
throw new ResourceNotFound<Challenge>(model.Id);

await Task.CompletedTask;
}
Expand Down

This file was deleted.

12 changes: 0 additions & 12 deletions src/Gameboard.Api/Features/ChallengeEvents/ChallengeEventMaps.cs

This file was deleted.

21 changes: 0 additions & 21 deletions src/Gameboard.Api/Features/ChallengeEvents/ChallengeEventModels.cs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Gameboard.Api.Validators
{
public class ChallengeGateValidator: IModelValidator
public class ChallengeGateValidator : IModelValidator
{
private readonly IChallengeGateStore _store;

Expand Down Expand Up @@ -36,29 +36,29 @@ public Task Validate(object model)
private async Task _validate(Entity model)
{
if ((await Exists(model.Id)).Equals(false))
throw new ResourceNotFound();
throw new ResourceNotFound<ChallengeGate>(model.Id);

await Task.CompletedTask;
}

private async Task _validate(NewChallengeGate model)
{
if ((await GameExists(model.GameId)).Equals(false))
throw new ResourceNotFound();
throw new ResourceNotFound<Game>(model.GameId);

if ((await SpecExists(model.TargetId)).Equals(false))
throw new ResourceNotFound();
throw new ResourceNotFound<ChallengeSpec>(model.TargetId, "The target spec");

if ((await SpecExists(model.RequiredId)).Equals(false))
throw new ResourceNotFound();
throw new ResourceNotFound<ChallengeSpec>(model.RequiredId, "The required spec");

await Task.CompletedTask;
}

private async Task _validate(ChangedChallengeGate model)
{
if ((await Exists(model.Id)).Equals(false))
throw new ResourceNotFound();
throw new ResourceNotFound<ChallengeGate>(model.Id);

await Task.CompletedTask;
}
Expand Down
Loading

0 comments on commit 0404712

Please sign in to comment.