KEK

Co-authored-by: MaxchilKH <m.w.bohdanowicz@gmail.com>
This commit is contained in:
maxchil 2020-10-02 21:27:58 +02:00
parent 8514e593fa
commit 3a2b9b64d5
16 changed files with 381 additions and 310 deletions

View File

@ -13,7 +13,7 @@ namespace InternshipSystem.Api.Commands
public DateTime? End { get; set; }
public UpdateMentor? Mentor { get; set; }
public List<long> Subjects { get; set; }
public InternshipType Type { get; set; }
public long? Type { get; set; }
}
public struct UpdateMentor

View File

@ -38,7 +38,7 @@ namespace InternshipSystem.Api.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[Authorize]
public async Task<ActionResult<IList<EditionResult>>> GetAvailableEditions([FromServices] User user, CancellationToken token)
public async Task<ActionResult<IEnumerable<EditionResult>>> GetAvailableEditions([FromServices] User user, CancellationToken token)
{
var editions =
await Context.Editions

View File

@ -6,9 +6,7 @@ using InternshipSystem.Api.Security;
using InternshipSystem.Api.UseCases;
using InternshipSystem.Repository;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization;
using InternshipSystem.Api.Services;
using InternshipSystem.Core;
using InternshipSystem.Core.Entity.Internship;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
@ -41,7 +39,12 @@ namespace InternshipSystem.Api.Controllers
[FromServices] User user,
CancellationToken cancellationToken)
{
var edition = await _context.Editions.FirstAsync(e => e.Id == user.EditionId, cancellationToken);
var edition = await _context.Editions
.Include(e => e.AvailableInternshipTypes)
.ThenInclude(t => t.InternshipType)
.Include(e => e.AvailableSubjects)
.ThenInclude(t => t.Subject)
.FirstAsync(e => e.Id == user.EditionId, cancellationToken);
var internshipRegistration =
await _context

View File

@ -33,7 +33,7 @@ namespace InternshipSystem.Api.Controllers
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[Authorize(Policy = Policies.RegisteredOnly)]
public async Task<ActionResult<IList<InternshipType>>> GetInternshipTypesForEdition([FromServices] User user, CancellationToken cancellationToken)
public async Task<ActionResult<IEnumerable<InternshipType>>> GetInternshipTypesForEdition([FromServices] User user, CancellationToken cancellationToken)
{
var edition =
await Context.Editions
@ -46,7 +46,7 @@ namespace InternshipSystem.Api.Controllers
return NotFound();
}
return Ok(edition.AvailableInternshipTypes);
return Ok(edition.AvailableInternshipTypes.Select(e => e.InternshipType));
}
[HttpGet("{internshipTypeId}")]
@ -64,7 +64,7 @@ namespace InternshipSystem.Api.Controllers
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[Authorize]
public async Task<ActionResult<IList<InternshipType>>> SearchInternshipTypes([FromBody] InternshipTypeSearchQuery searchQuery, CancellationToken cancellationToken)
public async Task<ActionResult<IEnumerable<InternshipType>>> SearchInternshipTypes([FromBody] InternshipTypeSearchQuery searchQuery, CancellationToken cancellationToken)
{
return await Context.InternshipTypes
.Where(t => string.IsNullOrEmpty(searchQuery.Type) || t.Type.Contains(searchQuery.Type))

View File

@ -6,6 +6,7 @@ using IdentityServer4.Extensions;
using InternshipSystem.Api.Commands;
using InternshipSystem.Api.Security;
using InternshipSystem.Core;
using InternshipSystem.Core.Entity.Internship;
using InternshipSystem.Core.UglyOrmArtifacts;
using InternshipSystem.Repository;
using Microsoft.EntityFrameworkCore;
@ -34,8 +35,12 @@ namespace InternshipSystem.Api.UseCases
{
subjectRegistration.Start = registrationCommand.Start ?? subjectRegistration.Start;
subjectRegistration.End = registrationCommand.End ?? subjectRegistration.End;
subjectRegistration.Type = registrationCommand.Type ?? subjectRegistration.Type;
if (registrationCommand.Type.HasValue)
{
UpdateInternshipType(registrationCommand.Type.Value);
}
if (registrationCommand.Mentor.HasValue)
{
UpdateMentor(registrationCommand.Mentor.Value);
@ -54,6 +59,12 @@ namespace InternshipSystem.Api.UseCases
return subjectRegistration.ValidateStatus(_edition);
}
private void UpdateInternshipType(long typeId)
{
var editionInternshipType = _edition.AvailableInternshipTypes.FirstOrDefault(i => i.InternshipTypeId == typeId);
subjectRegistration.Type = editionInternshipType?.InternshipType ?? subjectRegistration.Type;
}
private async Task UpdateCompanyAndBranch(UpdateCompany companyUpdate, CancellationToken cancellationToken)
{
var company = subjectRegistration.Company;

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using InternshipSystem.Core.Entity.Internship;
using InternshipSystem.Core.UglyOrmArtifacts;
@ -13,11 +14,8 @@ namespace InternshipSystem.Core
public DateTime ReportingStart { get; set; }
public Course Course { get; set; }
public List<Internship> Internships { get; set; }
public InternshipType AllowedInternshipTypes { get; set; }
public List<EditionSubject> AvailableSubjects { get; set; }
public List<InternshipType> AvailableInternshipTypes { get; set; }
public List<EditionInternshipType> AvailableInternshipTypes { get; set; }
public bool IsOpen => EditionFinish < DateTime.Today;
@ -31,11 +29,6 @@ namespace InternshipSystem.Core
};
}
public bool IsInternshipTypeAllowed(InternshipType registrationQueryType)
{
return AvailableInternshipTypes.Contains(registrationQueryType);
}
public void RegisterInternship(Student student)
{
var internship = Internship.CreateStudentsInternship(student);
@ -47,5 +40,15 @@ namespace InternshipSystem.Core
{
return start >= EditionStart && end <= EditionFinish;
}
public bool IsTypeAvailable(InternshipType internshipType)
{
return AvailableInternshipTypes.Any(e => e.InternshipType == internshipType);
}
public bool AreSubjectsAvailable(IEnumerable<long> internshipSubjects)
{
return internshipSubjects.All(s => AvailableSubjects.Any(su => su.InternshipSubjectId == s));
}
}
}

View File

@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using InternshipSystem.Core.ValueObject;
namespace InternshipSystem.Core
namespace InternshipSystem.Core.Entity.Internship
{
public class Internship
{

View File

@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentValidation;
using FluentValidation.Results;
using InternshipSystem.Core.Entity.Internship;
using InternshipSystem.Core.UglyOrmArtifacts;
namespace InternshipSystem.Core
namespace InternshipSystem.Core.Entity.Internship
{
public class InternshipRegistration
{
@ -50,9 +49,11 @@ namespace InternshipSystem.Core
.SetValidator(new Mentor.Validate())
.NotNull();
RuleFor(x => x.Subjects)
.NotEmpty();
.NotEmpty()
.Must(s => edition.AreSubjectsAvailable(s.Select(su => su.InternshipSubjectId)));
RuleFor(x => x.Type)
.NotNull();
.NotNull()
.Must(edition.IsTypeAvailable);
RuleFor(x => x.Start)
.GreaterThanOrEqualTo(edition.EditionStart)
.LessThan(x => x.End)

View File

@ -0,0 +1,16 @@
using System;
using InternshipSystem.Core.Entity.Internship;
namespace InternshipSystem.Core.UglyOrmArtifacts
{
public class EditionInternshipType
{
public Edition Edition { get; set; }
public Guid EditionId { get; set; }
public InternshipType InternshipType { get; set; }
public long InternshipTypeId { get; set; }
}
}

View File

@ -208,12 +208,24 @@ namespace InternshipSystem.Repository
{
Name = "Informatyka",
},
AvailableInternshipTypes = new List<InternshipType>
AvailableInternshipTypes = new List<EditionInternshipType>
{
Context.InternshipTypes.First(t => t.Type.Equals("UOP")),
Context.InternshipTypes.First(t => t.Type.Equals("UZ")),
Context.InternshipTypes.First(t => t.Type.Equals("UD")),
Context.InternshipTypes.First(t => t.Type.Equals("FreeInternship")),
new EditionInternshipType
{
InternshipType = Context.InternshipTypes.First(t => t.Type.Equals("UOP"))
},
new EditionInternshipType
{
InternshipType = Context.InternshipTypes.First(t => t.Type.Equals("UZ"))
},
new EditionInternshipType
{
InternshipType = Context.InternshipTypes.First(t => t.Type.Equals("UD"))
},
new EditionInternshipType
{
InternshipType = Context.InternshipTypes.First(t => t.Type.Equals("FreeInternship"))
},
},
Internships = new List<Internship>(),
}

View File

@ -46,6 +46,22 @@ namespace InternshipSystem.Repository
.WithMany()
.HasForeignKey(subject => subject.InternshipSubjectId);
});
modelBuilder.Entity<EditionInternshipType>(builder =>
{
builder
.HasKey(type => new { type.EditionId, type.InternshipTypeId});
builder
.HasOne(k => k.Edition)
.WithMany(model => model.AvailableInternshipTypes)
.HasForeignKey(p => p.EditionId);
builder
.HasOne(k => k.InternshipType)
.WithMany()
.HasForeignKey(type => type.InternshipTypeId);
});
modelBuilder.Entity<EditionSubject>(builder =>
{

View File

@ -10,7 +10,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace InternshipSystem.Repository.Migrations
{
[DbContext(typeof(InternshipDbContext))]
[Migration("20201002175217_Initial")]
[Migration("20201002185255_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -145,10 +145,6 @@ namespace InternshipSystem.Repository.Migrations
.HasColumnName("id")
.HasColumnType("uuid");
b.Property<long?>("AllowedInternshipTypesId")
.HasColumnName("allowed_internship_types_id")
.HasColumnType("bigint");
b.Property<long?>("CourseId")
.HasColumnName("course_id")
.HasColumnType("bigint");
@ -168,71 +164,13 @@ namespace InternshipSystem.Repository.Migrations
b.HasKey("Id")
.HasName("pk_editions");
b.HasIndex("AllowedInternshipTypesId")
.HasName("ix_editions_allowed_internship_types_id");
b.HasIndex("CourseId")
.HasName("ix_editions_course_id");
b.ToTable("editions");
});
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipSubject", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("id")
.HasColumnType("bigint")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Description")
.HasColumnName("description")
.HasColumnType("text");
b.Property<string>("DescriptionEng")
.HasColumnName("description_eng")
.HasColumnType("text");
b.HasKey("Id")
.HasName("pk_internship_subject");
b.ToTable("internship_subject");
});
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipType", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("id")
.HasColumnType("bigint")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Description")
.HasColumnName("description")
.HasColumnType("text");
b.Property<string>("DescriptionEng")
.HasColumnName("description_eng")
.HasColumnType("text");
b.Property<Guid?>("EditionId")
.HasColumnName("edition_id")
.HasColumnType("uuid");
b.Property<string>("Type")
.HasColumnName("type")
.HasColumnType("text");
b.HasKey("Id")
.HasName("pk_internship_types");
b.HasIndex("EditionId")
.HasName("ix_internship_types_edition_id");
b.ToTable("internship_types");
});
modelBuilder.Entity("InternshipSystem.Core.Internship", b =>
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.Internship", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
@ -278,7 +216,7 @@ namespace InternshipSystem.Repository.Migrations
b.ToTable("internship");
});
modelBuilder.Entity("InternshipSystem.Core.InternshipRegistration", b =>
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipRegistration", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
@ -325,6 +263,54 @@ namespace InternshipSystem.Repository.Migrations
b.ToTable("internship_registration");
});
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipSubject", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("id")
.HasColumnType("bigint")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Description")
.HasColumnName("description")
.HasColumnType("text");
b.Property<string>("DescriptionEng")
.HasColumnName("description_eng")
.HasColumnType("text");
b.HasKey("Id")
.HasName("pk_internship_subject");
b.ToTable("internship_subject");
});
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipType", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("id")
.HasColumnType("bigint")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Description")
.HasColumnName("description")
.HasColumnType("text");
b.Property<string>("DescriptionEng")
.HasColumnName("description_eng")
.HasColumnType("text");
b.Property<string>("Type")
.HasColumnName("type")
.HasColumnType("text");
b.HasKey("Id")
.HasName("pk_internship_types");
b.ToTable("internship_types");
});
modelBuilder.Entity("InternshipSystem.Core.Report", b =>
{
b.Property<long>("Id")
@ -423,6 +409,25 @@ namespace InternshipSystem.Repository.Migrations
b.ToTable("students");
});
modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.EditionInternshipType", b =>
{
b.Property<Guid>("EditionId")
.HasColumnName("edition_id")
.HasColumnType("uuid");
b.Property<long>("InternshipTypeId")
.HasColumnName("internship_type_id")
.HasColumnType("bigint");
b.HasKey("EditionId", "InternshipTypeId")
.HasName("pk_edition_internship_type");
b.HasIndex("InternshipTypeId")
.HasName("ix_edition_internship_type_internship_type_id");
b.ToTable("edition_internship_type");
});
modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.EditionSubject", b =>
{
b.Property<Guid>("EditionId")
@ -509,12 +514,12 @@ namespace InternshipSystem.Repository.Migrations
modelBuilder.Entity("InternshipSystem.Core.Document", b =>
{
b.HasOne("InternshipSystem.Core.Internship", null)
b.HasOne("InternshipSystem.Core.Entity.Internship.Internship", null)
.WithMany("Approvals")
.HasForeignKey("InternshipId")
.HasConstraintName("fk_document_internship_internship_id");
b.HasOne("InternshipSystem.Core.Internship", null)
b.HasOne("InternshipSystem.Core.Entity.Internship.Internship", null)
.WithMany("Documentation")
.HasForeignKey("InternshipId1")
.HasConstraintName("fk_document_internship_internship_id1");
@ -522,33 +527,20 @@ namespace InternshipSystem.Repository.Migrations
modelBuilder.Entity("InternshipSystem.Core.Edition", b =>
{
b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipType", "AllowedInternshipTypes")
.WithMany()
.HasForeignKey("AllowedInternshipTypesId")
.HasConstraintName("fk_editions_internship_types_allowed_internship_types_id");
b.HasOne("InternshipSystem.Core.Course", "Course")
.WithMany()
.HasForeignKey("CourseId")
.HasConstraintName("fk_editions_course_course_id");
});
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipType", b =>
{
b.HasOne("InternshipSystem.Core.Edition", null)
.WithMany("AvailableInternshipTypes")
.HasForeignKey("EditionId")
.HasConstraintName("fk_internship_types_editions_edition_id");
});
modelBuilder.Entity("InternshipSystem.Core.Internship", b =>
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.Internship", b =>
{
b.HasOne("InternshipSystem.Core.Edition", "Edition")
.WithMany("Internships")
.HasForeignKey("EditionId")
.HasConstraintName("fk_internship_editions_edition_id");
b.HasOne("InternshipSystem.Core.InternshipRegistration", "InternshipRegistration")
b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipRegistration", "InternshipRegistration")
.WithMany()
.HasForeignKey("InternshipRegistrationId")
.HasConstraintName("fk_internship_internship_registration_internship_registration_");
@ -564,7 +556,7 @@ namespace InternshipSystem.Repository.Migrations
.HasConstraintName("fk_internship_students_student_id");
});
modelBuilder.Entity("InternshipSystem.Core.InternshipRegistration", b =>
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipRegistration", b =>
{
b.HasOne("InternshipSystem.Core.BranchOffice", "BranchAddress")
.WithMany()
@ -616,6 +608,23 @@ namespace InternshipSystem.Repository.Migrations
});
});
modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.EditionInternshipType", b =>
{
b.HasOne("InternshipSystem.Core.Edition", "Edition")
.WithMany("AvailableInternshipTypes")
.HasForeignKey("EditionId")
.HasConstraintName("fk_edition_internship_type_editions_edition_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipType", "InternshipType")
.WithMany()
.HasForeignKey("InternshipTypeId")
.HasConstraintName("fk_edition_internship_type_internship_types_internship_type_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.EditionSubject", b =>
{
b.HasOne("InternshipSystem.Core.Edition", "Edition")
@ -635,7 +644,7 @@ namespace InternshipSystem.Repository.Migrations
modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.ProgramSubject", b =>
{
b.HasOne("InternshipSystem.Core.InternshipRegistration", "Registration")
b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipRegistration", "Registration")
.WithMany("Subjects")
.HasForeignKey("InternshipRegistrationId")
.HasConstraintName("fk_program_subject_internship_registration_internship_registrat")

View File

@ -50,6 +50,21 @@ namespace InternshipSystem.Repository.Migrations
table.PrimaryKey("pk_internship_subject", x => x.id);
});
migrationBuilder.CreateTable(
name: "internship_types",
columns: table => new
{
id = table.Column<long>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
type = table.Column<string>(nullable: true),
description = table.Column<string>(nullable: true),
description_eng = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_internship_types", x => x.id);
});
migrationBuilder.CreateTable(
name: "report",
columns: table => new
@ -125,6 +140,27 @@ namespace InternshipSystem.Repository.Migrations
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "editions",
columns: table => new
{
id = table.Column<Guid>(nullable: false),
edition_start = table.Column<DateTime>(nullable: false),
edition_finish = table.Column<DateTime>(nullable: false),
reporting_start = table.Column<DateTime>(nullable: false),
course_id = table.Column<long>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_editions", x => x.id);
table.ForeignKey(
name: "fk_editions_course_course_id",
column: x => x.course_id,
principalTable: "course",
principalColumn: "id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "internship_registration",
columns: table => new
@ -157,54 +193,38 @@ namespace InternshipSystem.Repository.Migrations
principalTable: "companies",
principalColumn: "id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "program_subject",
columns: table => new
{
internship_registration_id = table.Column<long>(nullable: false),
internship_subject_id = table.Column<long>(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
{
id = table.Column<Guid>(nullable: false),
edition_start = table.Column<DateTime>(nullable: false),
edition_finish = table.Column<DateTime>(nullable: false),
reporting_start = table.Column<DateTime>(nullable: false),
course_id = table.Column<long>(nullable: true),
allowed_internship_types_id = table.Column<long>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_editions", x => x.id);
table.ForeignKey(
name: "fk_editions_course_course_id",
column: x => x.course_id,
principalTable: "course",
name: "fk_internship_registration_internship_types_type_id",
column: x => x.type_id,
principalTable: "internship_types",
principalColumn: "id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "edition_internship_type",
columns: table => new
{
edition_id = table.Column<Guid>(nullable: false),
internship_type_id = table.Column<long>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_edition_internship_type", x => new { x.edition_id, x.internship_type_id });
table.ForeignKey(
name: "fk_edition_internship_type_editions_edition_id",
column: x => x.edition_id,
principalTable: "editions",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_edition_internship_type_internship_types_internship_type_id",
column: x => x.internship_type_id,
principalTable: "internship_types",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "edition_subject",
columns: table => new
@ -271,25 +291,27 @@ namespace InternshipSystem.Repository.Migrations
});
migrationBuilder.CreateTable(
name: "internship_types",
name: "program_subject",
columns: table => new
{
id = table.Column<long>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
type = table.Column<string>(nullable: true),
description = table.Column<string>(nullable: true),
description_eng = table.Column<string>(nullable: true),
edition_id = table.Column<Guid>(nullable: true)
internship_registration_id = table.Column<long>(nullable: false),
internship_subject_id = table.Column<long>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_internship_types", x => x.id);
table.PrimaryKey("pk_program_subject", x => new { x.internship_registration_id, x.internship_subject_id });
table.ForeignKey(
name: "fk_internship_types_editions_edition_id",
column: x => x.edition_id,
principalTable: "editions",
name: "fk_program_subject_internship_registration_internship_registrat",
column: x => x.internship_registration_id,
principalTable: "internship_registration",
principalColumn: "id",
onDelete: ReferentialAction.Restrict);
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(
@ -338,16 +360,16 @@ namespace InternshipSystem.Repository.Migrations
table: "document",
column: "internship_id1");
migrationBuilder.CreateIndex(
name: "ix_edition_internship_type_internship_type_id",
table: "edition_internship_type",
column: "internship_type_id");
migrationBuilder.CreateIndex(
name: "ix_edition_subject_internship_subject_id",
table: "edition_subject",
column: "internship_subject_id");
migrationBuilder.CreateIndex(
name: "ix_editions_allowed_internship_types_id",
table: "editions",
column: "allowed_internship_types_id");
migrationBuilder.CreateIndex(
name: "ix_editions_course_id",
table: "editions",
@ -388,42 +410,20 @@ namespace InternshipSystem.Repository.Migrations
table: "internship_registration",
column: "type_id");
migrationBuilder.CreateIndex(
name: "ix_internship_types_edition_id",
table: "internship_types",
column: "edition_id");
migrationBuilder.CreateIndex(
name: "ix_program_subject_internship_subject_id",
table: "program_subject",
column: "internship_subject_id");
migrationBuilder.AddForeignKey(
name: "fk_internship_registration_internship_types_type_id",
table: "internship_registration",
column: "type_id",
principalTable: "internship_types",
principalColumn: "id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "fk_editions_internship_types_allowed_internship_types_id",
table: "editions",
column: "allowed_internship_types_id",
principalTable: "internship_types",
principalColumn: "id",
onDelete: ReferentialAction.Restrict);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "fk_internship_types_editions_edition_id",
table: "internship_types");
migrationBuilder.DropTable(
name: "document");
migrationBuilder.DropTable(
name: "edition_internship_type");
migrationBuilder.DropTable(
name: "edition_subject");
@ -439,6 +439,9 @@ namespace InternshipSystem.Repository.Migrations
migrationBuilder.DropTable(
name: "internship_subject");
migrationBuilder.DropTable(
name: "editions");
migrationBuilder.DropTable(
name: "internship_registration");
@ -448,20 +451,17 @@ namespace InternshipSystem.Repository.Migrations
migrationBuilder.DropTable(
name: "students");
migrationBuilder.DropTable(
name: "course");
migrationBuilder.DropTable(
name: "branch_office");
migrationBuilder.DropTable(
name: "companies");
migrationBuilder.DropTable(
name: "editions");
migrationBuilder.DropTable(
name: "internship_types");
migrationBuilder.DropTable(
name: "course");
name: "companies");
}
}
}

View File

@ -143,10 +143,6 @@ namespace InternshipSystem.Repository.Migrations
.HasColumnName("id")
.HasColumnType("uuid");
b.Property<long?>("AllowedInternshipTypesId")
.HasColumnName("allowed_internship_types_id")
.HasColumnType("bigint");
b.Property<long?>("CourseId")
.HasColumnName("course_id")
.HasColumnType("bigint");
@ -166,71 +162,13 @@ namespace InternshipSystem.Repository.Migrations
b.HasKey("Id")
.HasName("pk_editions");
b.HasIndex("AllowedInternshipTypesId")
.HasName("ix_editions_allowed_internship_types_id");
b.HasIndex("CourseId")
.HasName("ix_editions_course_id");
b.ToTable("editions");
});
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipSubject", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("id")
.HasColumnType("bigint")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Description")
.HasColumnName("description")
.HasColumnType("text");
b.Property<string>("DescriptionEng")
.HasColumnName("description_eng")
.HasColumnType("text");
b.HasKey("Id")
.HasName("pk_internship_subject");
b.ToTable("internship_subject");
});
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipType", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("id")
.HasColumnType("bigint")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Description")
.HasColumnName("description")
.HasColumnType("text");
b.Property<string>("DescriptionEng")
.HasColumnName("description_eng")
.HasColumnType("text");
b.Property<Guid?>("EditionId")
.HasColumnName("edition_id")
.HasColumnType("uuid");
b.Property<string>("Type")
.HasColumnName("type")
.HasColumnType("text");
b.HasKey("Id")
.HasName("pk_internship_types");
b.HasIndex("EditionId")
.HasName("ix_internship_types_edition_id");
b.ToTable("internship_types");
});
modelBuilder.Entity("InternshipSystem.Core.Internship", b =>
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.Internship", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
@ -276,7 +214,7 @@ namespace InternshipSystem.Repository.Migrations
b.ToTable("internship");
});
modelBuilder.Entity("InternshipSystem.Core.InternshipRegistration", b =>
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipRegistration", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
@ -323,6 +261,54 @@ namespace InternshipSystem.Repository.Migrations
b.ToTable("internship_registration");
});
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipSubject", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("id")
.HasColumnType("bigint")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Description")
.HasColumnName("description")
.HasColumnType("text");
b.Property<string>("DescriptionEng")
.HasColumnName("description_eng")
.HasColumnType("text");
b.HasKey("Id")
.HasName("pk_internship_subject");
b.ToTable("internship_subject");
});
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipType", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("id")
.HasColumnType("bigint")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Description")
.HasColumnName("description")
.HasColumnType("text");
b.Property<string>("DescriptionEng")
.HasColumnName("description_eng")
.HasColumnType("text");
b.Property<string>("Type")
.HasColumnName("type")
.HasColumnType("text");
b.HasKey("Id")
.HasName("pk_internship_types");
b.ToTable("internship_types");
});
modelBuilder.Entity("InternshipSystem.Core.Report", b =>
{
b.Property<long>("Id")
@ -421,6 +407,25 @@ namespace InternshipSystem.Repository.Migrations
b.ToTable("students");
});
modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.EditionInternshipType", b =>
{
b.Property<Guid>("EditionId")
.HasColumnName("edition_id")
.HasColumnType("uuid");
b.Property<long>("InternshipTypeId")
.HasColumnName("internship_type_id")
.HasColumnType("bigint");
b.HasKey("EditionId", "InternshipTypeId")
.HasName("pk_edition_internship_type");
b.HasIndex("InternshipTypeId")
.HasName("ix_edition_internship_type_internship_type_id");
b.ToTable("edition_internship_type");
});
modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.EditionSubject", b =>
{
b.Property<Guid>("EditionId")
@ -507,12 +512,12 @@ namespace InternshipSystem.Repository.Migrations
modelBuilder.Entity("InternshipSystem.Core.Document", b =>
{
b.HasOne("InternshipSystem.Core.Internship", null)
b.HasOne("InternshipSystem.Core.Entity.Internship.Internship", null)
.WithMany("Approvals")
.HasForeignKey("InternshipId")
.HasConstraintName("fk_document_internship_internship_id");
b.HasOne("InternshipSystem.Core.Internship", null)
b.HasOne("InternshipSystem.Core.Entity.Internship.Internship", null)
.WithMany("Documentation")
.HasForeignKey("InternshipId1")
.HasConstraintName("fk_document_internship_internship_id1");
@ -520,33 +525,20 @@ namespace InternshipSystem.Repository.Migrations
modelBuilder.Entity("InternshipSystem.Core.Edition", b =>
{
b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipType", "AllowedInternshipTypes")
.WithMany()
.HasForeignKey("AllowedInternshipTypesId")
.HasConstraintName("fk_editions_internship_types_allowed_internship_types_id");
b.HasOne("InternshipSystem.Core.Course", "Course")
.WithMany()
.HasForeignKey("CourseId")
.HasConstraintName("fk_editions_course_course_id");
});
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipType", b =>
{
b.HasOne("InternshipSystem.Core.Edition", null)
.WithMany("AvailableInternshipTypes")
.HasForeignKey("EditionId")
.HasConstraintName("fk_internship_types_editions_edition_id");
});
modelBuilder.Entity("InternshipSystem.Core.Internship", b =>
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.Internship", b =>
{
b.HasOne("InternshipSystem.Core.Edition", "Edition")
.WithMany("Internships")
.HasForeignKey("EditionId")
.HasConstraintName("fk_internship_editions_edition_id");
b.HasOne("InternshipSystem.Core.InternshipRegistration", "InternshipRegistration")
b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipRegistration", "InternshipRegistration")
.WithMany()
.HasForeignKey("InternshipRegistrationId")
.HasConstraintName("fk_internship_internship_registration_internship_registration_");
@ -562,7 +554,7 @@ namespace InternshipSystem.Repository.Migrations
.HasConstraintName("fk_internship_students_student_id");
});
modelBuilder.Entity("InternshipSystem.Core.InternshipRegistration", b =>
modelBuilder.Entity("InternshipSystem.Core.Entity.Internship.InternshipRegistration", b =>
{
b.HasOne("InternshipSystem.Core.BranchOffice", "BranchAddress")
.WithMany()
@ -614,6 +606,23 @@ namespace InternshipSystem.Repository.Migrations
});
});
modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.EditionInternshipType", b =>
{
b.HasOne("InternshipSystem.Core.Edition", "Edition")
.WithMany("AvailableInternshipTypes")
.HasForeignKey("EditionId")
.HasConstraintName("fk_edition_internship_type_editions_edition_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipType", "InternshipType")
.WithMany()
.HasForeignKey("InternshipTypeId")
.HasConstraintName("fk_edition_internship_type_internship_types_internship_type_id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.EditionSubject", b =>
{
b.HasOne("InternshipSystem.Core.Edition", "Edition")
@ -633,7 +642,7 @@ namespace InternshipSystem.Repository.Migrations
modelBuilder.Entity("InternshipSystem.Core.UglyOrmArtifacts.ProgramSubject", b =>
{
b.HasOne("InternshipSystem.Core.InternshipRegistration", "Registration")
b.HasOne("InternshipSystem.Core.Entity.Internship.InternshipRegistration", "Registration")
.WithMany("Subjects")
.HasForeignKey("InternshipRegistrationId")
.HasConstraintName("fk_program_subject_internship_registration_internship_registrat")

View File

@ -96,7 +96,12 @@ namespace InternshipSystem.Api.Test
.UseNpgsql("Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=szwoniu")
.Options);
var ed = db.Editions.First();
var ed = db.Editions
.Include(e => e.AvailableInternshipTypes)
.ThenInclude(t => t.InternshipType)
.Include(e => e.AvailableSubjects)
.ThenInclude(t => t.Subject)
.First();
var user = new User
{
@ -124,25 +129,13 @@ namespace InternshipSystem.Api.Test
var update = new UpdateRegistrationForm
{
Mentor = new UpdateMentor
{
FirstName = "Cwalina"
},
Subjects = new List<long>
{
1,
2,
3
1,
2,
3
},
Company = new UpdateCompany
{
Name = "a",
BranchOffice = new UpdateBranchOffice
{
Street = "b"
}
},
Type = 1
};
var task = useCase.UpdateInternshipRegistration(update, CancellationToken.None);

View File

@ -1,4 +1,4 @@
using System;
using InternshipSystem.Core.Entity.Internship;
using Machine.Specifications;
// ReSharper disable InconsistentNaming