WIP
Some checks failed
Quality Check / Tests (pull_request) Successful in 59s
Quality Check / Checkstyle Main (pull_request) Successful in 45s
Build PR / Build and analyze (pull_request) Successful in 1m56s
gitea-sonarqube-bot ERROR

This commit is contained in:
Phan Huy Tran 2024-10-02 12:43:07 +02:00
parent 1e38efaa63
commit 790c2f4bc4
15 changed files with 92 additions and 5 deletions

@ -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"
}

@ -0,0 +1,2 @@
DELETE https://employee.szut.dev/employees/310
Authorization: Bearer {{auth_token}}

@ -0,0 +1,2 @@
GET https://employee.szut.dev/employees
Authorization: Bearer {{auth_token}}

@ -0,0 +1,2 @@
GET https://employee.szut.dev/employees/312
Authorization: Bearer {{auth_token}}

@ -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;

@ -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;
}