ui updates, use services
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
@ -6,6 +6,16 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="users.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="users.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BinaryDad.Extensions" Version="21.4.20.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
|
||||
|
@ -4,11 +4,11 @@ using System.Text.RegularExpressions;
|
||||
|
||||
namespace BinaryDad.AacpsBusAlert.Services
|
||||
{
|
||||
public class BusRouteService
|
||||
public class HtmlScrapeBusRouteService : IBusRouteService
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
public BusRouteService(IHttpClientFactory httpClientFactory)
|
||||
public HtmlScrapeBusRouteService(IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
httpClient = httpClientFactory.CreateClient();
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
namespace BinaryDad.AacpsBusAlert.Services
|
||||
{
|
||||
public interface IBusRouteService
|
||||
{
|
||||
Task<ICollection<BusRoute>> GetBusRoutesAsync();
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace BinaryDad.AacpsBusAlert.Services
|
||||
{
|
||||
public interface IUserService
|
||||
{
|
||||
ICollection<User> GetUsers();
|
||||
User GetUser(Guid id);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BinaryDad.AacpsBusAlert.Services
|
||||
{
|
||||
public class JsonUserService : IUserService
|
||||
{
|
||||
public ICollection<User> GetUsers()
|
||||
{
|
||||
var path = Path.Combine(AppContext.BaseDirectory, "users.json");
|
||||
|
||||
var usersJson = File.ReadAllText(path);
|
||||
|
||||
return JsonConvert.DeserializeObject<ICollection<User>>(usersJson);
|
||||
}
|
||||
|
||||
public User GetUser(Guid id)
|
||||
{
|
||||
return GetUsers().First(u => u.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
18
BinaryDad.AacpsBusAlert.Services/users.json
Normal file
18
BinaryDad.AacpsBusAlert.Services/users.json
Normal file
@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"Id": "b43f4f45-0f7b-4976-849d-8ad4b271199c",
|
||||
"Email": "ryan@binarydad.com",
|
||||
"Routes": [
|
||||
{
|
||||
"Id": "bfed1017-be53-42f9-bb46-ddbf27d4270f",
|
||||
"BusNumber": 203,
|
||||
"Label": "Con's bus'"
|
||||
},
|
||||
{
|
||||
"Id": "bfed1017-be53-42f9-bb46-ddbf27d4270f",
|
||||
"BusNumber": 365,
|
||||
"Label": "Cam's bus'"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
Reference in New Issue
Block a user