Se hizo toda la parte del Unit Of Work y estoy a punto de terminar la de tests unitarios
This commit is contained in:
Alejandro Sarmiento
2024-02-28 22:40:34 +01:00
parent b55f2be085
commit 81a3e91d6e
67 changed files with 1112 additions and 1375 deletions

View File

@@ -25,7 +25,7 @@ namespace CleanArchitecture.API.Controllers
public async Task<ActionResult<int>> CreateStreamer([FromBody] CreateStreamerCommand command)
{
var response = await mediator.Send(command);
return Ok(new { StreamerId = response });
return Ok(response);
}
[HttpPut(Name = "UpdateStreamer")]
@@ -35,8 +35,8 @@ namespace CleanArchitecture.API.Controllers
[ProducesDefaultResponseType]
public async Task<ActionResult> UpdateStreamer([FromBody] UpdateStreamerCommand command)
{
await mediator.Send(command);
return NoContent();
var createdStreamer = await mediator.Send(command);
return Ok(createdStreamer);
}
[HttpDelete("{id}", Name = "DeleteStreamer")]
@@ -44,7 +44,7 @@ namespace CleanArchitecture.API.Controllers
[ProducesResponseType((int)HttpStatusCode.NoContent)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesDefaultResponseType]
public async Task<ActionResult> DeleteStreamer(int id)
public async Task<ActionResult> DeleteStreamer(Guid id)
{
var request = new DeleteStreamerCommand() { Id = id };
await mediator.Send(request);

View File

@@ -1,4 +1,11 @@
using CleanArchitecture.Application.Features.Videos.Queries.GetVideosList;
using CleanArchitecture.Application.Features.Streamers.Commands.CreateStreamer;
using CleanArchitecture.Application.Features.Streamers.Commands.DeleteStreamer;
using CleanArchitecture.Application.Features.Streamers.Commands.UpdateStreamer;
using CleanArchitecture.Application.Features.Videos.Commands.CreateVideo;
using CleanArchitecture.Application.Features.Videos.Commands.DeleteVideo;
using CleanArchitecture.Application.Features.Videos.Commands.UpdateVideo;
using CleanArchitecture.Application.Features.Videos.Queries.GetVideosList;
using CleanArchitecture.Domain;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -27,5 +34,37 @@ namespace CleanArchitecture.API.Controllers
var videos = await mediator.Send(query);
return Ok(videos);
}
[HttpPost(Name = "CreateVideo")]
[Authorize(Roles = "Administrator")]
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
public async Task<ActionResult<Video>> CreateVideo([FromBody] CreateVideoCommand command)
{
var response = await mediator.Send(command);
return Ok(response);
}
[HttpPut(Name = "UpdateVideo")]
[Authorize(Roles = "Administrator")]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesDefaultResponseType]
public async Task<ActionResult<Video>> UpdateVideo([FromBody] UpdateVideoCommand command)
{
var response = await mediator.Send(command);
return Ok(response);
}
[HttpDelete("{id}", Name = "DeleteVideo")]
[Authorize(Roles = "Administrator")]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesDefaultResponseType]
public async Task<ActionResult> DeleteVideo(Guid id)
{
var request = new DeleteVideoCommand() { Id = id };
await mediator.Send(request);
return NoContent();
}
}
}

View File

@@ -1,7 +1,7 @@
{
"ConnectionStrings": {
"ConnectionString": "server=localhost;database=CleanArchitecture;user=root;password=securePassword",
"ConnectionString": "server=localhost;database=CleanArchitectureV2;user=root;password=securePassword",
"IdentityConnectionString": "server=localhost;database=CleanArchitecture.Security;user=root;password=securePassword"
},
"EmailSettings": {

View File

@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.18.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CleanArchitecture.Application\CleanArchitecture.Application.csproj" />
<ProjectReference Include="..\CleanArchitecture.Data\CleanArchitecture.Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Features\Video\Commands\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,42 @@
using AutoMapper;
using CleanArchitecture.Application.Contracts.Persistence;
using CleanArchitecture.Application.Features.Videos.Queries.GetVideosList;
using CleanArchitecture.Application.Mappings;
using CleanArchitecture.Application.UnitTests.Mocks;
using Moq;
using Shouldly;
using Xunit;
namespace CleanArchitecture.Application.UnitTests.Features.Video.Queries
{
public class GetVideosListQueryHandlerXUnitTests
{
private readonly IMapper mapper;
private readonly Mock<IUnitOfWork> mockUnitOfWork;
public GetVideosListQueryHandlerXUnitTests()
{
mockUnitOfWork = MockUnitOfWork.GetUnitOfWork();
var mapperConfiguration = new MapperConfiguration(cfg =>
{
cfg.AddProfile<MappingProfile>();
});
mapper = mapperConfiguration.CreateMapper();
}
[Fact]
public async Task GetVideoListTest()
{
var handler = new GetVideosListQueryHandler(mockUnitOfWork.Object, mapper);
var request = new GetVideosListQuery("Alex");
var result = await handler.Handle(request, CancellationToken.None);
result.ShouldBeOfType<List<VideosVm>>();
result.Count.ShouldBe(1);
}
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CleanArchitecture.Application.UnitTests.Mocks
{
internal class MockStreamerRepository
{
}
}

View File

@@ -0,0 +1,18 @@
using CleanArchitecture.Application.Contracts.Persistence;
using Moq;
namespace CleanArchitecture.Application.UnitTests.Mocks
{
public static class MockUnitOfWork
{
public static Mock<IUnitOfWork> GetUnitOfWork()
{
var mockUnitOfWork = new Mock<IUnitOfWork>();
var mockVideoRepository = MockVideoRepository.GetVideoRepository();
mockUnitOfWork.Setup(uow => uow.VideoRepository).Returns(mockVideoRepository.Object);
return mockUnitOfWork;
}
}
}

View File

@@ -0,0 +1,33 @@
using AutoFixture;
using CleanArchitecture.Application.Contracts.Persistence;
using CleanArchitecture.Domain;
using CleanArchitecture.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using Moq;
using CleanArchitecture.Infrastructure.Repositories;
namespace CleanArchitecture.Application.UnitTests.Mocks
{
public static class MockVideoRepository
{
public static Mock<VideoRepository> GetVideoRepository()
{
var fixture = new Fixture();
fixture.Behaviors.Add(new OmitOnRecursionBehavior());
var videos = fixture.CreateMany<Video>().ToList();
videos.Add(fixture.Build<Video>().With(tr => tr.CreatedBy, "Alex").Create());
var options = new DbContextOptionsBuilder<StreamerDbContext>()
.UseInMemoryDatabase(databaseName: $"StreamerDbContext-{Guid.NewGuid()}").Options;
var streamerDbContextFake = new StreamerDbContext(options);
streamerDbContextFake.Videos!.AddRange(videos);
streamerDbContextFake.SaveChanges();
var mockRepository = new Mock<VideoRepository>(streamerDbContextFake);
return mockRepository;
}
}
}

View File

@@ -15,7 +15,6 @@
<Folder Include="Features\Directors\Commands\UpdateDirector\" />
<Folder Include="Features\Directors\Queries\" />
<Folder Include="Features\Streamers\Queries\" />
<Folder Include="Features\Videos\Commands\" />
</ItemGroup>
<ItemGroup>

View File

@@ -15,7 +15,7 @@ namespace CleanArchitecture.Application.Contracts.Persistence
Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null,
List<Expression<Func<T, object>>>? includes = null,
bool disableTracking = true);
Task<T> GetByIdAsync(int id);
Task<T> GetByIdAsync(Guid id);
Task<T> AddAsync(T entity);
Task<T> UpdateAsync(T entity);

View File

@@ -2,7 +2,7 @@
namespace CleanArchitecture.Application.Features.Directors.Commands.CreateDirector
{
public class CreateDirectorCommand: IRequest<int>
public class CreateDirectorCommand: IRequest<Guid>
{
public string Nombre { get; set; } = string.Empty;
public string Apellido { get; set; } = string.Empty;

View File

@@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging;
namespace CleanArchitecture.Application.Features.Directors.Commands.CreateDirector
{
public class CreateDirectorCommandHandler : IRequestHandler<CreateDirectorCommand, int>
public class CreateDirectorCommandHandler : IRequestHandler<CreateDirectorCommand, Guid>
{
private readonly ILogger<CreateDirectorCommandHandler> logger;
private readonly IMapper mapper;
@@ -19,7 +19,7 @@ namespace CleanArchitecture.Application.Features.Directors.Commands.CreateDirect
this.unitOfWork = unitOfWork;
}
public Task<int> Handle(CreateDirectorCommand request, CancellationToken cancellationToken)
public Task<Guid> Handle(CreateDirectorCommand request, CancellationToken cancellationToken)
{
var directorEntity = mapper.Map<Director>(request);
unitOfWork.Repository<Director>().AddEntity(directorEntity);

View File

@@ -1,8 +1,9 @@
using MediatR;
using CleanArchitecture.Domain;
using MediatR;
namespace CleanArchitecture.Application.Features.Streamers.Commands.CreateStreamer
{
public class CreateStreamerCommand : IRequest<int>
public class CreateStreamerCommand : IRequest<Streamer>
{
public string Nombre { get; set; } = string.Empty;
public string Url { get; set; } = string.Empty;

View File

@@ -8,16 +8,16 @@ using Microsoft.Extensions.Logging;
namespace CleanArchitecture.Application.Features.Streamers.Commands.CreateStreamer
{
public class CreateStreamerCommandHandler(IUnitOfWork _unitOfWork, IMapper _mapper,
IEmailService _emailService, ILogger<CreateStreamerCommandHandler> _logger) :
IRequestHandler<CreateStreamerCommand, int>
public class CreateVideoCommandHandler(IUnitOfWork _unitOfWork, IMapper _mapper,
IEmailService _emailService, ILogger<CreateVideoCommandHandler> _logger) :
IRequestHandler<CreateStreamerCommand, Streamer>
{
private readonly IUnitOfWork unitOfWork = _unitOfWork;
private readonly IMapper mapper = _mapper;
private readonly IEmailService emailService = _emailService;
private readonly ILogger<CreateStreamerCommandHandler> logger = _logger;
private readonly ILogger<CreateVideoCommandHandler> logger = _logger;
public async Task<int> Handle(CreateStreamerCommand request, CancellationToken cancellationToken)
public async Task<Streamer> Handle(CreateStreamerCommand request, CancellationToken cancellationToken)
{
var streamerEntity = mapper.Map<Streamer>(request);
unitOfWork.StreamerRepository.AddEntity(streamerEntity);
@@ -26,7 +26,7 @@ namespace CleanArchitecture.Application.Features.Streamers.Commands.CreateStream
{
logger.LogInformation($"Streamer {streamerEntity.Id} is successfully created.");
await SendEmail(streamerEntity);
return streamerEntity.Id;
return streamerEntity;
}
else
{

View File

@@ -4,6 +4,6 @@ namespace CleanArchitecture.Application.Features.Streamers.Commands.DeleteStream
{
public class DeleteStreamerCommand: IRequest<Unit>
{
public int Id { get; set; }
public Guid Id { get; set; }
}
}

View File

@@ -1,10 +1,11 @@
using MediatR;
using CleanArchitecture.Domain;
using MediatR;
namespace CleanArchitecture.Application.Features.Streamers.Commands.UpdateStreamer
{
public class UpdateStreamerCommand : IRequest<Unit>
public class UpdateStreamerCommand : IRequest<Streamer>
{
public int Id { get; set; }
public Guid Id { get; set; }
public string Nombre { get; set; } = string.Empty;
public string Url { get; set; } = string.Empty;
}

View File

@@ -7,7 +7,7 @@ using Microsoft.Extensions.Logging;
namespace CleanArchitecture.Application.Features.Streamers.Commands.UpdateStreamer
{
public class UpdateStreamerCommandHandler : IRequestHandler<UpdateStreamerCommand, Unit>
public class UpdateStreamerCommandHandler : IRequestHandler<UpdateStreamerCommand, Streamer>
{
private readonly IUnitOfWork unitOfWork;
private readonly IMapper mapper;
@@ -21,7 +21,7 @@ namespace CleanArchitecture.Application.Features.Streamers.Commands.UpdateStream
this.logger = logger;
}
public async Task<Unit> Handle(UpdateStreamerCommand request, CancellationToken cancellationToken)
public async Task<Streamer> Handle(UpdateStreamerCommand request, CancellationToken cancellationToken)
{
var streamerToUpdate = await unitOfWork.StreamerRepository.GetByIdAsync(request.Id);
if(streamerToUpdate == null)
@@ -33,11 +33,16 @@ namespace CleanArchitecture.Application.Features.Streamers.Commands.UpdateStream
mapper.Map(request, streamerToUpdate, typeof(UpdateStreamerCommand), typeof(Streamer));
unitOfWork.StreamerRepository.UpdateEntity(streamerToUpdate);
await unitOfWork.Complete();
var result = await unitOfWork.Complete();
if(result == 0)
{
logger.LogError($"{Guid.NewGuid()} - Update of streamer {request.Id} failed.");
throw new Exception($"Update of streamer {request.Id} failed.");
}
logger.LogInformation($"Streamer {streamerToUpdate.Id} is successfully updated.");
return Unit.Value;
return streamerToUpdate;
}
}
}

View File

@@ -0,0 +1,11 @@
using CleanArchitecture.Domain;
using MediatR;
namespace CleanArchitecture.Application.Features.Videos.Commands.CreateVideo
{
public class CreateVideoCommand : IRequest<Video>
{
public string Nombre { get; set; } = string.Empty;
public Guid StreamerId { get; set; }
}
}

View File

@@ -0,0 +1,57 @@
using AutoMapper;
using CleanArchitecture.Application.Contracts.Infrastructure;
using CleanArchitecture.Application.Contracts.Persistence;
using CleanArchitecture.Application.Models;
using CleanArchitecture.Domain;
using MediatR;
using Microsoft.Extensions.Logging;
namespace CleanArchitecture.Application.Features.Videos.Commands.CreateVideo
{
public class CreateVideoCommandHandler(IUnitOfWork _unitOfWork, IMapper _mapper,
IEmailService _emailService, ILogger<CreateVideoCommandHandler> _logger) :
IRequestHandler<CreateVideoCommand, Video>
{
private readonly IUnitOfWork unitOfWork = _unitOfWork;
private readonly IMapper mapper = _mapper;
private readonly IEmailService emailService = _emailService;
private readonly ILogger<CreateVideoCommandHandler> logger = _logger;
public async Task<Video> Handle(CreateVideoCommand request, CancellationToken cancellationToken)
{
var videoEntity = mapper.Map<Video>(request);
unitOfWork.VideoRepository.AddEntity(videoEntity);
var response = await unitOfWork.Complete();
if(response > 0)
{
logger.LogInformation($"Video {videoEntity.Id} is successfully created.");
await SendEmail(videoEntity);
return videoEntity;
}
else
{
throw new Exception("Failed to create the video.");
}
}
private async Task SendEmail(Video video)
{
var email = new Email()
{
To = "alejandro@asarmiento.es",
Body = $"Nuevo video fue creado. Id: {video.Id}",
Subject = "Mensaje de alerta, Video Creado"
};
try
{
await emailService.SendEmail(email);
}
catch (Exception ex)
{
logger.LogError($"Ha ocurrido un error al enviar el email. Error: {ex.Message}");
}
}
}
}

View File

@@ -0,0 +1,17 @@
using FluentValidation;
namespace CleanArchitecture.Application.Features.Videos.Commands.CreateVideo
{
public class CreateVideoCommandValidator : AbstractValidator<CreateVideoCommand>
{
public CreateVideoCommandValidator()
{
RuleFor(p => p.Nombre)
.NotEmpty().WithMessage("{Nombre} is required.")
.NotNull()
.MaximumLength(50).WithMessage("{Nombre} must not exceed 50 characters.");
}
}
}

View File

@@ -0,0 +1,9 @@
using MediatR;
namespace CleanArchitecture.Application.Features.Videos.Commands.DeleteVideo
{
public class DeleteVideoCommand: IRequest<bool>
{
public Guid Id { get; set; }
}
}

View File

@@ -0,0 +1,39 @@
using AutoMapper;
using CleanArchitecture.Application.Contracts.Persistence;
using CleanArchitecture.Application.Exceptions;
using CleanArchitecture.Domain;
using MediatR;
using Microsoft.Extensions.Logging;
namespace CleanArchitecture.Application.Features.Videos.Commands.DeleteVideo
{
public class DeleteVideoCommandHandler : IRequestHandler<DeleteVideoCommand, bool>
{
private readonly IUnitOfWork unitOfWork;
private readonly IMapper mapper;
private readonly ILogger<DeleteVideoCommandHandler> logger;
public DeleteVideoCommandHandler(IUnitOfWork unitOfWork, IMapper mapper, ILogger<DeleteVideoCommandHandler> logger)
{
this.unitOfWork = unitOfWork;
this.mapper = mapper;
this.logger = logger;
}
public async Task<bool> Handle(DeleteVideoCommand request, CancellationToken cancellationToken)
{
var videoToDelete = await unitOfWork.VideoRepository.GetByIdAsync(request.Id);
if (videoToDelete == null)
{
logger.LogError($"Video with id {request.Id} not found.");
throw new NotFoundException(nameof(Streamer), request.Id);
}
unitOfWork.VideoRepository.DeleteEntity(videoToDelete);
await unitOfWork.Complete();
logger.LogInformation($"Video {videoToDelete.Id} is successfully deleted.");
return true;
}
}
}

View File

@@ -0,0 +1,12 @@
using CleanArchitecture.Domain;
using MediatR;
namespace CleanArchitecture.Application.Features.Videos.Commands.UpdateVideo
{
public class UpdateVideoCommand : IRequest<Video>
{
public Guid Id { get; set; }
public string Nombre { get; set; } = string.Empty;
}
}

View File

@@ -0,0 +1,43 @@
using AutoMapper;
using CleanArchitecture.Application.Contracts.Persistence;
using CleanArchitecture.Application.Exceptions;
using CleanArchitecture.Domain;
using MediatR;
using Microsoft.Extensions.Logging;
namespace CleanArchitecture.Application.Features.Videos.Commands.UpdateVideo
{
public class UpdateVideoCommandHandler : IRequestHandler<UpdateVideoCommand, Video>
{
private readonly IUnitOfWork unitOfWork;
private readonly IMapper mapper;
private readonly ILogger<UpdateVideoCommandHandler> logger;
public UpdateVideoCommandHandler(IUnitOfWork unitOfWork,
IMapper mapper, ILogger<UpdateVideoCommandHandler> logger)
{
this.unitOfWork = unitOfWork;
this.mapper = mapper;
this.logger = logger;
}
public async Task<Video> Handle(UpdateVideoCommand request, CancellationToken cancellationToken)
{
var videoToUpdate = await unitOfWork.VideoRepository.GetByIdAsync(request.Id);
if(videoToUpdate == null)
{
logger.LogError($"Video with id {request.Id} not found.");
throw new NotFoundException(nameof(Video), request.Id);
}
mapper.Map(request, videoToUpdate, typeof(UpdateVideoCommand), typeof(Video));
unitOfWork.VideoRepository.UpdateEntity(videoToUpdate);
await unitOfWork.Complete();
logger.LogInformation($"Video {videoToUpdate.Id} is successfully updated.");
return videoToUpdate;
}
}
}

View File

@@ -0,0 +1,21 @@
using FluentValidation;
namespace CleanArchitecture.Application.Features.Videos.Commands.UpdateVideo
{
public class UpdateVideoCommandValidator: AbstractValidator<UpdateVideoCommand>
{
public UpdateVideoCommandValidator()
{
RuleFor(x=>x.Nombre)
.NotEmpty().WithMessage("{Nombre} is required.")
.NotNull()
.MaximumLength(50).WithMessage("{Nombre} must not exceed 50 characters.");
RuleFor(x => x.Id)
.NotEmpty().WithMessage("{Id} is required.")
.NotNull();
}
}
}

View File

@@ -3,6 +3,6 @@
public class VideosVm
{
public string? Nombre { get; set; }
public int StreamerId { get; set; }
public Guid StreamerId { get; set; }
}
}

View File

@@ -2,6 +2,8 @@
using CleanArchitecture.Application.Features.Directors.Commands.CreateDirector;
using CleanArchitecture.Application.Features.Streamers.Commands.CreateStreamer;
using CleanArchitecture.Application.Features.Streamers.Commands.UpdateStreamer;
using CleanArchitecture.Application.Features.Videos.Commands.CreateVideo;
using CleanArchitecture.Application.Features.Videos.Commands.UpdateVideo;
using CleanArchitecture.Application.Features.Videos.Queries.GetVideosList;
using CleanArchitecture.Domain;
@@ -15,10 +17,16 @@ namespace CleanArchitecture.Application.Mappings
#region Video
CreateMap<Video, VideosVm>();
CreateMap<VideosVm, Video>();
CreateMap<CreateVideoCommand, Video>();
CreateMap<Video, CreateVideoCommand>();
CreateMap<UpdateVideoCommand, Video>();
CreateMap<Video, UpdateVideoCommand>();
#endregion Video
#region Streamer
CreateMap<CreateStreamerCommand, Streamer>();
CreateMap<CreateStreamerCommand, Streamer>();
CreateMap<Streamer, CreateStreamerCommand>();
CreateMap<UpdateStreamerCommand, Streamer>();

View File

@@ -25,4 +25,8 @@
<ProjectReference Include="..\CleanArchitecture.Domain\CleanArchitecture.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>

View File

@@ -1,163 +0,0 @@
// <auto-generated />
using System;
using CleanArchitecture.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace CleanArchitecture.Data.Migrations
{
[DbContext(typeof(StreamerDbContext))]
[Migration("20240215190923_Second-Migration")]
partial class SecondMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("CleanArchitecture.Domain.Actor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Apellido")
.HasColumnType("longtext");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("Actor");
});
modelBuilder.Entity("CleanArchitecture.Domain.Director", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Apellido")
.HasColumnType("longtext");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.Property<int>("VideoId")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Director");
});
modelBuilder.Entity("CleanArchitecture.Domain.Streamer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.Property<string>("Url")
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("Streamers");
});
modelBuilder.Entity("CleanArchitecture.Domain.Video", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<int?>("DirectorId")
.HasColumnType("int");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.Property<int>("StreamerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DirectorId")
.IsUnique();
b.HasIndex("StreamerId");
b.ToTable("Videos");
});
modelBuilder.Entity("CleanArchitecture.Domain.VideoActor", b =>
{
b.Property<int>("VideoId")
.HasColumnType("int");
b.Property<int>("ActorId")
.HasColumnType("int");
b.HasKey("VideoId", "ActorId");
b.HasIndex("ActorId");
b.ToTable("VideoActor");
});
modelBuilder.Entity("CleanArchitecture.Domain.Video", b =>
{
b.HasOne("CleanArchitecture.Domain.Director", "Director")
.WithOne("Video")
.HasForeignKey("CleanArchitecture.Domain.Video", "DirectorId");
b.HasOne("CleanArchitecture.Domain.Streamer", "Streamer")
.WithMany("Videos")
.HasForeignKey("StreamerId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Director");
b.Navigation("Streamer");
});
modelBuilder.Entity("CleanArchitecture.Domain.VideoActor", b =>
{
b.HasOne("CleanArchitecture.Domain.Actor", null)
.WithMany()
.HasForeignKey("ActorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("CleanArchitecture.Domain.Video", null)
.WithMany()
.HasForeignKey("VideoId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("CleanArchitecture.Domain.Director", b =>
{
b.Navigation("Video");
});
modelBuilder.Entity("CleanArchitecture.Domain.Streamer", b =>
{
b.Navigation("Videos");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,148 +0,0 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CleanArchitecture.Data.Migrations
{
/// <inheritdoc />
public partial class SecondMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Videos_Streamers_StreamerId",
table: "Videos");
migrationBuilder.AddColumn<int>(
name: "DirectorId",
table: "Videos",
type: "int",
nullable: true);
migrationBuilder.CreateTable(
name: "Actor",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Nombre = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Apellido = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
table.PrimaryKey("PK_Actor", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "Director",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Nombre = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Apellido = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
VideoId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Director", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "VideoActor",
columns: table => new
{
VideoId = table.Column<int>(type: "int", nullable: false),
ActorId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_VideoActor", x => new { x.VideoId, x.ActorId });
table.ForeignKey(
name: "FK_VideoActor_Actor_ActorId",
column: x => x.ActorId,
principalTable: "Actor",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_VideoActor_Videos_VideoId",
column: x => x.VideoId,
principalTable: "Videos",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_Videos_DirectorId",
table: "Videos",
column: "DirectorId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_VideoActor_ActorId",
table: "VideoActor",
column: "ActorId");
migrationBuilder.AddForeignKey(
name: "FK_Videos_Director_DirectorId",
table: "Videos",
column: "DirectorId",
principalTable: "Director",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Videos_Streamers_StreamerId",
table: "Videos",
column: "StreamerId",
principalTable: "Streamers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Videos_Director_DirectorId",
table: "Videos");
migrationBuilder.DropForeignKey(
name: "FK_Videos_Streamers_StreamerId",
table: "Videos");
migrationBuilder.DropTable(
name: "Director");
migrationBuilder.DropTable(
name: "VideoActor");
migrationBuilder.DropTable(
name: "Actor");
migrationBuilder.DropIndex(
name: "IX_Videos_DirectorId",
table: "Videos");
migrationBuilder.DropColumn(
name: "DirectorId",
table: "Videos");
migrationBuilder.AddForeignKey(
name: "FK_Videos_Streamers_StreamerId",
table: "Videos",
column: "StreamerId",
principalTable: "Streamers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@@ -1,215 +0,0 @@
// <auto-generated />
using System;
using CleanArchitecture.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace CleanArchitecture.Data.Migrations
{
[DbContext(typeof(StreamerDbContext))]
[Migration("20240215201317_BaseDomainModelUpdate")]
partial class BaseDomainModelUpdate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("CleanArchitecture.Domain.Actor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Apellido")
.HasColumnType("longtext");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("Actor");
});
modelBuilder.Entity("CleanArchitecture.Domain.Director", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Apellido")
.HasColumnType("longtext");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.Property<int>("VideoId")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Director");
});
modelBuilder.Entity("CleanArchitecture.Domain.Streamer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.Property<string>("Url")
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("Streamers");
});
modelBuilder.Entity("CleanArchitecture.Domain.Video", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<int?>("DirectorId")
.HasColumnType("int");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.Property<int>("StreamerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DirectorId")
.IsUnique();
b.HasIndex("StreamerId");
b.ToTable("Videos");
});
modelBuilder.Entity("CleanArchitecture.Domain.VideoActor", b =>
{
b.Property<int>("VideoId")
.HasColumnType("int");
b.Property<int>("ActorId")
.HasColumnType("int");
b.HasKey("VideoId", "ActorId");
b.HasIndex("ActorId");
b.ToTable("VideoActor");
});
modelBuilder.Entity("CleanArchitecture.Domain.Video", b =>
{
b.HasOne("CleanArchitecture.Domain.Director", "Director")
.WithOne("Video")
.HasForeignKey("CleanArchitecture.Domain.Video", "DirectorId");
b.HasOne("CleanArchitecture.Domain.Streamer", "Streamer")
.WithMany("Videos")
.HasForeignKey("StreamerId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Director");
b.Navigation("Streamer");
});
modelBuilder.Entity("CleanArchitecture.Domain.VideoActor", b =>
{
b.HasOne("CleanArchitecture.Domain.Actor", "Actor")
.WithMany()
.HasForeignKey("ActorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("CleanArchitecture.Domain.Video", "Video")
.WithMany()
.HasForeignKey("VideoId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Actor");
b.Navigation("Video");
});
modelBuilder.Entity("CleanArchitecture.Domain.Director", b =>
{
b.Navigation("Video");
});
modelBuilder.Entity("CleanArchitecture.Domain.Streamer", b =>
{
b.Navigation("Videos");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,187 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CleanArchitecture.Data.Migrations
{
/// <inheritdoc />
public partial class BaseDomainModelUpdate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "CreatedBy",
table: "Videos",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<DateTime>(
name: "CreatedDate",
table: "Videos",
type: "datetime(6)",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "LastModifiedBy",
table: "Videos",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<DateTime>(
name: "LastModifiedDate",
table: "Videos",
type: "datetime(6)",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "CreatedBy",
table: "Streamers",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<DateTime>(
name: "CreatedDate",
table: "Streamers",
type: "datetime(6)",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "LastModifiedBy",
table: "Streamers",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<DateTime>(
name: "LastModifiedDate",
table: "Streamers",
type: "datetime(6)",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "CreatedBy",
table: "Director",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<DateTime>(
name: "CreatedDate",
table: "Director",
type: "datetime(6)",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "LastModifiedBy",
table: "Director",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<DateTime>(
name: "LastModifiedDate",
table: "Director",
type: "datetime(6)",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "CreatedBy",
table: "Actor",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<DateTime>(
name: "CreatedDate",
table: "Actor",
type: "datetime(6)",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "LastModifiedBy",
table: "Actor",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<DateTime>(
name: "LastModifiedDate",
table: "Actor",
type: "datetime(6)",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CreatedBy",
table: "Videos");
migrationBuilder.DropColumn(
name: "CreatedDate",
table: "Videos");
migrationBuilder.DropColumn(
name: "LastModifiedBy",
table: "Videos");
migrationBuilder.DropColumn(
name: "LastModifiedDate",
table: "Videos");
migrationBuilder.DropColumn(
name: "CreatedBy",
table: "Streamers");
migrationBuilder.DropColumn(
name: "CreatedDate",
table: "Streamers");
migrationBuilder.DropColumn(
name: "LastModifiedBy",
table: "Streamers");
migrationBuilder.DropColumn(
name: "LastModifiedDate",
table: "Streamers");
migrationBuilder.DropColumn(
name: "CreatedBy",
table: "Director");
migrationBuilder.DropColumn(
name: "CreatedDate",
table: "Director");
migrationBuilder.DropColumn(
name: "LastModifiedBy",
table: "Director");
migrationBuilder.DropColumn(
name: "LastModifiedDate",
table: "Director");
migrationBuilder.DropColumn(
name: "CreatedBy",
table: "Actor");
migrationBuilder.DropColumn(
name: "CreatedDate",
table: "Actor");
migrationBuilder.DropColumn(
name: "LastModifiedBy",
table: "Actor");
migrationBuilder.DropColumn(
name: "LastModifiedDate",
table: "Actor");
}
}
}

View File

@@ -1,230 +0,0 @@
// <auto-generated />
using System;
using CleanArchitecture.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace CleanArchitecture.Data.Migrations
{
[DbContext(typeof(StreamerDbContext))]
[Migration("20240218123327_cleanArchitectureFromApi")]
partial class cleanArchitectureFromApi
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("CleanArchitecture.Domain.Actor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Apellido")
.HasColumnType("longtext");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("Actor");
});
modelBuilder.Entity("CleanArchitecture.Domain.Director", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Apellido")
.HasColumnType("longtext");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.Property<int>("VideoId")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Director");
});
modelBuilder.Entity("CleanArchitecture.Domain.Streamer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.Property<string>("Url")
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("Streamers");
});
modelBuilder.Entity("CleanArchitecture.Domain.Video", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<int?>("DirectorId")
.HasColumnType("int");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.Property<int>("StreamerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DirectorId")
.IsUnique();
b.HasIndex("StreamerId");
b.ToTable("Videos");
});
modelBuilder.Entity("CleanArchitecture.Domain.VideoActor", b =>
{
b.Property<int>("VideoId")
.HasColumnType("int");
b.Property<int>("ActorId")
.HasColumnType("int");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<int>("Id")
.HasColumnType("int");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.HasKey("VideoId", "ActorId");
b.HasIndex("ActorId");
b.ToTable("VideoActor");
});
modelBuilder.Entity("CleanArchitecture.Domain.Video", b =>
{
b.HasOne("CleanArchitecture.Domain.Director", "Director")
.WithOne("Video")
.HasForeignKey("CleanArchitecture.Domain.Video", "DirectorId");
b.HasOne("CleanArchitecture.Domain.Streamer", "Streamer")
.WithMany("Videos")
.HasForeignKey("StreamerId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Director");
b.Navigation("Streamer");
});
modelBuilder.Entity("CleanArchitecture.Domain.VideoActor", b =>
{
b.HasOne("CleanArchitecture.Domain.Actor", "Actor")
.WithMany()
.HasForeignKey("ActorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("CleanArchitecture.Domain.Video", "Video")
.WithMany()
.HasForeignKey("VideoId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Actor");
b.Navigation("Video");
});
modelBuilder.Entity("CleanArchitecture.Domain.Director", b =>
{
b.Navigation("Video");
});
modelBuilder.Entity("CleanArchitecture.Domain.Streamer", b =>
{
b.Navigation("Videos");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,72 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CleanArchitecture.Data.Migrations
{
/// <inheritdoc />
public partial class cleanArchitectureFromApi : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "CreatedBy",
table: "VideoActor",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<DateTime>(
name: "CreatedDate",
table: "VideoActor",
type: "datetime(6)",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "Id",
table: "VideoActor",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<string>(
name: "LastModifiedBy",
table: "VideoActor",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<DateTime>(
name: "LastModifiedDate",
table: "VideoActor",
type: "datetime(6)",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CreatedBy",
table: "VideoActor");
migrationBuilder.DropColumn(
name: "CreatedDate",
table: "VideoActor");
migrationBuilder.DropColumn(
name: "Id",
table: "VideoActor");
migrationBuilder.DropColumn(
name: "LastModifiedBy",
table: "VideoActor");
migrationBuilder.DropColumn(
name: "LastModifiedDate",
table: "VideoActor");
}
}
}

View File

@@ -1,4 +1,5 @@
// <auto-generated />
using System;
using CleanArchitecture.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
@@ -7,10 +8,10 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace CleanArchitecture.Data.Migrations
namespace CleanArchitecture.Infrastructure.Migrations
{
[DbContext(typeof(StreamerDbContext))]
[Migration("20240215100525_InitialMigration")]
[Migration("20240221215002_Initial-Migration")]
partial class InitialMigration
{
/// <inheritdoc />
@@ -23,9 +24,22 @@ namespace CleanArchitecture.Data.Migrations
modelBuilder.Entity("CleanArchitecture.Domain.Streamer", b =>
{
b.Property<int>("Id")
b.Property<byte[]>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
.HasColumnType("binary(16)")
.HasColumnName("Id");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
@@ -40,15 +54,29 @@ namespace CleanArchitecture.Data.Migrations
modelBuilder.Entity("CleanArchitecture.Domain.Video", b =>
{
b.Property<int>("Id")
b.Property<byte[]>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
.HasColumnType("binary(16)")
.HasColumnName("Id");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.Property<int>("StreamerId")
.HasColumnType("int");
b.Property<byte[]>("StreamerId")
.IsRequired()
.HasColumnType("binary(16)");
b.HasKey("Id");
@@ -60,13 +88,18 @@ namespace CleanArchitecture.Data.Migrations
modelBuilder.Entity("CleanArchitecture.Domain.Video", b =>
{
b.HasOne("CleanArchitecture.Domain.Streamer", "Streamer")
.WithMany()
.WithMany("Videos")
.HasForeignKey("StreamerId")
.OnDelete(DeleteBehavior.Cascade)
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Streamer");
});
modelBuilder.Entity("CleanArchitecture.Domain.Streamer", b =>
{
b.Navigation("Videos");
});
#pragma warning restore 612, 618
}
}

View File

@@ -1,9 +1,9 @@
using Microsoft.EntityFrameworkCore.Metadata;
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CleanArchitecture.Data.Migrations
namespace CleanArchitecture.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class InitialMigration : Migration
@@ -18,11 +18,16 @@ namespace CleanArchitecture.Data.Migrations
name: "Streamers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Id = table.Column<byte[]>(type: "binary(16)", nullable: false),
Nombre = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Url = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
CreatedDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
CreatedBy = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
LastModifiedDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
LastModifiedBy = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
@@ -35,11 +40,16 @@ namespace CleanArchitecture.Data.Migrations
name: "Videos",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Id = table.Column<byte[]>(type: "binary(16)", nullable: false),
Nombre = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
StreamerId = table.Column<int>(type: "int", nullable: false)
StreamerId = table.Column<byte[]>(type: "binary(16)", nullable: false),
CreatedDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
CreatedBy = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
LastModifiedDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
LastModifiedBy = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
@@ -48,8 +58,7 @@ namespace CleanArchitecture.Data.Migrations
name: "FK_Videos_Streamers_StreamerId",
column: x => x.StreamerId,
principalTable: "Streamers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
principalColumn: "Id");
})
.Annotation("MySql:CharSet", "utf8mb4");

View File

@@ -1,227 +0,0 @@
// <auto-generated />
using System;
using CleanArchitecture.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace CleanArchitecture.Data.Migrations
{
[DbContext(typeof(StreamerDbContext))]
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("CleanArchitecture.Domain.Actor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Apellido")
.HasColumnType("longtext");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("Actor");
});
modelBuilder.Entity("CleanArchitecture.Domain.Director", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Apellido")
.HasColumnType("longtext");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.Property<int>("VideoId")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Director");
});
modelBuilder.Entity("CleanArchitecture.Domain.Streamer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.Property<string>("Url")
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("Streamers");
});
modelBuilder.Entity("CleanArchitecture.Domain.Video", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<int?>("DirectorId")
.HasColumnType("int");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.Property<int>("StreamerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DirectorId")
.IsUnique();
b.HasIndex("StreamerId");
b.ToTable("Videos");
});
modelBuilder.Entity("CleanArchitecture.Domain.VideoActor", b =>
{
b.Property<int>("VideoId")
.HasColumnType("int");
b.Property<int>("ActorId")
.HasColumnType("int");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<int>("Id")
.HasColumnType("int");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.HasKey("VideoId", "ActorId");
b.HasIndex("ActorId");
b.ToTable("VideoActor");
});
modelBuilder.Entity("CleanArchitecture.Domain.Video", b =>
{
b.HasOne("CleanArchitecture.Domain.Director", "Director")
.WithOne("Video")
.HasForeignKey("CleanArchitecture.Domain.Video", "DirectorId");
b.HasOne("CleanArchitecture.Domain.Streamer", "Streamer")
.WithMany("Videos")
.HasForeignKey("StreamerId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Director");
b.Navigation("Streamer");
});
modelBuilder.Entity("CleanArchitecture.Domain.VideoActor", b =>
{
b.HasOne("CleanArchitecture.Domain.Actor", "Actor")
.WithMany()
.HasForeignKey("ActorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("CleanArchitecture.Domain.Video", "Video")
.WithMany()
.HasForeignKey("VideoId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Actor");
b.Navigation("Video");
});
modelBuilder.Entity("CleanArchitecture.Domain.Director", b =>
{
b.Navigation("Video");
});
modelBuilder.Entity("CleanArchitecture.Domain.Streamer", b =>
{
b.Navigation("Videos");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,103 @@
// <auto-generated />
using System;
using CleanArchitecture.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace CleanArchitecture.Infrastructure.Migrations
{
[DbContext(typeof(StreamerDbContext))]
partial class StreamerDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("CleanArchitecture.Domain.Streamer", b =>
{
b.Property<byte[]>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("binary(16)")
.HasColumnName("Id");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.Property<string>("Url")
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("Streamers");
});
modelBuilder.Entity("CleanArchitecture.Domain.Video", b =>
{
b.Property<byte[]>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("binary(16)")
.HasColumnName("Id");
b.Property<string>("CreatedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("CreatedDate")
.HasColumnType("datetime(6)");
b.Property<string>("LastModifiedBy")
.HasColumnType("longtext");
b.Property<DateTime?>("LastModifiedDate")
.HasColumnType("datetime(6)");
b.Property<string>("Nombre")
.HasColumnType("longtext");
b.Property<byte[]>("StreamerId")
.IsRequired()
.HasColumnType("binary(16)");
b.HasKey("Id");
b.HasIndex("StreamerId");
b.ToTable("Videos");
});
modelBuilder.Entity("CleanArchitecture.Domain.Video", b =>
{
b.HasOne("CleanArchitecture.Domain.Streamer", "Streamer")
.WithMany("Videos")
.HasForeignKey("StreamerId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Streamer");
});
modelBuilder.Entity("CleanArchitecture.Domain.Streamer", b =>
{
b.Navigation("Videos");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -10,10 +10,16 @@ using System.Threading.Tasks;
namespace CleanArchitecture.Infrastructure.Persistence
{
/// <summary>
/// Add-Migration Migration-Name -Context StreamerDbContext
/// Remove-Migration -Context StreamerDbContext
/// Update-Database -Context StreamerDbContext
/// </summary>
public class StreamerDbContext : DbContext
{
public StreamerDbContext(DbContextOptions<StreamerDbContext> options) : base(options)
{
public StreamerDbContext(DbContextOptions<StreamerDbContext> options) : base(options)
{
}
//protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
@@ -26,13 +32,13 @@ namespace CleanArchitecture.Infrastructure.Persistence
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
{
foreach(var entry in ChangeTracker.Entries<BaseDomainModel>())
foreach (var entry in ChangeTracker.Entries<BaseDomainModel>())
{
switch (entry.State)
{
case EntityState.Modified:
entry.Entity.LastModifiedBy = "System";
entry.Entity.LastModifiedDate = DateTime.Now;
entry.Entity.LastModifiedDate = DateTime.Now;
break;
case EntityState.Added:
entry.Entity.CreatedDate = DateTime.Now;
@@ -43,7 +49,7 @@ namespace CleanArchitecture.Infrastructure.Persistence
case EntityState.Unchanged:
break;
case EntityState.Deleted:
break;
break;
default:
break;
}
@@ -53,37 +59,70 @@ namespace CleanArchitecture.Infrastructure.Persistence
protected override void OnModelCreating(ModelBuilder mb)
{
mb.Entity<Streamer>()
.HasMany(x => x.Videos)
mb.Entity<Streamer>(entity =>
{
entity.Property(e => e.Id)
.HasColumnName("Id")
.HasColumnType("binary(16)") // Especifica el tipo de columna y tamaño correcto
.HasConversion(
id => id.ToByteArray(), // Convierte de Guid a byte[] al guardar
bytes => new Guid(bytes) // Convierte de byte[] a Guid al leer
);
entity.HasMany(x => x.Videos)
.WithOne(x => x.Streamer)
.HasForeignKey(x => x.StreamerId)
.IsRequired()
.OnDelete(DeleteBehavior.Restrict);
});
mb.Entity<Video>()
.HasMany(x => x.Actores)
mb.Entity<Video>(entity =>
{
entity.Property(e => e.Id)
.HasColumnName("Id")
.HasColumnType("binary(16)") // Especifica el tipo de columna y tamaño correcto
.HasConversion(
id => id.ToByteArray(), // Convierte de Guid a byte[] al guardar
bytes => new Guid(bytes) // Convierte de byte[] a Guid al leer
);
entity.HasOne(x => x.Streamer)
.WithMany(x => x.Videos)
.UsingEntity<VideoActor>(
pt => pt.HasKey(t => new { t.VideoId, t.ActorId })
);
.HasForeignKey(x => x.StreamerId)
.IsRequired()
.OnDelete(DeleteBehavior.NoAction);
});
mb.Entity<Video>()
.HasOne(v => v.Director) // Navegación desde Video a Director
.WithOne(d => d.Video) // Navegación inversa desde Director a Video
.HasForeignKey<Director>(d => d.VideoId); // Especifica que la propiedad VideoId en Director es la clave foránea
//mb.Entity<Streamer>()
// .HasMany(x => x.Videos)
// .WithOne(x => x.Streamer)
// .HasForeignKey(x => x.StreamerId)
// .IsRequired()
// .OnDelete(DeleteBehavior.Restrict);
mb.Entity<Director>()
.HasOne(v => v.Video) // Navegación desde Video a Director
.WithOne(d => d.Director) // Navegación inversa desde Director a Video
.HasForeignKey<Video>(d => d.DirectorId); // Especifica que la propiedad VideoId en Director es la clave foránea
//mb.Entity<Video>()
// .HasMany(x => x.Actores)
// .WithMany(x => x.Videos)
// .UsingEntity<VideoActor>(
// pt => pt.HasKey(t => new { t.VideoId, t.ActorId })
//);
//mb.Entity<Video>()
// .HasOne(v => v.Director) // Navegación desde Video a Director
// .WithOne(d => d.Video) // Navegación inversa desde Director a Video
// .HasForeignKey<Director>(d => d.VideoId); // Especifica que la propiedad VideoId en Director es la clave foránea
//mb.Entity<Director>()
// .HasOne(v => v.Video) // Navegación desde Video a Director
// .WithOne(d => d.Director) // Navegación inversa desde Director a Video
// .HasForeignKey<Video>(d => d.DirectorId); // Especifica que la propiedad VideoId en Director es la clave foránea
}
public virtual DbSet<Streamer> Streamers { get; set; }
public virtual DbSet<Video> Videos { get; set; }
public virtual DbSet<Actor> Actor { get; set; }
public virtual DbSet<Director> Director { get; set; }
public virtual DbSet<VideoActor> VideoActor { get; set; }
//public virtual DbSet<Actor> Actor { get; set; }
//public virtual DbSet<Director> Director { get; set; }
//public virtual DbSet<VideoActor> VideoActor { get; set; }
}
}

View File

@@ -55,7 +55,7 @@ namespace CleanArchitecture.Infrastructure.Repositories
return await query.ToListAsync();
}
public virtual async Task<T> GetByIdAsync(int id)
public virtual async Task<T> GetByIdAsync(Guid id)
{
return await context.Set<T>().FindAsync(id);
}

View File

@@ -11,7 +11,7 @@ namespace CleanArchitecture.Infrastructure.Repositories
{
public class StreamerRepository: RepositoryBase<Streamer>, IStreamerRepository
{
public StreamerRepository(StreamerDbContext context) : base(context) { }
public StreamerRepository(StreamerDbContext context) : base(context) { }
}
}

View File

@@ -1,13 +1,13 @@
using CleanArchitecture.Application.Contracts.Persistence;
using CleanArchitecture.Domain.Common;
using CleanArchitecture.Infrastructure.Persistence;
using System.Collections;
namespace CleanArchitecture.Infrastructure.Repositories
{
public class UnitOfWork : IUnitOfWork
{
private Hashtable repositories;
using CleanArchitecture.Application.Contracts.Persistence;
using CleanArchitecture.Domain.Common;
using CleanArchitecture.Infrastructure.Persistence;
using System.Collections;
namespace CleanArchitecture.Infrastructure.Repositories
{
public class UnitOfWork : IUnitOfWork
{
private Hashtable repositories;
private readonly StreamerDbContext context;
private IVideoRepository videoRepository;
@@ -17,39 +17,39 @@ namespace CleanArchitecture.Infrastructure.Repositories
public IVideoRepository VideoRepository => videoRepository ?? new VideoRepository(context);
public IStreamerRepository StreamerRepository => streamerRepository ?? new StreamerRepository(context);
public UnitOfWork(StreamerDbContext _context)
{
context = _context;
}
public async Task<int> Complete()
{
return await context.SaveChangesAsync();
}
public void Dispose()
{
context.Dispose();
}
public IAsyncRepository<T> Repository<T>() where T : BaseDomainModel
{
if (repositories == null)
{
repositories = new Hashtable();
}
var type = typeof(T).Name;
if (!repositories.ContainsKey(type))
{
var repositoryType = typeof(RepositoryBase<>);
var repositoryInstance = Activator.CreateInstance(repositoryType.MakeGenericType(typeof(T)), context);
repositories.Add(type, repositoryInstance);
}
return (IAsyncRepository<T>)repositories[type];
}
}
}
public UnitOfWork(StreamerDbContext _context)
{
context = _context;
}
public async Task<int> Complete()
{
return await context.SaveChangesAsync();
}
public void Dispose()
{
context.Dispose();
}
public IAsyncRepository<T> Repository<T>() where T : BaseDomainModel
{
if (repositories == null)
{
repositories = new Hashtable();
}
var type = typeof(T).Name;
if (!repositories.ContainsKey(type))
{
var repositoryType = typeof(RepositoryBase<>);
var repositoryInstance = Activator.CreateInstance(repositoryType.MakeGenericType(typeof(T)), context);
repositories.Add(type, repositoryInstance);
}
return (IAsyncRepository<T>)repositories[type];
}
}
}

View File

@@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
namespace CleanArchitecture.Infrastructure.Repositories
{
internal class VideoRepository : RepositoryBase<Video>, IVideoRepository
public class VideoRepository : RepositoryBase<Video>, IVideoRepository
{
public VideoRepository(StreamerDbContext context) : base(context) { }

View File

@@ -4,9 +4,9 @@ namespace CleanArchitecture.Domain
{
public class Actor : BaseDomainModel
{
public Actor()
{
Videos = new HashSet<Video>();
public Actor()
{
Videos = new HashSet<Video>();
}
public string? Nombre { get; set; }

View File

@@ -8,7 +8,7 @@ namespace CleanArchitecture.Domain.Common
{
public abstract class BaseDomainModel
{
public int Id { get; set; }
public Guid Id { get; set; }
public DateTime? CreatedDate { get; set; }
public string? CreatedBy { get; set; }

View File

@@ -4,18 +4,18 @@ namespace CleanArchitecture.Domain
{
public class Video : BaseDomainModel
{
public Video()
{
Actores = [];
}
//public Video()
//{
// Actores = [];
//}
public string? Nombre { get; set; }
public int StreamerId { get; set; }
public Guid StreamerId { get; set; }
public virtual Streamer? Streamer { get; set; }
public int? DirectorId { get; set; }
public virtual Director? Director { get; set; }
//public int? DirectorId { get; set; }
//public virtual Director? Director { get; set; }
public virtual ICollection<Actor>? Actores { get; set; }
//public virtual ICollection<Actor>? Actores { get; set; }
}

View File

@@ -23,7 +23,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CleanArchitecture.API", "Cl
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CleanArchitecture.Application", "CleanArchitecture.Application\CleanArchitecture.Application.csproj", "{B9B096A1-C916-40DF-9F9F-9CF384CC0398}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CleanArchitecture.Identity", "CleanArchitecture.Identity\CleanArchitecture.Identity.csproj", "{2D1CFE96-C41D-4EFC-9DBA-10249988D9FF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CleanArchitecture.Identity", "CleanArchitecture.Identity\CleanArchitecture.Identity.csproj", "{2D1CFE96-C41D-4EFC-9DBA-10249988D9FF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CleanArchitecture.Application.UnitTests", "CleanArchitecture.Application.UnitTests\CleanArchitecture.Application.UnitTests.csproj", "{CF5179BD-2D75-4CEF-BE42-EFC20EEE6021}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -51,6 +53,10 @@ Global
{2D1CFE96-C41D-4EFC-9DBA-10249988D9FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D1CFE96-C41D-4EFC-9DBA-10249988D9FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D1CFE96-C41D-4EFC-9DBA-10249988D9FF}.Release|Any CPU.Build.0 = Release|Any CPU
{CF5179BD-2D75-4CEF-BE42-EFC20EEE6021}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF5179BD-2D75-4CEF-BE42-EFC20EEE6021}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF5179BD-2D75-4CEF-BE42-EFC20EEE6021}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF5179BD-2D75-4CEF-BE42-EFC20EEE6021}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -64,6 +70,7 @@ Global
{4B1B4D47-84CF-4CAA-9A0A-69D8AC16463E} = {6EB52FD0-D3E0-4D88-BD5B-424229B76BD1}
{B9B096A1-C916-40DF-9F9F-9CF384CC0398} = {8BFA0E48-D4BE-48A4-B625-7FD3C7CBC88F}
{2D1CFE96-C41D-4EFC-9DBA-10249988D9FF} = {39B5751D-BEC9-4C98-9183-D5AE52248ABA}
{CF5179BD-2D75-4CEF-BE42-EFC20EEE6021} = {BB068D3E-ACDC-4C82-95F5-5368BEEF1CCD}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1D95339D-3ACA-48AD-B094-1C90F6DB327B}

View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34607.119
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MandarCorreo", "MandarCorreo\MandarCorreo.csproj", "{9033A5CD-22DD-40DF-907F-E7F23A6CB5C6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9033A5CD-22DD-40DF-907F-E7F23A6CB5C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9033A5CD-22DD-40DF-907F-E7F23A6CB5C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9033A5CD-22DD-40DF-907F-E7F23A6CB5C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9033A5CD-22DD-40DF-907F-E7F23A6CB5C6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CB12919E-932A-4A8F-870B-DFE108FDD721}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,28 @@
using System.Net.Mail;
using System.Net;
try
{
SmtpClient client = new SmtpClient("mail.asarmiento.es", 587)
{
Credentials = new NetworkCredential("alejandro@asarmiento.es", "Toledo.480200"),
EnableSsl = true
};
MailMessage mailMessage = new MailMessage
{
From = new MailAddress("alejandro@asarmiento.es"),
Subject = "Vacaciones de este año",
Body = "Este año me da que no vamos a tener vacaciones =(",
IsBodyHtml = false,
};
mailMessage.To.Add("alejandro.sarsan@gmail.com");
client.Send(mailMessage);
Console.WriteLine("Correo enviado con éxito.");
}
catch (Exception ex)
{
Console.WriteLine("No se pudo enviar el correo. Error: " + ex.Message);
}

View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,6 @@
@MongoProject.API_HostAddress = http://localhost:5197
GET {{MongoProject.API_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@@ -0,0 +1,23 @@
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseAuthorization();
app.MapControllers();
app.Run();

View File

@@ -0,0 +1,31 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:34210",
"sslPort": 0
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5197",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,17 @@
using MongoProject.Domain.Common;
namespace MongoProject.Domain
{
public class Actor : BaseDomainModel
{
public Actor()
{
Videos = new HashSet<Video>();
}
public string? Nombre { get; set; }
public string? Apellido { get; set; }
public virtual ICollection<Video>? Videos { get; set; }
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MongoProject.Domain.Common
{
public abstract class BaseDomainModel
{
public int Id { get; set; }
public DateTime? CreatedDate { get; set; }
public string? CreatedBy { get; set; }
public DateTime? LastModifiedDate { get; set; }
public string? LastModifiedBy { get; set; }
}
}

View File

@@ -0,0 +1,41 @@
namespace MongoProject.Domain.Common
{
public abstract class ValueObject
{
protected static bool EqualOperator(ValueObject left, ValueObject right)
{
if (left is null ^ right is null)
{
return false;
}
return ReferenceEquals(left, right) || left.Equals(right);
}
protected static bool NotEqualOperator(ValueObject left, ValueObject right)
{
return !(EqualOperator(left, right));
}
protected abstract IEnumerable<object> GetEqualityComponents();
public override bool Equals(object obj)
{
if (obj == null || obj.GetType() != GetType())
{
return false;
}
var other = (ValueObject)obj;
return this.GetEqualityComponents().SequenceEqual(other.GetEqualityComponents());
}
public override int GetHashCode()
{
return GetEqualityComponents()
.Select(x => x != null ? x.GetHashCode() : 0)
.Aggregate((x, y) => x ^ y);
}
// Other utility methods
}
}

View File

@@ -0,0 +1,13 @@
using MongoProject.Domain.Common;
namespace MongoProject.Domain
{
public class Director : BaseDomainModel
{
public string? Nombre { get; set; }
public string? Apellido { get; set; }
public int VideoId { get; set; }
public virtual Video? Video { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,16 @@
using MongoProject.Domain.Common;
namespace MongoProject.Domain
{
public class Streamer : BaseDomainModel
{
public int Id { get; set; }
public DateTime? CreatedDate { get; set; }
public string? CreatedBy { get; set; }
public DateTime? LastModifiedDate { get; set; }
public string? LastModifiedBy { get; set; }
public string? Nombre { get; set; }
public string? Url { get; set; }
public ICollection<Video>? Videos { get; set; }
}
}

View File

@@ -0,0 +1,22 @@
using MongoProject.Domain.Common;
namespace MongoProject.Domain
{
public class Video : BaseDomainModel
{
public Video()
{
Actores = [];
}
public string? Nombre { get; set; }
public int StreamerId { get; set; }
public virtual Streamer? Streamer { get; set; }
public int? DirectorId { get; set; }
public virtual Director? Director { get; set; }
public virtual ICollection<Actor>? Actores { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
using MongoProject.Domain.Common;
namespace MongoProject.Domain
{
public class VideoActor : BaseDomainModel
{
public int VideoId { get; set; }
public virtual Video? Video { get; set; }
public int ActorId { get; set; }
public virtual Actor? Actor { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,60 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34607.119
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{529D43D8-F144-4D48-B288-95CB3A180D65}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "API", "API", "{9E57EC3A-4903-499C-A438-DD9D2FC0A3B3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{24633152-BD8D-42B7-BC1D-0D4A9DE1F181}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructure", "Infrastructure", "{89FFD380-F129-41F0-9A5D-94FE5FBB5266}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoProject.Application", "MongoProject.Application\MongoProject.Application.csproj", "{BD54D679-B40F-48D6-9FFD-792FBD8FCCA4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoProject.Domain", "MongoProject.Domain\MongoProject.Domain.csproj", "{65F56A3D-BB3C-4F1F-8F23-A3033EDC2AEB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoProject.Infrastructure", "MongoProject.Infrastructure\MongoProject.Infrastructure.csproj", "{EE7D69D7-BDC7-4879-8466-58A2310BFC36}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoProject.API", "MongoProject.API\MongoProject.API.csproj", "{F237EEC3-972D-48EE-81E9-170FEDEF866F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BD54D679-B40F-48D6-9FFD-792FBD8FCCA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD54D679-B40F-48D6-9FFD-792FBD8FCCA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD54D679-B40F-48D6-9FFD-792FBD8FCCA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD54D679-B40F-48D6-9FFD-792FBD8FCCA4}.Release|Any CPU.Build.0 = Release|Any CPU
{65F56A3D-BB3C-4F1F-8F23-A3033EDC2AEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{65F56A3D-BB3C-4F1F-8F23-A3033EDC2AEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65F56A3D-BB3C-4F1F-8F23-A3033EDC2AEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65F56A3D-BB3C-4F1F-8F23-A3033EDC2AEB}.Release|Any CPU.Build.0 = Release|Any CPU
{EE7D69D7-BDC7-4879-8466-58A2310BFC36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE7D69D7-BDC7-4879-8466-58A2310BFC36}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE7D69D7-BDC7-4879-8466-58A2310BFC36}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE7D69D7-BDC7-4879-8466-58A2310BFC36}.Release|Any CPU.Build.0 = Release|Any CPU
{F237EEC3-972D-48EE-81E9-170FEDEF866F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F237EEC3-972D-48EE-81E9-170FEDEF866F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F237EEC3-972D-48EE-81E9-170FEDEF866F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F237EEC3-972D-48EE-81E9-170FEDEF866F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9E57EC3A-4903-499C-A438-DD9D2FC0A3B3} = {529D43D8-F144-4D48-B288-95CB3A180D65}
{24633152-BD8D-42B7-BC1D-0D4A9DE1F181} = {529D43D8-F144-4D48-B288-95CB3A180D65}
{89FFD380-F129-41F0-9A5D-94FE5FBB5266} = {529D43D8-F144-4D48-B288-95CB3A180D65}
{BD54D679-B40F-48D6-9FFD-792FBD8FCCA4} = {24633152-BD8D-42B7-BC1D-0D4A9DE1F181}
{65F56A3D-BB3C-4F1F-8F23-A3033EDC2AEB} = {24633152-BD8D-42B7-BC1D-0D4A9DE1F181}
{EE7D69D7-BDC7-4879-8466-58A2310BFC36} = {89FFD380-F129-41F0-9A5D-94FE5FBB5266}
{F237EEC3-972D-48EE-81E9-170FEDEF866F} = {9E57EC3A-4903-499C-A438-DD9D2FC0A3B3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {ABD21FD9-C4B4-4EDF-83C2-F6A6207C89A3}
EndGlobalSection
EndGlobal