mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-13 22:06:29 +01:00
66 lines
2.4 KiB
C#
66 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 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),
|
|
new StationsAndBikesContainer(stationsAllResponse.GetStationsAllMutable(), bikesAvailableResponse.GetBikesAvailable()),
|
|
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 occpied 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(),
|
|
bikesAvailableResponse.GetGeneralData());
|
|
}
|
|
}
|
|
}
|