adding
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Azure;
|
||||
using Azure.Storage.Blobs;
|
||||
using Azure.Storage.Blobs.Models;
|
||||
|
||||
namespace LCU.API.Internal.DocumentLib.DataAccess;
|
||||
|
||||
public class BlobApiDao : IBlobApiDao
|
||||
{
|
||||
private readonly BlobContainerClient _client;
|
||||
|
||||
public BlobApiDao(IBlobStorageClient storageClient)
|
||||
{
|
||||
_client = storageClient.GetClient();
|
||||
}
|
||||
|
||||
public async Task<Guid> SaveDocumentToBlob(byte[] fileData)
|
||||
{
|
||||
var blobDocumentId = Guid.NewGuid();
|
||||
|
||||
using var stream = new MemoryStream(fileData, false);
|
||||
await _client.GetBlobClient(blobDocumentId.ToString()).UploadAsync(stream);
|
||||
return blobDocumentId;
|
||||
}
|
||||
|
||||
public async Task UpdateDocumentInBlob(Guid blobDocumentId, byte[] fileData)
|
||||
{
|
||||
using var stream = new MemoryStream(fileData, false);
|
||||
await _client.GetBlobClient(blobDocumentId.ToString()).UploadAsync(stream, true);
|
||||
}
|
||||
|
||||
public async Task<Response> RemoveDocumentFromBlob(Guid blobDocumentId)
|
||||
{
|
||||
return await _client.GetBlobClient(blobDocumentId.ToString())
|
||||
.DeleteAsync(DeleteSnapshotsOption.IncludeSnapshots);
|
||||
}
|
||||
|
||||
public async Task<Response<BlobDownloadStreamingResult>> GetDocumentFromBlob(Guid blobDocumentId)
|
||||
{
|
||||
return await _client.GetBlobClient(blobDocumentId.ToString()).DownloadStreamingAsync();
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
using Azure.Storage.Blobs;
|
||||
using LCU.API.Internal.DocumentLib.Configurations;
|
||||
|
||||
namespace LCU.API.Internal.DocumentLib.DataAccess;
|
||||
|
||||
public class BlobStorageClient : IBlobStorageClient
|
||||
{
|
||||
private readonly BlobContainerClient _containerClient;
|
||||
|
||||
public BlobStorageClient(BlobStorageConfiguration config)
|
||||
{
|
||||
var serviceClient = new BlobServiceClient(config.ConnectionString);
|
||||
_containerClient = serviceClient.GetBlobContainerClient(config.ContainerName);
|
||||
}
|
||||
|
||||
public BlobContainerClient GetClient()
|
||||
{
|
||||
return _containerClient;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Azure;
|
||||
using Azure.Storage.Blobs.Models;
|
||||
|
||||
namespace LCU.API.Internal.DocumentLib.DataAccess;
|
||||
|
||||
public interface IBlobApiDao
|
||||
{
|
||||
Task<Guid> SaveDocumentToBlob(byte[] fileData);
|
||||
Task UpdateDocumentInBlob(Guid blobDocumentId, byte[] fileData);
|
||||
Task<Response> RemoveDocumentFromBlob(Guid blobDocumentId);
|
||||
Task<Response<BlobDownloadStreamingResult>> GetDocumentFromBlob(Guid blobDocumentId);
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
using Azure.Storage.Blobs;
|
||||
|
||||
namespace LCU.API.Internal.DocumentLib.DataAccess;
|
||||
|
||||
public interface IBlobStorageClient
|
||||
{
|
||||
BlobContainerClient GetClient();
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using LCU.API.Internal.NotificationsApiLib.Models;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LCU.API.Internal.DocumentLib.DataAccess
|
||||
{
|
||||
public interface INotificationApiDao
|
||||
{
|
||||
Task SendEmailAsync(EmailRequest emailRequest);
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using LCU.API.Internal.DocumentLib.Configurations;
|
||||
using LCU.API.Internal.DocumentLib.Utilities;
|
||||
using LCU.API.Internal.NotificationsApiLib.Models;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
|
||||
namespace LCU.API.Internal.DocumentLib.DataAccess
|
||||
{
|
||||
public class NotificationApiDao : INotificationApiDao
|
||||
{
|
||||
private readonly NotificationApiConfiguration _notificationApiConfiguration;
|
||||
public NotificationApiDao(NotificationApiConfiguration notificationApiConfiguration)
|
||||
{
|
||||
_notificationApiConfiguration = notificationApiConfiguration;
|
||||
}
|
||||
|
||||
public async Task SendEmailAsync(EmailRequest emailRequest)
|
||||
{
|
||||
await HttpUtilities.PostAsync<EmailRequest>(new Uri(_notificationApiConfiguration.EmailUrl),
|
||||
emailRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user