Files
blazor-cms/Features/Thirdparty/Patient/PatientService.cs
T
2026-07-21 13:52:43 +07:00

86 lines
3.4 KiB
C#

using Indotalent.ConfigBackEnd.Interfaces;
using Indotalent.ConfigFrontEnd.Common;
using Indotalent.Features.Thirdparty.Patient.Cqrs;
using Indotalent.Infrastructure.Authentication.Identity;
using Indotalent.Shared.Models;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using RestSharp;
namespace Indotalent.Features.Thirdparty.Patient;
public class PatientService : BaseService
{
private readonly RestClient _client;
public PatientService(
IHttpClientFactory clientFactory,
NavigationManager nav,
ISnackbar snackbar,
ICurrentUserService currentUserService,
TokenProvider tokenProvider)
: base(clientFactory, nav, snackbar, currentUserService, tokenProvider)
{
_client = new RestClient(nav.BaseUri);
}
public async Task<ApiResponse<List<GetPatientListResponse>>?> GetPatientListAsync()
{
var request = new RestRequest("api/patient", Method.Get);
return await ExecuteWithResponseAsync<List<GetPatientListResponse>>(_client, request);
}
public async Task<ApiResponse<GetPatientByIdResponse>?> GetPatientByIdAsync(string id)
{
var request = new RestRequest($"api/patient/{id}", Method.Get);
return await ExecuteWithResponseAsync<GetPatientByIdResponse>(_client, request);
}
public async Task<ApiResponse<LookupPatientResponse>?> GetPatientLookupAsync()
{
var request = new RestRequest("api/patient/lookup", Method.Get);
return await ExecuteWithResponseAsync<LookupPatientResponse>(_client, request);
}
public async Task<ApiResponse<CreatePatientResponse>?> CreatePatientAsync(CreatePatientRequest data)
{
var request = new RestRequest("api/patient", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<CreatePatientResponse>(_client, request);
}
public async Task<bool> DeletePatientByIdAsync(string id)
{
var request = new RestRequest($"api/patient/delete/{id}", Method.Post);
var response = await ExecuteWithResponseAsync<object>(_client, request);
return response?.IsSuccess ?? false;
}
public async Task<ApiResponse<UpdatePatientResponse>?> UpdatePatientAsync(UpdatePatientRequest data)
{
var request = new RestRequest("api/patient/update", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<UpdatePatientResponse>(_client, request);
}
public async Task<ApiResponse<CreatePatientContactResponse>?> CreatePatientContactAsync(CreatePatientContactRequest data)
{
var request = new RestRequest("api/patient/patient-contact", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<CreatePatientContactResponse>(_client, request);
}
public async Task<ApiResponse<UpdatePatientContactResponse>?> UpdatePatientContactAsync(UpdatePatientContactRequest data)
{
var request = new RestRequest("api/patient/patient-contact/update", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<UpdatePatientContactResponse>(_client, request);
}
public async Task<bool> DeletePatientContactAsync(string id)
{
var request = new RestRequest($"api/patient/patient-contact/delete/{id}", Method.Post);
var response = await ExecuteWithResponseAsync<object>(_client, request);
return response?.IsSuccess ?? false;
}
}