mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 23:18:56 -07:00
48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using RadicadeServer.DB;
|
|
using RadicadeServer.Extensions;
|
|
using RadicadeServer.RecNet.Enums.Rooms;
|
|
using RadicadeServer.RecNet.Responses;
|
|
using RadicadeServer.RecNet.Rooms;
|
|
using RadicadeServer.Utils;
|
|
|
|
namespace RadicadeServer.API.Rooms.V1
|
|
{
|
|
[Route("api/rooms/v1")]
|
|
public class RoomsV1 : Controller
|
|
{
|
|
RecDBContext db;
|
|
public RoomsV1(RecDBContext context)
|
|
{
|
|
this.db = context;
|
|
}
|
|
|
|
[HttpGet("filters")]
|
|
public async Task<ActionResult<RoomFilters>> GetRoomFilters()
|
|
{
|
|
var dbFilters = await db.ServerConfig.FirstOrDefaultAsync(x => x.Key == "Filters");
|
|
if (dbFilters == null)
|
|
return NotFound();
|
|
|
|
var filters = dbFilters.Value.Split(',', StringSplitOptions.TrimEntries).ToList();
|
|
|
|
return new RoomFilters { PinnedFilters = filters , PopularFilters = filters, TrendingFilters = filters };
|
|
}
|
|
|
|
[HttpPost("verifyRole"), Authorize]
|
|
public async Task<Success?> VerifyRole([FromForm] long roomId, [FromForm] RoleType role, [FromForm] string? context)
|
|
{
|
|
var userId = User.GetUserId();
|
|
|
|
var roomRole = await RoomUtils.VerifyRole((long)userId!, roomId, role);
|
|
|
|
if (!roomRole)
|
|
return new Success(false, "Invalid roles", false);
|
|
else
|
|
return new Success(true, null, null);
|
|
}
|
|
}
|
|
}
|