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
71 changes: 71 additions & 0 deletions backend/WizardRPG.Api/Controllers/CreatureTamingController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WizardRPG.Api.DTOs.CreatureTaming;
using WizardRPG.Api.Services;

namespace WizardRPG.Api.Controllers;

[ApiController]
[Route("api/[controller]")]
[Authorize]
public class CreatureTamingController : ControllerBase
{
private readonly ICreatureTamingService _creatureTamingService;

public CreatureTamingController(ICreatureTamingService creatureTamingService)
=> _creatureTamingService = creatureTamingService;

private Guid CurrentPlayerId => Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)
?? User.FindFirstValue("sub")
?? throw new UnauthorizedAccessException());

/// <summary>Get all available creature types (catalog).</summary>
[HttpGet("creatures")]
[AllowAnonymous]
public async Task<ActionResult<List<CreatureResponse>>> GetCreatures()
{
var creatures = await _creatureTamingService.GetAllCreaturesAsync();
return Ok(creatures);
}

/// <summary>Get all creatures tamed by the current player.</summary>
[HttpGet("my-creatures")]
public async Task<ActionResult<List<PlayerCreatureResponse>>> GetMyCreatures()
{
var creatures = await _creatureTamingService.GetPlayerCreaturesAsync(CurrentPlayerId);
return Ok(creatures);
}

/// <summary>Explore the wilderness to discover a magical creature. Costs 50 gold.</summary>
[HttpPost("explore")]
public async Task<ActionResult<ExploreResponse>> Explore()
{
var result = await _creatureTamingService.ExploreAsync(CurrentPlayerId);
return Ok(result);
}

/// <summary>Tame a discovered creature and add it to your collection.</summary>
[HttpPost("tame")]
public async Task<ActionResult<PlayerCreatureResponse>> Tame([FromBody] TameCreatureRequest request)
{
var creature = await _creatureTamingService.TameCreatureAsync(CurrentPlayerId, request);
return Created($"api/creaturetaming/my-creatures", creature);
}

/// <summary>Care for a tamed creature: feed, train, or let it rest.</summary>
[HttpPost("care/{creatureId:guid}")]
public async Task<ActionResult<CareResponse>> CareForCreature(Guid creatureId, [FromBody] CareForCreatureRequest request)
{
var result = await _creatureTamingService.CareForCreatureAsync(CurrentPlayerId, creatureId, request);
return Ok(result);
}

/// <summary>Get passive bonuses from all loyal creatures (loyalty > 50).</summary>
[HttpGet("bonuses")]
public async Task<ActionResult<Dictionary<string, int>>> GetBonuses()
{
var bonuses = await _creatureTamingService.GetCreatureBonusesAsync(CurrentPlayerId);
return Ok(bonuses);
}
}
65 changes: 65 additions & 0 deletions backend/WizardRPG.Api/Controllers/DungeonCrawlerController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WizardRPG.Api.DTOs.DungeonCrawler;
using WizardRPG.Api.Services;

namespace WizardRPG.Api.Controllers;

[ApiController]
[Route("api/[controller]")]
[Authorize]
public class DungeonCrawlerController : ControllerBase
{
private readonly IDungeonCrawlerService _dungeonCrawlerService;

public DungeonCrawlerController(IDungeonCrawlerService dungeonCrawlerService) => _dungeonCrawlerService = dungeonCrawlerService;

private Guid CurrentPlayerId => Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)
?? User.FindFirstValue("sub")
?? throw new UnauthorizedAccessException());

/// <summary>Start a new dungeon run.</summary>
[HttpPost("start")]
public async Task<ActionResult<object>> StartRun()
{
var (run, room) = await _dungeonCrawlerService.StartRunAsync(CurrentPlayerId);
return Created($"api/dungeoncrawler/active", new { run, room });
}

/// <summary>Get the active dungeon run and current room.</summary>
[HttpGet("active")]
public async Task<ActionResult<object>> GetActiveRun()
{
var result = await _dungeonCrawlerService.GetActiveRunAsync(CurrentPlayerId);
if (result == null)
return NotFound(new { message = "No active dungeon run." });

var (run, room) = result.Value;
return Ok(new { run, room });
}

/// <summary>Make a choice in the current room.</summary>
[HttpPost("{runId:guid}/action")]
public async Task<ActionResult<DungeonActionResponse>> MakeChoice(Guid runId, [FromBody] DungeonActionRequest request)
{
var response = await _dungeonCrawlerService.MakeChoiceAsync(CurrentPlayerId, runId, request);
return Ok(response);
}

/// <summary>Escape the dungeon with your collected loot.</summary>
[HttpPost("{runId:guid}/escape")]
public async Task<ActionResult<DungeonRunResponse>> Escape(Guid runId)
{
var run = await _dungeonCrawlerService.EscapeAsync(CurrentPlayerId, runId);
return Ok(run);
}

/// <summary>Get dungeon run history.</summary>
[HttpGet("history")]
public async Task<ActionResult<List<DungeonRunResponse>>> GetHistory()
{
var runs = await _dungeonCrawlerService.GetRunHistoryAsync(CurrentPlayerId);
return Ok(runs);
}
}
55 changes: 55 additions & 0 deletions backend/WizardRPG.Api/Controllers/PotionBrewingController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WizardRPG.Api.DTOs.PotionBrewing;
using WizardRPG.Api.Services;

namespace WizardRPG.Api.Controllers;

[ApiController]
[Route("api/[controller]")]
[Authorize]
public class PotionBrewingController : ControllerBase
{
private readonly IPotionBrewingService _potionBrewingService;

public PotionBrewingController(IPotionBrewingService potionBrewingService) => _potionBrewingService = potionBrewingService;

private Guid CurrentPlayerId => Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)
?? User.FindFirstValue("sub")
?? throw new UnauthorizedAccessException());

/// <summary>Get all potion recipes.</summary>
[HttpGet("recipes")]
[AllowAnonymous]
public async Task<ActionResult<List<PotionRecipeResponse>>> GetRecipes()
{
var recipes = await _potionBrewingService.GetRecipesAsync();
return Ok(recipes);
}

/// <summary>Get all available ingredients.</summary>
[HttpGet("ingredients")]
[AllowAnonymous]
public async Task<ActionResult<List<PotionIngredientResponse>>> GetIngredients()
{
var ingredients = await _potionBrewingService.GetIngredientsAsync();
return Ok(ingredients);
}

/// <summary>Attempt to brew a potion.</summary>
[HttpPost("brew")]
public async Task<ActionResult<BrewAttemptResponse>> BrewPotion([FromBody] BrewPotionRequest request)
{
var result = await _potionBrewingService.BrewPotionAsync(CurrentPlayerId, request);
return Created($"api/potionbrewing/history/{result.Id}", result);
}

/// <summary>Get the current player's brew history.</summary>
[HttpGet("history")]
public async Task<ActionResult<List<BrewAttemptResponse>>> GetBrewHistory()
{
var history = await _potionBrewingService.GetPlayerBrewHistoryAsync(CurrentPlayerId);
return Ok(history);
}
}
58 changes: 58 additions & 0 deletions backend/WizardRPG.Api/Controllers/QuizController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WizardRPG.Api.DTOs.Quiz;
using WizardRPG.Api.Models;
using WizardRPG.Api.Services;

namespace WizardRPG.Api.Controllers;

[ApiController]
[Route("api/[controller]")]
[Authorize]
public class QuizController : ControllerBase
{
private readonly IQuizService _quizService;

public QuizController(IQuizService quizService) => _quizService = quizService;

private Guid CurrentPlayerId => Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)
?? User.FindFirstValue("sub")
?? throw new UnauthorizedAccessException());

/// <summary>Get random quiz questions (correct answers not included).</summary>
[HttpGet("questions")]
[AllowAnonymous]
public async Task<ActionResult<List<QuizQuestionResponse>>> GetQuestions(
[FromQuery] int count = 5,
[FromQuery] QuizDifficulty? difficulty = null)
{
var questions = await _quizService.GetRandomQuestionsAsync(count, difficulty);
return Ok(questions);
}

/// <summary>Submit quiz answers and receive results.</summary>
[HttpPost("submit")]
public async Task<ActionResult<QuizResultResponse>> SubmitQuiz([FromBody] SubmitQuizRequest request)
{
var result = await _quizService.SubmitQuizAsync(CurrentPlayerId, request);
return Ok(result);
}

/// <summary>Get the current player's quiz history.</summary>
[HttpGet("history")]
public async Task<ActionResult<List<QuizResultResponse>>> GetHistory()
{
var history = await _quizService.GetQuizHistoryAsync(CurrentPlayerId);
return Ok(history);
}

/// <summary>Get the quiz leaderboard.</summary>
[HttpGet("leaderboard")]
[AllowAnonymous]
public async Task<ActionResult<List<QuizLeaderboardEntry>>> GetLeaderboard([FromQuery] int top = 10)
{
var leaderboard = await _quizService.GetLeaderboardAsync(top);
return Ok(leaderboard);
}
}
63 changes: 63 additions & 0 deletions backend/WizardRPG.Api/Controllers/WhisperingWallsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WizardRPG.Api.DTOs.WhisperingWalls;
using WizardRPG.Api.Services;

namespace WizardRPG.Api.Controllers;

[ApiController]
[Route("api/[controller]")]
[Authorize]
public class WhisperingWallsController : ControllerBase
{
private readonly IWhisperingWallsService _whisperingWallsService;

public WhisperingWallsController(IWhisperingWallsService whisperingWallsService) =>
_whisperingWallsService = whisperingWallsService;

private Guid CurrentPlayerId => Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)
?? User.FindFirstValue("sub")
?? throw new UnauthorizedAccessException());

/// <summary>Get all available story arcs.</summary>
[HttpGet("stories")]
[AllowAnonymous]
public async Task<ActionResult<List<StoryArcResponse>>> GetStoryArcs()
{
var arcs = await _whisperingWallsService.GetStoryArcsAsync();
return Ok(arcs);
}

/// <summary>Start or restart a story arc.</summary>
[HttpPost("start")]
public async Task<ActionResult<StoryChapterResponse>> StartStory([FromQuery] string storyArc)
{
var chapter = await _whisperingWallsService.StartStoryAsync(CurrentPlayerId, storyArc);
return Ok(chapter);
}

/// <summary>Get the current chapter for a story arc.</summary>
[HttpGet("current")]
public async Task<ActionResult<StoryChapterResponse>> GetCurrentChapter([FromQuery] string storyArc)
{
var chapter = await _whisperingWallsService.GetCurrentChapterAsync(CurrentPlayerId, storyArc);
return Ok(chapter);
}

/// <summary>Make a choice in the current chapter.</summary>
[HttpPost("choose")]
public async Task<ActionResult<MakeChoiceResponse>> MakeChoice([FromBody] MakeChoiceRequest request)
{
var result = await _whisperingWallsService.MakeChoiceAsync(CurrentPlayerId, request);
return Ok(result);
}

/// <summary>Get all story progress for the current player.</summary>
[HttpGet("progress")]
public async Task<ActionResult<List<PlayerStoryProgressResponse>>> GetProgress()
{
var progress = await _whisperingWallsService.GetProgressAsync(CurrentPlayerId);
return Ok(progress);
}
}
61 changes: 61 additions & 0 deletions backend/WizardRPG.Api/Controllers/WizardChessController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WizardRPG.Api.DTOs.WizardChess;
using WizardRPG.Api.Services;

namespace WizardRPG.Api.Controllers;

[ApiController]
[Route("api/[controller]")]
[Authorize]
public class WizardChessController : ControllerBase
{
private readonly IWizardChessService _chessService;

public WizardChessController(IWizardChessService chessService) => _chessService = chessService;

private Guid CurrentPlayerId => Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)
?? User.FindFirstValue("sub")
?? throw new UnauthorizedAccessException());

/// <summary>Create a new chess match.</summary>
[HttpPost("create")]
public async Task<ActionResult<ChessMatchResponse>> CreateMatch([FromBody] CreateChessMatchRequest request)
{
var match = await _chessService.CreateMatchAsync(CurrentPlayerId, request);
return Created($"api/wizardchess/{match.Id}", match);
}

/// <summary>Get a specific chess match.</summary>
[HttpGet("{matchId:guid}")]
public async Task<ActionResult<ChessMatchResponse>> GetMatch(Guid matchId)
{
var match = await _chessService.GetMatchAsync(matchId);
return Ok(match);
}

/// <summary>Get all matches for the current player.</summary>
[HttpGet("matches")]
public async Task<ActionResult<List<ChessMatchResponse>>> GetMyMatches()
{
var matches = await _chessService.GetPlayerMatchesAsync(CurrentPlayerId);
return Ok(matches);
}

/// <summary>Make a move in a chess match.</summary>
[HttpPost("{matchId:guid}/move")]
public async Task<ActionResult<ChessMoveResponse>> MakeMove(Guid matchId, [FromBody] ChessMoveRequest request)
{
var result = await _chessService.MakeMoveAsync(CurrentPlayerId, matchId, request);
return Ok(result);
}

/// <summary>Forfeit a chess match.</summary>
[HttpPost("{matchId:guid}/forfeit")]
public async Task<ActionResult<ChessMatchResponse>> Forfeit(Guid matchId)
{
var match = await _chessService.ForfeitAsync(CurrentPlayerId, matchId);
return Ok(match);
}
}
Loading