Files
Hushian/Presentation/HushianWebApp/Service/ChatService.cs

129 lines
5.0 KiB
C#
Raw Normal View History

2025-07-28 17:41:14 +03:30
using Common.Dtos.Conversation;
using Common.Enums;
using System.Net.Http.Json;
namespace HushianWebApp.Service
{
public class ChatService
{
private readonly BaseController _baseController;
const string BaseRoute = "v1/Chat/";
2025-07-29 17:07:37 +03:30
public ChatService(BaseController baseController)
{
_baseController = baseController;
}
2025-07-28 17:41:14 +03:30
//Inbox1
public async Task<List<ChatItemDto>> ChatAwaitingOurResponse()
{
var response = await _baseController.Get($"{BaseRoute}ChatsAwaitingOurResponse");
if (response.IsSuccessStatusCode)
return await response.Content.ReadFromJsonAsync<List<ChatItemDto>>();
return new();
}
//Inbox2
public async Task<List<ChatItemDto>> MyChatsIsInProgress()
{
var response = await _baseController.Post($"{BaseRoute}MyChats", ConversationStatus.InProgress);
if (response.IsSuccessStatusCode)
return await response.Content.ReadFromJsonAsync<List<ChatItemDto>>();
return new();
}
//Inbox3
public async Task<List<ChatItemDto>> MyChatsIsFinished()
{
var response = await _baseController.Post($"{BaseRoute}MyChats", ConversationStatus.Finished);
if (response.IsSuccessStatusCode)
return await response.Content.ReadFromJsonAsync<List<ChatItemDto>>();
return new();
}
public async Task<ChatItemDto> NewChatFromCurrentUser(ADD_ConversationDto conversation)
{
var response = await _baseController.Post($"{BaseRoute}NewChatFromCurrentUser", conversation);
if (response.IsSuccessStatusCode)
return await response.Content.ReadFromJsonAsync<ChatItemDto>();
return null;
}
public async Task<ChatItemResponseDto?> ADDChatResponse(int ConversationID, string text, ConversationType type)
{
var response = await _baseController.Post($"{BaseRoute}ADDChatResponse", new ADD_ConversationResponseDto()
{
ConversationID = ConversationID,
Text = text,
Type = type
});
if (response.IsSuccessStatusCode)
return await response.Content.ReadFromJsonAsync<ChatItemResponseDto>();
return null;
}
2025-08-03 23:01:44 +03:30
2025-08-09 18:55:06 +03:30
// Send chat response with optional file attachment (e.g., image)
public async Task<ChatItemResponseDto?> ADDChatResponse(int conversationID, string text, ConversationType type,
string? fileName, string? fileType, byte[]? fileContent)
{
var response = await _baseController.Post($"{BaseRoute}ADDChatResponse", new ADD_ConversationResponseDto()
{
ConversationID = conversationID,
Text = text,
Type = type,
FileName = fileName,
FileType = fileType,
FileContent = fileContent
});
if (response.IsSuccessStatusCode)
return await response.Content.ReadFromJsonAsync<ChatItemResponseDto>();
return null;
}
2025-08-03 17:22:49 +03:30
public async Task<bool> OpenChat(int ChatID)
{
var response = await _baseController.Put($"{BaseRoute}OpenChat/{ChatID}");
return response.IsSuccessStatusCode;
}
2025-07-29 00:00:16 +03:30
public async Task<bool> ChatIsFinish(int ChatID)
{
var response = await _baseController.Put($"{BaseRoute}ChatIsFinish/{ChatID}");
2025-08-03 17:22:49 +03:30
return response.IsSuccessStatusCode;
}
2025-08-03 23:41:54 +03:30
public async Task<bool> Attachedto(int toExperID, int ChatID)
{
var response = await _baseController.Put($"{BaseRoute}Attached-to/{toExperID}/{ChatID}");
return response.IsSuccessStatusCode;
}
2025-08-03 17:22:49 +03:30
public async Task<bool> ChatIsFinishFromUser(int ChatID)
{
var response = await _baseController.Put($"{BaseRoute}ChatIsFinishFromUser/{ChatID}");
2025-07-29 00:00:16 +03:30
return response.IsSuccessStatusCode;
}
2025-08-03 23:01:44 +03:30
2025-07-29 17:07:37 +03:30
public async Task<bool> MarkAsReadChatItemAsync(int ID)
{
var response = await _baseController.Put($"{BaseRoute}MarkAsReadChatItem/{ID}");
return response.IsSuccessStatusCode;
}
2025-07-30 23:49:51 +03:30
public async Task<ChatItemDto?> GetLastOpenChatInCompany(int CompanyID)
2025-07-30 16:39:37 +03:30
{
2025-07-30 23:49:51 +03:30
var response = await _baseController.Get($"{BaseRoute}User/LastOpenChatInCompany/{CompanyID}");
if (response.StatusCode==System.Net.HttpStatusCode.OK)
return await response.Content.ReadFromJsonAsync<ChatItemDto>();
return null;
2025-07-30 16:39:37 +03:30
}
2025-08-02 19:00:53 +03:30
public async Task<ChatItemDto?> Getchat(int ChatID)
{
var response = await _baseController.Get($"{BaseRoute}User/Chat/{ChatID}");
if (response.StatusCode == System.Net.HttpStatusCode.OK)
return await response.Content.ReadFromJsonAsync<ChatItemDto>();
return null;
}
2025-07-28 17:41:14 +03:30
}
}