Add project files.

This commit is contained in:
Sergio Matias Urquin
2025-04-29 18:39:57 -06:00
parent 116793710f
commit 6358f5f199
110 changed files with 4484 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
using Core.Blueprint.DAL.Infrastructure.Contracts;
using Core.Blueprint.Domain.Entities;
using Microsoft.Extensions.Logging;
using MongoDB.Driver;
namespace Core.Blueprint.DAL.Infrastructure.Repository
{
public sealed class BlueprintRepository: IBlueprintRepository
{
private readonly IMongoContext _context;
private readonly ILogger<BlueprintRepository> _logger;
private readonly IMongoCollection<BlueprintCollection> _collection;
public BlueprintRepository(IMongoContext context, IProxyBlobStorage blobProxy, ILogger<BlueprintRepository> logger)
{
_context = context;
_logger = logger;
_collection = _context.Database.GetCollection<BlueprintCollection>("Blueprints");
}
public async ValueTask<BlueprintCollection> GetByIdAsync(string id)
{
var result = await _collection.FindAsync(b => b.Id == id);
return result.First();
}
async ValueTask<IQueryable<BlueprintCollection>> IRepositoryBase<BlueprintCollection>.GetAllAsync()
{
var result = await _collection.FindAsync(_ => true);
return (await result.ToListAsync()).AsQueryable();
}
async ValueTask<BlueprintCollection> IRepositoryBase<BlueprintCollection>.CreateAsync(BlueprintCollection blueprint)
{
blueprint.Id = null;
await _collection.InsertOneAsync(blueprint);
return blueprint;
}
public async Task<bool> UpdateAsync(string id, BlueprintCollection blueprint)
{
var result = await _collection.ReplaceOneAsync(b => b.Id == id, blueprint);
return result.IsAcknowledged && result.ModifiedCount > 0;
}
public async Task<bool> DeleteAsync(string id)
{
var result = await _collection.DeleteOneAsync(b => b.Id == id);
return result.IsAcknowledged && result.DeletedCount > 0;
}
}
}

View File

@@ -0,0 +1,54 @@
using Core.Blueprint.DAL.Infrastructure.Context;
using Core.Blueprint.DAL.Infrastructure.Contracts;
using Core.Blueprint.Domain.Entities;
namespace Core.Blueprint.DAL.Infrastructure.Repository
{
public abstract class RepositorySqlBase<T> : IRepositoryIdentityBase<T> where T: AbsEntity
{
protected SqlServerContext _dbContext;
protected RepositorySqlBase(SqlServerContext dbContext)
{
_dbContext = dbContext;
}
public async ValueTask<T> CreateAsync(T blueprint)
{
blueprint.Id = Guid.NewGuid().ToString();
_dbContext.Add(blueprint);
await _dbContext.SaveChangesAsync();
return blueprint;
}
public async Task<bool> DeleteAsync(string id)
{
var item = await GetByIdAsync(id);
if (item == null)
{
return false;
}
_dbContext.Remove(item);
await _dbContext.SaveChangesAsync();
return true;
}
public async ValueTask<IQueryable<T>> GetAllAsync()
{
return _dbContext.Set<T>();
}
public async ValueTask<T> GetByIdAsync(string id)
{
var result = await _dbContext.FindAsync<T>(id);
return result;
}
public async Task<bool> UpdateAsync(string id, T entity)
{
_dbContext.Update(entity);
await _dbContext.SaveChangesAsync();
return true;
}
}
}

View File

@@ -0,0 +1,33 @@
using Core.Blueprint.DAL.Infrastructure.Contracts;
using Core.Blueprint.Domain.Dtos;
namespace Core.Blueprint.DAL.Infrastructure.Repository
{
public class SampleImageRepository : ISampleImageRepository
{
private readonly IProxyBlobStorage _proxyBlobStorage;
public SampleImageRepository(IProxyBlobStorage proxyBlobStorage)
{
_proxyBlobStorage = proxyBlobStorage;
}
public async IAsyncEnumerable<ImageUrlDto> GetAllImagesUrls()
{
await using (var images = _proxyBlobStorage.ListAllItemsAsync().GetAsyncEnumerator())
{
await images.MoveNextAsync();
yield return images.Current;
}
}
public async Task<ImageUrlDto> GetFirstImageUrl()
{
return await _proxyBlobStorage.GetFirstImageUrlAsync();
}
public async Task<ImageUrlDto> GetUploadUrl()
{
return await _proxyBlobStorage.GetUploadUrl();
}
}
}

View File

@@ -0,0 +1,16 @@
using Core.Blueprint.DAL.Infrastructure.Context;
using Core.Blueprint.DAL.Infrastructure.Contracts;
using Core.Blueprint.Domain.Entities;
using Microsoft.Extensions.Logging;
namespace Core.Blueprint.DAL.Infrastructure.Repository
{
public class SampleItemRepository : RepositorySqlBase<SampleItem>, ISampleItemRepository
{
private readonly ILogger<SampleItemRepository> _logger;
public SampleItemRepository(SqlServerContext dbContext, ILogger<SampleItemRepository> logger) : base(dbContext)
{
_logger = logger;
}
}
}

View File

@@ -0,0 +1,41 @@
using Azure.Security.KeyVault.Secrets;
using Core.Blueprint.DAL.Infrastructure.Contracts;
using Core.Blueprint.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Core.Blueprint.DAL.Infrastructure.Repository
{
public class SecretRepository : ISecretRepository
{
private readonly SecretClient _client;
public SecretRepository(SecretClient client)
{
_client = client;
}
public async Task<Secret> GetSecret(string secretName, CancellationToken cancellationToken)
{
var ret = await _client.GetSecretAsync(secretName, cancellationToken: cancellationToken);
return new Secret() { Value = ret.Value?.Value };
}
public async Task SetSecret(string secretName, string secretValue, CancellationToken cancellationToken)
{
await _client.SetSecretAsync(new KeyVaultSecret(secretName, secretValue), cancellationToken: cancellationToken);
}
public async Task RemoveSecret(string secretName, CancellationToken cancellationToken)
{
await _client.StartDeleteSecretAsync(secretName, cancellationToken: cancellationToken);
}
}
}