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 { /// /// Used to modify accounts / profiles in 2017-2019 although gets phased out as time goes on... /// [Route(template: "api/[controller]/v2")] [ApiController] public class PlayersController(FileService fileService) : ControllerBase { /// /// Sets the players displayName /// /// The displayName the player is requesting /// OkResponse [HttpPost(template: "displayName")] public async Task> 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(profileData)!; profile.DisplayName = name; fileService.SetData("profile.json", JsonSerializer.Serialize(profile)); await NotificationController.Notify(profile.Id, PushNotificationId.SubscriptionUpdateProfile, profile); return Ok(OkResponse.Ok()); } } }