public async Task <HuntViewModel> GetHunt([FromQuery] string huntName, [FromQuery] int?huntId) { if (string.IsNullOrWhiteSpace(huntName) && !huntId.HasValue) { throw new ArgumentException("You must use either the hunt name or id"); } Hunt hunt; if (huntId.HasValue) { Logger.LogDebug($"Checking hunt by id: {huntId}"); hunt = await HuntService.GetHunt(huntId.Value); if (hunt == null) { throw new ArgumentException($"No hunt could be found with id {huntId}"); } } else { Logger.LogDebug($"Checking for hunt with name {huntName}"); hunt = await HuntService.GetHunt(huntName); if (hunt == null) { throw new ArgumentException($"No hunt could be found with the name {huntName}"); } } return(Mapper.Map <HuntViewModel>(hunt)); }
public HuntServiceTests() { Mapper = A.Fake <IMapper>(); Logger = A.Dummy <ILogger <HuntService> >(); HuntRepository = A.Fake <IRepository <Data.Hunt> >(); HuntStepRepository = A.Fake <IRepository <Data.HuntStep> >(); HuntStepLinkRepository = A.Fake <IRepository <Data.HuntStepLink> >(); Service = new HuntService(HuntRepository, HuntStepRepository, HuntStepLinkRepository, Mapper, Logger); }
public async Task <IActionResult> GetHunts() { var hunts = await HuntService.GetHunts(); if (hunts != null && hunts.Any()) { var viewModels = hunts.Select(Mapper.Map <HuntViewModel>); return(Json(viewModels)); } return(NoContent()); }
public async Task <IActionResult> GetFirstStep([FromRoute] int id) { var step = await HuntService.GetFirstStep(id); if (step == null) { return(StatusCode(StatusCodes.Status204NoContent, "No steps found")); } var mapped = Mapper.Map <HuntStepViewModel>(step); return(Json(mapped)); }
public async Task <IActionResult> SubmitResponse([FromRoute] int id, [FromBody] HuntStepResponse response) { var next = await HuntService.CheckResponse(id, response.Response); if (next == null) { return(BadRequest("That response was incorrect")); } var mapped = Mapper.Map <HuntStepViewModel>(next); var possibleNextSteps = await HuntService.GetNext(next.HuntStepId); mapped.IsFinished = possibleNextSteps == null || !possibleNextSteps.Any(); return(Json(mapped)); }