Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f44e3bdd2b | ||
|
|
9780168b45 |
@@ -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);
|
||||
|
||||
@@ -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 = "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.");
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.");
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
BIN
CleanArchitecture/comandos.txt
Normal file
BIN
CleanArchitecture/comandos.txt
Normal file
Binary file not shown.
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user