using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using gehGassi.Dto; using gehGassiApp.Core.Interfaces; using gehGassiApp.Core.Resources; using gehGassiApp.Domain.Lookup; namespace gehGassiApp.Core.Services { /// /// Service der Lookups durchführen kann /// public class LookupService : ILookupService { private readonly ICommunicationService _communicationService; /// /// Erstellt eine Instanz /// /// Instanz eines ICommunicationService public LookupService(ICommunicationService communicationService) { _communicationService = communicationService; } /// /// Gibt eine Liste von dogOwnern und/oder DogWalkern für einen Lookup zurück /// /// Filter /// Anzahl max. Datensätze /// Aktuelles Accesstoken /// CancellationToken /// ListCommunicationResult public async Task>> GetEntitiesAsync(string filter, int take, string accessToken, CancellationToken token) { var result = new CommunicationResult>() { Value = new List() }; var isConnected = await _communicationService.IsConnected(); if (isConnected) { var lookupResult = await _communicationService.LookupEntitiesAsync(filter, take, accessToken, token); if (lookupResult.Success) return lookupResult; } else { result.Success = false; result.ErrorCode = CommunicationErrors.ServerNoConnection; result.ErrorMessage = Errors.Server_NoConnection; } return result; } /// /// Gibt eine Liste von Dogwalkern mit Distanz zur aktuellen Position zurück /// /// Id die ignoriert werden soll falls der Benutzer DogOwner und DogWalker ist /// Breitengrad /// Längengrad /// Anzahl Walker gewünscht /// Aktuelles Accesstoken /// CancellationToken /// CommunicationResult public async Task>> GetWalkersAsync(string ignoreId, double lat, double lng, int take, string accessToken, CancellationToken token) { var result = new CommunicationResult>() { Value = new List() }; var isConnected = await _communicationService.IsConnected(); if (isConnected) { var lookupResult = await _communicationService.LookupDogWalkersAsync(ignoreId, lat, lng, take, accessToken, token); System.Diagnostics.Debug.WriteLine($"Walker Lookup Result: {lookupResult.Success} | {lookupResult.ErrorCode} | {lookupResult.ErrorMessage}"); if (lookupResult.Success) return lookupResult; } else { result.Success = false; result.ErrorCode = CommunicationErrors.ServerNoConnection; result.ErrorMessage = Errors.Server_NoConnection; } return result; } /// /// Gibt Detailinfos zu einem DogWalker zurück /// /// Id des Dogwalkers /// Aktuelles Accesstoken /// CancellationToken /// CommunicationResult public async Task> GetWalkerAsync(string dogWalkerId, string accessToken, CancellationToken token) { var result = new CommunicationResult() { Value = new DogWalkerInfo() }; var isConnected = await _communicationService.IsConnected(); if (isConnected) { var lookupResult = await _communicationService.LookupDogWalkerAsync(dogWalkerId, accessToken, token); if (lookupResult.Success) return lookupResult; } else { result.Success = false; result.ErrorCode = CommunicationErrors.ServerNoConnection; result.ErrorMessage = Errors.Server_NoConnection; } return result; } } }