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

41 lines
1.5 KiB
C#

using Microsoft.AspNetCore.Mvc;
using RecRoomArchive.Controllers.API.Notification;
using RecRoomArchive.Models.API.Notification;
using RecRoomArchive.Models.API.Players;
using RecRoomArchive.Models.Common;
using RecRoomArchive.Services;
using System.Text.Json;
namespace RecRoomArchive.Controllers.API.Players.V2
{
/// <summary>
/// Used to modify accounts / profiles in 2017-2019 although gets phased out as time goes on...
/// </summary>
[Route(template: "api/[controller]/v2")]
[ApiController]
public class PlayersController(FileService fileService) : ControllerBase
{
/// <summary>
/// Sets the players displayName
/// </summary>
/// <param name="name">The displayName the player is requesting</param>
/// <returns>OkResponse</returns>
[HttpPost(template: "displayName")]
public async Task<ActionResult<OkResponse>> SetDisplayName([FromForm(Name = "Name")] string name)
{
var profileData = fileService.GetData("profile.json");
if (profileData == null)
return BadRequest("Profile is not populated");
var profile = JsonSerializer.Deserialize<BaseProfile>(profileData)!;
profile.DisplayName = name;
fileService.SetData("profile.json", JsonSerializer.Serialize(profile));
await NotificationController.Notify(profile.Id, PushNotificationId.SubscriptionUpdateProfile, profile);
return Ok(OkResponse.Ok());
}
}
}