mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-26 07:28:45 -07:00
0779aa8439
- Implemented ProgressionEventsController to handle progression event retrieval and active events. - Created RoomConsumablesController for listing and purchasing room consumables. - Developed RoomCurrenciesController for managing room currencies, including creation, updates, and balance retrieval. - Added RoomEarningsDistributionsController to fetch earnings distribution data for rooms. - Introduced ScreenShareReportsController for reporting screen share incidents. - Established SubscriptionSeasonsController to provide current subscription season details and rewards. - Launched UgcPurchasablesController for managing user-generated content purchasables, including bulk operations. - Added new data entities for customization and room economy, including custom avatar items, room currencies, and UGC purchasables.
84 lines
2.9 KiB
C#
84 lines
2.9 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using DorkNet.Models.Players;
|
|
using DorkNet.Server.Auth;
|
|
using DorkNet.Server.Services;
|
|
|
|
namespace DorkNet.Server.Controllers.API.Players.V2;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]/v2")]
|
|
[Authorize]
|
|
public class PlayersController(PlayerService playerService, NotificationService notificationService) : ControllerBase
|
|
{
|
|
private long CurrentPlayerId => this.RequireCurrentPlayerId();
|
|
|
|
[HttpGet("me")]
|
|
public async Task<ActionResult<PlayerProfile>> GetSelf()
|
|
{
|
|
var player = await playerService.GetByIdAsync(CurrentPlayerId);
|
|
if (player is null) return NotFound();
|
|
return Ok(PlayerService.ToProfile(player));
|
|
}
|
|
|
|
[HttpGet("/api/players/v4/current/contact")]
|
|
public async Task<IActionResult> CurrentContact()
|
|
{
|
|
var player = await playerService.GetByIdAsync(CurrentPlayerId);
|
|
if (player is null) return NotFound();
|
|
return Ok(new
|
|
{
|
|
AccountId = (int)player.Id,
|
|
Email = player.Email ?? string.Empty,
|
|
Phone = player.Phone ?? string.Empty,
|
|
CanReceiveInvites = player.CanReceiveInvites,
|
|
});
|
|
}
|
|
|
|
[HttpGet("{id:long}")]
|
|
public async Task<ActionResult<PlayerProfile>> GetById(long id)
|
|
{
|
|
var player = await playerService.GetByIdAsync(id);
|
|
if (player is null) return NotFound();
|
|
return Ok(PlayerService.ToProfile(player));
|
|
}
|
|
|
|
[HttpGet("search")]
|
|
public async Task<ActionResult<List<PlayerProfile>>> Search([FromQuery] string query)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(query)) return Ok(new List<PlayerProfile>());
|
|
var results = await playerService.SearchAsync(query);
|
|
return Ok(results.Select(PlayerService.ToProfile).ToList());
|
|
}
|
|
|
|
[HttpPost("displayName")]
|
|
public async Task<ActionResult<PlayerProfile>> UpdateDisplayName([FromForm] string? DisplayName)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(DisplayName))
|
|
return BadRequest("DisplayName is required");
|
|
|
|
var updated = await playerService.UpdateDisplayNameAsync(CurrentPlayerId, DisplayName);
|
|
if (!updated) return NotFound();
|
|
|
|
var player = await playerService.GetByIdAsync(CurrentPlayerId);
|
|
await notificationService.AccountChanged(player!);
|
|
return Ok(PlayerService.ToProfile(player!));
|
|
}
|
|
|
|
[HttpPut("{id:long}")]
|
|
public async Task<ActionResult<PlayerProfile>> UpdateProfile(long id, [FromBody] UpdateProfileRequest req)
|
|
{
|
|
if (id != CurrentPlayerId) return Forbid();
|
|
|
|
if (req.DisplayName is not null)
|
|
await playerService.UpdateDisplayNameAsync(id, req.DisplayName);
|
|
|
|
if (req.Bio is not null)
|
|
await playerService.UpdateBioAsync(id, req.Bio);
|
|
|
|
var player = await playerService.GetByIdAsync(id);
|
|
await notificationService.AccountChanged(player!);
|
|
return Ok(PlayerService.ToProfile(player!));
|
|
}
|
|
}
|