feat: Update project/create.html
parent
0a0cf82da1
commit
4b80a1082d
|
@ -101,6 +101,7 @@ public class ProjectController {
|
||||||
*/
|
*/
|
||||||
@PostMapping({ "/", "" })
|
@PostMapping({ "/", "" })
|
||||||
public ResponseEntity<Project> post(@RequestBody Project project) {
|
public ResponseEntity<Project> post(@RequestBody Project project) {
|
||||||
|
System.out.println(project);
|
||||||
Project savedProject = projectActions.saveProject(project);
|
Project savedProject = projectActions.saveProject(project);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(savedProject);
|
return ResponseEntity.status(HttpStatus.CREATED).body(savedProject);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package com.maradona.backend.entities;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -81,6 +83,7 @@ public class Employee {
|
||||||
*/
|
*/
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
@JoinTable(name = "employee_project", joinColumns = @JoinColumn(name = "employee_eid"), inverseJoinColumns = @JoinColumn(name = "project_pid"))
|
@JoinTable(name = "employee_project", joinColumns = @JoinColumn(name = "employee_eid"), inverseJoinColumns = @JoinColumn(name = "project_pid"))
|
||||||
|
@JsonBackReference
|
||||||
private List<Project> projects;
|
private List<Project> projects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,6 +5,8 @@ import lombok.Data;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a project.
|
* Represents a project.
|
||||||
*
|
*
|
||||||
|
@ -36,6 +38,7 @@ public class Project {
|
||||||
* This is a list of references to the employee entity.
|
* This is a list of references to the employee entity.
|
||||||
*/
|
*/
|
||||||
@ManyToMany(mappedBy = "projects")
|
@ManyToMany(mappedBy = "projects")
|
||||||
|
@JsonManagedReference
|
||||||
private List<Employee> employees;
|
private List<Employee> employees;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,7 +16,8 @@
|
||||||
<div class="content container mt-4">
|
<div class="content container mt-4">
|
||||||
<h2 class="mb-4">Create Project</h2>
|
<h2 class="mb-4">Create Project</h2>
|
||||||
<form
|
<form
|
||||||
th:action="@{/projects/save}"
|
id="createProjectForm"
|
||||||
|
th:action="@{/api/project}"
|
||||||
th:object="${project}"
|
th:object="${project}"
|
||||||
method="post"
|
method="post"
|
||||||
class="project-card"
|
class="project-card"
|
||||||
|
@ -52,6 +53,25 @@
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="workload">Workload:</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
id="workload"
|
||||||
|
th:field="*{workload}"
|
||||||
|
class="form-control"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="description">Description:</label>
|
||||||
|
<textarea
|
||||||
|
id="description"
|
||||||
|
th:field="*{description}"
|
||||||
|
class="form-control"
|
||||||
|
required
|
||||||
|
></textarea>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<button type="submit" class="btn-create-project">
|
<button type="submit" class="btn-create-project">
|
||||||
Save Project
|
Save Project
|
||||||
|
@ -62,5 +82,37 @@
|
||||||
</div>
|
</div>
|
||||||
<div th:replace="~{/core/_footer :: footer}"></div>
|
<div th:replace="~{/core/_footer :: footer}"></div>
|
||||||
</div>
|
</div>
|
||||||
|
<script>
|
||||||
|
document
|
||||||
|
.getElementById("createProjectForm")
|
||||||
|
.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/project", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(jsonData),
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
if (response.ok) {
|
||||||
|
window.location.href = "/projects";
|
||||||
|
} else {
|
||||||
|
return response.json().then((error) => {
|
||||||
|
console.error("Error:", error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Error:", error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue