using Microsoft.AspNetCore.Mvc; namespace ChatRoom; /// /// Service. Class must be marked public, otherwise ASP.NET core runtime will not find it. /// /// Look into FromXXX attributes if you need to map inputs to custom parts of HTTP request. /// [Route("chatRoom")] [ApiController] public class ChatRoomController : ControllerBase { /// /// Service logic. This is created in Server.StartServer() and received through DI in constructor. /// private readonly ChatRoomLogic logic; /// /// Constructor /// /// Logic to use. This will get passed through DI. public ChatRoomController(ChatRoomLogic logic) { this.logic = logic; } /// /// Register client with a name /// /// Name of client, can be duplicate between clients /// Client ID [HttpPost("/registerClient")] public ActionResult RegisterClient(string name) { return logic.RegisterClient(name); } /// /// Get number of strikes a participant has /// /// Client ID /// Number of strikes [HttpGet("/getStrikes")] public ActionResult GetStrikes(int clientId) { return logic.GetStrikes(clientId); } /// /// Get timestamp until when the client is blocked /// /// Client ID /// Optional datetime object [HttpGet("/getBlockedUntil")] public ActionResult GetBlockedUntil(int clientId) { return logic.GetBlockedUntil(clientId); } /// /// Send a message, will be given to a moderator to be approved /// /// Client ID /// Message contents /// Does this message need to be censored? /// Was sending successful, can fail if user is blocked [HttpPost("/sendMessage")] public ActionResult SendMessage(int clientId, string contents, bool needsToBeCensored) { return logic.SendMessage(clientId, contents, needsToBeCensored); } /// /// Get the next message which hasn't been approved or rejected /// /// Message object. Returns null if there is no message [HttpGet("/getNewMessage")] public ActionResult GetNewMessage() { return logic.GetNewMessage(); } /// /// Reject a message /// /// Message ID [HttpPost("/rejectMessage")] public void RejectMessage(int messageId) { logic.RejectMessage(messageId); } /// /// Approve a message /// /// Message ID [HttpPost("/approveMessage")] public void ApproveMessage(int messageId) { logic.ApproveMessage(messageId); } }