diff --git a/STYLEGUIDE.md b/STYLEGUIDE.md deleted file mode 100644 index 67f2fde5..00000000 --- a/STYLEGUIDE.md +++ /dev/null @@ -1,9 +0,0 @@ -# Styleguide in project - - -## Frontend -### Overriding of MUI components -Follow the guide on https://mui.com/material-ui/customization/how-to-customize/ - -For implementaion examples using @mui/material/styled, see component: -[VibesNavBarTabs.tsx](/frontend/src/app/components/VibesNavBarTabs.tsx) diff --git a/backend/Api/Cache/CacheKeys.cs b/backend/Api/Cache/CacheKeys.cs index 5bd0e341..981e7f90 100644 --- a/backend/Api/Cache/CacheKeys.cs +++ b/backend/Api/Cache/CacheKeys.cs @@ -2,5 +2,6 @@ namespace Api.Cache; public enum CacheKeys { - ConsultantAvailability8Weeks + ConsultantAvailability8Weeks, + OrganisationsPrConsultant } \ No newline at end of file diff --git a/backend/Api/Consultants/ConsultantController.cs b/backend/Api/Consultants/ConsultantController.cs index 525194fc..22cc5b71 100644 --- a/backend/Api/Consultants/ConsultantController.cs +++ b/backend/Api/Consultants/ConsultantController.cs @@ -2,6 +2,7 @@ using Core.DomainModels; using Core.Services; using Database.DatabaseContext; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -9,7 +10,8 @@ namespace Api.Consultants; -[Route("v0/consultants")] +[Authorize] +[Route("/v0/{orgUrlKey}/consultants")] [ApiController] public class ConsultantController : ControllerBase { @@ -26,10 +28,11 @@ public ConsultantController(ApplicationContext context, IMemoryCache cache, Cons [HttpGet] public ActionResult> Get( + [FromRoute] string orgUrlKey, [FromQuery(Name = "weeks")] int numberOfWeeks = 8, [FromQuery(Name = "includeOccupied")] bool includeOccupied = true) { - var consultants = GetConsultantsWithAvailability(numberOfWeeks) + var consultants = GetConsultantsWithAvailability(orgUrlKey, numberOfWeeks) .Where(c => includeOccupied || c.IsOccupied @@ -56,7 +59,7 @@ public async Task, ProblemHttpResult, Vali var newConsultant = CreateConsultantFromModel(basicConsultant, selectedDepartment); await AddConsultantToDatabaseAsync(_context, newConsultant); - ClearConsultantCache(); + ClearConsultantCache(selectedDepartment.Organization.UrlKey); return TypedResults.Created($"/consultant/{newConsultant.Id}", basicConsultant); } @@ -67,24 +70,24 @@ public async Task, ProblemHttpResult, Vali } } - private List GetConsultantsWithAvailability(int numberOfWeeks) + private List GetConsultantsWithAvailability(string orgUrlKey, int numberOfWeeks) { if (numberOfWeeks == 8) { - _cache.TryGetValue(CacheKeys.ConsultantAvailability8Weeks, + _cache.TryGetValue( + $"{orgUrlKey}/{CacheKeys.ConsultantAvailability8Weeks}", out List? cachedConsultants); if (cachedConsultants != null) return cachedConsultants; } - var consultants = LoadConsultantAvailability(numberOfWeeks) + var consultants = LoadConsultantAvailability(orgUrlKey, numberOfWeeks) .Select(c => _consultantService.MapConsultantToReadModel(c, numberOfWeeks)).ToList(); - - _cache.Set(CacheKeys.ConsultantAvailability8Weeks, consultants); + _cache.Set($"{orgUrlKey}/{CacheKeys.ConsultantAvailability8Weeks}", consultants); return consultants; } - private List LoadConsultantAvailability(int numberOfWeeks) + private List LoadConsultantAvailability(string orgUrlKey, int numberOfWeeks) { var applicableWeeks = DateService.GetNextWeeks(numberOfWeeks); var firstDayOfCurrentWeek = DateService.GetFirstDayOfWeekContainingDate(DateTime.Now); @@ -119,6 +122,8 @@ private List LoadConsultantAvailability(int numberOfWeeks) (pa.Year <= yearA && minWeekA <= pa.WeekNumber && pa.WeekNumber <= maxWeekA) || (yearB <= pa.Year && minWeekB <= pa.WeekNumber && pa.WeekNumber <= maxWeekB))) .Include(c => c.Department) + .ThenInclude(d => d.Organization) + .Where(c => c.Department.Organization.UrlKey == orgUrlKey) .Include(c => c.Staffings.Where(s => (s.Year <= yearA && minWeekA <= s.Week && s.Week <= maxWeekA) || (yearB <= s.Year && minWeekB <= s.Week && s.Week <= maxWeekB))) @@ -154,9 +159,9 @@ private static async Task AddConsultantToDatabaseAsync(ApplicationContext db, Co await db.SaveChangesAsync(); } - private void ClearConsultantCache() + private void ClearConsultantCache(string orgUrlKey) { - _cache.Remove(CacheKeys.ConsultantAvailability8Weeks); + _cache.Remove($"{orgUrlKey}/{CacheKeys.ConsultantAvailability8Weeks}"); } diff --git a/backend/Api/Consultants/ConsultantService.cs b/backend/Api/Consultants/ConsultantService.cs index 0b62667f..03c9696a 100644 --- a/backend/Api/Consultants/ConsultantService.cs +++ b/backend/Api/Consultants/ConsultantService.cs @@ -21,7 +21,7 @@ public ConsultantReadModel MapConsultantToReadModel(Consultant consultant, int w const double tolerance = 0.1; var bookedHours = GetBookedHoursForWeeks(consultant, weeks); - var isOccupied = bookedHours.All(b => b.BookedHours >= GetHoursPrWeek() - tolerance); + var isOccupied = bookedHours.All(b => b.BookedHours >= GetHoursPrWeek(consultant) - tolerance); return new ConsultantReadModel( consultant.Id, @@ -36,7 +36,8 @@ public ConsultantReadModel MapConsultantToReadModel(Consultant consultant, int w public double GetBookedHours(Consultant consultant, int year, int week) { - var hoursPrWorkDay = _organizationOptions.HoursPerWorkday; + var hoursPrWorkDay = consultant.Department.Organization.HoursPerWorkday; + // var hoursPrWorkDay = _organizationOptions.HoursPerWorkday; var holidayHours = _holidayService.GetTotalHolidaysOfWeek(year, week) * hoursPrWorkDay; var vacationHours = consultant.Vacations.Count(v => DateService.DateIsInWeek(v.Date, year, week)) * @@ -73,8 +74,8 @@ public List GetBookedHoursForWeeks(Consultant consultant, in .ToList(); } - public double GetHoursPrWeek() + public double GetHoursPrWeek(Consultant consultant) { - return _organizationOptions.HoursPerWorkday * 5; + return consultant.Department.Organization.HoursPerWorkday * 5; } } \ No newline at end of file diff --git a/backend/Api/Departments/DeparmentController.cs b/backend/Api/Departments/DeparmentController.cs deleted file mode 100644 index 76405de6..00000000 --- a/backend/Api/Departments/DeparmentController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Database.DatabaseContext; -using Microsoft.AspNetCore.Mvc; - -[Route("/v0/departments")] -[ApiController] -public class DepartmentController : ControllerBase { - - [HttpGet] - public ActionResult> Get(ApplicationContext applicationContext){ - - return applicationContext.Department.Select(d => new DepartmentReadModel(d.Id, d.Name)).ToList(); - - } -} - -public record DepartmentReadModel(string Id, string Name); diff --git a/backend/Api/Organisation/DeparmentController.cs b/backend/Api/Organisation/DeparmentController.cs new file mode 100644 index 00000000..bb4d620d --- /dev/null +++ b/backend/Api/Organisation/DeparmentController.cs @@ -0,0 +1,42 @@ +using Database.DatabaseContext; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace Api.Organisation; + +[Route("/v0/organisations")] +[ApiController] +public class OrganisationController : ControllerBase +{ + private readonly ApplicationContext _applicationContext; + + public OrganisationController(ApplicationContext applicationContext) + { + _applicationContext = applicationContext; + } + + [HttpGet] + public ActionResult> Get() + { + return _applicationContext.Organization + .Select(organization => new OrganisationReadModel(organization.Name, organization.UrlKey)) + .ToList(); + } + + + [HttpGet] + [Route("{orgUrlKey}/departments")] + public ActionResult> GetDepartment([FromRoute] string orgUrlKey) + { + return _applicationContext.Organization + .Include(o => o.Departments) + .Single(o => o.UrlKey == orgUrlKey) + .Departments + .Select(d => new DepartmentReadModel(d.Id, d.Name)) + .ToList(); + } +} + +public record DepartmentReadModel(string Id, string Name); + +public record OrganisationReadModel(string Name, string UrlKey); \ No newline at end of file diff --git a/backend/Api/Program.cs b/backend/Api/Program.cs index 78ad8d80..ee59d56c 100644 --- a/backend/Api/Program.cs +++ b/backend/Api/Program.cs @@ -3,6 +3,7 @@ using Api.Options; using Database.DatabaseContext; using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; using Microsoft.EntityFrameworkCore; using Microsoft.Identity.Web; using Microsoft.OpenApi.Models; @@ -15,7 +16,7 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddMicrosoftIdentityWebApi(builder.Configuration); -builder.Services.AddAuthorization(opt => opt.FallbackPolicy = opt.DefaultPolicy); +builder.Services.AddAuthorization(opt => { opt.FallbackPolicy = opt.DefaultPolicy; }); builder.Services.AddDbContext(options => options.UseSqlServer(connection)); diff --git a/backend/Core/DomainModels/Absence.cs b/backend/Core/DomainModels/Absence.cs index 42f36a2f..ef3610b9 100644 --- a/backend/Core/DomainModels/Absence.cs +++ b/backend/Core/DomainModels/Absence.cs @@ -9,4 +9,5 @@ public class Absence public required string Name { get; set; } public required bool ExcludeFromBillRate { get; set; } = false; + public required Organization Organization { get; set; } } \ No newline at end of file diff --git a/backend/Core/DomainModels/Customer.cs b/backend/Core/DomainModels/Customer.cs index b0666ff2..9de19b5f 100644 --- a/backend/Core/DomainModels/Customer.cs +++ b/backend/Core/DomainModels/Customer.cs @@ -8,5 +8,6 @@ public class Customer public int Id { get; set; } public required string Name { get; set; } + public required Organization Organization { get; set; } public required List Projects { get; set; } } \ No newline at end of file diff --git a/backend/Core/DomainModels/Department.cs b/backend/Core/DomainModels/Department.cs index 97d7a5c8..2cb0d46f 100644 --- a/backend/Core/DomainModels/Department.cs +++ b/backend/Core/DomainModels/Department.cs @@ -8,5 +8,7 @@ public class Department [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public required string Id { get; set; } public required string Name { get; set; } + public int? Hotkey { get; set; } + public required Organization Organization { get; set; } [JsonIgnore] public required List Consultants { get; set; } } \ No newline at end of file diff --git a/backend/Core/DomainModels/Organization.cs b/backend/Core/DomainModels/Organization.cs new file mode 100644 index 00000000..8b7de43b --- /dev/null +++ b/backend/Core/DomainModels/Organization.cs @@ -0,0 +1,20 @@ +using System.Text.Json.Serialization; + +namespace Core.DomainModels; + +public class Organization +{ + public required string Id { get; set; } // guid ? Decide What to set here first => + public required string Name { get; set; } + public required string UrlKey { get; set; } // "variant-as", "variant-sverige" + public required string Country { get; set; } + public required int NumberOfVacationDaysInYear { get; set; } + public required bool HasVacationInChristmas { get; set; } + public required double HoursPerWorkday { get; set; } + + [JsonIgnore] public List Departments { get; set; } + + public required List Customers { get; set; } + + public List AbsenceTypes { get; set; } +} \ No newline at end of file diff --git a/backend/Database/Database.csproj b/backend/Database/Database.csproj index 5e9f8a9e..a864ecc1 100644 --- a/backend/Database/Database.csproj +++ b/backend/Database/Database.csproj @@ -25,4 +25,8 @@ + + + + diff --git a/backend/Database/DatabaseContext/ApplicationContext.cs b/backend/Database/DatabaseContext/ApplicationContext.cs index 98159c0a..b730a378 100644 --- a/backend/Database/DatabaseContext/ApplicationContext.cs +++ b/backend/Database/DatabaseContext/ApplicationContext.cs @@ -13,6 +13,7 @@ public ApplicationContext(DbContextOptions options) : base(options) public DbSet Consultant { get; set; } = null!; public DbSet Competence { get; set; } = null!; public DbSet Department { get; set; } = null!; + public DbSet Organization { get; set; } = null!; public DbSet PlannedAbsence { get; set; } = null!; public DbSet Vacation { get; set; } = null!; public DbSet Customer { get; set; } = null!; @@ -29,6 +30,19 @@ protected override void ConfigureConventions(ModelConfigurationBuilder configura protected override void OnModelCreating(ModelBuilder modelBuilder) { + modelBuilder.Entity() + .HasMany(org => org.Departments) + .WithOne(dept => dept.Organization); + + modelBuilder.Entity() + .HasMany(organization => organization.AbsenceTypes) + .WithOne(absence => absence.Organization); + + modelBuilder.Entity() + .HasMany(organization => organization.Customers) + .WithOne(customer => customer.Organization); + + modelBuilder.Entity() .HasMany(customer => customer.Projects) .WithOne(project => project.Customer); @@ -41,10 +55,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMany(p => p.Consultants) .WithMany(c => c.Projects) .UsingEntity( - r => r.HasOne(s => s.Consultant) + staffing => staffing.HasOne(s => s.Consultant) .WithMany(c => c.Staffings) .OnDelete(DeleteBehavior.ClientCascade), - l => l + staffing => staffing .HasOne(s => s.Project) .WithMany(c => c.Staffings) .OnDelete(DeleteBehavior.Cascade) @@ -100,6 +114,18 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) new() { Id = "project-mgmt", Name = "Project Management" } }); + modelBuilder.Entity() + .HasData(new + { + Id = "variant-as", + Name = "Variant AS", + UrlKey = "variant-as", + Country = "norway", + HoursPerWorkday = 7.5, + HasVacationInChristmas = true, + NumberOfVacationDaysInYear = 25 + }); + modelBuilder.Entity() .HasData(new { Id = "trondheim", Name = "Trondheim", OrganizationId = "variant-as" }); diff --git a/backend/Database/Migrations/20230915072931_InitialCreate.Designer.cs b/backend/Database/Migrations/20230915072931_InitialCreate.Designer.cs deleted file mode 100644 index 1f19a123..00000000 --- a/backend/Database/Migrations/20230915072931_InitialCreate.Designer.cs +++ /dev/null @@ -1,235 +0,0 @@ -// -using System; -using Database.DatabaseContext; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace backend.Migrations -{ - [DbContext(typeof(ApplicationContext))] - [Migration("20230915072931_InitialCreate")] - partial class InitialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.10") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("CompetenceConsultant", b => - { - b.Property("CompetencesId") - .HasColumnType("nvarchar(450)"); - - b.Property("ConsultantId") - .HasColumnType("int"); - - b.HasKey("CompetencesId", "ConsultantId"); - - b.HasIndex("ConsultantId"); - - b.ToTable("CompetenceConsultant"); - }); - - modelBuilder.Entity("backend.DomainModels.Competence", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Competence"); - - b.HasData( - new - { - Id = "frontend", - Name = "Frontend" - }, - new - { - Id = "backend", - Name = "Backend" - }, - new - { - Id = "design", - Name = "Design" - }, - new - { - Id = "project-mgmt", - Name = "Project Management" - }); - }); - - modelBuilder.Entity("backend.DomainModels.Consultant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Degree") - .HasColumnType("nvarchar(max)"); - - b.Property("DepartmentId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("EndDate") - .HasColumnType("datetime2"); - - b.Property("GraduationYear") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("StartDate") - .HasColumnType("datetime2"); - - b.HasKey("Id"); - - b.HasIndex("DepartmentId"); - - b.ToTable("Consultant"); - - b.HasData( - new - { - Id = 1, - Degree = "Master", - DepartmentId = "trondheim", - Email = "j@variant.no", - GraduationYear = 2019, - Name = "Jonas", - StartDate = new DateTime(2020, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified) - }); - }); - - modelBuilder.Entity("backend.DomainModels.Department", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("OrganizationId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("OrganizationId"); - - b.ToTable("Department"); - - b.HasData( - new - { - Id = "trondheim", - Name = "Trondheim", - OrganizationId = "variant-as" - }); - }); - - modelBuilder.Entity("backend.DomainModels.Organization", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("nvarchar(450)"); - - b.Property("HoursPerWorkday") - .HasColumnType("real"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Organization"); - - b.HasData( - new - { - Id = "variant-as", - HoursPerWorkday = 7.5f, - Name = "Variant AS" - }); - }); - - modelBuilder.Entity("CompetenceConsultant", b => - { - b.HasOne("backend.DomainModels.Competence", null) - .WithMany() - .HasForeignKey("CompetencesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("backend.DomainModels.Consultant", null) - .WithMany() - .HasForeignKey("ConsultantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("backend.DomainModels.Consultant", b => - { - b.HasOne("backend.DomainModels.Department", "Department") - .WithMany("Consultants") - .HasForeignKey("DepartmentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Department"); - }); - - modelBuilder.Entity("backend.DomainModels.Department", b => - { - b.HasOne("backend.DomainModels.Organization", "Organization") - .WithMany("Departments") - .HasForeignKey("OrganizationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Organization"); - }); - - modelBuilder.Entity("backend.DomainModels.Department", b => - { - b.Navigation("Consultants"); - }); - - modelBuilder.Entity("backend.DomainModels.Organization", b => - { - b.Navigation("Departments"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/backend/Database/Migrations/20230915072931_InitialCreate.cs b/backend/Database/Migrations/20230915072931_InitialCreate.cs deleted file mode 100644 index 0d69b902..00000000 --- a/backend/Database/Migrations/20230915072931_InitialCreate.cs +++ /dev/null @@ -1,170 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional - -namespace backend.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Competence", - columns: table => new - { - Id = table.Column(type: "nvarchar(450)", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Competence", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Organization", - columns: table => new - { - Id = table.Column(type: "nvarchar(450)", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: false), - HoursPerWorkday = table.Column(type: "real", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Organization", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Department", - columns: table => new - { - Id = table.Column(type: "nvarchar(450)", nullable: false), - OrganizationId = table.Column(type: "nvarchar(450)", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Department", x => x.Id); - table.ForeignKey( - name: "FK_Department_Organization_OrganizationId", - column: x => x.OrganizationId, - principalTable: "Organization", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Consultant", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(type: "nvarchar(max)", nullable: false), - Email = table.Column(type: "nvarchar(max)", nullable: false), - StartDate = table.Column(type: "datetime2", nullable: true), - EndDate = table.Column(type: "datetime2", nullable: true), - DepartmentId = table.Column(type: "nvarchar(450)", nullable: false), - Degree = table.Column(type: "nvarchar(max)", nullable: true), - GraduationYear = table.Column(type: "int", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Consultant", x => x.Id); - table.ForeignKey( - name: "FK_Consultant_Department_DepartmentId", - column: x => x.DepartmentId, - principalTable: "Department", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "CompetenceConsultant", - columns: table => new - { - CompetencesId = table.Column(type: "nvarchar(450)", nullable: false), - ConsultantId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_CompetenceConsultant", x => new { x.CompetencesId, x.ConsultantId }); - table.ForeignKey( - name: "FK_CompetenceConsultant_Competence_CompetencesId", - column: x => x.CompetencesId, - principalTable: "Competence", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_CompetenceConsultant_Consultant_ConsultantId", - column: x => x.ConsultantId, - principalTable: "Consultant", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.InsertData( - table: "Competence", - columns: new[] { "Id", "Name" }, - values: new object[,] - { - { "backend", "Backend" }, - { "design", "Design" }, - { "frontend", "Frontend" }, - { "project-mgmt", "Project Management" } - }); - - migrationBuilder.InsertData( - table: "Organization", - columns: new[] { "Id", "HoursPerWorkday", "Name" }, - values: new object[] { "variant-as", 7.5f, "Variant AS" }); - - migrationBuilder.InsertData( - table: "Department", - columns: new[] { "Id", "Name", "OrganizationId" }, - values: new object[] { "trondheim", "Trondheim", "variant-as" }); - - migrationBuilder.InsertData( - table: "Consultant", - columns: new[] { "Id", "Degree", "DepartmentId", "Email", "EndDate", "GraduationYear", "Name", "StartDate" }, - values: new object[] { 1, "Master", "trondheim", "j@variant.no", null, 2019, "Jonas", new DateTime(2020, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified) }); - - migrationBuilder.CreateIndex( - name: "IX_CompetenceConsultant_ConsultantId", - table: "CompetenceConsultant", - column: "ConsultantId"); - - migrationBuilder.CreateIndex( - name: "IX_Consultant_DepartmentId", - table: "Consultant", - column: "DepartmentId"); - - migrationBuilder.CreateIndex( - name: "IX_Department_OrganizationId", - table: "Department", - column: "OrganizationId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "CompetenceConsultant"); - - migrationBuilder.DropTable( - name: "Competence"); - - migrationBuilder.DropTable( - name: "Consultant"); - - migrationBuilder.DropTable( - name: "Department"); - - migrationBuilder.DropTable( - name: "Organization"); - } - } -} diff --git a/backend/Database/Migrations/20230919085422_VacationAndAbsence.Designer.cs b/backend/Database/Migrations/20230919085422_VacationAndAbsence.Designer.cs deleted file mode 100644 index 92896494..00000000 --- a/backend/Database/Migrations/20230919085422_VacationAndAbsence.Designer.cs +++ /dev/null @@ -1,318 +0,0 @@ -// -using System; -using Database.DatabaseContext; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace backend.Migrations -{ - [DbContext(typeof(ApplicationContext))] - [Migration("20230919085422_VacationAndAbsence")] - partial class VacationAndAbsence - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.10") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("CompetenceConsultant", b => - { - b.Property("CompetencesId") - .HasColumnType("nvarchar(450)"); - - b.Property("ConsultantId") - .HasColumnType("int"); - - b.HasKey("CompetencesId", "ConsultantId"); - - b.HasIndex("ConsultantId"); - - b.ToTable("CompetenceConsultant"); - }); - - modelBuilder.Entity("backend.ApplicationCore.DomainModels.Competence", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Competence"); - - b.HasData( - new - { - Id = "frontend", - Name = "Frontend" - }, - new - { - Id = "backend", - Name = "Backend" - }, - new - { - Id = "design", - Name = "Design" - }, - new - { - Id = "project-mgmt", - Name = "Project Management" - }); - }); - - modelBuilder.Entity("backend.ApplicationCore.DomainModels.Consultant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Degree") - .HasColumnType("nvarchar(max)"); - - b.Property("DepartmentId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("EndDate") - .HasColumnType("datetime2"); - - b.Property("GraduationYear") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("StartDate") - .HasColumnType("datetime2"); - - b.HasKey("Id"); - - b.HasIndex("DepartmentId"); - - b.ToTable("Consultant"); - - b.HasData( - new - { - Id = 1, - Degree = "Master", - DepartmentId = "trondheim", - Email = "j@variant.no", - GraduationYear = 2019, - Name = "Jonas", - StartDate = new DateTime(2020, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified) - }); - }); - - modelBuilder.Entity("backend.ApplicationCore.DomainModels.Department", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("OrganizationId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("OrganizationId"); - - b.ToTable("Department"); - - b.HasData( - new - { - Id = "trondheim", - Name = "Trondheim", - OrganizationId = "variant-as" - }); - }); - - modelBuilder.Entity("backend.ApplicationCore.DomainModels.Organization", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("nvarchar(450)"); - - b.Property("HoursPerWorkday") - .HasColumnType("real"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Organization"); - - b.HasData( - new - { - Id = "variant-as", - HoursPerWorkday = 7.5f, - Name = "Variant AS" - }); - }); - - modelBuilder.Entity("backend.ApplicationCore.DomainModels.PlannedAbsence", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ApplicableDays") - .HasColumnType("int"); - - b.Property("ConsultantId") - .HasColumnType("int"); - - b.Property("Fraction") - .HasColumnType("float"); - - b.Property("Type") - .HasColumnType("int"); - - b.Property("WeekNumber") - .HasColumnType("int"); - - b.Property("Year") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ConsultantId"); - - b.ToTable("PlannedAbsence"); - }); - - modelBuilder.Entity("backend.ApplicationCore.DomainModels.Vacation", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ConsultantId") - .HasColumnType("int"); - - b.Property("Date") - .HasColumnType("datetime2"); - - b.HasKey("Id"); - - b.HasIndex("ConsultantId"); - - b.ToTable("Vacation"); - }); - - modelBuilder.Entity("CompetenceConsultant", b => - { - b.HasOne("backend.ApplicationCore.DomainModels.Competence", null) - .WithMany() - .HasForeignKey("CompetencesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("backend.ApplicationCore.DomainModels.Consultant", null) - .WithMany() - .HasForeignKey("ConsultantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("backend.ApplicationCore.DomainModels.Consultant", b => - { - b.HasOne("backend.ApplicationCore.DomainModels.Department", "Department") - .WithMany("Consultants") - .HasForeignKey("DepartmentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Department"); - }); - - modelBuilder.Entity("backend.ApplicationCore.DomainModels.Department", b => - { - b.HasOne("backend.ApplicationCore.DomainModels.Organization", "Organization") - .WithMany("Departments") - .HasForeignKey("OrganizationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Organization"); - }); - - modelBuilder.Entity("backend.ApplicationCore.DomainModels.PlannedAbsence", b => - { - b.HasOne("backend.ApplicationCore.DomainModels.Consultant", "Consultant") - .WithMany("PlannedAbsences") - .HasForeignKey("ConsultantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Consultant"); - }); - - modelBuilder.Entity("backend.ApplicationCore.DomainModels.Vacation", b => - { - b.HasOne("backend.ApplicationCore.DomainModels.Consultant", "Consultant") - .WithMany("Vacations") - .HasForeignKey("ConsultantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Consultant"); - }); - - modelBuilder.Entity("backend.ApplicationCore.DomainModels.Consultant", b => - { - b.Navigation("PlannedAbsences"); - - b.Navigation("Vacations"); - }); - - modelBuilder.Entity("backend.ApplicationCore.DomainModels.Department", b => - { - b.Navigation("Consultants"); - }); - - modelBuilder.Entity("backend.ApplicationCore.DomainModels.Organization", b => - { - b.Navigation("Departments"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/backend/Database/Migrations/20230919085422_VacationAndAbsence.cs b/backend/Database/Migrations/20230919085422_VacationAndAbsence.cs deleted file mode 100644 index c3e886e5..00000000 --- a/backend/Database/Migrations/20230919085422_VacationAndAbsence.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace backend.Migrations -{ - /// - public partial class VacationAndAbsence : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "PlannedAbsence", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ConsultantId = table.Column(type: "int", nullable: false), - Type = table.Column(type: "int", nullable: false), - Year = table.Column(type: "int", nullable: false), - WeekNumber = table.Column(type: "int", nullable: false), - ApplicableDays = table.Column(type: "int", nullable: false), - Fraction = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_PlannedAbsence", x => x.Id); - table.ForeignKey( - name: "FK_PlannedAbsence_Consultant_ConsultantId", - column: x => x.ConsultantId, - principalTable: "Consultant", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Vacation", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ConsultantId = table.Column(type: "int", nullable: false), - Date = table.Column(type: "datetime2", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Vacation", x => x.Id); - table.ForeignKey( - name: "FK_Vacation_Consultant_ConsultantId", - column: x => x.ConsultantId, - principalTable: "Consultant", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_PlannedAbsence_ConsultantId", - table: "PlannedAbsence", - column: "ConsultantId"); - - migrationBuilder.CreateIndex( - name: "IX_Vacation_ConsultantId", - table: "Vacation", - column: "ConsultantId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "PlannedAbsence"); - - migrationBuilder.DropTable( - name: "Vacation"); - } - } -} diff --git a/backend/Database/Migrations/20230926080554_StaffingAbsence.Designer.cs b/backend/Database/Migrations/20230926080554_StaffingAbsence.Designer.cs deleted file mode 100644 index bc600c1e..00000000 --- a/backend/Database/Migrations/20230926080554_StaffingAbsence.Designer.cs +++ /dev/null @@ -1,500 +0,0 @@ -// -using System; -using Database.DatabaseContext; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace backend.Migrations -{ - [DbContext(typeof(ApplicationContext))] - [Migration("20230926080554_StaffingAbsence")] - partial class StaffingAbsence - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.10") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("CompetenceConsultant", b => - { - b.Property("CompetencesId") - .HasColumnType("nvarchar(450)"); - - b.Property("ConsultantId") - .HasColumnType("int"); - - b.HasKey("CompetencesId", "ConsultantId"); - - b.HasIndex("ConsultantId"); - - b.ToTable("CompetenceConsultant"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Absence", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ExcludeFromBillRate") - .HasColumnType("bit"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("OrganizationId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("OrganizationId"); - - b.ToTable("Absence"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Competence", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Competence"); - - b.HasData( - new - { - Id = "frontend", - Name = "Frontend" - }, - new - { - Id = "backend", - Name = "Backend" - }, - new - { - Id = "design", - Name = "Design" - }, - new - { - Id = "project-mgmt", - Name = "Project Management" - }); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Consultant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Degree") - .HasColumnType("nvarchar(max)"); - - b.Property("DepartmentId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("EndDate") - .HasColumnType("datetime2"); - - b.Property("GraduationYear") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("StartDate") - .HasColumnType("datetime2"); - - b.HasKey("Id"); - - b.HasIndex("DepartmentId"); - - b.ToTable("Consultant"); - - b.HasData( - new - { - Id = 1, - Degree = "Master", - DepartmentId = "trondheim", - Email = "j@variant.no", - GraduationYear = 2019, - Name = "Jonas", - StartDate = new DateTime(2020, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified) - }); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Customer", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("OrganizationId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("OrganizationId"); - - b.ToTable("Customer"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Department", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("OrganizationId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("OrganizationId"); - - b.ToTable("Department"); - - b.HasData( - new - { - Id = "trondheim", - Name = "Trondheim", - OrganizationId = "variant-as" - }); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Organization", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("nvarchar(450)"); - - b.Property("HoursPerWorkday") - .HasColumnType("real"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Organization"); - - b.HasData( - new - { - Id = "variant-as", - HoursPerWorkday = 7.5f, - Name = "Variant AS" - }); - }); - - modelBuilder.Entity("backend.Core.DomainModels.PlannedAbsence", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("AbsenceId") - .HasColumnType("int"); - - b.Property("ConsultantId") - .HasColumnType("int"); - - b.Property("Hours") - .HasColumnType("float"); - - b.Property("WeekNumber") - .HasColumnType("int"); - - b.Property("Year") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("AbsenceId"); - - b.HasIndex("ConsultantId"); - - b.ToTable("PlannedAbsence"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Project", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CustomerId") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("State") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.HasIndex("CustomerId"); - - b.ToTable("Project"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Staffing", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ConsultantId") - .HasColumnType("int"); - - b.Property("Hours") - .HasColumnType("float"); - - b.Property("ProjectId") - .HasColumnType("int"); - - b.Property("Week") - .HasColumnType("int"); - - b.Property("Year") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ConsultantId"); - - b.HasIndex("ProjectId"); - - b.ToTable("Staffing"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Vacation", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ConsultantId") - .HasColumnType("int"); - - b.Property("Date") - .HasColumnType("datetime2"); - - b.HasKey("Id"); - - b.HasIndex("ConsultantId"); - - b.ToTable("Vacation"); - }); - - modelBuilder.Entity("CompetenceConsultant", b => - { - b.HasOne("backend.Core.DomainModels.Competence", null) - .WithMany() - .HasForeignKey("CompetencesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("backend.Core.DomainModels.Consultant", null) - .WithMany() - .HasForeignKey("ConsultantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Absence", b => - { - b.HasOne("backend.Core.DomainModels.Organization", "Organization") - .WithMany("AbsenceTypes") - .HasForeignKey("OrganizationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Organization"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Consultant", b => - { - b.HasOne("backend.Core.DomainModels.Department", "Department") - .WithMany("Consultants") - .HasForeignKey("DepartmentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Department"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Customer", b => - { - b.HasOne("backend.Core.DomainModels.Organization", "Organization") - .WithMany("Customers") - .HasForeignKey("OrganizationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Organization"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Department", b => - { - b.HasOne("backend.Core.DomainModels.Organization", "Organization") - .WithMany("Departments") - .HasForeignKey("OrganizationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Organization"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.PlannedAbsence", b => - { - b.HasOne("backend.Core.DomainModels.Absence", "Absence") - .WithMany() - .HasForeignKey("AbsenceId") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.HasOne("backend.Core.DomainModels.Consultant", "Consultant") - .WithMany("PlannedAbsences") - .HasForeignKey("ConsultantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Absence"); - - b.Navigation("Consultant"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Project", b => - { - b.HasOne("backend.Core.DomainModels.Customer", "Customer") - .WithMany("Projects") - .HasForeignKey("CustomerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Customer"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Staffing", b => - { - b.HasOne("backend.Core.DomainModels.Consultant", "Consultant") - .WithMany("Staffings") - .HasForeignKey("ConsultantId") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.HasOne("backend.Core.DomainModels.Project", "Project") - .WithMany("Staffings") - .HasForeignKey("ProjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Consultant"); - - b.Navigation("Project"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Vacation", b => - { - b.HasOne("backend.Core.DomainModels.Consultant", "Consultant") - .WithMany("Vacations") - .HasForeignKey("ConsultantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Consultant"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Consultant", b => - { - b.Navigation("PlannedAbsences"); - - b.Navigation("Staffings"); - - b.Navigation("Vacations"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Customer", b => - { - b.Navigation("Projects"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Department", b => - { - b.Navigation("Consultants"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Organization", b => - { - b.Navigation("AbsenceTypes"); - - b.Navigation("Customers"); - - b.Navigation("Departments"); - }); - - modelBuilder.Entity("backend.Core.DomainModels.Project", b => - { - b.Navigation("Staffings"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/backend/Database/Migrations/20230926080554_StaffingAbsence.cs b/backend/Database/Migrations/20230926080554_StaffingAbsence.cs deleted file mode 100644 index 67e4a49e..00000000 --- a/backend/Database/Migrations/20230926080554_StaffingAbsence.cs +++ /dev/null @@ -1,196 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace backend.Migrations -{ - /// - public partial class StaffingAbsence : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "ApplicableDays", - table: "PlannedAbsence"); - - migrationBuilder.RenameColumn( - name: "Type", - table: "PlannedAbsence", - newName: "AbsenceId"); - - migrationBuilder.RenameColumn( - name: "Fraction", - table: "PlannedAbsence", - newName: "Hours"); - - migrationBuilder.CreateTable( - name: "Absence", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(type: "nvarchar(max)", nullable: false), - ExcludeFromBillRate = table.Column(type: "bit", nullable: false), - OrganizationId = table.Column(type: "nvarchar(450)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Absence", x => x.Id); - table.ForeignKey( - name: "FK_Absence_Organization_OrganizationId", - column: x => x.OrganizationId, - principalTable: "Organization", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Customer", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(type: "nvarchar(max)", nullable: false), - OrganizationId = table.Column(type: "nvarchar(450)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Customer", x => x.Id); - table.ForeignKey( - name: "FK_Customer_Organization_OrganizationId", - column: x => x.OrganizationId, - principalTable: "Organization", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Project", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - CustomerId = table.Column(type: "int", nullable: false), - State = table.Column(type: "nvarchar(max)", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Project", x => x.Id); - table.ForeignKey( - name: "FK_Project_Customer_CustomerId", - column: x => x.CustomerId, - principalTable: "Customer", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Staffing", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ProjectId = table.Column(type: "int", nullable: false), - ConsultantId = table.Column(type: "int", nullable: false), - Year = table.Column(type: "int", nullable: false), - Week = table.Column(type: "int", nullable: false), - Hours = table.Column(type: "float", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Staffing", x => x.Id); - table.ForeignKey( - name: "FK_Staffing_Consultant_ConsultantId", - column: x => x.ConsultantId, - principalTable: "Consultant", - principalColumn: "Id"); - table.ForeignKey( - name: "FK_Staffing_Project_ProjectId", - column: x => x.ProjectId, - principalTable: "Project", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_PlannedAbsence_AbsenceId", - table: "PlannedAbsence", - column: "AbsenceId"); - - migrationBuilder.CreateIndex( - name: "IX_Absence_OrganizationId", - table: "Absence", - column: "OrganizationId"); - - migrationBuilder.CreateIndex( - name: "IX_Customer_OrganizationId", - table: "Customer", - column: "OrganizationId"); - - migrationBuilder.CreateIndex( - name: "IX_Project_CustomerId", - table: "Project", - column: "CustomerId"); - - migrationBuilder.CreateIndex( - name: "IX_Staffing_ConsultantId", - table: "Staffing", - column: "ConsultantId"); - - migrationBuilder.CreateIndex( - name: "IX_Staffing_ProjectId", - table: "Staffing", - column: "ProjectId"); - - migrationBuilder.AddForeignKey( - name: "FK_PlannedAbsence_Absence_AbsenceId", - table: "PlannedAbsence", - column: "AbsenceId", - principalTable: "Absence", - principalColumn: "Id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_PlannedAbsence_Absence_AbsenceId", - table: "PlannedAbsence"); - - migrationBuilder.DropTable( - name: "Absence"); - - migrationBuilder.DropTable( - name: "Staffing"); - - migrationBuilder.DropTable( - name: "Project"); - - migrationBuilder.DropTable( - name: "Customer"); - - migrationBuilder.DropIndex( - name: "IX_PlannedAbsence_AbsenceId", - table: "PlannedAbsence"); - - migrationBuilder.RenameColumn( - name: "Hours", - table: "PlannedAbsence", - newName: "Fraction"); - - migrationBuilder.RenameColumn( - name: "AbsenceId", - table: "PlannedAbsence", - newName: "Type"); - - migrationBuilder.AddColumn( - name: "ApplicableDays", - table: "PlannedAbsence", - type: "int", - nullable: false, - defaultValue: 0); - } - } -} diff --git a/backend/Database/Migrations/20230927080712_AddedHolidayModelAndFloatToDoubleCastFix.cs b/backend/Database/Migrations/20230927080712_AddedHolidayModelAndFloatToDoubleCastFix.cs deleted file mode 100644 index c8a542ae..00000000 --- a/backend/Database/Migrations/20230927080712_AddedHolidayModelAndFloatToDoubleCastFix.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace backend.Migrations -{ - /// - public partial class AddedHolidayModelAndFloatToDoubleCastFix : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn( - name: "HoursPerWorkday", - table: "Organization", - type: "float", - nullable: false, - oldClrType: typeof(float), - oldType: "real"); - - migrationBuilder.UpdateData( - table: "Organization", - keyColumn: "Id", - keyValue: "variant-as", - column: "HoursPerWorkday", - value: 7.5); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn( - name: "HoursPerWorkday", - table: "Organization", - type: "real", - nullable: false, - oldClrType: typeof(double), - oldType: "float"); - - migrationBuilder.UpdateData( - table: "Organization", - keyColumn: "Id", - keyValue: "variant-as", - column: "HoursPerWorkday", - value: 7.5f); - } - } -} diff --git a/backend/Database/Migrations/20231004195542_RemovedOrganization.Designer.cs b/backend/Database/Migrations/20231004195542_RemovedOrganization.Designer.cs deleted file mode 100644 index 162c4307..00000000 --- a/backend/Database/Migrations/20231004195542_RemovedOrganization.Designer.cs +++ /dev/null @@ -1,413 +0,0 @@ -// -using System; -using Database.DatabaseContext; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace backend.Migrations -{ - [DbContext(typeof(ApplicationContext))] - [Migration("20231004195542_RemovedOrganization")] - partial class RemovedOrganization - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.10") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("CompetenceConsultant", b => - { - b.Property("CompetencesId") - .HasColumnType("nvarchar(450)"); - - b.Property("ConsultantId") - .HasColumnType("int"); - - b.HasKey("CompetencesId", "ConsultantId"); - - b.HasIndex("ConsultantId"); - - b.ToTable("CompetenceConsultant"); - }); - - modelBuilder.Entity("Core.DomainModels.Absence", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ExcludeFromBillRate") - .HasColumnType("bit"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Absence"); - }); - - modelBuilder.Entity("Core.DomainModels.Competence", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Competence"); - - b.HasData( - new - { - Id = "frontend", - Name = "Frontend" - }, - new - { - Id = "backend", - Name = "Backend" - }, - new - { - Id = "design", - Name = "Design" - }, - new - { - Id = "project-mgmt", - Name = "Project Management" - }); - }); - - modelBuilder.Entity("Core.DomainModels.Consultant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Degree") - .HasColumnType("nvarchar(max)"); - - b.Property("DepartmentId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("EndDate") - .HasColumnType("datetime2"); - - b.Property("GraduationYear") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("StartDate") - .HasColumnType("datetime2"); - - b.HasKey("Id"); - - b.HasIndex("DepartmentId"); - - b.ToTable("Consultant"); - - b.HasData( - new - { - Id = 1, - Degree = "Master", - DepartmentId = "trondheim", - Email = "j@variant.no", - GraduationYear = 2019, - Name = "Jonas", - StartDate = new DateTime(2020, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified) - }); - }); - - modelBuilder.Entity("Core.DomainModels.Customer", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Customer"); - }); - - modelBuilder.Entity("Core.DomainModels.Department", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Department"); - - b.HasData( - new - { - Id = "trondheim", - Name = "Trondheim" - }); - }); - - modelBuilder.Entity("Core.DomainModels.PlannedAbsence", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("AbsenceId") - .HasColumnType("int"); - - b.Property("ConsultantId") - .HasColumnType("int"); - - b.Property("Hours") - .HasColumnType("float"); - - b.Property("WeekNumber") - .HasColumnType("int"); - - b.Property("Year") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("AbsenceId"); - - b.HasIndex("ConsultantId"); - - b.ToTable("PlannedAbsence"); - }); - - modelBuilder.Entity("Core.DomainModels.Project", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CustomerId") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("State") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.HasIndex("CustomerId"); - - b.ToTable("Project"); - }); - - modelBuilder.Entity("Core.DomainModels.Staffing", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ConsultantId") - .HasColumnType("int"); - - b.Property("Hours") - .HasColumnType("float"); - - b.Property("ProjectId") - .HasColumnType("int"); - - b.Property("Week") - .HasColumnType("int"); - - b.Property("Year") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ConsultantId"); - - b.HasIndex("ProjectId"); - - b.ToTable("Staffing"); - }); - - modelBuilder.Entity("Core.DomainModels.Vacation", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ConsultantId") - .HasColumnType("int"); - - b.Property("Date") - .HasColumnType("datetime2"); - - b.HasKey("Id"); - - b.HasIndex("ConsultantId"); - - b.ToTable("Vacation"); - }); - - modelBuilder.Entity("CompetenceConsultant", b => - { - b.HasOne("Core.DomainModels.Competence", null) - .WithMany() - .HasForeignKey("CompetencesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Core.DomainModels.Consultant", null) - .WithMany() - .HasForeignKey("ConsultantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Core.DomainModels.Consultant", b => - { - b.HasOne("Core.DomainModels.Department", "Department") - .WithMany("Consultants") - .HasForeignKey("DepartmentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Department"); - }); - - modelBuilder.Entity("Core.DomainModels.PlannedAbsence", b => - { - b.HasOne("Core.DomainModels.Absence", "Absence") - .WithMany() - .HasForeignKey("AbsenceId") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.HasOne("Core.DomainModels.Consultant", "Consultant") - .WithMany("PlannedAbsences") - .HasForeignKey("ConsultantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Absence"); - - b.Navigation("Consultant"); - }); - - modelBuilder.Entity("Core.DomainModels.Project", b => - { - b.HasOne("Core.DomainModels.Customer", "Customer") - .WithMany("Projects") - .HasForeignKey("CustomerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Customer"); - }); - - modelBuilder.Entity("Core.DomainModels.Staffing", b => - { - b.HasOne("Core.DomainModels.Consultant", "Consultant") - .WithMany("Staffings") - .HasForeignKey("ConsultantId") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.HasOne("Core.DomainModels.Project", "Project") - .WithMany("Staffings") - .HasForeignKey("ProjectId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Consultant"); - - b.Navigation("Project"); - }); - - modelBuilder.Entity("Core.DomainModels.Vacation", b => - { - b.HasOne("Core.DomainModels.Consultant", "Consultant") - .WithMany("Vacations") - .HasForeignKey("ConsultantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Consultant"); - }); - - modelBuilder.Entity("Core.DomainModels.Consultant", b => - { - b.Navigation("PlannedAbsences"); - - b.Navigation("Staffings"); - - b.Navigation("Vacations"); - }); - - modelBuilder.Entity("Core.DomainModels.Customer", b => - { - b.Navigation("Projects"); - }); - - modelBuilder.Entity("Core.DomainModels.Department", b => - { - b.Navigation("Consultants"); - }); - - modelBuilder.Entity("Core.DomainModels.Project", b => - { - b.Navigation("Staffings"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/backend/Database/Migrations/20231004195542_RemovedOrganization.cs b/backend/Database/Migrations/20231004195542_RemovedOrganization.cs deleted file mode 100644 index dcdeb30d..00000000 --- a/backend/Database/Migrations/20231004195542_RemovedOrganization.cs +++ /dev/null @@ -1,142 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace backend.Migrations -{ - /// - public partial class RemovedOrganization : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Absence_Organization_OrganizationId", - table: "Absence"); - - migrationBuilder.DropForeignKey( - name: "FK_Customer_Organization_OrganizationId", - table: "Customer"); - - migrationBuilder.DropForeignKey( - name: "FK_Department_Organization_OrganizationId", - table: "Department"); - - migrationBuilder.DropTable( - name: "Organization"); - - migrationBuilder.DropIndex( - name: "IX_Department_OrganizationId", - table: "Department"); - - migrationBuilder.DropIndex( - name: "IX_Customer_OrganizationId", - table: "Customer"); - - migrationBuilder.DropIndex( - name: "IX_Absence_OrganizationId", - table: "Absence"); - - migrationBuilder.DropColumn( - name: "OrganizationId", - table: "Department"); - - migrationBuilder.DropColumn( - name: "OrganizationId", - table: "Customer"); - - migrationBuilder.DropColumn( - name: "OrganizationId", - table: "Absence"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "OrganizationId", - table: "Department", - type: "nvarchar(450)", - nullable: false, - defaultValue: ""); - - migrationBuilder.AddColumn( - name: "OrganizationId", - table: "Customer", - type: "nvarchar(450)", - nullable: false, - defaultValue: ""); - - migrationBuilder.AddColumn( - name: "OrganizationId", - table: "Absence", - type: "nvarchar(450)", - nullable: false, - defaultValue: ""); - - migrationBuilder.CreateTable( - name: "Organization", - columns: table => new - { - Id = table.Column(type: "nvarchar(450)", nullable: false), - HoursPerWorkday = table.Column(type: "float", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Organization", x => x.Id); - }); - - migrationBuilder.UpdateData( - table: "Department", - keyColumn: "Id", - keyValue: "trondheim", - column: "OrganizationId", - value: "variant-as"); - - migrationBuilder.InsertData( - table: "Organization", - columns: new[] { "Id", "HoursPerWorkday", "Name" }, - values: new object[] { "variant-as", 7.5, "Variant AS" }); - - migrationBuilder.CreateIndex( - name: "IX_Department_OrganizationId", - table: "Department", - column: "OrganizationId"); - - migrationBuilder.CreateIndex( - name: "IX_Customer_OrganizationId", - table: "Customer", - column: "OrganizationId"); - - migrationBuilder.CreateIndex( - name: "IX_Absence_OrganizationId", - table: "Absence", - column: "OrganizationId"); - - migrationBuilder.AddForeignKey( - name: "FK_Absence_Organization_OrganizationId", - table: "Absence", - column: "OrganizationId", - principalTable: "Organization", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - - migrationBuilder.AddForeignKey( - name: "FK_Customer_Organization_OrganizationId", - table: "Customer", - column: "OrganizationId", - principalTable: "Organization", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - - migrationBuilder.AddForeignKey( - name: "FK_Department_Organization_OrganizationId", - table: "Department", - column: "OrganizationId", - principalTable: "Organization", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - } -} diff --git a/backend/Database/Migrations/20230927080712_AddedHolidayModelAndFloatToDoubleCastFix.Designer.cs b/backend/Database/Migrations/20231017124126_Initial.Designer.cs similarity index 80% rename from backend/Database/Migrations/20230927080712_AddedHolidayModelAndFloatToDoubleCastFix.Designer.cs rename to backend/Database/Migrations/20231017124126_Initial.Designer.cs index 50b3dbc6..9d0a175f 100644 --- a/backend/Database/Migrations/20230927080712_AddedHolidayModelAndFloatToDoubleCastFix.Designer.cs +++ b/backend/Database/Migrations/20231017124126_Initial.Designer.cs @@ -9,11 +9,11 @@ #nullable disable -namespace backend.Migrations +namespace Database.Migrations { [DbContext(typeof(ApplicationContext))] - [Migration("20230927080712_AddedHolidayModelAndFloatToDoubleCastFix")] - partial class AddedHolidayModelAndFloatToDoubleCastFix + [Migration("20231017124126_Initial")] + partial class Initial { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -40,7 +40,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CompetenceConsultant"); }); - modelBuilder.Entity("backend.Core.DomainModels.Absence", b => + modelBuilder.Entity("Core.DomainModels.Absence", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -66,7 +66,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("Absence"); }); - modelBuilder.Entity("backend.Core.DomainModels.Competence", b => + modelBuilder.Entity("Core.DomainModels.Competence", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -103,7 +103,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) }); }); - modelBuilder.Entity("backend.Core.DomainModels.Consultant", b => + modelBuilder.Entity("Core.DomainModels.Consultant", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -154,7 +154,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) }); }); - modelBuilder.Entity("backend.Core.DomainModels.Customer", b => + modelBuilder.Entity("Core.DomainModels.Customer", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -177,12 +177,15 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("Customer"); }); - modelBuilder.Entity("backend.Core.DomainModels.Department", b => + modelBuilder.Entity("Core.DomainModels.Department", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("nvarchar(450)"); + b.Property("Hotkey") + .HasColumnType("int"); + b.Property("Name") .IsRequired() .HasColumnType("nvarchar(max)"); @@ -206,12 +209,18 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) }); }); - modelBuilder.Entity("backend.Core.DomainModels.Organization", b => + modelBuilder.Entity("Core.DomainModels.Organization", b => { b.Property("Id") - .ValueGeneratedOnAdd() .HasColumnType("nvarchar(450)"); + b.Property("Country") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("HasVacationInChristmas") + .HasColumnType("bit"); + b.Property("HoursPerWorkday") .HasColumnType("float"); @@ -219,6 +228,13 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("nvarchar(max)"); + b.Property("NumberOfVacationDaysInYear") + .HasColumnType("int"); + + b.Property("UrlKey") + .IsRequired() + .HasColumnType("nvarchar(max)"); + b.HasKey("Id"); b.ToTable("Organization"); @@ -227,12 +243,16 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) new { Id = "variant-as", + Country = "norway", + HasVacationInChristmas = true, HoursPerWorkday = 7.5, - Name = "Variant AS" + Name = "Variant AS", + NumberOfVacationDaysInYear = 25, + UrlKey = "variant-as" }); }); - modelBuilder.Entity("backend.Core.DomainModels.PlannedAbsence", b => + modelBuilder.Entity("Core.DomainModels.PlannedAbsence", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -264,7 +284,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("PlannedAbsence"); }); - modelBuilder.Entity("backend.Core.DomainModels.Project", b => + modelBuilder.Entity("Core.DomainModels.Project", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -290,7 +310,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("Project"); }); - modelBuilder.Entity("backend.Core.DomainModels.Staffing", b => + modelBuilder.Entity("Core.DomainModels.Staffing", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -322,7 +342,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("Staffing"); }); - modelBuilder.Entity("backend.Core.DomainModels.Vacation", b => + modelBuilder.Entity("Core.DomainModels.Vacation", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -345,22 +365,22 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) modelBuilder.Entity("CompetenceConsultant", b => { - b.HasOne("backend.Core.DomainModels.Competence", null) + b.HasOne("Core.DomainModels.Competence", null) .WithMany() .HasForeignKey("CompetencesId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("backend.Core.DomainModels.Consultant", null) + b.HasOne("Core.DomainModels.Consultant", null) .WithMany() .HasForeignKey("ConsultantId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); - modelBuilder.Entity("backend.Core.DomainModels.Absence", b => + modelBuilder.Entity("Core.DomainModels.Absence", b => { - b.HasOne("backend.Core.DomainModels.Organization", "Organization") + b.HasOne("Core.DomainModels.Organization", "Organization") .WithMany("AbsenceTypes") .HasForeignKey("OrganizationId") .OnDelete(DeleteBehavior.Cascade) @@ -369,9 +389,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Navigation("Organization"); }); - modelBuilder.Entity("backend.Core.DomainModels.Consultant", b => + modelBuilder.Entity("Core.DomainModels.Consultant", b => { - b.HasOne("backend.Core.DomainModels.Department", "Department") + b.HasOne("Core.DomainModels.Department", "Department") .WithMany("Consultants") .HasForeignKey("DepartmentId") .OnDelete(DeleteBehavior.Cascade) @@ -380,9 +400,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Navigation("Department"); }); - modelBuilder.Entity("backend.Core.DomainModels.Customer", b => + modelBuilder.Entity("Core.DomainModels.Customer", b => { - b.HasOne("backend.Core.DomainModels.Organization", "Organization") + b.HasOne("Core.DomainModels.Organization", "Organization") .WithMany("Customers") .HasForeignKey("OrganizationId") .OnDelete(DeleteBehavior.Cascade) @@ -391,9 +411,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Navigation("Organization"); }); - modelBuilder.Entity("backend.Core.DomainModels.Department", b => + modelBuilder.Entity("Core.DomainModels.Department", b => { - b.HasOne("backend.Core.DomainModels.Organization", "Organization") + b.HasOne("Core.DomainModels.Organization", "Organization") .WithMany("Departments") .HasForeignKey("OrganizationId") .OnDelete(DeleteBehavior.Cascade) @@ -402,15 +422,15 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Navigation("Organization"); }); - modelBuilder.Entity("backend.Core.DomainModels.PlannedAbsence", b => + modelBuilder.Entity("Core.DomainModels.PlannedAbsence", b => { - b.HasOne("backend.Core.DomainModels.Absence", "Absence") + b.HasOne("Core.DomainModels.Absence", "Absence") .WithMany() .HasForeignKey("AbsenceId") .OnDelete(DeleteBehavior.ClientCascade) .IsRequired(); - b.HasOne("backend.Core.DomainModels.Consultant", "Consultant") + b.HasOne("Core.DomainModels.Consultant", "Consultant") .WithMany("PlannedAbsences") .HasForeignKey("ConsultantId") .OnDelete(DeleteBehavior.Cascade) @@ -421,9 +441,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Navigation("Consultant"); }); - modelBuilder.Entity("backend.Core.DomainModels.Project", b => + modelBuilder.Entity("Core.DomainModels.Project", b => { - b.HasOne("backend.Core.DomainModels.Customer", "Customer") + b.HasOne("Core.DomainModels.Customer", "Customer") .WithMany("Projects") .HasForeignKey("CustomerId") .OnDelete(DeleteBehavior.Cascade) @@ -432,15 +452,15 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Navigation("Customer"); }); - modelBuilder.Entity("backend.Core.DomainModels.Staffing", b => + modelBuilder.Entity("Core.DomainModels.Staffing", b => { - b.HasOne("backend.Core.DomainModels.Consultant", "Consultant") + b.HasOne("Core.DomainModels.Consultant", "Consultant") .WithMany("Staffings") .HasForeignKey("ConsultantId") .OnDelete(DeleteBehavior.ClientCascade) .IsRequired(); - b.HasOne("backend.Core.DomainModels.Project", "Project") + b.HasOne("Core.DomainModels.Project", "Project") .WithMany("Staffings") .HasForeignKey("ProjectId") .OnDelete(DeleteBehavior.Cascade) @@ -451,9 +471,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Navigation("Project"); }); - modelBuilder.Entity("backend.Core.DomainModels.Vacation", b => + modelBuilder.Entity("Core.DomainModels.Vacation", b => { - b.HasOne("backend.Core.DomainModels.Consultant", "Consultant") + b.HasOne("Core.DomainModels.Consultant", "Consultant") .WithMany("Vacations") .HasForeignKey("ConsultantId") .OnDelete(DeleteBehavior.Cascade) @@ -462,7 +482,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Navigation("Consultant"); }); - modelBuilder.Entity("backend.Core.DomainModels.Consultant", b => + modelBuilder.Entity("Core.DomainModels.Consultant", b => { b.Navigation("PlannedAbsences"); @@ -471,17 +491,17 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Navigation("Vacations"); }); - modelBuilder.Entity("backend.Core.DomainModels.Customer", b => + modelBuilder.Entity("Core.DomainModels.Customer", b => { b.Navigation("Projects"); }); - modelBuilder.Entity("backend.Core.DomainModels.Department", b => + modelBuilder.Entity("Core.DomainModels.Department", b => { b.Navigation("Consultants"); }); - modelBuilder.Entity("backend.Core.DomainModels.Organization", b => + modelBuilder.Entity("Core.DomainModels.Organization", b => { b.Navigation("AbsenceTypes"); @@ -490,7 +510,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Navigation("Departments"); }); - modelBuilder.Entity("backend.Core.DomainModels.Project", b => + modelBuilder.Entity("Core.DomainModels.Project", b => { b.Navigation("Staffings"); }); diff --git a/backend/Database/Migrations/20231017124126_Initial.cs b/backend/Database/Migrations/20231017124126_Initial.cs new file mode 100644 index 00000000..3f3da3f1 --- /dev/null +++ b/backend/Database/Migrations/20231017124126_Initial.cs @@ -0,0 +1,371 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace Database.Migrations +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Competence", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Competence", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Organization", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + UrlKey = table.Column(type: "nvarchar(max)", nullable: false), + Country = table.Column(type: "nvarchar(max)", nullable: false), + NumberOfVacationDaysInYear = table.Column(type: "int", nullable: false), + HasVacationInChristmas = table.Column(type: "bit", nullable: false), + HoursPerWorkday = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Organization", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Absence", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + ExcludeFromBillRate = table.Column(type: "bit", nullable: false), + OrganizationId = table.Column(type: "nvarchar(450)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Absence", x => x.Id); + table.ForeignKey( + name: "FK_Absence_Organization_OrganizationId", + column: x => x.OrganizationId, + principalTable: "Organization", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Customer", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + OrganizationId = table.Column(type: "nvarchar(450)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Customer", x => x.Id); + table.ForeignKey( + name: "FK_Customer_Organization_OrganizationId", + column: x => x.OrganizationId, + principalTable: "Organization", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Department", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Hotkey = table.Column(type: "int", nullable: true), + OrganizationId = table.Column(type: "nvarchar(450)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Department", x => x.Id); + table.ForeignKey( + name: "FK_Department_Organization_OrganizationId", + column: x => x.OrganizationId, + principalTable: "Organization", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Project", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CustomerId = table.Column(type: "int", nullable: false), + State = table.Column(type: "nvarchar(max)", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Project", x => x.Id); + table.ForeignKey( + name: "FK_Project_Customer_CustomerId", + column: x => x.CustomerId, + principalTable: "Customer", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Consultant", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + StartDate = table.Column(type: "datetime2", nullable: true), + EndDate = table.Column(type: "datetime2", nullable: true), + DepartmentId = table.Column(type: "nvarchar(450)", nullable: false), + Degree = table.Column(type: "nvarchar(max)", nullable: true), + GraduationYear = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Consultant", x => x.Id); + table.ForeignKey( + name: "FK_Consultant_Department_DepartmentId", + column: x => x.DepartmentId, + principalTable: "Department", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "CompetenceConsultant", + columns: table => new + { + CompetencesId = table.Column(type: "nvarchar(450)", nullable: false), + ConsultantId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CompetenceConsultant", x => new { x.CompetencesId, x.ConsultantId }); + table.ForeignKey( + name: "FK_CompetenceConsultant_Competence_CompetencesId", + column: x => x.CompetencesId, + principalTable: "Competence", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_CompetenceConsultant_Consultant_ConsultantId", + column: x => x.ConsultantId, + principalTable: "Consultant", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PlannedAbsence", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + AbsenceId = table.Column(type: "int", nullable: false), + ConsultantId = table.Column(type: "int", nullable: false), + Year = table.Column(type: "int", nullable: false), + WeekNumber = table.Column(type: "int", nullable: false), + Hours = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PlannedAbsence", x => x.Id); + table.ForeignKey( + name: "FK_PlannedAbsence_Absence_AbsenceId", + column: x => x.AbsenceId, + principalTable: "Absence", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_PlannedAbsence_Consultant_ConsultantId", + column: x => x.ConsultantId, + principalTable: "Consultant", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Staffing", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ProjectId = table.Column(type: "int", nullable: false), + ConsultantId = table.Column(type: "int", nullable: false), + Year = table.Column(type: "int", nullable: false), + Week = table.Column(type: "int", nullable: false), + Hours = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Staffing", x => x.Id); + table.ForeignKey( + name: "FK_Staffing_Consultant_ConsultantId", + column: x => x.ConsultantId, + principalTable: "Consultant", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Staffing_Project_ProjectId", + column: x => x.ProjectId, + principalTable: "Project", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Vacation", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ConsultantId = table.Column(type: "int", nullable: false), + Date = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Vacation", x => x.Id); + table.ForeignKey( + name: "FK_Vacation_Consultant_ConsultantId", + column: x => x.ConsultantId, + principalTable: "Consultant", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.InsertData( + table: "Competence", + columns: new[] { "Id", "Name" }, + values: new object[,] + { + { "backend", "Backend" }, + { "design", "Design" }, + { "frontend", "Frontend" }, + { "project-mgmt", "Project Management" } + }); + + migrationBuilder.InsertData( + table: "Organization", + columns: new[] { "Id", "Country", "HasVacationInChristmas", "HoursPerWorkday", "Name", "NumberOfVacationDaysInYear", "UrlKey" }, + values: new object[] { "variant-as", "norway", true, 7.5, "Variant AS", 25, "variant-as" }); + + migrationBuilder.InsertData( + table: "Department", + columns: new[] { "Id", "Hotkey", "Name", "OrganizationId" }, + values: new object[] { "trondheim", null, "Trondheim", "variant-as" }); + + migrationBuilder.InsertData( + table: "Consultant", + columns: new[] { "Id", "Degree", "DepartmentId", "Email", "EndDate", "GraduationYear", "Name", "StartDate" }, + values: new object[] { 1, "Master", "trondheim", "j@variant.no", null, 2019, "Jonas", new DateTime(2020, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified) }); + + migrationBuilder.CreateIndex( + name: "IX_Absence_OrganizationId", + table: "Absence", + column: "OrganizationId"); + + migrationBuilder.CreateIndex( + name: "IX_CompetenceConsultant_ConsultantId", + table: "CompetenceConsultant", + column: "ConsultantId"); + + migrationBuilder.CreateIndex( + name: "IX_Consultant_DepartmentId", + table: "Consultant", + column: "DepartmentId"); + + migrationBuilder.CreateIndex( + name: "IX_Customer_OrganizationId", + table: "Customer", + column: "OrganizationId"); + + migrationBuilder.CreateIndex( + name: "IX_Department_OrganizationId", + table: "Department", + column: "OrganizationId"); + + migrationBuilder.CreateIndex( + name: "IX_PlannedAbsence_AbsenceId", + table: "PlannedAbsence", + column: "AbsenceId"); + + migrationBuilder.CreateIndex( + name: "IX_PlannedAbsence_ConsultantId", + table: "PlannedAbsence", + column: "ConsultantId"); + + migrationBuilder.CreateIndex( + name: "IX_Project_CustomerId", + table: "Project", + column: "CustomerId"); + + migrationBuilder.CreateIndex( + name: "IX_Staffing_ConsultantId", + table: "Staffing", + column: "ConsultantId"); + + migrationBuilder.CreateIndex( + name: "IX_Staffing_ProjectId", + table: "Staffing", + column: "ProjectId"); + + migrationBuilder.CreateIndex( + name: "IX_Vacation_ConsultantId", + table: "Vacation", + column: "ConsultantId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CompetenceConsultant"); + + migrationBuilder.DropTable( + name: "PlannedAbsence"); + + migrationBuilder.DropTable( + name: "Staffing"); + + migrationBuilder.DropTable( + name: "Vacation"); + + migrationBuilder.DropTable( + name: "Competence"); + + migrationBuilder.DropTable( + name: "Absence"); + + migrationBuilder.DropTable( + name: "Project"); + + migrationBuilder.DropTable( + name: "Consultant"); + + migrationBuilder.DropTable( + name: "Customer"); + + migrationBuilder.DropTable( + name: "Department"); + + migrationBuilder.DropTable( + name: "Organization"); + } + } +} diff --git a/backend/Database/Migrations/ApplicationContextModelSnapshot.cs b/backend/Database/Migrations/ApplicationContextModelSnapshot.cs index 946bfb53..439ece9c 100644 --- a/backend/Database/Migrations/ApplicationContextModelSnapshot.cs +++ b/backend/Database/Migrations/ApplicationContextModelSnapshot.cs @@ -8,7 +8,7 @@ #nullable disable -namespace backend.Migrations +namespace Database.Migrations { [DbContext(typeof(ApplicationContext))] partial class ApplicationContextModelSnapshot : ModelSnapshot @@ -52,8 +52,14 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("nvarchar(max)"); + b.Property("OrganizationId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + b.HasKey("Id"); + b.HasIndex("OrganizationId"); + b.ToTable("Absence"); }); @@ -157,8 +163,14 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("nvarchar(max)"); + b.Property("OrganizationId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + b.HasKey("Id"); + b.HasIndex("OrganizationId"); + b.ToTable("Customer"); }); @@ -168,19 +180,72 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("nvarchar(450)"); + b.Property("Hotkey") + .HasColumnType("int"); + b.Property("Name") .IsRequired() .HasColumnType("nvarchar(max)"); + b.Property("OrganizationId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + b.HasKey("Id"); + b.HasIndex("OrganizationId"); + b.ToTable("Department"); b.HasData( new { Id = "trondheim", - Name = "Trondheim" + Name = "Trondheim", + OrganizationId = "variant-as" + }); + }); + + modelBuilder.Entity("Core.DomainModels.Organization", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("Country") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("HasVacationInChristmas") + .HasColumnType("bit"); + + b.Property("HoursPerWorkday") + .HasColumnType("float"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("NumberOfVacationDaysInYear") + .HasColumnType("int"); + + b.Property("UrlKey") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Organization"); + + b.HasData( + new + { + Id = "variant-as", + Country = "norway", + HasVacationInChristmas = true, + HoursPerWorkday = 7.5, + Name = "Variant AS", + NumberOfVacationDaysInYear = 25, + UrlKey = "variant-as" }); }); @@ -310,6 +375,17 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired(); }); + modelBuilder.Entity("Core.DomainModels.Absence", b => + { + b.HasOne("Core.DomainModels.Organization", "Organization") + .WithMany("AbsenceTypes") + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Organization"); + }); + modelBuilder.Entity("Core.DomainModels.Consultant", b => { b.HasOne("Core.DomainModels.Department", "Department") @@ -321,6 +397,28 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("Department"); }); + modelBuilder.Entity("Core.DomainModels.Customer", b => + { + b.HasOne("Core.DomainModels.Organization", "Organization") + .WithMany("Customers") + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Organization"); + }); + + modelBuilder.Entity("Core.DomainModels.Department", b => + { + b.HasOne("Core.DomainModels.Organization", "Organization") + .WithMany("Departments") + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Organization"); + }); + modelBuilder.Entity("Core.DomainModels.PlannedAbsence", b => { b.HasOne("Core.DomainModels.Absence", "Absence") @@ -400,6 +498,15 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("Consultants"); }); + modelBuilder.Entity("Core.DomainModels.Organization", b => + { + b.Navigation("AbsenceTypes"); + + b.Navigation("Customers"); + + b.Navigation("Departments"); + }); + modelBuilder.Entity("Core.DomainModels.Project", b => { b.Navigation("Staffings"); diff --git a/frontend/README.md b/frontend/README.md index 8bd0ae5c..b7d1ae19 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -41,16 +41,3 @@ You can check out [the Next.js GitHub repository](https://github.com/vercel/next ## Deployment See [project root README](../README.md). - -## Issues - -This seem to be a bug in the MUI package. It is only triggered when importing styled from `@mui/material`: - -```ts -import { styled } from "@mui/material"; - -// As a workaround, I recommend importing { styled } from styles instead: -import { styled } from "@mui/material/styles"; -``` - -https://github.com/vercel/next.js/issues/55663 diff --git a/frontend/mockdata/mockConsultants.ts b/frontend/mockdata/mockConsultants.ts deleted file mode 100644 index 1a7a52d0..00000000 --- a/frontend/mockdata/mockConsultants.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Consultant } from "@/types"; - -export const MockConsultants: Consultant[] = [ - { - id: "id", - name: "Test Consultant", - email: "test@company.io", - competences: ["Frontend"], - department: "My Department", - bookings: [{ year: 2023, weekNumber: 10, bookedHours: 10 }], - }, -]; diff --git a/frontend/mockdata/mockData.ts b/frontend/mockdata/mockData.ts new file mode 100644 index 00000000..f2f98df3 --- /dev/null +++ b/frontend/mockdata/mockData.ts @@ -0,0 +1,26 @@ +import { Consultant, Department, Organisation } from "@/types"; + +export const MockConsultants: Consultant[] = [ + { + id: "id", + name: "Test Consultant", + email: "test@company.io", + competences: ["Frontend"], + department: "My Department", + bookings: [{ year: 2023, weekNumber: 10, bookedHours: 10 }], + }, +]; + +export const MockDepartments: Department[] = [ + { + id: "myDepartment", + name: "My Department", + }, +]; + +export const MockOrganisations: Organisation[] = [ + { + name: "My Organisation", + urlKey: "my-org", + }, +]; diff --git a/frontend/mockdata/mockDepartments.ts b/frontend/mockdata/mockDepartments.ts deleted file mode 100644 index aa2d3db0..00000000 --- a/frontend/mockdata/mockDepartments.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Department, Consultant } from "@/types"; - -export const MockDepartments: Department[] = [ - { - id: "myDepartment", - name: "My Department", - }, -]; diff --git a/frontend/next.config.js b/frontend/next.config.js index 3a48579c..d8d5f63e 100644 --- a/frontend/next.config.js +++ b/frontend/next.config.js @@ -4,11 +4,6 @@ const nextConfig = { distDir: "build", swcMinify: true, - modularizeImports: { - "@mui/icons-material": { - transform: "@mui/icons-material/{{member}}", - }, - }, }; module.exports = nextConfig; diff --git a/frontend/src/app/bemanning/layout.tsx b/frontend/src/app/[organisation]/bemanning/layout.tsx similarity index 100% rename from frontend/src/app/bemanning/layout.tsx rename to frontend/src/app/[organisation]/bemanning/layout.tsx diff --git a/frontend/src/app/bemanning/page.tsx b/frontend/src/app/[organisation]/bemanning/page.tsx similarity index 57% rename from frontend/src/app/bemanning/page.tsx rename to frontend/src/app/[organisation]/bemanning/page.tsx index 2901efb0..9939cc9b 100644 --- a/frontend/src/app/bemanning/page.tsx +++ b/frontend/src/app/[organisation]/bemanning/page.tsx @@ -2,8 +2,15 @@ import FilteredConsultantsList from "@/components/FilteredConsultantsList"; import { fetchWithToken } from "@/data/fetchWithToken"; import { Consultant } from "@/types"; -export default async function Bemanning() { - const consultants = (await fetchWithToken("consultants")) ?? []; +export default async function Bemanning({ + params, +}: { + params: { organisation: string }; +}) { + const consultants = + (await fetchWithToken( + `${params.organisation}/consultants`, + )) ?? []; return (
diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index 1e343bfb..5a4a5881 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -1,5 +1,18 @@ import { redirect } from "next/navigation"; +import { fetchWithToken } from "@/data/fetchWithToken"; +import { Consultant, Organisation } from "@/types"; +import Link from "next/link"; -export default function Root() { - redirect("/bemanning"); +export default async function Root() { + const orgs = (await fetchWithToken("organisations")) ?? []; + return ( +
    + {orgs.map((o) => ( +
  • + {o.name} +
  • + ))} +
+ ); + //redirect("/bemanning"); } diff --git a/frontend/src/components/DepartmentFilter.tsx b/frontend/src/components/DepartmentFilter.tsx index 5485bd09..c2d2916f 100644 --- a/frontend/src/components/DepartmentFilter.tsx +++ b/frontend/src/components/DepartmentFilter.tsx @@ -3,7 +3,10 @@ import { fetchWithToken } from "@/data/fetchWithToken"; import { Department } from "@/types"; export default async function DepartmentFilter() { - const departments = (await fetchWithToken("departments")) ?? []; + const departments = + (await fetchWithToken( + "organisations/variant-norge/departments", + )) ?? []; if (departments.length > 0) { return ( diff --git a/frontend/src/components/FilterButton.tsx b/frontend/src/components/FilterButton.tsx index 054ba132..a6b9ab63 100644 --- a/frontend/src/components/FilterButton.tsx +++ b/frontend/src/components/FilterButton.tsx @@ -1,9 +1,10 @@ "use client"; -import { useRouter, useSearchParams } from "next/navigation"; +import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useState } from "react"; export default function FilterButton({ filterName }: { filterName: string }) { const router = useRouter(); + const pathname = usePathname(); const searchParams = useSearchParams(); const [isButtonActive, setIsButtonActive] = useState(checkFilterInUrl); @@ -21,7 +22,9 @@ export default function FilterButton({ filterName }: { filterName: string }) { newFilters.splice(filterIndex, 1); } const newFilterString = newFilters.join(",").replace(/^,/, ""); - router.push(`/bemanning?search=${currentSearch}&filter=${newFilterString}`); + router.push( + `${pathname}?search=${currentSearch}&filter=${newFilterString}`, + ); } function checkFilterInUrl() { diff --git a/frontend/src/components/NavBar/NavBar.tsx b/frontend/src/components/NavBar/NavBar.tsx index e8559595..a8c58963 100644 --- a/frontend/src/components/NavBar/NavBar.tsx +++ b/frontend/src/components/NavBar/NavBar.tsx @@ -6,13 +6,13 @@ export default function NavBar() { return (
- +
Variant logo diff --git a/frontend/src/components/SearchBarComponent.tsx b/frontend/src/components/SearchBarComponent.tsx index f056babb..80c485a8 100644 --- a/frontend/src/components/SearchBarComponent.tsx +++ b/frontend/src/components/SearchBarComponent.tsx @@ -1,11 +1,12 @@ "use client"; -import { useRouter, useSearchParams } from "next/navigation"; +import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useEffect, useRef, useState } from "react"; import { Search } from "react-feather"; export default function SearchBarComponent() { const router = useRouter(); const searchParams = useSearchParams(); + const pathname = usePathname(); const [searchText, setSearchText] = useState( searchParams.get("search") || "", ); @@ -13,8 +14,8 @@ export default function SearchBarComponent() { useEffect(() => { const currentFilter = searchParams.get("filter") || ""; - router.push(`/bemanning?search=${searchText}&filter=${currentFilter}`); - }, [searchText, searchParams, router]); + router.push(`${pathname}?search=${searchText}&filter=${currentFilter}`); + }, [searchText, searchParams, router, pathname]); useEffect(() => { function keyDownHandler(e: { code: string }) { diff --git a/frontend/src/data/fetchWithToken.ts b/frontend/src/data/fetchWithToken.ts index 55fb36f6..6e680f9b 100644 --- a/frontend/src/data/fetchWithToken.ts +++ b/frontend/src/data/fetchWithToken.ts @@ -1,9 +1,12 @@ -import { MockConsultants } from "../../mockdata/mockConsultants"; -import { MockDepartments } from "../../mockdata/mockDepartments"; import { authOptions, getCustomServerSession, } from "@/app/api/auth/[...nextauth]/route"; +import { + MockConsultants, + MockDepartments, + MockOrganisations, +} from "../../mockdata/mockData"; export async function fetchWithToken(path: string): Promise { if (process.env.NEXT_PUBLIC_NO_AUTH) { @@ -26,8 +29,12 @@ export async function fetchWithToken(path: string): Promise { method: "GET", headers: headers, }; - const response = await fetch(`${apiBackendUrl}/${path}`, options); - return (await response.json()) as T; + try { + const response = await fetch(`${apiBackendUrl}/${path}`, options); + return (await response.json()) as T; + } catch (e) { + console.error(e); + } } function mockedCall(path: string): Promise { @@ -38,5 +45,8 @@ function mockedCall(path: string): Promise { if (path.includes("departments")) { resolve(MockDepartments as T); } + if (path.includes("organisations")) { + resolve(MockOrganisations as T); + } }); } diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 5492e420..65dffa48 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -17,3 +17,8 @@ export type Department = { id: string; name: string; }; + +export type Organisation = { + name: string; + urlKey: string; +}; diff --git a/frontend/tests/consultant-list.spec.ts b/frontend/tests/consultant-list.spec.ts index 7b3401b7..35595b61 100644 --- a/frontend/tests/consultant-list.spec.ts +++ b/frontend/tests/consultant-list.spec.ts @@ -1,7 +1,10 @@ import { test, expect } from "@playwright/test"; -test("has title", async ({ page }) => { +test("Has organisation index page", async ({ page }) => { await page.goto("/"); + const orgLink = page.getByText("My Organisation"); + await orgLink.click(); + const consultantName = page.getByText("Test Consultant"); await expect(consultantName).toBeVisible();