using Microsoft.AspNetCore.Mvc; using RecRoomArchive.Controllers.API.Notification; using RecRoomArchive.Models.API.Notification; using RecRoomArchive.Models.API.Players; using RecRoomArchive.Services; using System.Text.Json; namespace RecRoomArchive.Controllers.API.Images.V2 { [Route("api/[controller]/v2")] [ApiController] public class ImagesController(FileService fileService, ImageService imageService) : ControllerBase { [HttpPost(template: "profile")] public async Task SetProfileImage(IFormFile image) { using var stream = image.OpenReadStream(); var imageName = await imageService.SaveImageAsync(stream); var profileData = fileService.GetData("profile.json"); if (profileData == null) return BadRequest("Profile is not populated"); var profile = JsonSerializer.Deserialize(profileData)!; profile.ProfileImageName = imageName; fileService.SetData("profile.json", JsonSerializer.Serialize(profile)); await NotificationController.Notify(profile.Id, PushNotificationId.SubscriptionUpdateProfile, profile); return Ok(); } } }