// // Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License. // using Astral.ApiServer.Models; using Astral.ApiServer.Models.Requests; using Astral.ApiServer.Models.Responses; using Astral.Services.Interfaces; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Astral.ApiServer.Controllers.V1; /// /// User api controller. /// [Route("api/v1/user")] [Consumes("application/json")] [Authorize] public class UserApiController : BaseApiController { private readonly IIdentityProvider _identityProvider; private readonly IUserPresenceService _userPresenceService; /// /// Initializes a new instance of the class. /// /// Instance of . /// Instance of . public UserApiController( IIdentityProvider identityProvider, IUserPresenceService userPresenceService) { _identityProvider = identityProvider; _userPresenceService = userPresenceService; } /// /// Get the user's profile. /// [HttpGet("profile")] public IActionResult GetUserProfile() { var userId = _identityProvider.GetUserId(); var userName = _identityProvider.GetUserName(); return SuccessResult(new UserProfileResponseModel() { User = new UserProfileModel() { AccountId = userId, Username = userName, XmppPassword = string.Empty, DiscourseApiKey = string.Empty, WalletId = Guid.Empty } }); } /// /// Receive a user's heartbeat. /// [Authorize] [HttpPut("heartbeat")] public async Task ReceiveHeartbeat() { await _userPresenceService.HandleHeartbeat(); return SuccessResult(); } /// /// Receive a user's location heartbeat. /// [Authorize] [HttpPut("location")] public async Task ReceiveLocation([FromBody] HeartbeatRootRequestModel heartbeatModel) { return SuccessResult(); } /// /// Receive the user's public key. /// [HttpPut("public_key")] [Authorize] [Consumes("multipart/form-data")] public async Task PutPublicKey() { var cert = HttpContext.Request.Form.Files.GetFile("public_key"); if (cert is null) { return FailureResult(); } await using (var stream = cert.OpenReadStream()) { await _userPresenceService.ConsumePublicKey(stream); } return SuccessResult(); } /// /// Receive the user settings from the client. /// TODO: Investigate this functionality. /// [Consumes("application/json")] [HttpPost("locker")] public IActionResult PostLockerContents() { return SuccessResult(); } /// /// Return user settings to the client. /// TODO: Investigate this functionality. /// [Produces("application/json")] [HttpGet("locker")] public IActionResult GetLockerContents() { var req = Request; return SuccessResult(new object()); } }