Initial commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System.Net.Http.Json;
|
||||
using RobotNet10.RobotApp.Shared.DockStation;
|
||||
|
||||
namespace RobotNet10.RobotApp.Client.Services;
|
||||
|
||||
public class DockStationApiService(HttpClient httpClient)
|
||||
{
|
||||
private const string BaseUrl = "api/dock-station-config";
|
||||
|
||||
public async Task<List<DockStationConfigSummaryDto>> GetAllAsync()
|
||||
=> await httpClient.GetFromJsonAsync<List<DockStationConfigSummaryDto>>(BaseUrl) ?? [];
|
||||
|
||||
public async Task<DockStationConfigDto?> GetByIdAsync(Guid id)
|
||||
=> await httpClient.GetFromJsonAsync<DockStationConfigDto>($"{BaseUrl}/{id}");
|
||||
|
||||
public async Task<DockStationConfigDto> CreateAsync(CreateDockStationConfigRequest request)
|
||||
{
|
||||
var response = await httpClient.PostAsJsonAsync(BaseUrl, request);
|
||||
response.EnsureSuccessStatusCode();
|
||||
return await response.Content.ReadFromJsonAsync<DockStationConfigDto>()
|
||||
?? throw new InvalidOperationException("Failed to deserialize created dock station config.");
|
||||
}
|
||||
|
||||
public async Task<DockStationConfigDto> UpdateAsync(Guid id, UpdateDockStationConfigRequest request)
|
||||
{
|
||||
var response = await httpClient.PutAsJsonAsync($"{BaseUrl}/{id}", request);
|
||||
response.EnsureSuccessStatusCode();
|
||||
return await response.Content.ReadFromJsonAsync<DockStationConfigDto>()
|
||||
?? throw new InvalidOperationException("Failed to deserialize updated dock station config.");
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(Guid id)
|
||||
{
|
||||
var response = await httpClient.DeleteAsync($"{BaseUrl}/{id}");
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user