Files
RRAC/RecRoomArchive/Controllers/API/Players/PlayersController.cs
T
2026-02-27 19:30:49 -08:00

81 lines
3.0 KiB
C#

using Microsoft.AspNetCore.Mvc;
using RecRoomArchive.Models.API.Players;
using RecRoomArchive.Services;
using System.ComponentModel.DataAnnotations;
namespace RecRoomArchive.Controllers.API.Players
{
/// <summary>
/// Used in August 2016 RecNet
/// </summary>
[Route(template: "api/[controller]")]
[ApiController]
public class PlayersController(AccountService accountService) : ControllerBase
{
/// <summary>
/// Returns the profile tied to a SteamID (If it exists)
/// </summary>
/// <param name="steamId">The SteamID of the player we are trying to get the profile of</param>
/// <returns>The profile of the player, if it exists</returns>
[HttpGet]
public async Task<ActionResult<AugustProfile>> GetProfile([Required, FromQuery] ulong steamId)
{
var baseProfile = accountService.GetSelfAccount();
if (baseProfile == null)
return NotFound();
var profile = new AugustProfile(baseProfile)
{
SteamID = steamId
};
return profile;
}
/// <summary>
/// Creates a profile and links it to a SteamID if the player does not already exist
/// </summary>
/// <param name="steamId">The SteamID of the player that we are creating a profile for</param>
/// <param name="username">The Steam username of the player that we are creating a profile for</param>
/// <returns>A new AugustProfile</returns>
[HttpPost]
public async Task<ActionResult<AugustProfile>> CreateProfile(
[Required, FromForm(Name = "SteamID")] ulong steamId,
[Required, FromForm(Name = "Name")] string username)
{
if (!accountService.AccountExists())
{
accountService.CreateAccount(username);
}
var baseProfile = accountService.GetSelfAccount();
if (baseProfile == null)
return NotFound();
var profile = new AugustProfile(baseProfile)
{
SteamID = steamId
};
return profile;
}
/// <summary>
/// Stores data related to the player onto the server
/// </summary>
/// <param name="profileId">The Id of the Profile we are storing data for</param>
/// <param name="model">The data the client posts...it happens to be an entire profile but we can take only the data we need :)</param>
/// <returns>A successful response, likely will just return the updated profile</returns>
[HttpPut(template: "{profileId:long}")]
public async Task<ActionResult<AugustProfile>> UpdateProfile([Required] ulong profileId, [FromBody] AugustProfile model)
{
var baseProfile = accountService.GetSelfAccount();
if (baseProfile == null)
return NotFound();
var profile = new AugustProfile(baseProfile);
return profile;
}
}
}