Add remaining project files
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
using DeluxeBackend.Models;
|
||||
using DeluxeBackend.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using static DeluxeBackend.Enums;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using static DeluxeBackend.Extensions.RoomExtensions;
|
||||
|
||||
namespace DeluxeBackend.Controllers.Rooms
|
||||
{
|
||||
[Route("Rooms")]
|
||||
[ApiController]
|
||||
public class GetController(ILiteDbService db, IJwtService jwt, DiscordBotService discord) : ControllerBase
|
||||
{
|
||||
[HttpGet("rooms")]
|
||||
public async Task<IActionResult> Room([FromQuery(Name = "name"), Required] string roomName, [FromQuery(Name = "include")] RoomDetailsMask include = RoomDetailsMask.None)
|
||||
{
|
||||
Room? room = db.Rooms.Include(x => x.Creator).FindOne(x => x.Name == roomName);
|
||||
if (room == null) return NotFound();
|
||||
|
||||
Account? account = await jwt.GetLogin(User);
|
||||
|
||||
if (room.Accessibility == RoomAccessibility.Private)
|
||||
{
|
||||
if (account == null) return NotFound();
|
||||
|
||||
if (!room.HasRole(account.Id, RoomRoleType.CoOwner))
|
||||
{
|
||||
AccountPresence presence = db.Presences.Include(x => x.Account).Include(x => x.Instance).Include(x => x.Instance!.SubRoom).Include(x => x.Instance!.SubRoom!.Room).Include(x => x.Instance!.SubRoom!.Room!.Creator).FindOne(x => x.Account.Id == account.Id);
|
||||
presence ??= new AccountPresence
|
||||
{
|
||||
Account = account,
|
||||
};
|
||||
bool blockData = true;
|
||||
if (presence.Instance != null)
|
||||
{
|
||||
if (presence.Instance!.SubRoom!.Room!.Id == room.Id)
|
||||
{
|
||||
blockData = false;
|
||||
}
|
||||
}
|
||||
if (blockData) { include &= ~RoomDetailsMask.DataBlob; }
|
||||
}
|
||||
}
|
||||
if (room.Accessibility == RoomAccessibility.Unlisted)
|
||||
{
|
||||
if (account == null) return NotFound();
|
||||
}
|
||||
if (account == null)
|
||||
{
|
||||
include &= ~RoomDetailsMask.DataBlob;
|
||||
}
|
||||
|
||||
return Ok(await room.ToDictionary(discord, db, include));
|
||||
}
|
||||
|
||||
[HttpGet("rooms/{roomId}")]
|
||||
public async Task<IActionResult> RoomById([FromRoute(Name = "roomId"), Required] int roomId, [FromQuery(Name = "include")] RoomDetailsMask include = RoomDetailsMask.None)
|
||||
{
|
||||
Room? room = db.Rooms.Include(x => x.Creator).FindById(roomId);
|
||||
if (room == null) return NotFound();
|
||||
|
||||
Account? account = await jwt.GetLogin(User);
|
||||
|
||||
if (room.Accessibility == RoomAccessibility.Private)
|
||||
{
|
||||
if (account == null) return NotFound();
|
||||
|
||||
if (!room.HasRole(account.Id, RoomRoleType.CoOwner))
|
||||
{
|
||||
AccountPresence presence = db.Presences.Include(x => x.Account).Include(x => x.Instance).Include(x => x.Instance!.SubRoom).Include(x => x.Instance!.SubRoom!.Room).Include(x => x.Instance!.SubRoom!.Room!.Creator).FindOne(x => x.Account.Id == account.Id);
|
||||
presence ??= new AccountPresence
|
||||
{
|
||||
Account = account,
|
||||
};
|
||||
bool blockData = true;
|
||||
if (presence.Instance != null)
|
||||
{
|
||||
if (presence.Instance!.SubRoom!.Room!.Id == room.Id)
|
||||
{
|
||||
blockData = false;
|
||||
}
|
||||
}
|
||||
if (blockData) { include &= ~RoomDetailsMask.DataBlob; }
|
||||
}
|
||||
}
|
||||
if (room.Accessibility == RoomAccessibility.Unlisted)
|
||||
{
|
||||
if (account == null) return NotFound();
|
||||
}
|
||||
if (account == null)
|
||||
{
|
||||
include &= ~RoomDetailsMask.DataBlob;
|
||||
}
|
||||
|
||||
return Ok(await room.ToDictionary(discord, db, include));
|
||||
}
|
||||
|
||||
[HttpGet("rooms/bulk")]
|
||||
public async Task<IActionResult> Bulk([FromQuery(Name = "name")] List<string> roomNames, [FromQuery(Name = "id")] List<long> roomIds)
|
||||
{
|
||||
roomNames ??= [];
|
||||
roomIds ??= [];
|
||||
|
||||
Account? account = await jwt.GetLogin(User);
|
||||
|
||||
var rooms = db.Rooms
|
||||
.Include(x => x.Creator)
|
||||
.FindAll()
|
||||
.Where(x =>
|
||||
roomIds.Contains(x.Id) ||
|
||||
roomNames.Contains(x.Name))
|
||||
.ToList();
|
||||
|
||||
List<Dictionary<string, object>> response = [];
|
||||
|
||||
foreach (var room in rooms)
|
||||
{
|
||||
if (room.Accessibility == RoomAccessibility.Private)
|
||||
{
|
||||
if (account == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (room.Accessibility == RoomAccessibility.Unlisted)
|
||||
{
|
||||
if (account == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
response.Add(await room.ToDictionary(discord, db, RoomDetailsMask.None));
|
||||
}
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user