2021-05-13 20:03:07 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using TINK.Model.Bike;
|
|
|
|
|
using TINK.Model.Services.CopriApi;
|
2021-06-26 20:57:55 +02:00
|
|
|
|
using TINK.Repository;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
|
|
|
|
namespace TINK.Model.Connector
|
|
|
|
|
{
|
|
|
|
|
/// <summary> Provides query functionality for a logged in user. </summary>
|
|
|
|
|
public class QueryLoggedIn : BaseLoggedIn, IQuery
|
|
|
|
|
{
|
|
|
|
|
/// <summary> Cached copri server. </summary>
|
|
|
|
|
private readonly ICopriServer server;
|
|
|
|
|
|
|
|
|
|
/// <summary>Constructs a copri query object.</summary>
|
|
|
|
|
/// <param name="p_oCopriServer">Server which implements communication.</param>
|
|
|
|
|
public QueryLoggedIn(ICopriServerBase p_oCopriServer,
|
|
|
|
|
string p_strSessionCookie,
|
|
|
|
|
string p_strMail,
|
|
|
|
|
Func<DateTime> p_oDateTimeProvider) : base(p_oCopriServer, p_strSessionCookie, p_strMail, p_oDateTimeProvider)
|
|
|
|
|
{
|
|
|
|
|
server = p_oCopriServer as ICopriServer;
|
|
|
|
|
if (server == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"Copri server is not of expected typ. Type detected is {p_oCopriServer.GetType()}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
server = p_oCopriServer as ICopriServer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary> Gets all stations including postions.</summary>
|
|
|
|
|
public async Task<Result<StationsAndBikesContainer>> GetBikesAndStationsAsync()
|
|
|
|
|
{
|
|
|
|
|
var stationResponse = await server.GetStationsAsync();
|
|
|
|
|
var bikesAvailableResponse = await server.GetBikesAvailableAsync();
|
|
|
|
|
var bikesOccupiedResponse = await server.GetBikesOccupiedAsync();
|
|
|
|
|
|
|
|
|
|
return new Result<StationsAndBikesContainer>(
|
|
|
|
|
typeof(CopriCallsMonkeyStore),
|
|
|
|
|
new StationsAndBikesContainer(
|
|
|
|
|
stationResponse.GetStationsAllMutable(),
|
2022-01-04 18:54:03 +01:00
|
|
|
|
UpdaterJSON.GetBikesAll(bikesAvailableResponse, bikesOccupiedResponse, Mail, DateTimeProvider)),
|
|
|
|
|
stationResponse.GetGeneralData());
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary> Gets bikes occupied. </summary>
|
|
|
|
|
/// <returns>Collection of bikes.</returns>
|
|
|
|
|
public async Task<Result<BikeCollection>> GetBikesOccupiedAsync()
|
|
|
|
|
{
|
2022-01-04 18:54:03 +01:00
|
|
|
|
var bikesOccupiedResponse = (await server.GetBikesOccupiedAsync());
|
2021-05-13 20:03:07 +02:00
|
|
|
|
return new Result<BikeCollection>(
|
2022-01-04 18:54:03 +01:00
|
|
|
|
typeof(CopriCallsMonkeyStore),
|
|
|
|
|
bikesOccupiedResponse.GetBikesOccupied(Mail, DateTimeProvider),
|
|
|
|
|
bikesOccupiedResponse.GetGeneralData());
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
/// <summary> Gets bikes available and bikes occupied. </summary>
|
|
|
|
|
/// <returns>Collection of bikes.</returns>
|
|
|
|
|
public async Task<Result<BikeCollection>> GetBikesAsync()
|
|
|
|
|
{
|
2022-01-04 18:54:03 +01:00
|
|
|
|
var bikesAvailableResponse = await server.GetBikesAvailableAsync();
|
|
|
|
|
var bikesOccupiedResponse = await server.GetBikesOccupiedAsync();
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
|
|
|
|
return new Result<BikeCollection>(
|
|
|
|
|
typeof(CopriCallsMonkeyStore),
|
2022-01-04 18:54:03 +01:00
|
|
|
|
UpdaterJSON.GetBikesAll(bikesAvailableResponse, bikesOccupiedResponse, Mail, DateTimeProvider),
|
|
|
|
|
bikesAvailableResponse.GetGeneralData());
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|