diff --git a/src/InternshipSystem.Api/Commands/UpdateRegistrationForm.cs b/src/InternshipSystem.Api/Commands/UpdateRegistrationForm.cs index 605d012..ddb6e5b 100644 --- a/src/InternshipSystem.Api/Commands/UpdateRegistrationForm.cs +++ b/src/InternshipSystem.Api/Commands/UpdateRegistrationForm.cs @@ -12,7 +12,7 @@ namespace InternshipSystem.Api.Commands public DateTime? Start { get; set; } public DateTime? End { get; set; } public UpdateMentor? Mentor { get; set; } - public List Subjects { get; set; } + public List Subjects { get; set; } public InternshipType Type { get; set; } } diff --git a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs index 0fd4a25..9c7a49e 100644 --- a/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs +++ b/src/InternshipSystem.Api/Controllers/InternshipRegistrationController.cs @@ -51,8 +51,10 @@ namespace InternshipSystem.Api.Controllers .Where(i => i.Student.Id == user.PersonNumber) .Select(i => i.InternshipRegistration) .Include(r => r.BranchAddress) + .Include(r => r.Type) + .Include(r => r.Subjects) .Include(r => r.Company) - .ThenInclude(c => c.Branches) + .Include(r => r.Company.Branches) .FirstAsync(cancellationToken); var useCase = new UpdateInternshipRegistrationUseCase(_context, internshipRegistration, edition, user); @@ -82,7 +84,6 @@ namespace InternshipSystem.Api.Controllers .Include(i => i.InternshipRegistration.Company) .Include(i => i.InternshipRegistration.BranchAddress) .Include(i => i.InternshipRegistration.Type) - .Include(i => i.InternshipProgram) .Include(i => i.Report) .Include(i => i.Approvals) .Include(i => i.Documentation) diff --git a/src/InternshipSystem.Api/UseCases/UpdateInternshipRegistrationUseCase.cs b/src/InternshipSystem.Api/UseCases/UpdateInternshipRegistrationUseCase.cs index 1eca45a..c7d1793 100644 --- a/src/InternshipSystem.Api/UseCases/UpdateInternshipRegistrationUseCase.cs +++ b/src/InternshipSystem.Api/UseCases/UpdateInternshipRegistrationUseCase.cs @@ -109,14 +109,14 @@ namespace InternshipSystem.Api.UseCases subjectRegistration.Company = company; } - private void UpdateSubjects(IEnumerable subjects) + private void UpdateSubjects(IEnumerable subjects) { subjectRegistration.Subjects = subjects .Select(i => new ProgramSubject { Registration = subjectRegistration, - InternshipSubjectId = i.Id + InternshipSubjectId = i }) .ToList(); } diff --git a/src/InternshipSystem.Core/Entity/Internship/Internship.cs b/src/InternshipSystem.Core/Entity/Internship/Internship.cs index 24bd08b..f511d1d 100644 --- a/src/InternshipSystem.Core/Entity/Internship/Internship.cs +++ b/src/InternshipSystem.Core/Entity/Internship/Internship.cs @@ -10,7 +10,6 @@ namespace InternshipSystem.Core public long Id { get; set; } public Student Student { get; set; } public InternshipRegistration InternshipRegistration { get; set; } - public InternshipProgram InternshipProgram { get; set; } public Report Report { get; set; } public List Approvals { get; set; } public List Documentation { get; set; } @@ -43,7 +42,6 @@ namespace InternshipSystem.Core internship.Student = student; internship.InternshipRegistration = InternshipRegistration.Create(); - internship.InternshipProgram = InternshipProgram.Create(); internship.Report = Report.Create(); internship.Approvals = new List(); internship.Documentation = new List(); diff --git a/src/InternshipSystem.Core/Entity/Internship/InternshipProgram.cs b/src/InternshipSystem.Core/Entity/Internship/InternshipProgram.cs deleted file mode 100644 index f5fc545..0000000 --- a/src/InternshipSystem.Core/Entity/Internship/InternshipProgram.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using InternshipSystem.Core.Entity.Internship; -using InternshipSystem.Core.UglyOrmArtifacts; - -namespace InternshipSystem.Core -{ - public class InternshipProgram - { - public long Id { get; set; } - public Mentor Mentor { get; set; } - public DocumentState State { get; set; } - public List ChosenSubjects { get; set; } - - public static InternshipProgram Create() - { - return new InternshipProgram(); - } - } -} \ No newline at end of file diff --git a/src/InternshipSystem.Repository/DatabaseFiller.cs b/src/InternshipSystem.Repository/DatabaseFiller.cs index 64b0621..fba4bf7 100644 --- a/src/InternshipSystem.Repository/DatabaseFiller.cs +++ b/src/InternshipSystem.Repository/DatabaseFiller.cs @@ -245,9 +245,6 @@ namespace InternshipSystem.Repository .First(c => c.Name.Equals("Intel")) .Branches .First(), - }, - InternshipProgram = new InternshipProgram - { Mentor = new Mentor { FirstName = "Horacy", @@ -255,7 +252,7 @@ namespace InternshipSystem.Repository Email = "howos@intel.com", PhoneNumber = "605-555-555", }, - ChosenSubjects = new List + Subjects = new List { new ProgramSubject { @@ -294,9 +291,6 @@ namespace InternshipSystem.Repository .First(c => c.Name.Equals("Asseco Poland")) .Branches .First(), - }, - InternshipProgram = new InternshipProgram - { Mentor = new Mentor { FirstName = "Henryk", @@ -304,7 +298,7 @@ namespace InternshipSystem.Repository Email = "hepol@asseco.pl", PhoneNumber = "555-525-545", }, - ChosenSubjects = new List + Subjects = new List { new ProgramSubject { diff --git a/src/InternshipSystem.Repository/InternshipDbContext.cs b/src/InternshipSystem.Repository/InternshipDbContext.cs index f9d8576..4d7560e 100644 --- a/src/InternshipSystem.Repository/InternshipDbContext.cs +++ b/src/InternshipSystem.Repository/InternshipDbContext.cs @@ -27,8 +27,9 @@ namespace InternshipSystem.Repository modelBuilder.Entity() .OwnsOne(bo => bo.Address); - modelBuilder.Entity() - .OwnsOne(ip => ip.Mentor); + + modelBuilder.Entity() + .OwnsOne(ir => ir.Mentor); modelBuilder.Entity(builder => { diff --git a/src/InternshipSystem.Repository/Migrations/20200927114840_init.Designer.cs b/src/InternshipSystem.Repository/Migrations/20201002175217_Initial.Designer.cs similarity index 92% rename from src/InternshipSystem.Repository/Migrations/20200927114840_init.Designer.cs rename to src/InternshipSystem.Repository/Migrations/20201002175217_Initial.Designer.cs index 79cf8f6..872b214 100644 --- a/src/InternshipSystem.Repository/Migrations/20200927114840_init.Designer.cs +++ b/src/InternshipSystem.Repository/Migrations/20201002175217_Initial.Designer.cs @@ -10,8 +10,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace InternshipSystem.Repository.Migrations { [DbContext(typeof(InternshipDbContext))] - [Migration("20200927114840_init")] - partial class init + [Migration("20201002175217_Initial")] + partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -33,6 +33,10 @@ namespace InternshipSystem.Repository.Migrations .HasColumnName("company_id") .HasColumnType("bigint"); + b.Property("Provider") + .HasColumnName("provider") + .HasColumnType("bigint"); + b.HasKey("Id") .HasName("pk_branch_office"); @@ -58,6 +62,10 @@ namespace InternshipSystem.Repository.Migrations .HasColumnName("nip") .HasColumnType("text"); + b.Property("Provider") + .HasColumnName("provider") + .HasColumnType("bigint"); + b.HasKey("Id") .HasName("pk_companies"); @@ -240,10 +248,6 @@ namespace InternshipSystem.Repository.Migrations .HasColumnName("grade") .HasColumnType("real"); - b.Property("InternshipProgramId") - .HasColumnName("internship_program_id") - .HasColumnType("bigint"); - b.Property("InternshipRegistrationId") .HasColumnName("internship_registration_id") .HasColumnType("bigint"); @@ -262,9 +266,6 @@ namespace InternshipSystem.Repository.Migrations b.HasIndex("EditionId") .HasName("ix_internship_edition_id"); - b.HasIndex("InternshipProgramId") - .HasName("ix_internship_internship_program_id"); - b.HasIndex("InternshipRegistrationId") .HasName("ix_internship_internship_registration_id"); @@ -277,24 +278,6 @@ namespace InternshipSystem.Repository.Migrations b.ToTable("internship"); }); - modelBuilder.Entity("InternshipSystem.Core.InternshipProgram", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("State") - .HasColumnName("state") - .HasColumnType("integer"); - - b.HasKey("Id") - .HasName("pk_internship_program"); - - b.ToTable("internship_program"); - }); - modelBuilder.Entity("InternshipSystem.Core.InternshipRegistration", b => { b.Property("Id") @@ -461,15 +444,15 @@ namespace InternshipSystem.Repository.Migrations modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.ProgramSubject", b => { - b.Property("InternshipProgramId") - .HasColumnName("internship_program_id") + b.Property("InternshipRegistrationId") + .HasColumnName("internship_registration_id") .HasColumnType("bigint"); b.Property("InternshipSubjectId") .HasColumnName("internship_subject_id") .HasColumnType("bigint"); - b.HasKey("InternshipProgramId", "InternshipSubjectId") + b.HasKey("InternshipRegistrationId", "InternshipSubjectId") .HasName("pk_program_subject"); b.HasIndex("InternshipSubjectId") @@ -565,11 +548,6 @@ namespace InternshipSystem.Repository.Migrations .HasForeignKey("EditionId") .HasConstraintName("fk_internship_editions_edition_id"); - b.HasOne("InternshipSystem.Core.InternshipProgram", "InternshipProgram") - .WithMany() - .HasForeignKey("InternshipProgramId") - .HasConstraintName("fk_internship_internship_program_internship_program_id"); - b.HasOne("InternshipSystem.Core.InternshipRegistration", "InternshipRegistration") .WithMany() .HasForeignKey("InternshipRegistrationId") @@ -586,11 +564,26 @@ namespace InternshipSystem.Repository.Migrations .HasConstraintName("fk_internship_students_student_id"); }); - modelBuilder.Entity("InternshipSystem.Core.InternshipProgram", b => + modelBuilder.Entity("InternshipSystem.Core.InternshipRegistration", b => { + b.HasOne("InternshipSystem.Core.BranchOffice", "BranchAddress") + .WithMany() + .HasForeignKey("BranchAddressId") + .HasConstraintName("fk_internship_registration_branch_office_branch_address_id"); + + b.HasOne("InternshipSystem.Core.Company", "Company") + .WithMany() + .HasForeignKey("CompanyId") + .HasConstraintName("fk_internship_registration_companies_company_id"); + + b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipType", "Type") + .WithMany() + .HasForeignKey("TypeId") + .HasConstraintName("fk_internship_registration_internship_types_type_id"); + b.OwnsOne("InternshipSystem.Core.Mentor", "Mentor", b1 => { - b1.Property("InternshipProgramId") + b1.Property("InternshipRegistrationId") .ValueGeneratedOnAdd() .HasColumnName("id") .HasColumnType("bigint") @@ -612,35 +605,17 @@ namespace InternshipSystem.Repository.Migrations .HasColumnName("phone_number") .HasColumnType("text"); - b1.HasKey("InternshipProgramId") - .HasName("pk_internship_program"); + b1.HasKey("InternshipRegistrationId") + .HasName("pk_internship_registration"); - b1.ToTable("internship_program"); + b1.ToTable("internship_registration"); b1.WithOwner() - .HasForeignKey("InternshipProgramId") - .HasConstraintName("fk_mentor_internship_program_internship_program_id"); + .HasForeignKey("InternshipRegistrationId") + .HasConstraintName("fk_mentor_internship_registration_internship_registration_id"); }); }); - modelBuilder.Entity("InternshipSystem.Core.InternshipRegistration", b => - { - b.HasOne("InternshipSystem.Core.BranchOffice", "BranchAddress") - .WithMany() - .HasForeignKey("BranchAddressId") - .HasConstraintName("fk_internship_registration_branch_office_branch_address_id"); - - b.HasOne("InternshipSystem.Core.Company", "Company") - .WithMany() - .HasForeignKey("CompanyId") - .HasConstraintName("fk_internship_registration_companies_company_id"); - - b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipType", "Type") - .WithMany() - .HasForeignKey("TypeId") - .HasConstraintName("fk_internship_registration_internship_types_type_id"); - }); - modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.EditionSubject", b => { b.HasOne("InternshipSystem.Core.Edition", "Edition") @@ -660,10 +635,10 @@ namespace InternshipSystem.Repository.Migrations modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.ProgramSubject", b => { - b.HasOne("InternshipSystem.Core.InternshipProgram", "Program") - .WithMany("ChosenSubjects") - .HasForeignKey("InternshipProgramId") - .HasConstraintName("fk_program_subject_internship_program_internship_program_id") + b.HasOne("InternshipSystem.Core.InternshipRegistration", "Registration") + .WithMany("Subjects") + .HasForeignKey("InternshipRegistrationId") + .HasConstraintName("fk_program_subject_internship_registration_internship_registrat") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); diff --git a/src/InternshipSystem.Repository/Migrations/20200927114840_init.cs b/src/InternshipSystem.Repository/Migrations/20201002175217_Initial.cs similarity index 92% rename from src/InternshipSystem.Repository/Migrations/20200927114840_init.cs rename to src/InternshipSystem.Repository/Migrations/20201002175217_Initial.cs index 623be9c..3e03b42 100644 --- a/src/InternshipSystem.Repository/Migrations/20200927114840_init.cs +++ b/src/InternshipSystem.Repository/Migrations/20201002175217_Initial.cs @@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace InternshipSystem.Repository.Migrations { - public partial class init : Migration + public partial class Initial : Migration { protected override void Up(MigrationBuilder migrationBuilder) { @@ -15,7 +15,8 @@ namespace InternshipSystem.Repository.Migrations id = table.Column(nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), nip = table.Column(nullable: true), - name = table.Column(nullable: true) + name = table.Column(nullable: true), + provider = table.Column(nullable: false) }, constraints: table => { @@ -35,23 +36,6 @@ namespace InternshipSystem.Repository.Migrations table.PrimaryKey("pk_course", x => x.id); }); - migrationBuilder.CreateTable( - name: "internship_program", - columns: table => new - { - id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - first_name = table.Column(nullable: true), - last_name = table.Column(nullable: true), - email = table.Column(nullable: true), - phone_number = table.Column(nullable: true), - state = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_internship_program", x => x.id); - }); - migrationBuilder.CreateTable( name: "internship_subject", columns: table => new @@ -127,6 +111,7 @@ namespace InternshipSystem.Repository.Migrations city = table.Column(nullable: true), postal_code = table.Column(nullable: true), country = table.Column(nullable: true), + provider = table.Column(nullable: false), company_id = table.Column(nullable: true) }, constraints: table => @@ -140,30 +125,6 @@ namespace InternshipSystem.Repository.Migrations onDelete: ReferentialAction.Restrict); }); - migrationBuilder.CreateTable( - name: "program_subject", - columns: table => new - { - internship_program_id = table.Column(nullable: false), - internship_subject_id = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_program_subject", x => new { x.internship_program_id, x.internship_subject_id }); - table.ForeignKey( - name: "fk_program_subject_internship_program_internship_program_id", - column: x => x.internship_program_id, - principalTable: "internship_program", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_program_subject_internship_subject_internship_subject_id", - column: x => x.internship_subject_id, - principalTable: "internship_subject", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - migrationBuilder.CreateTable( name: "internship_registration", columns: table => new @@ -174,6 +135,10 @@ namespace InternshipSystem.Repository.Migrations branch_address_id = table.Column(nullable: true), start = table.Column(nullable: false), end = table.Column(nullable: false), + first_name = table.Column(nullable: true), + last_name = table.Column(nullable: true), + email = table.Column(nullable: true), + phone_number = table.Column(nullable: true), type_id = table.Column(nullable: true), state = table.Column(nullable: false) }, @@ -194,6 +159,30 @@ namespace InternshipSystem.Repository.Migrations onDelete: ReferentialAction.Restrict); }); + migrationBuilder.CreateTable( + name: "program_subject", + columns: table => new + { + internship_registration_id = table.Column(nullable: false), + internship_subject_id = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_program_subject", x => new { x.internship_registration_id, x.internship_subject_id }); + table.ForeignKey( + name: "fk_program_subject_internship_registration_internship_registrat", + column: x => x.internship_registration_id, + principalTable: "internship_registration", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "fk_program_subject_internship_subject_internship_subject_id", + column: x => x.internship_subject_id, + principalTable: "internship_subject", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "editions", columns: table => new @@ -248,7 +237,6 @@ namespace InternshipSystem.Repository.Migrations .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), student_id = table.Column(nullable: true), internship_registration_id = table.Column(nullable: true), - internship_program_id = table.Column(nullable: true), report_id = table.Column(nullable: true), edition_id = table.Column(nullable: true), grade = table.Column(nullable: true) @@ -262,12 +250,6 @@ namespace InternshipSystem.Repository.Migrations principalTable: "editions", principalColumn: "id", onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "fk_internship_internship_program_internship_program_id", - column: x => x.internship_program_id, - principalTable: "internship_program", - principalColumn: "id", - onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "fk_internship_internship_registration_internship_registration_", column: x => x.internship_registration_id, @@ -376,11 +358,6 @@ namespace InternshipSystem.Repository.Migrations table: "internship", column: "edition_id"); - migrationBuilder.CreateIndex( - name: "ix_internship_internship_program_id", - table: "internship", - column: "internship_program_id"); - migrationBuilder.CreateIndex( name: "ix_internship_internship_registration_id", table: "internship", @@ -462,9 +439,6 @@ namespace InternshipSystem.Repository.Migrations migrationBuilder.DropTable( name: "internship_subject"); - migrationBuilder.DropTable( - name: "internship_program"); - migrationBuilder.DropTable( name: "internship_registration"); diff --git a/src/InternshipSystem.Repository/Migrations/InternshipDbContextModelSnapshot.cs b/src/InternshipSystem.Repository/Migrations/InternshipDbContextModelSnapshot.cs index 529a966..e2dc33c 100644 --- a/src/InternshipSystem.Repository/Migrations/InternshipDbContextModelSnapshot.cs +++ b/src/InternshipSystem.Repository/Migrations/InternshipDbContextModelSnapshot.cs @@ -31,6 +31,10 @@ namespace InternshipSystem.Repository.Migrations .HasColumnName("company_id") .HasColumnType("bigint"); + b.Property("Provider") + .HasColumnName("provider") + .HasColumnType("bigint"); + b.HasKey("Id") .HasName("pk_branch_office"); @@ -56,6 +60,10 @@ namespace InternshipSystem.Repository.Migrations .HasColumnName("nip") .HasColumnType("text"); + b.Property("Provider") + .HasColumnName("provider") + .HasColumnType("bigint"); + b.HasKey("Id") .HasName("pk_companies"); @@ -238,10 +246,6 @@ namespace InternshipSystem.Repository.Migrations .HasColumnName("grade") .HasColumnType("real"); - b.Property("InternshipProgramId") - .HasColumnName("internship_program_id") - .HasColumnType("bigint"); - b.Property("InternshipRegistrationId") .HasColumnName("internship_registration_id") .HasColumnType("bigint"); @@ -260,9 +264,6 @@ namespace InternshipSystem.Repository.Migrations b.HasIndex("EditionId") .HasName("ix_internship_edition_id"); - b.HasIndex("InternshipProgramId") - .HasName("ix_internship_internship_program_id"); - b.HasIndex("InternshipRegistrationId") .HasName("ix_internship_internship_registration_id"); @@ -275,24 +276,6 @@ namespace InternshipSystem.Repository.Migrations b.ToTable("internship"); }); - modelBuilder.Entity("InternshipSystem.Core.InternshipProgram", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("State") - .HasColumnName("state") - .HasColumnType("integer"); - - b.HasKey("Id") - .HasName("pk_internship_program"); - - b.ToTable("internship_program"); - }); - modelBuilder.Entity("InternshipSystem.Core.InternshipRegistration", b => { b.Property("Id") @@ -459,15 +442,15 @@ namespace InternshipSystem.Repository.Migrations modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.ProgramSubject", b => { - b.Property("InternshipProgramId") - .HasColumnName("internship_program_id") + b.Property("InternshipRegistrationId") + .HasColumnName("internship_registration_id") .HasColumnType("bigint"); b.Property("InternshipSubjectId") .HasColumnName("internship_subject_id") .HasColumnType("bigint"); - b.HasKey("InternshipProgramId", "InternshipSubjectId") + b.HasKey("InternshipRegistrationId", "InternshipSubjectId") .HasName("pk_program_subject"); b.HasIndex("InternshipSubjectId") @@ -563,11 +546,6 @@ namespace InternshipSystem.Repository.Migrations .HasForeignKey("EditionId") .HasConstraintName("fk_internship_editions_edition_id"); - b.HasOne("InternshipSystem.Core.InternshipProgram", "InternshipProgram") - .WithMany() - .HasForeignKey("InternshipProgramId") - .HasConstraintName("fk_internship_internship_program_internship_program_id"); - b.HasOne("InternshipSystem.Core.InternshipRegistration", "InternshipRegistration") .WithMany() .HasForeignKey("InternshipRegistrationId") @@ -584,11 +562,26 @@ namespace InternshipSystem.Repository.Migrations .HasConstraintName("fk_internship_students_student_id"); }); - modelBuilder.Entity("InternshipSystem.Core.InternshipProgram", b => + modelBuilder.Entity("InternshipSystem.Core.InternshipRegistration", b => { + b.HasOne("InternshipSystem.Core.BranchOffice", "BranchAddress") + .WithMany() + .HasForeignKey("BranchAddressId") + .HasConstraintName("fk_internship_registration_branch_office_branch_address_id"); + + b.HasOne("InternshipSystem.Core.Company", "Company") + .WithMany() + .HasForeignKey("CompanyId") + .HasConstraintName("fk_internship_registration_companies_company_id"); + + b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipType", "Type") + .WithMany() + .HasForeignKey("TypeId") + .HasConstraintName("fk_internship_registration_internship_types_type_id"); + b.OwnsOne("InternshipSystem.Core.Mentor", "Mentor", b1 => { - b1.Property("InternshipProgramId") + b1.Property("InternshipRegistrationId") .ValueGeneratedOnAdd() .HasColumnName("id") .HasColumnType("bigint") @@ -610,35 +603,17 @@ namespace InternshipSystem.Repository.Migrations .HasColumnName("phone_number") .HasColumnType("text"); - b1.HasKey("InternshipProgramId") - .HasName("pk_internship_program"); + b1.HasKey("InternshipRegistrationId") + .HasName("pk_internship_registration"); - b1.ToTable("internship_program"); + b1.ToTable("internship_registration"); b1.WithOwner() - .HasForeignKey("InternshipProgramId") - .HasConstraintName("fk_mentor_internship_program_internship_program_id"); + .HasForeignKey("InternshipRegistrationId") + .HasConstraintName("fk_mentor_internship_registration_internship_registration_id"); }); }); - modelBuilder.Entity("InternshipSystem.Core.InternshipRegistration", b => - { - b.HasOne("InternshipSystem.Core.BranchOffice", "BranchAddress") - .WithMany() - .HasForeignKey("BranchAddressId") - .HasConstraintName("fk_internship_registration_branch_office_branch_address_id"); - - b.HasOne("InternshipSystem.Core.Company", "Company") - .WithMany() - .HasForeignKey("CompanyId") - .HasConstraintName("fk_internship_registration_companies_company_id"); - - b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipType", "Type") - .WithMany() - .HasForeignKey("TypeId") - .HasConstraintName("fk_internship_registration_internship_types_type_id"); - }); - modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.EditionSubject", b => { b.HasOne("InternshipSystem.Core.Edition", "Edition") @@ -658,10 +633,10 @@ namespace InternshipSystem.Repository.Migrations modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.ProgramSubject", b => { - b.HasOne("InternshipSystem.Core.InternshipProgram", "Program") - .WithMany("ChosenSubjects") - .HasForeignKey("InternshipProgramId") - .HasConstraintName("fk_program_subject_internship_program_internship_program_id") + b.HasOne("InternshipSystem.Core.InternshipRegistration", "Registration") + .WithMany("Subjects") + .HasForeignKey("InternshipRegistrationId") + .HasConstraintName("fk_program_subject_internship_registration_internship_registrat") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); diff --git a/test/InternshipSystem.Api.Test/InternshipSystem.cs b/test/InternshipSystem.Api.Test/InternshipSystem.cs index 3e3632f..6041122 100644 --- a/test/InternshipSystem.Api.Test/InternshipSystem.cs +++ b/test/InternshipSystem.Api.Test/InternshipSystem.cs @@ -1,10 +1,16 @@ -using System; using System.Collections.Generic; +using System.Linq; using System.Text.Json; +using System.Threading; +using InternshipSystem.Api.Commands; using InternshipSystem.Api.Controllers; +using InternshipSystem.Api.Security; +using InternshipSystem.Api.UseCases; +using InternshipSystem.Core; using InternshipSystem.Repository; using Machine.Specifications; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; namespace InternshipSystem.Api.Test { @@ -59,15 +65,112 @@ namespace InternshipSystem.Api.Test private static CasUserProfile result; } + class When_doint_whatever + { + private Establish context = () => + { + var db = new InternshipDbContext(new DbContextOptionsBuilder() + .UseLoggerFactory(LoggerFactory.Create(b => b.AddConsole())) + .UseNpgsql("Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=szwoniu") + .Options); + + var company = Company.CreateCompany("a", "b"); + + var internship = db.Editions.First(); + + + db.Companies.Add(company); + + db.SaveChanges(); + }; + + private It should_whatev = () => true.ShouldBeTrue(); + } + class When_writing_tests_only_for_debug_because_i_gave_up_on_code_quality { private Establish context = () => { var db = new InternshipDbContext(new DbContextOptionsBuilder() + .UseLoggerFactory(LoggerFactory.Create(b => b.AddConsole())) .UseNpgsql("Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=szwoniu") .Options); + + var ed = db.Editions.First(); + + var user = new User + { + PersonNumber = 1 + }; - var e + var ir = db.Entry(ed) + .Collection(e => e.Internships) + .Query() + .Include(i => i.InternshipRegistration) + .ThenInclude(r => r.BranchAddress) + .Include(i => i.InternshipRegistration) + .ThenInclude(r => r.Company) + .Include(i => i.InternshipRegistration) + .ThenInclude(c => c.Company.Branches) + .Include(i => i.InternshipRegistration) + .ThenInclude(c => c.Type) + .Include(i => i.InternshipRegistration) + .ThenInclude(c => c.Subjects) + .Where(i => i.Student.Id == user.PersonNumber) + .Select(i => i.InternshipRegistration) + .First(); + + var useCase = new UpdateInternshipRegistrationUseCase(db, ir, ed, user); + + var update = new UpdateRegistrationForm + { + Mentor = new UpdateMentor + { + FirstName = "Cwalina" + }, + Subjects = new List + { + 1, + 2, + 3 + }, + Company = new UpdateCompany + { + Name = "a", + BranchOffice = new UpdateBranchOffice + { + Street = "b" + } + }, + + }; + + var task = useCase.UpdateInternshipRegistration(update, CancellationToken.None); + + task.Wait(); + + var result = task.Result; + + db.SaveChanges(); + + ir = db.Entry(ed) + .Collection(e => e.Internships) + .Query() + .Include(i => i.InternshipRegistration) + .ThenInclude(r => r.BranchAddress) + .Include(i => i.InternshipRegistration) + .ThenInclude(r => r.Company) + .Include(i => i.InternshipRegistration) + .ThenInclude(c => c.Company.Branches) + .Include(i => i.InternshipRegistration) + .ThenInclude(c => c.Type) + .Include(i => i.InternshipRegistration) + .ThenInclude(c => c.Subjects) + .Where(i => i.Student.Id == user.PersonNumber) + .Select(i => i.InternshipRegistration) + .First(); }; + + private It should_nop = () => true.ShouldBeTrue(); } }