60 lines
2.4 KiB
C#
60 lines
2.4 KiB
C#
|
|
using System.Net.Http;
|
||
|
|
using System.Net.Http.Json;
|
||
|
|
using EngineeringSync.Domain.Entities;
|
||
|
|
|
||
|
|
namespace EngineeringSync.TrayApp.Services;
|
||
|
|
|
||
|
|
public class ApiClient(HttpClient http)
|
||
|
|
{
|
||
|
|
private const string Base = "http://localhost:5050/api";
|
||
|
|
|
||
|
|
public Task<List<ProjectConfig>?> GetProjectsAsync() =>
|
||
|
|
http.GetFromJsonAsync<List<ProjectConfig>>($"{Base}/projects");
|
||
|
|
|
||
|
|
public Task<List<PendingChange>?> GetChangesAsync(Guid projectId) =>
|
||
|
|
http.GetFromJsonAsync<List<PendingChange>>($"{Base}/changes/{projectId}");
|
||
|
|
|
||
|
|
public Task<List<ScanResultDto>?> ScanFoldersAsync(string engineeringPath, string simulationPath, string fileExtensions) =>
|
||
|
|
http.GetFromJsonAsync<List<ScanResultDto>>($"{Base}/projects/scan?engineeringPath={Uri.EscapeDataString(engineeringPath)}&simulationPath={Uri.EscapeDataString(simulationPath)}&fileExtensions={Uri.EscapeDataString(fileExtensions)}");
|
||
|
|
|
||
|
|
public async Task CreateProjectAsync(CreateProjectDto dto)
|
||
|
|
{
|
||
|
|
var resp = await http.PostAsJsonAsync($"{Base}/projects", dto);
|
||
|
|
resp.EnsureSuccessStatusCode();
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task UpdateProjectAsync(Guid id, UpdateProjectDto dto)
|
||
|
|
{
|
||
|
|
var resp = await http.PutAsJsonAsync($"{Base}/projects/{id}", dto);
|
||
|
|
resp.EnsureSuccessStatusCode();
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task DeleteProjectAsync(Guid id)
|
||
|
|
{
|
||
|
|
var resp = await http.DeleteAsync($"{Base}/projects/{id}");
|
||
|
|
resp.EnsureSuccessStatusCode();
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task SyncChangesAsync(List<Guid> ids)
|
||
|
|
{
|
||
|
|
var resp = await http.PostAsJsonAsync($"{Base}/sync", new { ChangeIds = ids });
|
||
|
|
resp.EnsureSuccessStatusCode();
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task IgnoreChangesAsync(List<Guid> ids)
|
||
|
|
{
|
||
|
|
var resp = await http.PostAsJsonAsync($"{Base}/ignore", new { ChangeIds = ids });
|
||
|
|
resp.EnsureSuccessStatusCode();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public record CreateProjectDto(string Name, string EngineeringPath, string SimulationPath,
|
||
|
|
string FileExtensions, bool IsActive = true, bool BackupEnabled = true,
|
||
|
|
string? BackupPath = null, int MaxBackupsPerFile = 0);
|
||
|
|
|
||
|
|
public record UpdateProjectDto(string Name, string EngineeringPath, string SimulationPath,
|
||
|
|
string FileExtensions, bool IsActive, bool BackupEnabled = true,
|
||
|
|
string? BackupPath = null, int MaxBackupsPerFile = 0);
|
||
|
|
|
||
|
|
public record ScanResultDto(string RelativePath, string ChangeType, long Size, DateTime LastModified);
|