feat: Implement add employee to project route (SCRUM-2) #32
12
requests/employee/createEmployee.http
Normal file
12
requests/employee/createEmployee.http
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
POST https://employee.szut.dev/employees
|
||||||
|
Authorization: Bearer {{auth_token}}
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"firstName": "yomom",
|
||||||
|
"lastName": "yomom",
|
||||||
|
"street": "yomom",
|
||||||
|
"postcode": "yomom",
|
||||||
|
"city": "yomom",
|
||||||
|
"phone": "yomom"
|
||||||
jank marked this conversation as resolved
Outdated
|
|||||||
|
}
|
2
requests/employee/deleteEmployee.http
Normal file
2
requests/employee/deleteEmployee.http
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
DELETE https://employee.szut.dev/employees/310
|
||||||
|
Authorization: Bearer {{auth_token}}
|
2
requests/employee/getAllEmployees.http
Normal file
2
requests/employee/getAllEmployees.http
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
GET https://employee.szut.dev/employees
|
||||||
|
Authorization: Bearer {{auth_token}}
|
2
requests/employee/getEmployee.http
Normal file
2
requests/employee/getEmployee.http
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
GET https://employee.szut.dev/employees/312
|
||||||
|
Authorization: Bearer {{auth_token}}
|
2
requests/project/addEmployeeToProject.http
Normal file
2
requests/project/addEmployeeToProject.http
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
POST http://localhost:8080/projects/1/employees/312
|
||||||
|
Authorization: Bearer {{auth_token}}
|
@ -1,4 +1,4 @@
|
|||||||
package de.szut.lf8_starter.project.action;
|
package de.szut.lf8_starter.project.action.crud;
|
||||||
|
|
||||||
import de.szut.lf8_starter.project.ProjectEntity;
|
import de.szut.lf8_starter.project.ProjectEntity;
|
||||||
import de.szut.lf8_starter.project.ProjectMapper;
|
import de.szut.lf8_starter.project.ProjectMapper;
|
@ -1,4 +1,4 @@
|
|||||||
package de.szut.lf8_starter.project.action;
|
package de.szut.lf8_starter.project.action.crud;
|
||||||
|
|
||||||
import de.szut.lf8_starter.project.ProjectMapper;
|
import de.szut.lf8_starter.project.ProjectMapper;
|
||||||
import de.szut.lf8_starter.project.ProjectService;
|
import de.szut.lf8_starter.project.ProjectService;
|
@ -1,4 +1,4 @@
|
|||||||
package de.szut.lf8_starter.project.action;
|
package de.szut.lf8_starter.project.action.crud;
|
||||||
|
|
||||||
import de.szut.lf8_starter.project.ProjectEntity;
|
import de.szut.lf8_starter.project.ProjectEntity;
|
||||||
import de.szut.lf8_starter.project.ProjectMapper;
|
import de.szut.lf8_starter.project.ProjectMapper;
|
||||||
@ -11,7 +11,10 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
|||||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
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;
|
import java.util.Optional;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package de.szut.lf8_starter.project.action;
|
package de.szut.lf8_starter.project.action.crud;
|
||||||
|
|
||||||
import de.szut.lf8_starter.project.ProjectEntity;
|
import de.szut.lf8_starter.project.ProjectEntity;
|
||||||
import de.szut.lf8_starter.project.ProjectMapper;
|
import de.szut.lf8_starter.project.ProjectMapper;
|
49
src/main/java/de/szut/lf8_starter/project/action/employee/AddEmployeeToProjectAction.java
Normal file
49
src/main/java/de/szut/lf8_starter/project/action/employee/AddEmployeeToProjectAction.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package de.szut.lf8_starter.project.action.employee;
|
||||||
|
|
||||||
|
import de.szut.lf8_starter.project.ProjectEntity;
|
||||||
|
import de.szut.lf8_starter.project.ProjectService;
|
||||||
|
import org.springframework.http.*;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class AddEmployeeToProjectAction {
|
||||||
|
private final ProjectService projectService;
|
||||||
|
private final RestTemplate restTemplate;
|
||||||
|
|
||||||
|
public AddEmployeeToProjectAction(ProjectService projectService, RestTemplate restTemplate) {
|
||||||
|
this.projectService = projectService;
|
||||||
|
this.restTemplate = restTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/projects/{projectId}/employees/{employeeId}")
|
||||||
|
public ResponseEntity<Object> create(
|
||||||
|
@PathVariable Long projectId,
|
||||||
|
@PathVariable Long employeeId,
|
||||||
|
@RequestHeader("Authorization") String accessToken
|
||||||
|
) {
|
||||||
|
Optional<ProjectEntity> project = this.projectService.findById(projectId);
|
||||||
|
|
||||||
|
if (project.isEmpty()) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setBearerAuth(accessToken.replace("Bearer ", ""));
|
||||||
|
|
||||||
|
HttpEntity<String> requestEntity = new HttpEntity<>(headers);
|
||||||
|
|
||||||
|
String url = "https://employee.szut.dev/employees/" + employeeId;
|
||||||
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class);
|
||||||
|
|
||||||
|
System.out.println("Employee Data: " + response.getBody());
|
||||||
|
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package de.szut.lf8_starter.project.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonNaming;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class BearerTokenResponseDto {
|
||||||
|
private String accessToken;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user
@ptran Dont use yomom as test user