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