2026-07-23 13:54:06 -07:00

46 lines
1.5 KiB
C#

using qtc_api.Services.RoomService;
namespace qtc_api.Controllers
{
[Route("api/rooms")]
[ApiController]
public class RoomsController : ControllerBase
{
public IRoomService _roomService;
public IHubContext<ChatHub> _hubContext;
public RoomsController(IRoomService roomService, IHubContext<ChatHub> hubContext)
{
_roomService = roomService;
_hubContext = hubContext;
}
[HttpPost("create-room")]
[Authorize(Roles = "Admin")]
public async Task<ActionResult<ServiceResponse<Room>>> CreateRoom(string userId, RoomDto request)
{
var response = await _roomService.AddRoom(userId, request);
await _hubContext.Clients.All.SendAsync("RefreshRoomList");
return Ok(response);
}
[HttpDelete("delete-room")]
[Authorize(Roles = "Admin")]
public async Task<ActionResult<ServiceResponse<Room>>> DeleteRoom(string roomId)
{
var response = await _roomService.DeleteRoom(roomId);
await _hubContext.Clients.Group(roomId).SendAsync("RoomDeleted");
await _hubContext.Clients.All.SendAsync("RefreshRoomList");
return Ok(response);
}
[HttpGet("get-all-rooms")]
[Authorize]
public async Task<ActionResult<ServiceResponse<List<Room>>>> GetAllRooms()
{
var rooms = await _roomService.GetAllRooms();
return Ok(rooms);
}
}
}