Skip to content

Commit

Permalink
created new consultant page and filter on competance (#448)
Browse files Browse the repository at this point in the history
Co-authored-by: md <[email protected]>
  • Loading branch information
Dahly96 and md authored Feb 29, 2024
1 parent d3c286e commit 15d9c0f
Show file tree
Hide file tree
Showing 24 changed files with 551 additions and 18 deletions.
17 changes: 17 additions & 0 deletions backend/Api/Common/StorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ public StorageService(IMemoryCache cache, ApplicationContext context)

}

public List<Consultant> GetConsultants(string orgUrlKey)
{

var consultants = _dbContext.Consultant
.Include(c => c.Department)
.ThenInclude(d => d.Organization)
.Include(c => c.CompetenceConsultant)
.ThenInclude(cc => cc.Competence)
.Where(c => c.Department.Organization.UrlKey == orgUrlKey)
.ToList();

return consultants;

}

public List<Consultant> GetConsultantsEmploymentVariant(string orgUrlKey)
{

Expand Down Expand Up @@ -111,6 +126,8 @@ private List<Consultant> LoadConsultantsFromDb(string orgUrlKey)
var consultantList = _dbContext.Consultant
.Include(consultant => consultant.Department)
.ThenInclude(department => department.Organization)
.Include(c => c.CompetenceConsultant)
.ThenInclude(cc => cc.Competence)
.Where(consultant => consultant.Department.Organization.UrlKey == orgUrlKey)
.OrderBy(consultant => consultant.Name)
.ToList();
Expand Down
28 changes: 28 additions & 0 deletions backend/Api/Consultants/CompetenceController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations;
using Database.DatabaseContext;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace Api.Organisation;

[Route("/v0/competences")]
[ApiController]
public class CompetenceController : ControllerBase
{
private readonly ApplicationContext _applicationContext;

public CompetenceController(ApplicationContext applicationContext)
{
_applicationContext = applicationContext;
}

[HttpGet]
public ActionResult<List<CompetenceReadModel>> Get()
{
return _applicationContext.Competence
.Select(competence => new CompetenceReadModel(competence.Id, competence.Name))
.ToList();
}
}

public record CompetenceReadModel([property: Required] string Id, [property: Required] string Name);
17 changes: 16 additions & 1 deletion backend/Api/Consultants/ConsultantController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public ConsultantController(ApplicationContext context, IMemoryCache cache)


[HttpGet]
[Route("{Email}")]
public ActionResult<SingleConsultantReadModel> Get([FromRoute] string orgUrlKey,
[FromQuery(Name = "Email")] string? email = "")
[FromRoute(Name = "Email")] string? email = "")
{
var service = new StorageService(_cache, _context);

Expand All @@ -40,6 +41,20 @@ public ActionResult<SingleConsultantReadModel> Get([FromRoute] string orgUrlKey,
return Ok( new SingleConsultantReadModel(consultant));
}

[HttpGet]
public ActionResult<List<SingleConsultantReadModel>> GetAll([FromRoute] string orgUrlKey)
{
var service = new StorageService(_cache, _context);

var consultants = service.GetConsultants(orgUrlKey);

List<SingleConsultantReadModel> readModels = consultants
.Select(c => new SingleConsultantReadModel(c))
.ToList();

return Ok(readModels);
}

[HttpGet]
[Route("employment")]
public ActionResult<List<ConsultantsEmploymentReadModel>> GetConsultantsEmployment([FromRoute] string orgUrlKey)
Expand Down
26 changes: 23 additions & 3 deletions backend/Api/Consultants/ConsultantReadModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

namespace Api.Consultants;

public record SingleConsultantReadModel([property: Required] int Id,
public record SingleConsultantReadModel(
[property: Required] int Id,
[property: Required] string Name,
[property: Required] string Email,
[property: Required] List<string> Competences,
[property: Required] DateOnly? StartDate,
[property: Required] DateOnly? EndDate,
[property: Required] List<CompetenceReadModel> Competences,
[property: Required] string Department,
[property: Required] int? GraduationYear,
[property: Required] int YearsOfExperience,
[property: Required] Degree Degree)

Expand All @@ -17,15 +21,31 @@ public SingleConsultantReadModel(Consultant consultant)
consultant.Id,
consultant.Name,
consultant.Email,
consultant.Competences.Select(c => c.Name).ToList(),
consultant.StartDate,
consultant.EndDate,
consultant.CompetenceConsultant.Select(cc => new CompetenceReadModel(cc.Competence.Id, cc.Competence.Name)).ToList(),
consultant.Department.Name,
consultant.GraduationYear,
consultant.YearsOfExperience,
consultant.Degree ?? Degree.Master
)
{
}
}

public record CompetenceReadModel(
[property: Required] string Id,
[property: Required] string Name)
{
public CompetenceReadModel(Competence competence)
: this(
competence.Id,
competence.Name
)
{
}
}

public record ConsultantsEmploymentReadModel(
[property: Required] string Email,
[property: Required] DateOnly? StartDate,
Expand Down
16 changes: 14 additions & 2 deletions backend/Api/StaffingController/StaffingReadModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public record StaffingReadModel(
[property: Required] int Id,
[property: Required] string Name,
[property: Required] string Email,
[property: Required] List<string> Competences,
[property: Required] List<CompetenceReadModel> Competences,
[property: Required] string Department,
[property: Required] int YearsOfExperience,
[property: Required] Degree Degree,
Expand All @@ -23,7 +23,7 @@ public StaffingReadModel(Consultant consultant, List<BookedHoursPerWeek> booking
consultant.Id,
consultant.Name,
consultant.Email,
consultant.Competences.Select(c => c.Name).ToList(),
consultant.CompetenceConsultant.Select(cc => new CompetenceReadModel(cc.Competence.Id, cc.Competence.Name)).ToList(),
consultant.Department.Name,
consultant.YearsOfExperience,
consultant.Degree ?? Degree.Master,
Expand All @@ -35,6 +35,18 @@ public StaffingReadModel(Consultant consultant, List<BookedHoursPerWeek> booking
}
}

public record CompetenceReadModel(
[property: Required] string Id,
[property: Required] string Name)
{
public CompetenceReadModel(Competence competence)
: this(
competence.Id,
competence.Name
)
{
}
}

public record BookedHoursPerWeek(
[property: Required] int Year,
Expand Down
13 changes: 11 additions & 2 deletions backend/Core/DomainModels/Consultant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Consultant
public int? GraduationYear { get; set; }
public int TransferredVacationDays { get; set; }

public List<Competence> Competences { get; set; } = new();
public ICollection<CompetenceConsultant> CompetenceConsultant { get; set; } = new List<CompetenceConsultant>();

public List<Vacation> Vacations { get; set; } = new();

Expand All @@ -28,6 +28,7 @@ public class Consultant
public List<Engagement> Projects { get; set; } = new();

public List<Staffing> Staffings { get; set; } = new();


public int YearsOfExperience
{
Expand Down Expand Up @@ -61,10 +62,18 @@ public int GetRemainingVacationDays(DateOnly day)

public class Competence
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public required string Id { get; set; }

public required string Name { get; set; }
public ICollection<CompetenceConsultant> CompetenceConsultant { get; set; } = new List<CompetenceConsultant>();
}

public class CompetenceConsultant
{
public int ConsultantId { get; set; }
public Consultant Consultant { get; set; } = null!;
public required string CompetencesId { get; set; }
public Competence Competence { get; set; } = null!;
}

public enum Degree
Expand Down
23 changes: 19 additions & 4 deletions backend/Database/DatabaseContext/ApplicationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public ApplicationContext(DbContextOptions options) : base(options)

public DbSet<Consultant> Consultant { get; set; } = null!;
public DbSet<Competence> Competence { get; set; } = null!;
public DbSet<CompetenceConsultant> CompetenceConsultant { get; set; } = null!;
public DbSet<Department> Department { get; set; } = null!;
public DbSet<Organization> Organization { get; set; } = null!;
public DbSet<Absence> Absence { get; set; } = null!;
Expand Down Expand Up @@ -115,20 +116,34 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.Property(v => v.EndDate)
.HasConversion<DateOnlyConverter>();

modelBuilder.Entity<Consultant>()
.HasMany(v => v.Competences)
.WithMany();
/*modelBuilder.Entity<Consultant>()
.HasMany(v => v.CompetenceConsultant)
.WithMany();*/

modelBuilder.Entity<Consultant>()
.Property(c => c.TransferredVacationDays)
.HasDefaultValue(0);

modelBuilder.Entity<CompetenceConsultant>()
.HasKey(us => new { us.ConsultantId, us.CompetencesId });

modelBuilder.Entity<CompetenceConsultant>()
.HasOne(us => us.Consultant)
.WithMany(u => u.CompetenceConsultant)
.HasForeignKey(us => us.ConsultantId);

modelBuilder.Entity<CompetenceConsultant>()
.HasOne(us => us.Competence)
.WithMany(s => s.CompetenceConsultant)
.HasForeignKey(us => us.CompetencesId);

modelBuilder.Entity<Competence>().HasData(new List<Competence>
{
new() { Id = "frontend", Name = "Frontend" },
new() { Id = "backend", Name = "Backend" },
new() { Id = "design", Name = "Design" },
new() { Id = "project-mgmt", Name = "Project Management" }
new() { Id = "project-mgmt", Name = "Project Management" },
new() { Id = "development", Name = "Utvikling" }
});

modelBuilder.Entity<Organization>()
Expand Down
10 changes: 9 additions & 1 deletion frontend/mockdata/mockData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CompetenceReadModel,
ConsultantReadModel,
Degree,
DepartmentReadModel,
Expand All @@ -22,7 +23,7 @@ export const MockConsultants: ConsultantReadModel[] = [
id: 1,
name: "Test Consultant",
email: "[email protected]",
competences: ["Frontend"],
competences: [{ id: "development", name: "Utvikling" }],
department: "My Department",
bookings: [
{
Expand Down Expand Up @@ -61,3 +62,10 @@ export const MockEngagements: EngagementPerCustomerReadModel[] = [
engagements: [],
},
];

export const MockCompetences: CompetenceReadModel[] = [
{
id: "development",
name: "Utvikling",
},
];
19 changes: 18 additions & 1 deletion frontend/src/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,27 @@ export interface ConsultantReadModel {
name: string;
/** @minLength 1 */
email: string;
competences: string[];
startDate?: Date;
endDate?: Date;
competences: Competence[];
/** @minLength 1 */
department: string;
/** @format int32 */
yearsOfExperience: number;
graduationYear?: number;
degree: Degree;
bookings: BookedHoursPerWeek[];
detailedBooking: DetailedBooking[];
isOccupied: boolean;
}

export type Competence = {
/** @minLength 1 */
id: string;
/** @minLength 1 */
name: string;
};

export enum Degree {
Master = "Master",
Bachelor = "Bachelor",
Expand All @@ -73,6 +83,13 @@ export interface DepartmentReadModel {
hotkey?: number | null;
}

export interface CompetenceReadModel {
/** @minLength 1 */
id: string;
/** @minLength 1 */
name: string;
}

export interface DetailedBooking {
bookingDetails: BookingDetails;
hours: WeeklyHours[];
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/app/[organisation]/bemanning/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CompetenceReadModel,
ConsultantReadModel,
DepartmentReadModel,
EngagementPerCustomerReadModel,
Expand Down Expand Up @@ -35,6 +36,9 @@ export default async function Bemanning({
`organisations/${params.organisation}/departments`,
)) ?? [];

const competences =
(await fetchWithToken<CompetenceReadModel[]>(`competences`)) ?? [];

const customers =
(await fetchWithToken<EngagementPerCustomerReadModel[]>(
`${params.organisation}/projects`,
Expand All @@ -44,6 +48,7 @@ export default async function Bemanning({
<ConsultantFilterProvider
consultants={consultants}
departments={departments}
competences={competences}
customers={customers}
>
<StaffingContent />
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/[organisation]/ferie/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export default async function Ferie({
!process.env.NEXT_PUBLIC_NO_AUTH &&
(await getCustomServerSession(authOptions));

const userEmail =
const email =
session && session.user && session.user.email ? session.user.email : "";

const consultant =
(await fetchWithToken<ConsultantReadModel>(
`${params.organisation}/consultants?Email=${userEmail}`,
`${params.organisation}/consultants/${email}`,
)) ?? undefined;

const vacationDays =
Expand Down
Loading

0 comments on commit 15d9c0f

Please sign in to comment.