using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using gehGassi.Dto.Common; using gehGassi.Dto; using gehGassi.Dto.DogWalkers; using gehGassi.Dto.Walks; using gehGassiApp.Core.Interfaces; using gehGassiApp.Core.Resources; using gehGassiApp.Domain.Lookup; namespace gehGassiApp.Core.Services { /// /// Service der die Verwaltung von DogWalkern ermöglicht /// public class DogWalkerService : IDogWalkerService { private readonly ICommunicationService _communicationService; private readonly ILocationService _locationService; /// /// Erstellt eine Instanz /// /// Instanz eines ICommunicationService /// Instanz eines ILocationService public DogWalkerService(ICommunicationService communicationService, ILocationService locationService) { _communicationService = communicationService; _locationService = locationService; } /// /// Gibt Detailinfos zu einem DogWalker zurück /// /// Id des Dogwalkers /// Aktuelles Accesstoken /// CancellationToken /// CommunicationResult public async Task> GetDogWalkerAsync(string dogWalkerId, string accessToken, CancellationToken token) { var result = new CommunicationResult() { Value = new DogWalkerInfo() }; var isConnected = await _communicationService.IsConnected(); if (isConnected) { var dogWalkerResult = await _communicationService.GetDogWalkerAsync(dogWalkerId, accessToken, token); if (dogWalkerResult.Success) return dogWalkerResult; } else { result.Success = false; result.ErrorCode = CommunicationErrors.ServerNoConnection; result.ErrorMessage = Errors.Server_NoConnection; } return result; } /// /// Gibt Dogwalker vom Server zurück /// /// Query-Objekt für Dogwalker /// Aktuelle Position /// Aktuelles Accesstoken /// CancellationToken /// ListCommunicationResult public async Task>> GetDogWalkersAsync(DogWalkerQueryDto query, LocationDto location, string accessToken, CancellationToken token) { var result = new ListCommunicationResult>() { Value = new List() }; var isConnected = await _communicationService.IsConnected(); if (isConnected) { query.Location = location; var queryResult = await _communicationService.GetDogWalkersAsync(query, accessToken, token); if (queryResult.Success && queryResult.Value.Count >= 1) { return queryResult; } } else { result.Success = false; result.ErrorCode = CommunicationErrors.ServerNoConnection; result.ErrorMessage = Errors.Server_NoConnection; } return result; } /// /// Gibt Dogwalker als Lookup vom Server zurück /// /// Query-Objekt für Dogwalker /// Aktuelle Position /// Aktuelles Accesstoken /// CancellationToken /// ListCommunicationResult public async Task>> GetDogWalkersLookupAsync(DogWalkerQueryDto query, LocationDto location, string accessToken, CancellationToken token) { var result = new ListCommunicationResult>() { Value = new List() }; var isConnected = await _communicationService.IsConnected(); if (isConnected) { query.Location = location; var queryResult = await _communicationService.GetDogWalkersLookupAsync(query, accessToken, token); if (queryResult.Success && queryResult.Value.Count >= 1) { return queryResult; } } else { result.Success = false; result.ErrorCode = CommunicationErrors.ServerNoConnection; result.ErrorMessage = Errors.Server_NoConnection; } return result; } } }