2 Commits

Author SHA1 Message Date
Alejandro Sarmiento
f44e3bdd2b revisar que se ha hecho aqui 2024-04-01 14:33:28 +02:00
Alejandro Sarmiento
9780168b45 Merge branch 'master' into release 2024-03-14 22:54:07 +01:00
12 changed files with 24 additions and 19 deletions

View File

@@ -17,8 +17,8 @@ namespace CleanArchitecture.Application.Contracts.Persistence
bool disableTracking = true);
Task<T> GetByIdAsync(Guid id);
Task<T> AddAsync(T entity);
Task<T> UpdateAsync(T entity);
Task<T> AddAsync(T entity, string userThatMakesAction = "");
Task<T> UpdateAsync(T entity, string userThatMakesAction = "");
Task DeleteAsync(T entity);
void AddEntity(T entity);

View File

@@ -9,6 +9,6 @@ namespace CleanArchitecture.Application.Contracts.Persistence
IVideoRepository VideoRepository { get; }
IAsyncRepository<T> Repository<T>() where T : BaseDomainModel;
Task<int> Complete();
Task<int> Complete(string userThatMakesAction = "");
}
}

View File

@@ -7,5 +7,6 @@ namespace CleanArchitecture.Application.Features.Videos.Commands.CreateVideo
{
public string Nombre { get; set; } = string.Empty;
public Guid StreamerId { get; set; }
public string UserThatMakesAction { get; set; } = string.Empty;
}
}

View File

@@ -21,7 +21,7 @@ namespace CleanArchitecture.Application.Features.Videos.Commands.CreateVideo
{
var videoEntity = mapper.Map<Video>(request);
unitOfWork.VideoRepository.AddEntity(videoEntity);
var response = await unitOfWork.Complete();
var response = await unitOfWork.Complete(request.UserThatMakesAction);
if(response > 0)
{
logger.LogInformation($"Video {videoEntity.Id} is successfully created.");

View File

@@ -7,6 +7,8 @@ namespace CleanArchitecture.Application.Features.Videos.Commands.UpdateVideo
{
public Guid Id { get; set; }
public string Nombre { get; set; } = string.Empty;
public string UserThatMakesAction { get; set; } = string.Empty;
}
}

View File

@@ -33,7 +33,7 @@ namespace CleanArchitecture.Application.Features.Videos.Commands.UpdateVideo
mapper.Map(request, videoToUpdate, typeof(UpdateVideoCommand), typeof(Video));
unitOfWork.VideoRepository.UpdateEntity(videoToUpdate);
await unitOfWork.Complete();
await unitOfWork.Complete(request.UserThatMakesAction);
logger.LogInformation($"Video {videoToUpdate.Id} is successfully updated.");

View File

@@ -30,19 +30,21 @@ namespace CleanArchitecture.Infrastructure.Persistence
// .EnableSensitiveDataLogging();
//}
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
public Task<int> SaveChangesAsync(string? userThatMakesAction = "", CancellationToken cancellationToken = default)
{
userThatMakesAction = userThatMakesAction ?? "System";
foreach (var entry in ChangeTracker.Entries<BaseDomainModel>())
{
switch (entry.State)
{
case EntityState.Modified:
entry.Entity.LastModifiedBy = "System";
entry.Entity.LastModifiedBy = userThatMakesAction;
entry.Entity.LastModifiedDate = DateTime.Now;
break;
case EntityState.Added:
entry.Entity.CreatedDate = DateTime.Now;
entry.Entity.CreatedBy = "System";
entry.Entity.CreatedBy = userThatMakesAction;
entry.Entity.CreatedDate = DateTime.Now;
break;
case EntityState.Detached:
break;

View File

@@ -6,12 +6,12 @@ namespace CleanArchitecture.Infrastructure.Persistence
public class StreamerDbContextSeed
{
public static async Task SeedAsync(StreamerDbContext context, ILogger<StreamerDbContextSeed> logger)
public static async Task SeedAsync(StreamerDbContext context, ILogger<StreamerDbContextSeed> logger, string userThatMakesAction = "")
{
if (!context.Streamers.Any())
{
context.AddRange(GetPreconfiguredStreamers());
await context.SaveChangesAsync();
await context.SaveChangesAsync(userThatMakesAction);
logger.LogInformation("Seed database associated with context {DbContextName} executed", typeof(StreamerDbContext).Name);
}
}

View File

@@ -60,18 +60,18 @@ namespace CleanArchitecture.Infrastructure.Repositories
return await context.Set<T>().FindAsync(id);
}
public async Task<T> AddAsync(T entity)
public async Task<T> AddAsync(T entity, string userThatMakesAction = "")
{
context.Set<T>().Add(entity);
await context.SaveChangesAsync();
await context.SaveChangesAsync(userThatMakesAction);
return entity;
}
public async Task<T> UpdateAsync(T entity)
public async Task<T> UpdateAsync(T entity, string userThatMakesAction = "")
{
context.Set<T>().Attach(entity);
context.Entry(entity).State = EntityState.Modified;
await context.SaveChangesAsync();
await context.SaveChangesAsync(userThatMakesAction);
return entity;
}

View File

@@ -24,9 +24,9 @@ namespace CleanArchitecture.Infrastructure.Repositories
public StreamerDbContext StreamerDbContext => context;
public async Task<int> Complete()
public async Task<int> Complete(string userThatMakesAction = "")
{
return await context.SaveChangesAsync();
return await context.SaveChangesAsync(userThatMakesAction);
}
public void Dispose()

Binary file not shown.

View File

@@ -3,7 +3,7 @@ kind: Deployment
metadata:
name: clean-architecture-deployment
spec:
replicas: 2
replicas: 16
selector:
matchLabels:
app: clean-architecture-backend
@@ -14,7 +14,7 @@ spec:
spec:
containers:
- name: clean-architecture-backend
image: dockerregistry.alexdev.es/clean-architecture-backend:0.0.48
image: dockerregistry.alexdev.es/clean-architecture-backend:0.0.59
ports:
- containerPort: 80
imagePullSecrets: