feat: Implement feature to list all employees from a project (SCRUM-46) #36
@ -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"
|
||||
]
|
||||
}
|
@ -1,2 +1,2 @@
|
||||
GET https://employee.szut.dev/employees/312
|
||||
GET https://employee.szut.dev/employees/315
|
||||
Authorization: Bearer {{auth_token}}
|
@ -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",
|
||||
|
2
requests/project/getEmployeesFromProject.http
Normal file
2
requests/project/getEmployeesFromProject.http
Normal file
@ -0,0 +1,2 @@
|
||||
GET http://localhost:8080/projects/2/employees
|
||||
Authorization: Bearer {{auth_token}}
|
@ -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<String> 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
51
src/main/java/de/szut/lf8_starter/project/action/employee/GetEmployeeFromProjectAction.java
Normal file
51
src/main/java/de/szut/lf8_starter/project/action/employee/GetEmployeeFromProjectAction.java
Normal file
@ -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<Object> create(
|
||||
@PathVariable Long projectId,
|
||||
@RequestHeader("Authorization") String accessToken
|
||||
) {
|
||||
Optional<ProjectEntity> project = projectService.findById(projectId);
|
||||
|
||||
if (project.isEmpty()) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
GetEmployeesFromProjectDto getEmployeesFromProjectDto = this.employeeFromProjectMapper
|
||||
.mapToGetEmployeesFromProjectDto(project.get(), accessToken);
|
||||
|
||||
return new ResponseEntity<>(getEmployeesFromProjectDto, HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package de.szut.lf8_starter.project.dto;
|
||||
package de.szut.lf8_starter.project.dto.employee;
|
||||
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonNaming;
|
@ -0,0 +1,11 @@
|
||||
package de.szut.lf8_starter.project.dto.employee;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class GetEmployeeDto {
|
||||
private long id;
|
||||
private GetSkillDto[] skillSet;
|
||||
}
|
17
src/main/java/de/szut/lf8_starter/project/dto/employee/GetEmployeesFromProjectDto.java
Normal file
17
src/main/java/de/szut/lf8_starter/project/dto/employee/GetEmployeesFromProjectDto.java
Normal file
@ -0,0 +1,17 @@
|
||||
package de.szut.lf8_starter.project.dto.employee;
|
||||
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonNaming;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
|
||||
public class GetEmployeesFromProjectDto {
|
||||
private long projectId;
|
||||
private String projectDescription;
|
||||
private ArrayList<GetEmployeeDto> employees;
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package de.szut.lf8_starter.project.dto.employee;
|
||||
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonNaming;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
|
||||
public class GetSkillDto {
|
||||
private String skill;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package de.szut.lf8_starter.project.dto;
|
||||
package de.szut.lf8_starter.project.dto.project;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
@ -1,4 +1,4 @@
|
||||
package de.szut.lf8_starter.project.dto;
|
||||
package de.szut.lf8_starter.project.dto.project;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
@ -1,4 +1,4 @@
|
||||
package de.szut.lf8_starter.project.dto;
|
||||
package de.szut.lf8_starter.project.dto.project;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
@ -0,0 +1,35 @@
|
||||
package de.szut.lf8_starter.project.mapper;
|
||||
|
||||
import de.szut.lf8_starter.employee.EmployeeService;
|
||||
import de.szut.lf8_starter.project.ProjectEntity;
|
||||
import de.szut.lf8_starter.project.dto.employee.GetEmployeeDto;
|
||||
import de.szut.lf8_starter.project.dto.employee.GetEmployeesFromProjectDto;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Service
|
||||
public class EmployeeFromProjectMapper {
|
||||
private final EmployeeService employeeService;
|
||||
|
||||
public EmployeeFromProjectMapper(EmployeeService employeeService) {
|
||||
this.employeeService = employeeService;
|
||||
}
|
||||
|
||||
public GetEmployeesFromProjectDto mapToGetEmployeesFromProjectDto(ProjectEntity projectEntity, String accessToken) {
|
||||
GetEmployeesFromProjectDto getEmployeesFromProjectDto = new GetEmployeesFromProjectDto();
|
||||
getEmployeesFromProjectDto.setProjectId(projectEntity.getId());
|
||||
getEmployeesFromProjectDto.setProjectDescription(projectEntity.getComment());
|
||||
|
||||
ArrayList<GetEmployeeDto> employeeDtos = new ArrayList<>();
|
||||
for (long id : projectEntity.getEmployees()) {
|
||||
GetEmployeeDto getEmployeeDto = this.employeeService.getEmployee(accessToken, id);
|
||||
|
||||
employeeDtos.add(getEmployeeDto);
|
||||
}
|
||||
|
||||
getEmployeesFromProjectDto.setEmployees(employeeDtos);
|
||||
|
||||
return getEmployeesFromProjectDto;
|
||||
}
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package de.szut.lf8_starter.project;
|
||||
package de.szut.lf8_starter.project.mapper;
|
||||
|
||||
import de.szut.lf8_starter.project.dto.CreateProjectDto;
|
||||
import de.szut.lf8_starter.project.dto.GetProjectDto;
|
||||
import de.szut.lf8_starter.project.dto.UpdateProjectDto;
|
||||
import de.szut.lf8_starter.project.ProjectEntity;
|
||||
import de.szut.lf8_starter.project.dto.project.CreateProjectDto;
|
||||
import de.szut.lf8_starter.project.dto.project.GetProjectDto;
|
||||
import de.szut.lf8_starter.project.dto.project.UpdateProjectDto;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
Loading…
Reference in New Issue
Block a user