48 lines
1.5 KiB
C#

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using qtc_api.Hubs;
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("cf", "rr");
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.All.SendAsync("cf", "rr");
return Ok(response);
}
[HttpGet("get-all-rooms")]
[Authorize]
public async Task<ActionResult<ServiceResponse<List<Room>>>> GetAllRooms()
{
var rooms = await _roomService.GetAllRooms();
return Ok(rooms);
}
}
}