TourIAm/TIAMWebApp/Shared/Services/ServiceProviderDataService.cs

204 lines
6.7 KiB
C#

using AyCode.Core.Loggers;
using AyCode.Interfaces.StorageHandlers;
using Microsoft.JSInterop;
using Newtonsoft.Json;
using SkiaSharp;
using System.Net.Http.Json;
using AyCode.Core.Helpers;
using AyCode.Services.Loggers;
using AyCode.Services.SignalRs;
using TIAM.Core.Loggers;
using TIAM.Database.DataLayers.Users;
using TIAM.Entities.Products;
using TIAM.Entities.ServiceProviders;
using TIAM.Entities.Users;
using TIAMWebApp.Shared.Application.Interfaces;
using TIAMWebApp.Shared.Application.Models;
using TIAMWebApp.Shared.Application.Models.ClientSide;
using TIAMWebApp.Shared.Application.Utility;
using TIAM.Services;
using System.Linq;
namespace TIAMWebApp.Shared.Application.Services
{
public class ServiceProviderDataService : IServiceProviderDataService
{
private readonly HttpClient http;
private readonly ISecureStorageHandler secureStorageHandler;
private readonly LoggerClient<ServiceProviderDataService> _logger;
private DevAdminSignalClient _devAdminSignalClient;
public ServiceProviderDataService(HttpClient http, ISecureStorageHandler secureStorageHandler, DevAdminSignalClient devAdminSignalClient, IEnumerable<IAcLogWriterClientBase> logWriters)
{
this.http = http;
this.secureStorageHandler = secureStorageHandler;
_devAdminSignalClient = devAdminSignalClient;
_logger = new LoggerClient<ServiceProviderDataService>(logWriters.ToArray());
}
//22.
public Task<bool> CreateUserProductMappingAsync(UserProductMapping userProductMapping)
{
throw new NotImplementedException();
}
//19.
public Task<bool> CreateProductAsync(Product product)
{
throw new NotImplementedException();
}
//15.
public Task<bool> CreateServiceProviderAsync(Company serviceProvider)
{
throw new NotImplementedException();
}
//21.
public Task DeleteProductAsync(Guid productId)
{
throw new NotImplementedException();
}
//13.
public Task DeleteServiceProviderAsync(Guid serviceProviderId)
{
throw new NotImplementedException();
}
//23.
public Task<List<UserProductMapping>> GetUserProductMappingsByProductIdAsync(Guid productId)
{
throw new NotImplementedException();
}
//17.
public async Task<Dictionary<Guid, string>?> GetPropertiesByOwnerIdAsync(Guid id)
{
Dictionary<Guid, string>? companyPropertiesByOwner;
//_devAdminSignalClient.SendMessageToServerAsync<Dictionary<Guid, string>>(SignalRTags.GetPropertiesByOwnerIdAsync, new SignalRequestByIdMessage(id), response =>
//{
// if (response.Status == SignalResponseStatus.Error)
// return;
// companyPropertiesByOwner = response.ResponseData;
// if (companyPropertiesByOwner != null) _logger.DetailConditional($"companyPropertiesByOwner async: {string.Join("; ", companyPropertiesByOwner.Values)}");
//}).Forget();
companyPropertiesByOwner = await _devAdminSignalClient.SendMessageToServerAsync<Dictionary<Guid, string>>(SignalRTags.GetPropertiesByOwnerIdAsync, new SignalRequestByIdMessage(id));
if (companyPropertiesByOwner != null) _logger.DetailConditional($"companyPropertiesByOwner: {string.Join("; ", companyPropertiesByOwner.Values)}");
return companyPropertiesByOwner;
//var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetServiceProvidersByOwnerId}";
//var response = await http.PostAsJsonAsync(url, id);
//if (response.IsSuccessStatusCode)
//{
// var result = await response.Content.ReadFromJsonAsync<Dictionary<Guid, string>>();
// string resultString = "";
// foreach (var item in result)
// {
// resultString += item.Value + ", ";
// }
// _logger.DetailConditional(resultString);
// return result;
//}
//else
//{
// return null;
//}
}
//18.
public Task<Company?> GetServiceProviderByIdAsync(Guid id)
{
throw new NotImplementedException();
}
//16.
public Task<List<Company>> GetServiceProvidersAsync()
{
throw new NotImplementedException();
}
//24.
public Task RemoveUserProductMappingsByContextIdAsync(Guid productId)
{
throw new NotImplementedException();
}
//20.
public Task<bool> UpdateProductAsync(Product product)
{
throw new NotImplementedException();
}
//14.
public Task<bool> UpdateServiceProviderAsync(Company serviceProvider)
{
throw new NotImplementedException();
}
public async Task<string> GetQRCodeByProductIdAsync(Guid productId)
{
var url = APIUrls.GetQrCodeByProductId;
var response = await http.PostAsJsonAsync(url, productId);
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsStringAsync();
_logger.Debug("SKBitmap width: " + result);
return result;
}
else
{
return null;
}
}
public async Task<IEnumerable<Product>> GetProductsForServiceProviderAsync(Guid serviceProviderId)
{
var url = APIUrls.GetProductsByServiceProviderId;
var response = await http.PostAsJsonAsync(url, serviceProviderId);
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsStringAsync();
//_logger.Detail("Json: " + result);
var data = JsonConvert.DeserializeObject<IEnumerable<Product>>(result);
if (data != null)
{
return data;
}
else {
return null;
}
}
else
{
return null;
}
}
public async Task<List<Product>> GetAllProductsAsync()
{
var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetAllProducts}";
var response = await http.GetFromJsonAsync(url, typeof (List<Product>));
if (response != null)
{
return (List<Product>)response;
}
else
{
return null;
}
}
}
}