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

60 lines
2.3 KiB
C#

using Indotalent.ConfigBackEnd.Interfaces;
using Indotalent.ConfigFrontEnd.Common;
using Indotalent.Features.Thirdparty.PatientGroup.Cqrs;
using Indotalent.Infrastructure.Authentication.Identity;
using Indotalent.Shared.Models;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using RestSharp;
namespace Indotalent.Features.Thirdparty.PatientGroup;
public class PatientGroupService : BaseService
{
private readonly RestClient _client;
public PatientGroupService(
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<GetPatientGroupListResponse>>?> GetPatientGroupListAsync()
{
var request = new RestRequest("api/patient-group", Method.Get);
return await ExecuteWithResponseAsync<List<GetPatientGroupListResponse>>(_client, request);
}
public async Task<ApiResponse<GetPatientGroupByIdResponse>?> GetPatientGroupByIdAsync(string id)
{
var request = new RestRequest($"api/patient-group/{id}", Method.Get);
return await ExecuteWithResponseAsync<GetPatientGroupByIdResponse>(_client, request);
}
public async Task<ApiResponse<CreatePatientGroupResponse>?> CreatePatientGroupAsync(CreatePatientGroupRequest data)
{
var request = new RestRequest("api/patient-group", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<CreatePatientGroupResponse>(_client, request);
}
public async Task<bool> DeletePatientGroupByIdAsync(string id)
{
var request = new RestRequest($"api/patient-group/delete/{id}", Method.Post);
var response = await ExecuteWithResponseAsync<object>(_client, request);
return response?.IsSuccess ?? false;
}
public async Task<ApiResponse<UpdatePatientGroupResponse>?> UpdatePatientGroupAsync(UpdatePatientGroupRequest data)
{
var request = new RestRequest("api/patient-group/update", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<UpdatePatientGroupResponse>(_client, request);
}
}