sharee.bike-App/SharedBusinessLogic/Services/CopriApi/CopriProviderMonkeyStore.cs

125 lines
5.4 KiB
C#
Raw Normal View History

2022-09-20 13:51:55 +02:00
using System;
2021-08-01 17:24:15 +02:00
using System.Collections.Generic;
2021-05-13 20:03:07 +02:00
using System.Threading.Tasks;
2024-04-09 12:53:23 +02:00
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Repository;
using ShareeBike.Repository.Request;
using ShareeBike.Repository.Response;
using ShareeBike.Repository.Response.Stations;
using ShareeBike.Services.CopriApi.Exception;
namespace ShareeBike.Model.Services.CopriApi
2021-05-13 20:03:07 +02:00
{
2023-02-22 14:03:35 +01:00
/// <summary> Object which manages calls to cache. </summary>
2022-09-06 16:08:19 +02:00
public class CopriProviderMonkeyStore : ICopriServer
{
/// <summary> Object which manages stored copri answers. </summary>
private readonly CopriCallsMonkeyStore monkeyStore;
/// <summary> True if connector has access to copri server, false if cached values are used. </summary>
public bool IsConnected => monkeyStore.IsConnected;
/// <summary> Gets the session cookie if user is logged in, an empty string otherwise. </summary>
public string SessionCookie => monkeyStore.SessionCookie;
/// <summary> Constructs object which Object which manages stored copri answers in a thread save way. </summary>
2024-04-09 12:53:23 +02:00
/// <param name="merchantId">Id of the merchant ShareeBike-App.</param>
2022-09-06 16:08:19 +02:00
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
2023-02-22 14:03:35 +01:00
/// <param name="smartDevice">Holds info about smart device.</param>
2022-09-06 16:08:19 +02:00
public CopriProviderMonkeyStore(
string merchantId,
string uiIsoLangugageName,
2023-02-22 14:03:35 +01:00
string sessionCookie,
ISmartDevice smartDevice = null)
2022-09-06 16:08:19 +02:00
{
2023-02-22 14:03:35 +01:00
monkeyStore = new CopriCallsMonkeyStore(merchantId, uiIsoLangugageName, sessionCookie, smartDevice);
2022-09-06 16:08:19 +02:00
}
/// <summary> Gets the merchant id.</summary>
public string MerchantId => monkeyStore.MerchantId;
public Task<ReservationBookingResponse> DoReserveAsync(string bikeId, Uri operatorUri)
2022-10-26 20:53:18 +02:00
=> throw new RequestNotCachableException(nameof(DoReserveAsync));
2022-09-06 16:08:19 +02:00
2024-04-09 12:53:23 +02:00
public Task<BookingActionResponse> DoCancelReservationAsync(string bikeId, Uri operatorUri)
2022-10-26 20:53:18 +02:00
=> throw new RequestNotCachableException(nameof(DoCancelReservationAsync));
2022-09-06 16:08:19 +02:00
public Task<ReservationBookingResponse> CalculateAuthKeysAsync(string bikeId, Uri operatorUri)
2022-10-26 20:53:18 +02:00
=> throw new RequestNotCachableException(nameof(CalculateAuthKeysAsync));
2022-09-06 16:08:19 +02:00
public async Task<ResponseBase> StartReturningBike(
string bikeId,
Uri operatorUri)
=> await monkeyStore.StartReturningBike(bikeId, operatorUri);
public async Task<ReservationBookingResponse> UpdateLockingStateAsync(
string bikeId,
lock_state state,
Uri operatorUri,
LocationDto geolocation,
2022-09-20 13:51:55 +02:00
double batteryLevel,
IVersionInfo versionInfo)
2022-09-06 16:08:19 +02:00
=> await monkeyStore.UpdateLockingStateAsync(
bikeId,
state,
operatorUri,
geolocation,
2022-09-20 13:51:55 +02:00
batteryLevel,
versionInfo);
2022-09-06 16:08:19 +02:00
2022-12-27 21:08:09 +01:00
public async Task<ReservationBookingResponse> DoBookAsync(Uri operatorUri, string bikeId, Guid guid, double batteryPercentage, LockingAction? nextAction = null)
=> await monkeyStore.DoBookAsync(operatorUri, bikeId, guid, batteryPercentage, nextAction);
2022-09-06 16:08:19 +02:00
public async Task<ReservationBookingResponse> BookAvailableAndStartOpeningAsync(
string bikeId,
Uri operatorUri)
=> await monkeyStore.BookAvailableAndStartOpeningAsync(bikeId, operatorUri);
public async Task<ReservationBookingResponse> BookReservedAndStartOpeningAsync(
string bikeId,
Uri operatorUri)
=> await monkeyStore.BookReservedAndStartOpeningAsync(bikeId, operatorUri);
public async Task<DoReturnResponse> DoReturn(
string bikeId,
LocationDto geolocation,
Uri operatorUri)
2023-02-22 14:03:35 +01:00
=> await monkeyStore.DoReturn(bikeId, geolocation, operatorUri);
2022-09-06 16:08:19 +02:00
public async Task<DoReturnResponse> ReturnAndStartClosingAsync(
string bikeId,
Uri operatorUri)
2023-02-22 14:03:35 +01:00
=> await monkeyStore.ReturnAndStartClosingAsync(bikeId, operatorUri);
2022-09-06 16:08:19 +02:00
public Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, int? currentChargeBars, string messge, bool bIsBikeBroke, Uri operatorUri)
2022-10-26 20:53:18 +02:00
=> throw new RequestNotCachableException(nameof(DoSubmitFeedback));
2022-09-06 16:08:19 +02:00
/// <summary> Submits mini survey to copri server. </summary>
/// <param name="answers">Collection of answers.</param>
public Task<ResponseBase> DoSubmitMiniSurvey(IDictionary<string, string> answers)
2022-10-26 20:53:18 +02:00
=> throw new RequestNotCachableException(nameof(DoSubmitMiniSurvey));
2022-09-06 16:08:19 +02:00
public async Task<AuthorizationResponse> DoAuthorizationAsync(string p_strMailAddress, string p_strPassword, string p_strDeviceId)
2022-10-26 20:53:18 +02:00
=> await monkeyStore.DoAuthorizationAsync(p_strMailAddress, p_strPassword, p_strDeviceId);
2022-09-06 16:08:19 +02:00
public async Task<AuthorizationoutResponse> DoAuthoutAsync()
2022-10-26 20:53:18 +02:00
=> await monkeyStore.DoAuthoutAsync();
2022-09-06 16:08:19 +02:00
2023-11-21 15:26:57 +01:00
/// <summary> Gets a list of bikes from Copri. </summary>
2023-11-06 12:23:09 +01:00
/// <param name="operatorUri">Uri of the operator host to get bikes from or null if bikes have to be gotten form primary host.</param>
2023-11-21 15:26:57 +01:00
/// <param name="stationId"> Id of station which is used for filtering bikes. Null if no filtering should be applied.</param>
/// <param name="bikeId"> Id of bike which is used for filtering bikes. Null if no filtering should be applied.</param>
public async Task<BikesAvailableResponse> GetBikesAvailableAsync(Uri operatorUri = null, string stationId = null, string bikeId = null)
=> await monkeyStore.GetBikesAvailableAsync(operatorUri, stationId, bikeId);
2022-09-06 16:08:19 +02:00
public async Task<BikesReservedOccupiedResponse> GetBikesOccupiedAsync()
2022-10-26 20:53:18 +02:00
=> await monkeyStore.GetBikesOccupiedAsync();
2022-09-06 16:08:19 +02:00
public async Task<StationsAvailableResponse> GetStationsAsync()
2022-10-26 20:53:18 +02:00
=> await monkeyStore.GetStationsAsync();
2022-09-06 16:08:19 +02:00
}
2021-05-13 20:03:07 +02:00
}