2021-05-13 20:03:07 +02:00
|
|
|
|
using Serilog;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using TINK.Model.Bike;
|
|
|
|
|
using TINK.Model.Services.CopriApi;
|
2021-06-26 20:57:55 +02:00
|
|
|
|
using TINK.Repository;
|
2022-01-04 18:54:03 +01:00
|
|
|
|
using TINK.Services.CopriApi;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
using BikeInfo = TINK.Model.Bike.BC.BikeInfo;
|
|
|
|
|
|
|
|
|
|
namespace TINK.Model.Connector
|
|
|
|
|
{
|
|
|
|
|
/// <summary> Provides query functionality without login. </summary>
|
|
|
|
|
public class Query : Base, 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 Query(ICopriServerBase p_oCopriServer) : base(p_oCopriServer)
|
|
|
|
|
{
|
|
|
|
|
server = p_oCopriServer as ICopriServer;
|
|
|
|
|
if (server == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"Copri server is not of expected typ. Type detected is {p_oCopriServer.GetType()}.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary> Gets all stations including postions.</summary>
|
|
|
|
|
public async Task<Result<StationsAndBikesContainer>> GetBikesAndStationsAsync()
|
|
|
|
|
{
|
|
|
|
|
var stationsAllResponse = await server.GetStationsAsync();
|
|
|
|
|
var bikesAvailableResponse = await server.GetBikesAvailableAsync();
|
|
|
|
|
|
|
|
|
|
return new Result<StationsAndBikesContainer>(
|
|
|
|
|
typeof(CopriCallsMonkeyStore),
|
2022-01-04 18:54:03 +01:00
|
|
|
|
new StationsAndBikesContainer(stationsAllResponse.GetStationsAllMutable(), bikesAvailableResponse.GetBikesAvailable()),
|
|
|
|
|
stationsAllResponse.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()
|
|
|
|
|
{
|
|
|
|
|
Log.ForContext<Query>().Error("Unexpected call to get be bikes occpied detected. No user is logged in.");
|
|
|
|
|
return new Result<BikeCollection>(
|
|
|
|
|
typeof(CopriCallsMonkeyStore),
|
2022-01-22 18:16:10 +01:00
|
|
|
|
await Task.FromResult(new BikeCollection(new Dictionary<string, BikeInfo>())),
|
2022-01-04 18:54:03 +01:00
|
|
|
|
new GeneralData(),
|
|
|
|
|
new Exception("Abfrage der reservierten/ gebuchten Räder fehlgeschlagen. Kein Benutzer angemeldet."));
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary> Gets 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();
|
2021-05-13 20:03:07 +02:00
|
|
|
|
return new Result<BikeCollection>(
|
2022-01-04 18:54:03 +01:00
|
|
|
|
typeof(CopriCallsMonkeyStore),
|
|
|
|
|
bikesAvailableResponse.GetBikesAvailable(),
|
|
|
|
|
bikesAvailableResponse.GetGeneralData());
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|