130 lines
5.1 KiB
C#
130 lines
5.1 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// Service der die Verwaltung von DogWalkern ermöglicht
|
|
/// </summary>
|
|
public class DogWalkerService : IDogWalkerService
|
|
{
|
|
private readonly ICommunicationService _communicationService;
|
|
private readonly ILocationService _locationService;
|
|
|
|
/// <summary>
|
|
/// Erstellt eine Instanz
|
|
/// </summary>
|
|
/// <param name="communicationService">Instanz eines ICommunicationService</param>
|
|
/// <param name="locationService">Instanz eines ILocationService</param>
|
|
public DogWalkerService(ICommunicationService communicationService, ILocationService locationService)
|
|
{
|
|
_communicationService = communicationService;
|
|
_locationService = locationService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt Detailinfos zu einem DogWalker zurück
|
|
/// </summary>
|
|
/// <param name="dogWalkerId">Id des Dogwalkers</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<DogWalkerInfo>> GetDogWalkerAsync(string dogWalkerId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<DogWalkerInfo>() { 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt Dogwalker vom Server zurück
|
|
/// </summary>
|
|
/// <param name="query">Query-Objekt für Dogwalker</param>
|
|
/// <param name="location">Aktuelle Position</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>ListCommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<DogWalkerInfo>>> GetDogWalkersAsync(DogWalkerQueryDto query, LocationDto location, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<DogWalkerInfo>>() { Value = new List<DogWalkerInfo>() };
|
|
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt Dogwalker als Lookup vom Server zurück
|
|
/// </summary>
|
|
/// <param name="query">Query-Objekt für Dogwalker</param>
|
|
/// <param name="location">Aktuelle Position</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>ListCommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<DogWalkerLookup>>> GetDogWalkersLookupAsync(DogWalkerQueryDto query, LocationDto location, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<DogWalkerLookup>>() { Value = new List<DogWalkerLookup>() };
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|