feat: Please sendh elp

pull/1/head
Lunix-420 2024-11-12 18:55:18 +01:00
parent 9a0ace7a70
commit b22b867a6c
2 changed files with 53 additions and 24 deletions

View File

@ -4,15 +4,19 @@ import com.maradona.backend.entities.Employee;
import com.maradona.backend.entities.EmployeeSecondarySkill; import com.maradona.backend.entities.EmployeeSecondarySkill;
import com.maradona.backend.entities.FormOfAddress; import com.maradona.backend.entities.FormOfAddress;
import com.maradona.backend.entities.PrimarySkill; import com.maradona.backend.entities.PrimarySkill;
import com.maradona.backend.entities.Project;
import com.maradona.backend.entities.SecondarySkill; import com.maradona.backend.entities.SecondarySkill;
import com.maradona.backend.repositories.EmployeeRepository; import com.maradona.backend.repositories.EmployeeRepository;
import com.maradona.backend.repositories.FormOfAddressRepository; import com.maradona.backend.repositories.FormOfAddressRepository;
import com.maradona.backend.repositories.PrimarySkillRepository; import com.maradona.backend.repositories.PrimarySkillRepository;
import com.maradona.backend.repositories.ProjectRepository;
import com.maradona.backend.repositories.SecondarySkillRepository; import com.maradona.backend.repositories.SecondarySkillRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -32,6 +36,9 @@ public class DefaultValueLoader implements CommandLineRunner {
@Autowired @Autowired
private FormOfAddressRepository formOfAddressRepository; private FormOfAddressRepository formOfAddressRepository;
@Autowired
private ProjectRepository projectRepository;
@Override @Override
public void run(String... args) { public void run(String... args) {
@ -104,5 +111,15 @@ public class DefaultValueLoader implements CommandLineRunner {
employee1.setSecondarySkills(employee1Skills); employee1.setSecondarySkills(employee1Skills);
employeeRepository.save(employee1); employeeRepository.save(employee1);
// add a default project
Project project = new Project();
project.setName("Project 1");
project.setStartDate(LocalDate.now());
project.setEndDate(LocalDate.now().plusDays(30));
project.setDescription("This is a project description");
// save project
project = projectRepository.save(project);
} }
} }

View File

@ -13,48 +13,30 @@
<div th:replace="~{/core/_header :: header(activePage='createSkill')}"></div> <div th:replace="~{/core/_header :: header(activePage='createSkill')}"></div>
<div class="content container mt-4"> <div class="content container mt-4">
<h2 class="mb-4">Create Skill</h2> <h2 class="mb-4">Create Skill</h2>
<form <form id="createSkillForm" class="project-card">
th:action="@{/skills/save}"
th:object="${skillPrototype}"
method="post"
class="project-card"
>
<div class="card-body"> <div class="card-body">
<!-- Primary Skill Input --> <!-- Primary Skill Input -->
<div class="form-group"> <div class="form-group">
<label for="primarySkill">Primary Skill:</label> <label for="primarySkill">Kategorie:</label>
<input <input
type="text" type="text"
id="primarySkill" id="primarySkill"
th:field="*{psid}" name="primarySkillDescription"
class="form-control" class="form-control"
required required
/> />
</div> </div>
<!-- Secondary Skill Input --> <!-- Secondary Skill Input -->
<div class="form-group"> <div class="form-group">
<label for="secondarySkill">Secondary Skill:</label> <label for="secondarySkill">Fähigkeit:</label>
<input <input
type="text" type="text"
id="secondarySkill" id="secondarySkill"
th:field="*{ssid}" name="secondarySkillDescription"
class="form-control" class="form-control"
required required
/> />
</div> </div>
<!-- Skill Level Input -->
<div class="form-group">
<label for="level">Skill Level:</label>
<input
type="number"
id="level"
th:field="*{level}"
class="form-control"
min="1"
max="5"
required
/>
</div>
<!-- Submit Button --> <!-- Submit Button -->
<button type="submit" class="btn-create-project">Create Skill</button> <button type="submit" class="btn-create-project">Create Skill</button>
</div> </div>
@ -62,5 +44,35 @@
</div> </div>
<div th:replace="~{/core/_footer :: footer}"></div> <div th:replace="~{/core/_footer :: footer}"></div>
</div> </div>
<script>
document.getElementById("createSkillForm").addEventListener("submit", function(event) {
event.preventDefault();
const form = event.target;
const formData = new FormData(form);
const jsonData = {};
formData.forEach((value, key) => {
jsonData[key] = value;
});
fetch("/api/secondary-skill", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(jsonData),
})
.then((response) => {
if (response.ok) {
window.location.href = "/skills";
} else {
return response.json().then((error) => {
console.error("Error:", error);
});
}
})
.catch((error) => {
console.error("Error:", error);
});
});
</script>
</body> </body>
</html> </html>