...
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
using Common.Dtos.Conversation;
|
||||
using Common.Enums;
|
||||
using Hushian.Application.Constants;
|
||||
using Hushian.Application.Services;
|
||||
using Hushian.Domain.Entites;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Hushian.WebApi.Controllers.v1
|
||||
{
|
||||
[Route("api/v1/[controller]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class ConversationController : ControllerBase
|
||||
{
|
||||
private readonly ConversationService _conversationService;
|
||||
private readonly CompanyService _companyService;
|
||||
private readonly ExperService _experService;
|
||||
public ConversationController(ConversationService conversationService, CompanyService companyService)
|
||||
{
|
||||
_conversationService = conversationService;
|
||||
_companyService = companyService;
|
||||
}
|
||||
|
||||
[HttpGet("MyConversation")]
|
||||
[Authorize(Roles = "Company,Exper")]
|
||||
public async Task<ActionResult> MyConversation(ConversationStatus status)
|
||||
{
|
||||
if (User.IsInRole("Exper"))
|
||||
{
|
||||
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int ExperID = Convert.ToInt32(strExperID);
|
||||
var response = await _conversationService.GetConversationByExperID(ExperID, status);
|
||||
return Ok(response);
|
||||
}
|
||||
else if (User.IsInRole("Company"))
|
||||
{
|
||||
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int CompanyID = Convert.ToInt32(strCompanyID);
|
||||
|
||||
var response = await _conversationService.GetConversationByCompanyID(CompanyID, status);
|
||||
return Ok(response);
|
||||
}
|
||||
return Forbid();
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("ConversationAwaitingOurResponse")]
|
||||
[Authorize(Roles = "Company,Exper")]
|
||||
public async Task<ActionResult> ConversationAwaitingOurResponse()
|
||||
{
|
||||
int CompanyID = 0;
|
||||
if (User.IsInRole("Exper"))
|
||||
{
|
||||
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int ExperID = Convert.ToInt32(strExperID);
|
||||
|
||||
CompanyID = await _experService.GetCompanyIDExper(ExperID);
|
||||
}
|
||||
else if (User.IsInRole("Company"))
|
||||
{
|
||||
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
CompanyID = Convert.ToInt32(strCompanyID);
|
||||
}
|
||||
|
||||
var response = await _conversationService.ConversationAwaitingOurResponse(CompanyID);
|
||||
return Ok(response);
|
||||
}
|
||||
[HttpGet("ConversationItems/{ConversationID}")]
|
||||
[Authorize(Roles = "Company,Exper,User")]
|
||||
public async Task<ActionResult> GetConversationItems(int ConversationID)
|
||||
{
|
||||
return Ok(await _conversationService.GetConversationItems(ConversationID));
|
||||
}
|
||||
[HttpPost("NewConversationFromCurrentUser")]
|
||||
public async Task<ActionResult> NewConversationFromCurrentUser(ADD_ConversationDto conversation)
|
||||
{
|
||||
string UserID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
var response = await _conversationService.NewConversation(conversation);
|
||||
return response.Success ? Ok(response.Value)
|
||||
: BadRequest(response.Errors);
|
||||
}
|
||||
[HttpPost("ADDConversationResponse")]
|
||||
[Authorize(Roles = "Company,User,Exper")]
|
||||
public async Task<ActionResult> ADDConversationResponse([FromBody] ADD_ConversationResponseDto ConversationItem)
|
||||
{
|
||||
|
||||
int? ExperID = null;
|
||||
if (User.IsInRole("Exper"))
|
||||
{
|
||||
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
ExperID = Convert.ToInt32(strExperID);
|
||||
ConversationItem.Type = ConversationType.EU;
|
||||
}
|
||||
|
||||
else if (User.IsInRole("User"))
|
||||
{
|
||||
ConversationItem.Type = ConversationType.UE;
|
||||
}
|
||||
else if (User.IsInRole("Company"))
|
||||
{
|
||||
ConversationItem.Type = ConversationType.CU;
|
||||
|
||||
}
|
||||
else return Unauthorized();
|
||||
|
||||
|
||||
var Response = await _conversationService.NewConversationResponse(ConversationItem, ExperID);
|
||||
return Response.Success ? Ok(Response.Value)
|
||||
: BadRequest(Response.Errors);
|
||||
}
|
||||
[HttpPut("MarkAsReadConversationItem/{ConversationItemID}")]
|
||||
[Authorize(Roles = "Company,User,Exper")]
|
||||
public async Task<ActionResult> MarkAsReadConversationItem(int ConversationItemID)
|
||||
{
|
||||
int? ExperID = null;
|
||||
ConversationType Type = ConversationType.UE;
|
||||
if (User.IsInRole("Exper"))
|
||||
{
|
||||
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
ExperID = Convert.ToInt32(strExperID);
|
||||
Type = ConversationType.EU;
|
||||
}
|
||||
|
||||
else if (User.IsInRole("User"))
|
||||
{
|
||||
Type = ConversationType.UE;
|
||||
}
|
||||
else if (User.IsInRole("Company"))
|
||||
{
|
||||
Type = ConversationType.CU;
|
||||
}
|
||||
else return Unauthorized();
|
||||
|
||||
return await _conversationService.MarkAsReadConversationItem(ConversationItemID, Type, ExperID) ? NoContent()
|
||||
: BadRequest(new List<string>() { "خطا در بروزرسانی گفتگو" });
|
||||
|
||||
}
|
||||
[HttpGet("ConversationIsFinish/{ConversationID}")]
|
||||
[Authorize(Roles = "Company,Exper")]
|
||||
public async Task<ActionResult> ConversationIsFinish(int ConversationID)
|
||||
{
|
||||
return await _conversationService.FinishConversation(ConversationID) ? NoContent()
|
||||
: BadRequest(new List<string> { "خطا در بروزرسانی وضعیت" });
|
||||
}
|
||||
[HttpGet("CountQueueCompany/{CompanyID}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<int>> GetCountQueueCompany(int CompanyID, int GroupID)
|
||||
{
|
||||
return Ok(await _conversationService.GetCountQueueCompany(CompanyID, GroupID));
|
||||
}
|
||||
[HttpGet("ConversationFromUserSide/{CompanyID}")]
|
||||
[Authorize(Roles = "User")]
|
||||
public async Task<ActionResult> GetConversationFromUserSide(int CompanyID)
|
||||
{
|
||||
string strUserID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int UserID = Convert.ToInt32(strUserID);
|
||||
var response = await _conversationService.GEtConversation(CompanyID, UserID);
|
||||
return Ok(response) ;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user