Merge pull request 'fix: Small changes' (#39) from 3002833/Backend:main into main

Reviewed-on: Maradona/Backend#39
pull/1/head
David Hess 2024-11-04 21:44:42 +01:00
commit 03d1819817
7 changed files with 111 additions and 139 deletions

Binary file not shown.

View File

@ -1,138 +1,108 @@
// package com.maradona.backend;
package com.maradona.backend;
// import com.maradona.backend.entities.Employee;
// import com.maradona.backend.entities.EmployeeSecondarySkill;
// import com.maradona.backend.entities.FormOfAddress;
// import com.maradona.backend.entities.PrimarySkill;
// import com.maradona.backend.entities.SecondarySkill;
// import com.maradona.backend.repositories.EmployeeRepository;
// import com.maradona.backend.repositories.FormOfAddressRepository;
// import com.maradona.backend.repositories.PrimarySkillRepository;
// import com.maradona.backend.repositories.SecondarySkillRepository;
// import com.maradona.backend.repositories.EmployeeSecondarySkillRepository;
// import com.maradona.backend.repositories.ProjectRepository;
// import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.boot.CommandLineRunner;
// import org.springframework.stereotype.Component;
import com.maradona.backend.entities.Employee;
import com.maradona.backend.entities.EmployeeSecondarySkill;
import com.maradona.backend.entities.FormOfAddress;
import com.maradona.backend.entities.PrimarySkill;
import com.maradona.backend.entities.SecondarySkill;
import com.maradona.backend.repositories.EmployeeRepository;
import com.maradona.backend.repositories.FormOfAddressRepository;
import com.maradona.backend.repositories.PrimarySkillRepository;
import com.maradona.backend.repositories.SecondarySkillRepository;
import com.maradona.backend.repositories.EmployeeSecondarySkillRepository;
import com.maradona.backend.repositories.ProjectRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
// import java.time.LocalTime;
// import java.util.ArrayList;
// import java.util.List;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
// @Component
// public class DefaultValueLoader implements CommandLineRunner {
@Component
public class DefaultValueLoader implements CommandLineRunner {
// @Autowired
// private PrimarySkillRepository primarySkillRepository;
@Autowired
private PrimarySkillRepository primarySkillRepository;
// @Autowired
// private SecondarySkillRepository secondarySkillRepository;
@Autowired
private SecondarySkillRepository secondarySkillRepository;
// @Autowired
// private EmployeeRepository employeeRepository;
@Autowired
private EmployeeRepository employeeRepository;
// @Autowired
// private FormOfAddressRepository formOfAddressRepository;
@Autowired
private FormOfAddressRepository formOfAddressRepository;
// @Autowired
// private EmployeeSecondarySkillRepository employeeSecondarySkillRepository;
@Override
public void run(String... args) throws Exception {
// Create form of addresses
FormOfAddress formOfAddress1 = new FormOfAddress();
formOfAddress1.setDescription("Herr");
// @Autowired
// private ProjectRepository projectRepository;
FormOfAddress formOfAddress2 = new FormOfAddress();
formOfAddress2.setDescription("Frau");
// @Override
// public void run(String... args) throws Exception {
// // Create form of addresses
// FormOfAddress formOfAddress1 = new FormOfAddress();
// formOfAddress1.setDescription("Herr");
FormOfAddress formOfAddress3 = new FormOfAddress();
formOfAddress3.setDescription("Einkaufstüte");
// FormOfAddress formOfAddress2 = new FormOfAddress();
// formOfAddress2.setDescription("Frau");
formOfAddress1 = formOfAddressRepository.save(formOfAddress1);
formOfAddress2 = formOfAddressRepository.save(formOfAddress2);
// FormOfAddress formOfAddress3 = new FormOfAddress();
// formOfAddress3.setDescription("Einkaufstüte");
// Create primary skills
PrimarySkill primarySkill1 = new PrimarySkill();
primarySkill1.setDescription("Software Development");
// formOfAddress1 = formOfAddressRepository.save(formOfAddress1);
// formOfAddress2 = formOfAddressRepository.save(formOfAddress2);
PrimarySkill primarySkill2 = new PrimarySkill();
primarySkill2.setDescription("Project Management");
// // Create primary skills
// PrimarySkill primarySkill1 = new PrimarySkill();
// primarySkill1.setDescription("Software Development");
primarySkillRepository.save(primarySkill1);
primarySkillRepository.save(primarySkill2);
// PrimarySkill primarySkill2 = new PrimarySkill();
// primarySkill2.setDescription("Project Management");
// Create secondary skills
SecondarySkill secondarySkill1 = new SecondarySkill();
secondarySkill1.setDescription("Java");
secondarySkill1.setPrimarySkill(primarySkill1);
// primarySkillRepository.save(primarySkill1);
// primarySkillRepository.save(primarySkill2);
SecondarySkill secondarySkill2 = new SecondarySkill();
secondarySkill2.setDescription("Agile Methodology");
secondarySkill2.setPrimarySkill(primarySkill2);
// // Create secondary skills
// SecondarySkill secondarySkill1 = new SecondarySkill();
// secondarySkill1.setDescription("Java");
// secondarySkill1.setPrimarySkill(primarySkill1);
SecondarySkill secondarySkill3 = new SecondarySkill();
secondarySkill3.setDescription("Risk Management");
secondarySkill3.setPrimarySkill(primarySkill2);
// SecondarySkill secondarySkill2 = new SecondarySkill();
// secondarySkill2.setDescription("Agile Methodology");
// secondarySkill2.setPrimarySkill(primarySkill2);
secondarySkillRepository.save(secondarySkill1);
secondarySkillRepository.save(secondarySkill2);
secondarySkillRepository.save(secondarySkill3);
// SecondarySkill secondarySkill3 = new SecondarySkill();
// secondarySkill3.setDescription("Risk Management");
// secondarySkill3.setPrimarySkill(primarySkill2);
// Create employees
Employee employee1 = new Employee();
employee1.setEmployeeNr(1);
employee1.setFirstName("Jane");
employee1.setLastName("Smith");
employee1.setDStart(LocalTime.of(9, 0));
employee1.setDEnd(LocalTime.of(17, 0));
employee1.setFormOfAddress(formOfAddress2);
// secondarySkillRepository.save(secondarySkill1);
// secondarySkillRepository.save(secondarySkill2);
// secondarySkillRepository.save(secondarySkill3);
employeeRepository.save(employee1);
// // Create employees
// Employee employee1 = new Employee();
// employee1.setEmployeeNr(1);
// employee1.setFirstName("John");
// employee1.setLastName("Doe");
// employee1.setMail("john.doe@example.com");
// employee1.setDStart(LocalTime.of(9, 0));
// employee1.setDEnd(LocalTime.of(17, 0));
// employee1.setFormOfAddress(formOfAddress1);
// Assign secondary skills to employees
EmployeeSecondarySkill employeeSecondarySkill1 = new EmployeeSecondarySkill();
employeeSecondarySkill1.setEmployee(employee1);
employeeSecondarySkill1.setSecondarySkill(secondarySkill1);
employeeSecondarySkill1.setLevel(4);
// Employee employee2 = new Employee();
// employee2.setEmployeeNr(2);
// employee2.setFirstName("Jane");
// employee2.setLastName("Smith");
// employee2.setMail("jane.smith@example.com");
// employee2.setDStart(LocalTime.of(9, 0));
// employee2.setDEnd(LocalTime.of(17, 0));
// employee2.setFormOfAddress(formOfAddress2);
EmployeeSecondarySkill employeeSecondarySkill2 = new EmployeeSecondarySkill();
employeeSecondarySkill2.setEmployee(employee1);
employeeSecondarySkill2.setSecondarySkill(secondarySkill2);
employeeSecondarySkill2.setLevel(3);
// employeeRepository.save(employee1);
// employeeRepository.save(employee2);
List<EmployeeSecondarySkill> employee1Skills = new ArrayList<>();
employee1Skills.add(employeeSecondarySkill1);
employee1Skills.add(employeeSecondarySkill2);
employee1.setSecondarySkills(employee1Skills);
// // Assign secondary skills to employees
// EmployeeSecondarySkill employeeSecondarySkill1 = new
// EmployeeSecondarySkill();
// employeeSecondarySkill1.setEmployee(employee1);
// employeeSecondarySkill1.setSecondarySkill(secondarySkill1);
// employeeSecondarySkill1.setLevel(4);
// EmployeeSecondarySkill employeeSecondarySkill2 = new
// EmployeeSecondarySkill();
// employeeSecondarySkill2.setEmployee(employee1);
// employeeSecondarySkill2.setSecondarySkill(secondarySkill2);
// employeeSecondarySkill2.setLevel(3);
// EmployeeSecondarySkill employeeSecondarySkill3 = new
// EmployeeSecondarySkill();
// employeeSecondarySkill3.setEmployee(employee2);
// employeeSecondarySkill3.setSecondarySkill(secondarySkill3);
// employeeSecondarySkill3.setLevel(5);
// List<EmployeeSecondarySkill> employee1Skills = new ArrayList<>();
// employee1Skills.add(employeeSecondarySkill1);
// employee1Skills.add(employeeSecondarySkill2);
// employee1.setSecondarySkills(employee1Skills);
// List<EmployeeSecondarySkill> employee2Skills = new ArrayList<>();
// employee2Skills.add(employeeSecondarySkill3);
// employee2.setSecondarySkills(employee2Skills);
// employeeRepository.save(employee1);
// employeeRepository.save(employee2);
// }
// }
employeeRepository.save(employee1);
}
}

View File

@ -41,10 +41,15 @@ public class SkillsController {
// Returns the skills overview page
@GetMapping({ "/", "" })
public String profile(Model model) {
// Gather the employee and skills data
var employeeData = employeeService.getEmployeeById(user);
model.addAttribute("employee", employeeData.orElse(null));
var skillData = skillService.getUserSkills(user);
// Add the data to the model for the frontend
model.addAttribute("employee", employeeData.orElse(null));
model.addAttribute("skillData", skillData);
// Return the skills overview page
return "skills/skills";
}
@ -67,18 +72,27 @@ public class SkillsController {
// Add a new skill to the user profile
@PostMapping("/add")
public String addSkill(@ModelAttribute SkillForm skillForm) {
// Gather the user and skill
var employee = employeeService.getEmployeeById(user).orElseThrow(() -> new RuntimeException("Employee not found"));
var secondarySkill = secondarySkillService.getSecondarySkillById(skillForm.getSecondarySkillId())
.orElseThrow(() -> new RuntimeException("Secondary Skill not found"));
// Test id employee already has the skill
for (EmployeeSecondarySkill skill : employee.getSecondarySkills()) {
if (skill.getSecondarySkill().getSsid().equals(skillForm.getSecondarySkillId())) {
return "redirect:/skills";
}
}
// Add the skill to the user profile
EmployeeSecondarySkill employeeSecondarySkill = new EmployeeSecondarySkill();
employeeSecondarySkill.setEmployee(employee);
employeeSecondarySkill.setSecondarySkill(secondarySkill);
employeeSecondarySkill.setLevel(skillForm.getLevel());
employee.getSecondarySkills().add(employeeSecondarySkill);
employeeService.saveEmployee(employee);
// Redirect to the skills overview page
return "redirect:/skills";
}

View File

@ -27,9 +27,6 @@ public class Employee {
@JoinColumn(name = "AID")
private FormOfAddress formOfAddress;
@Column(length = 150)
private String mail;
private LocalTime dStart;
private LocalTime dEnd;
@ -68,14 +65,6 @@ public class Employee {
return formOfAddress;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getMail() {
return mail;
}
public void setDStart(LocalTime dStart) {
this.dStart = dStart;
}

View File

@ -45,6 +45,9 @@ public class SkillService {
}
public Iterable<SkillDto> getUserSkills(Long userId) {
if (userId == null) {
return new ArrayList<>();
}
Employee employee = employeeRepository.findById(userId).orElse(null);
if (employee == null) {
return new ArrayList<>();

View File

@ -1,14 +1,12 @@
.project-card {
background-color: var(--cosmic-dark-dark);
color: var(--starlight-white-lighter);
border: 1px solid var(--cosmic-dark-medium);
border-radius: 5px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.project-card .card-title {
color: var(--starlight-white-lighter);
margin-bottom: 15px;
}
.project-card .card-text {
@ -32,7 +30,6 @@
background-color: var(--aurora-yellowgreen-lighter);
border: none;
border-radius: 4px;
margin-bottom: 20px;
}
.btn-create-project:hover {
@ -66,7 +63,7 @@
}
.form-control::placeholder {
color: var(--starlight-white-darker);
color: var(--cosmic-dark-dark);
}
.star-filled {

View File

@ -13,14 +13,13 @@
<h2 class="mb-4">Profile</h2>
<div class="project-card mb-4">
<div class="card-body">
<ul>
<li th:text="${employee.formOfAddress.description}">
Form of Address
</li>
<li th:text="${employee.firstName}">First Name</li>
<li th:text="${employee.lastName}">Last Name</li>
<li th:text="${employee.mail}">Email</li>
</ul>
<p>
<span th:text="${employee.formOfAddress.description}"
>Form of Address</span
>
<span th:text="${employee.firstName}">First Name</span>
<span th:text="${employee.lastName}">Last Name</span>
</p>
</div>
</div>
<div class="d-flex justify-content-between align-items-center mb-4">