using IM_API.Dtos; using IM_API.Interface.Services; using IM_API.Models; using IM_API.VOs.Conversation; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Security.Claims; namespace IM_API.Controllers { [Route("api/[controller]/[action]")] [Authorize] [ApiController] public class ConversationController : ControllerBase { private readonly IConversationService _conversationSerivice; private readonly ILogger _logger; public ConversationController(IConversationService conversationSerivice, ILogger logger) { _conversationSerivice = conversationSerivice; _logger = logger; } [HttpGet] public async Task List() { var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier); var list = await _conversationSerivice.GetConversationsAsync(int.Parse(userIdStr)); var res = new BaseResponse>(list); return Ok(res); } [HttpGet] public async Task Get([FromQuery]int conversationId) { var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier); var conversation = await _conversationSerivice.GetConversationByIdAsync(int.Parse(userIdStr), conversationId); var res = new BaseResponse(conversation); return Ok(res); } [HttpPost] public async Task Clear() { var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier); await _conversationSerivice.ClearConversationsAsync(int.Parse(userIdStr)); return Ok(new BaseResponse()); } [HttpPost] public async Task Delete(int cid) { await _conversationSerivice.DeleteConversationAsync(cid); return Ok(new BaseResponse()); } } }