Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
withinJoel committed Aug 22, 2024
1 parent ee3b5a9 commit a53f465
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'mysql:mysql-connector-java:8.0.33'
//implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-hateoas'

// Spring Boot Test starter
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/classes/java/main/com/example/teamsync/model/Employee.class
Binary file not shown.
Binary file not shown.
16 changes: 15 additions & 1 deletion build/resources/main/static/employees.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ <h2 class="card-title">Employee List</h2>
// Create an empty array to store department names
const departmentNames = [];

function generateToken() {
const CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
let token = '';
while (token.length < 64) { // length of the random string
const index = Math.floor(Math.random() * CHARS.length);
token += CHARS.charAt(index);
}
return token;
}

function fetchDepartments() {
fetch(departmentApiUrl)
.then(response => response.json())
Expand Down Expand Up @@ -193,6 +203,7 @@ <h2 class="card-title">Employee List</h2>
<th>Email</th>
<th>Age</th>
<th>Department</th>
<th>Access Token</th>
<th>Actions</th>
</tr>
`;
Expand All @@ -207,6 +218,7 @@ <h2 class="card-title">Employee List</h2>
<td>${employee.email}</td>
<td>${employee.age}</td>
<td>${employee.department}</td>
<td>${employee.token}</td>
<td>
<button class="btn-delete" onclick="deleteEmployee(${employee.id})">Delete</button>
</td>
Expand All @@ -224,13 +236,15 @@ <h2 class="card-title">Employee List</h2>
const age = document.getElementById('employee-age').value; // Get the age value
const email = document.getElementById('employee-email').value;
const department = document.getElementById('department-id').value;
const token = generateToken();
console.log(token);

fetch(employeeApiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ name, age, email, department }), // Include age in the JSON body
body: JSON.stringify({ name, age, email, department, token }), // Include age in the JSON body
})
.then(response => response.json())
.then(() => {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;

@RestController
Expand Down Expand Up @@ -54,6 +55,7 @@ public ResponseEntity<EmployeeResource> createEmployee(@RequestBody EmployeeDto
employee.setName(employeeDto.getName());
employee.setDepartment(employeeDto.getDepartment());
employee.setEmail(employeeDto.getEmail());
employee.setToken(employeeDto.getToken());
employee.setAge(employeeDto.getAge());

Employee savedEmployee = employeeService.createEmployee(employee);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public EmployeeResource toModel(Employee employee) {
resource.setAge(employee.getAge());
resource.setEmail(employee.getEmail());
resource.setDepartment(employee.getDepartment());
resource.setToken(employee.getToken());

// Populate the projects field
List<ProjectResource> projectResources = employee.getProjects().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class EmployeeResource extends RepresentationModel<EmployeeResource> {
private int age;
private String email;
private String department;
private String token;
private List<ProjectResource> projects;

// Getters and Setters
Expand Down Expand Up @@ -53,6 +54,14 @@ public void setDepartment(String department) {
this.department = department;
}

public String getToken() {
return token;
}

public void setToken(String token) {
this.token = token;
}

public List<ProjectResource> getProjects() {
return projects;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class EmployeeDto extends RepresentationModel<EmployeeDto> {
private String name;
private Integer age;
private String department;
private String token;
private String email;
private List<ProjectDto> projects;

Expand Down Expand Up @@ -54,6 +55,14 @@ public void setEmail(String email) {
this.email = email;
}

public String getToken() {
return token;
}

public void setToken(String token) {
this.token = token;
}

public List<ProjectDto> getProjects() {
return projects;
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/example/teamsync/model/Employee.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Employee {
private String department;
private String email;
private String name;
private String token;

@OneToMany(mappedBy = "employee")
private List<Project> projects;
Expand All @@ -31,6 +32,14 @@ public String getName() {
return name;
}

public String getToken() {
return token;
}

public void setToken(String token) {
this.token = token;
}

public void setName(String name) {
this.name = name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public void deleteProject(Long id) {
}

//Experimental Features


public Project findByDescription (String department) {
Project project = projectRepository.findByDescription(department);
return project;
Expand Down
16 changes: 15 additions & 1 deletion src/main/resources/static/employees.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ <h2 class="card-title">Employee List</h2>
// Create an empty array to store department names
const departmentNames = [];

function generateToken() {
const CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
let token = '';
while (token.length < 64) { // length of the random string
const index = Math.floor(Math.random() * CHARS.length);
token += CHARS.charAt(index);
}
return token;
}

function fetchDepartments() {
fetch(departmentApiUrl)
.then(response => response.json())
Expand Down Expand Up @@ -193,6 +203,7 @@ <h2 class="card-title">Employee List</h2>
<th>Email</th>
<th>Age</th>
<th>Department</th>
<th>Access Token</th>
<th>Actions</th>
</tr>
`;
Expand All @@ -207,6 +218,7 @@ <h2 class="card-title">Employee List</h2>
<td>${employee.email}</td>
<td>${employee.age}</td>
<td>${employee.department}</td>
<td>${employee.token}</td>
<td>
<button class="btn-delete" onclick="deleteEmployee(${employee.id})">Delete</button>
</td>
Expand All @@ -224,13 +236,15 @@ <h2 class="card-title">Employee List</h2>
const age = document.getElementById('employee-age').value; // Get the age value
const email = document.getElementById('employee-email').value;
const department = document.getElementById('department-id').value;
const token = generateToken();
console.log(token);

fetch(employeeApiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ name, age, email, department }), // Include age in the JSON body
body: JSON.stringify({ name, age, email, department, token }), // Include age in the JSON body
})
.then(response => response.json())
.then(() => {
Expand Down

0 comments on commit a53f465

Please sign in to comment.