From b5f93708c11bc9ae836ccdfab4959e986b915bb5 Mon Sep 17 00:00:00 2001
From: Phan Huy Tran
Date: Wed, 23 Oct 2024 11:58:29 +0200
Subject: [PATCH] Implement
---
requests/employee/createEmployee.http | 13 +++--
requests/employee/getEmployee.http | 2 +-
requests/project/createProject.http | 2 +-
requests/project/getEmployeesFromProject.http | 2 +
.../lf8_starter/employee/EmployeeService.java | 17 +++++++
.../project/action/RemoveProjectAction.java | 7 ++-
.../action/crud/CreateProjectAction.java | 6 +--
.../action/crud/GetAllProjectsAction.java | 4 +-
.../project/action/crud/GetProjectAction.java | 4 +-
.../action/crud/UpdateProjectAction.java | 6 +--
.../GetEmployeeFromProjectAction.java | 51 +++++++++++++++++++
.../dto/{ => employee}/EmployeeDto.java | 2 +-
.../project/dto/employee/GetEmployeeDto.java | 11 ++++
.../employee/GetEmployeesFromProjectDto.java | 17 +++++++
.../project/dto/employee/GetSkillDto.java | 13 +++++
.../dto/{ => project}/CreateProjectDto.java | 2 +-
.../dto/{ => project}/GetProjectDto.java | 2 +-
.../dto/{ => project}/UpdateProjectDto.java | 2 +-
.../mapper/EmployeeFromProjectMapper.java | 35 +++++++++++++
.../project/{ => mapper}/ProjectMapper.java | 9 ++--
20 files changed, 180 insertions(+), 27 deletions(-)
create mode 100644 requests/project/getEmployeesFromProject.http
create mode 100644 src/main/java/de/szut/lf8_starter/project/action/employee/GetEmployeeFromProjectAction.java
rename src/main/java/de/szut/lf8_starter/project/dto/{ => employee}/EmployeeDto.java (91%)
create mode 100644 src/main/java/de/szut/lf8_starter/project/dto/employee/GetEmployeeDto.java
create mode 100644 src/main/java/de/szut/lf8_starter/project/dto/employee/GetEmployeesFromProjectDto.java
create mode 100644 src/main/java/de/szut/lf8_starter/project/dto/employee/GetSkillDto.java
rename src/main/java/de/szut/lf8_starter/project/dto/{ => project}/CreateProjectDto.java (95%)
rename src/main/java/de/szut/lf8_starter/project/dto/{ => project}/GetProjectDto.java (94%)
rename src/main/java/de/szut/lf8_starter/project/dto/{ => project}/UpdateProjectDto.java (90%)
create mode 100644 src/main/java/de/szut/lf8_starter/project/mapper/EmployeeFromProjectMapper.java
rename src/main/java/de/szut/lf8_starter/project/{ => mapper}/ProjectMapper.java (90%)
diff --git a/requests/employee/createEmployee.http b/requests/employee/createEmployee.http
index a170fe2..b3f4591 100644
--- a/requests/employee/createEmployee.http
+++ b/requests/employee/createEmployee.http
@@ -3,10 +3,13 @@ Authorization: Bearer {{auth_token}}
Content-Type: application/json
{
- "firstName": "Jan",
- "lastName": "Klattenhoff",
- "street": "Pirolweg 17",
+ "firstName": "Jan1",
+ "lastName": "Klattenhoff1",
+ "street": "Pirolweg 171",
"postcode": "27777",
- "city": "Gandakersee",
- "phone": "017684984816"
+ "city": "Gandakersee1",
+ "phone": "0176849848161",
+ "skillSet": [
+ "1"
+ ]
}
\ No newline at end of file
diff --git a/requests/employee/getEmployee.http b/requests/employee/getEmployee.http
index eddf4d9..350a7fc 100644
--- a/requests/employee/getEmployee.http
+++ b/requests/employee/getEmployee.http
@@ -1,2 +1,2 @@
-GET https://employee.szut.dev/employees/312
+GET https://employee.szut.dev/employees/315
Authorization: Bearer {{auth_token}}
\ No newline at end of file
diff --git a/requests/project/createProject.http b/requests/project/createProject.http
index 7b08e28..3338a2c 100644
--- a/requests/project/createProject.http
+++ b/requests/project/createProject.http
@@ -6,7 +6,7 @@ Content-Type: application/json
{
"name": "name",
"leading_employee": 1,
- "employees": [2, 3],
+ "employees": [315, 312],
"contractor": 4,
"contractor_name": "Peter File",
"comment": "goal of project",
diff --git a/requests/project/getEmployeesFromProject.http b/requests/project/getEmployeesFromProject.http
new file mode 100644
index 0000000..d12dd96
--- /dev/null
+++ b/requests/project/getEmployeesFromProject.http
@@ -0,0 +1,2 @@
+GET http://localhost:8080/projects/2/employees
+Authorization: Bearer {{auth_token}}
\ No newline at end of file
diff --git a/src/main/java/de/szut/lf8_starter/employee/EmployeeService.java b/src/main/java/de/szut/lf8_starter/employee/EmployeeService.java
index a78f76b..907de80 100644
--- a/src/main/java/de/szut/lf8_starter/employee/EmployeeService.java
+++ b/src/main/java/de/szut/lf8_starter/employee/EmployeeService.java
@@ -1,5 +1,7 @@
package de.szut.lf8_starter.employee;
+import de.szut.lf8_starter.exceptionHandling.ResourceNotFoundException;
+import de.szut.lf8_starter.project.dto.employee.GetEmployeeDto;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@@ -31,4 +33,19 @@ public class EmployeeService {
return true;
}
+
+ public GetEmployeeDto getEmployee(String accessToken, Long employeeId) {
+ HttpHeaders headers = new HttpHeaders();
+ headers.setBearerAuth(accessToken.replace("Bearer ", ""));
+
+ HttpEntity requestEntity = new HttpEntity<>(headers);
+
+ String url = "https://employee.szut.dev/employees/" + employeeId;
+
+ try {
+ return restTemplate.exchange(url, HttpMethod.GET, requestEntity, GetEmployeeDto.class).getBody();
+ } catch (HttpClientErrorException.NotFound e) {
+ throw new ResourceNotFoundException("Employee not found");
+ }
+ }
}
diff --git a/src/main/java/de/szut/lf8_starter/project/action/RemoveProjectAction.java b/src/main/java/de/szut/lf8_starter/project/action/RemoveProjectAction.java
index d14dbee..efbd48d 100644
--- a/src/main/java/de/szut/lf8_starter/project/action/RemoveProjectAction.java
+++ b/src/main/java/de/szut/lf8_starter/project/action/RemoveProjectAction.java
@@ -2,14 +2,17 @@ package de.szut.lf8_starter.project.action;
import de.szut.lf8_starter.project.ProjectEntity;
import de.szut.lf8_starter.project.ProjectService;
-import de.szut.lf8_starter.project.dto.GetProjectDto;
+import de.szut.lf8_starter.project.dto.project.GetProjectDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
import java.util.Optional;
diff --git a/src/main/java/de/szut/lf8_starter/project/action/crud/CreateProjectAction.java b/src/main/java/de/szut/lf8_starter/project/action/crud/CreateProjectAction.java
index f21646d..1725ba8 100644
--- a/src/main/java/de/szut/lf8_starter/project/action/crud/CreateProjectAction.java
+++ b/src/main/java/de/szut/lf8_starter/project/action/crud/CreateProjectAction.java
@@ -1,10 +1,10 @@
package de.szut.lf8_starter.project.action.crud;
import de.szut.lf8_starter.project.ProjectEntity;
-import de.szut.lf8_starter.project.ProjectMapper;
import de.szut.lf8_starter.project.ProjectService;
-import de.szut.lf8_starter.project.dto.CreateProjectDto;
-import de.szut.lf8_starter.project.dto.GetProjectDto;
+import de.szut.lf8_starter.project.dto.project.CreateProjectDto;
+import de.szut.lf8_starter.project.dto.project.GetProjectDto;
+import de.szut.lf8_starter.project.mapper.ProjectMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
diff --git a/src/main/java/de/szut/lf8_starter/project/action/crud/GetAllProjectsAction.java b/src/main/java/de/szut/lf8_starter/project/action/crud/GetAllProjectsAction.java
index 5fb346a..97f5b9a 100644
--- a/src/main/java/de/szut/lf8_starter/project/action/crud/GetAllProjectsAction.java
+++ b/src/main/java/de/szut/lf8_starter/project/action/crud/GetAllProjectsAction.java
@@ -1,8 +1,8 @@
package de.szut.lf8_starter.project.action.crud;
-import de.szut.lf8_starter.project.ProjectMapper;
import de.szut.lf8_starter.project.ProjectService;
-import de.szut.lf8_starter.project.dto.GetProjectDto;
+import de.szut.lf8_starter.project.dto.project.GetProjectDto;
+import de.szut.lf8_starter.project.mapper.ProjectMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
diff --git a/src/main/java/de/szut/lf8_starter/project/action/crud/GetProjectAction.java b/src/main/java/de/szut/lf8_starter/project/action/crud/GetProjectAction.java
index eba31c1..041a26d 100644
--- a/src/main/java/de/szut/lf8_starter/project/action/crud/GetProjectAction.java
+++ b/src/main/java/de/szut/lf8_starter/project/action/crud/GetProjectAction.java
@@ -1,9 +1,9 @@
package de.szut.lf8_starter.project.action.crud;
import de.szut.lf8_starter.project.ProjectEntity;
-import de.szut.lf8_starter.project.ProjectMapper;
import de.szut.lf8_starter.project.ProjectService;
-import de.szut.lf8_starter.project.dto.GetProjectDto;
+import de.szut.lf8_starter.project.dto.project.GetProjectDto;
+import de.szut.lf8_starter.project.mapper.ProjectMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
diff --git a/src/main/java/de/szut/lf8_starter/project/action/crud/UpdateProjectAction.java b/src/main/java/de/szut/lf8_starter/project/action/crud/UpdateProjectAction.java
index 29a4ad5..3a169cf 100644
--- a/src/main/java/de/szut/lf8_starter/project/action/crud/UpdateProjectAction.java
+++ b/src/main/java/de/szut/lf8_starter/project/action/crud/UpdateProjectAction.java
@@ -1,10 +1,10 @@
package de.szut.lf8_starter.project.action.crud;
import de.szut.lf8_starter.project.ProjectEntity;
-import de.szut.lf8_starter.project.ProjectMapper;
import de.szut.lf8_starter.project.ProjectService;
-import de.szut.lf8_starter.project.dto.GetProjectDto;
-import de.szut.lf8_starter.project.dto.UpdateProjectDto;
+import de.szut.lf8_starter.project.dto.project.GetProjectDto;
+import de.szut.lf8_starter.project.dto.project.UpdateProjectDto;
+import de.szut.lf8_starter.project.mapper.ProjectMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
diff --git a/src/main/java/de/szut/lf8_starter/project/action/employee/GetEmployeeFromProjectAction.java b/src/main/java/de/szut/lf8_starter/project/action/employee/GetEmployeeFromProjectAction.java
new file mode 100644
index 0000000..f9d339c
--- /dev/null
+++ b/src/main/java/de/szut/lf8_starter/project/action/employee/GetEmployeeFromProjectAction.java
@@ -0,0 +1,51 @@
+package de.szut.lf8_starter.project.action.employee;
+
+import de.szut.lf8_starter.project.ProjectEntity;
+import de.szut.lf8_starter.project.ProjectService;
+import de.szut.lf8_starter.project.dto.employee.GetEmployeesFromProjectDto;
+import de.szut.lf8_starter.project.mapper.EmployeeFromProjectMapper;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Optional;
+
+@RestController
+public class GetEmployeeFromProjectAction {
+ private final ProjectService projectService;
+ private final EmployeeFromProjectMapper employeeFromProjectMapper;
+
+ public GetEmployeeFromProjectAction(ProjectService projectService, EmployeeFromProjectMapper employeeFromProjectMapper) {
+ this.projectService = projectService;
+ this.employeeFromProjectMapper = employeeFromProjectMapper;
+ }
+
+ @Operation(summary = "Get all employees from project")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Outputs projects with employees"),
+ @ApiResponse(responseCode = "404", description = "Project not found", content = @Content)
+ })
+ @GetMapping("/projects/{projectId}/employees")
+ public ResponseEntity