mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-12-25 08:36:27 +01:00
67 lines
2.4 KiB
C#
67 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Serilog;
|
|
using TINK.Model.Bikes;
|
|
using TINK.Model.Connector.Updater;
|
|
using TINK.Model.Services.CopriApi;
|
|
using TINK.Repository;
|
|
using TINK.Services.CopriApi;
|
|
using BikeInfo = TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo;
|
|
|
|
namespace TINK.Model.Connector
|
|
{
|
|
/// <summary> Provides query functionality from cache 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="copriServer">Server which implements communication.</param>
|
|
public Query(ICopriServerBase copriServer) : base(copriServer)
|
|
{
|
|
server = copriServer as ICopriServer;
|
|
if (server == null)
|
|
{
|
|
throw new ArgumentException($"Copri server is not of expected type. Type detected is {copriServer.GetType()}.");
|
|
}
|
|
}
|
|
|
|
/// <summary> Gets all stations including positions.</summary>
|
|
public async Task<Result<StationsAndBikesContainer>> GetBikesAndStationsAsync()
|
|
{
|
|
var stationsAllResponse = await server.GetStationsAsync();
|
|
|
|
return new Result<StationsAndBikesContainer>(
|
|
typeof(CopriCallsMonkeyStore),
|
|
new StationsAndBikesContainer(
|
|
stationsAllResponse.GetStationsAllMutable(),
|
|
new BikeCollection() /* There are no bikes occupied because user is not logged in. */),
|
|
stationsAllResponse.GetGeneralData());
|
|
}
|
|
|
|
/// <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 occupied detected. No user is logged in.");
|
|
return new Result<BikeCollection>(
|
|
typeof(CopriCallsMonkeyStore),
|
|
await Task.FromResult(new BikeCollection(new Dictionary<string, BikeInfo>())),
|
|
new GeneralData(),
|
|
new Exception("Abfrage der reservierten/ gebuchten Räder fehlgeschlagen. Kein Benutzer angemeldet."));
|
|
}
|
|
|
|
/// <summary> Gets bikes occupied. </summary>
|
|
/// <returns> Collection of bikes. </returns>
|
|
public async Task<Result<BikeCollection>> GetBikesAsync()
|
|
{
|
|
var bikesAvailableResponse = await server.GetBikesAvailableAsync();
|
|
return new Result<BikeCollection>(
|
|
typeof(CopriCallsMonkeyStore),
|
|
bikesAvailableResponse.GetBikesAvailable(Bikes.BikeInfoNS.BC.DataSource.Cache),
|
|
bikesAvailableResponse.GetGeneralData());
|
|
}
|
|
}
|
|
}
|