2023-09-26 15:22:26 -05:00
|
|
|
|
using DamageAssesment.Api.Responses.Interfaces;
|
|
|
|
|
using DamageAssesment.Api.Responses.Models;
|
2023-08-15 22:52:30 -05:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
2023-09-26 15:22:26 -05:00
|
|
|
|
namespace DamageAssesment.Api.Responses.Services
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
public class AttachmentServiceProvider : ServiceProviderBase, IAttachmentServiceProvider
|
|
|
|
|
{
|
2023-09-13 00:28:24 -05:00
|
|
|
|
public AttachmentServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<AttachmentServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Attachment"), configuration.GetValue<string>("EndPointSettings:AttachmentUrlBase"))
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-19 23:32:30 -05:00
|
|
|
|
public async Task<List<Attachment>> getAttachmentsAsync(string token)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-09-19 23:32:30 -05:00
|
|
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token);
|
2023-09-04 20:31:41 -05:00
|
|
|
|
var attachments = JsonConvert.DeserializeObject<List<Attachment>>(responseJsonString);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
|
|
|
|
if (attachments == null || !attachments.Any())
|
2023-09-04 20:31:41 -05:00
|
|
|
|
return new List<Attachment>();
|
2023-08-15 22:52:30 -05:00
|
|
|
|
else return attachments;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: AttachmentServiceProvider.getAttachmentsAsync()");
|
2023-09-04 20:31:41 -05:00
|
|
|
|
return new List<Attachment>();
|
2023-08-15 22:52:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-19 23:32:30 -05:00
|
|
|
|
public async Task<IEnumerable<Attachment>> PostAttachmentsAsync(AttachmentInfo attachmentInfo, string token)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-09-04 20:31:41 -05:00
|
|
|
|
var requestJsonString = JsonConvert.SerializeObject(attachmentInfo);
|
2023-09-19 23:32:30 -05:00
|
|
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Post, url, requestJsonString, token);
|
2023-09-04 20:31:41 -05:00
|
|
|
|
var attachments = JsonConvert.DeserializeObject<IEnumerable<Attachment>>(responseJsonString);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
|
|
|
|
if (attachments == null)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogError($"Attachments cannot be added - Ref: AttachmentServiceProvider.PostAttachmentsAsync()");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
else return attachments;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: AttachmentServiceProvider.PostAttachmentsAsync()");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|