Compare commits

...

5 commits

Author SHA1 Message Date
f469876785
Merge pull request 'PMT-40: alle Projekte eines Bestimmten Mitarbeiters abfragen' (!18) from story/PMT-40-alle-projekte-eines-bestimmten into trunk
All checks were successful
Quality Check / Validate OAS (push) Successful in 33s
Quality Check / Linting (push) Successful in 1m13s
Quality Check / Testing (push) Successful in 1m19s
Quality Check / Static Analysis (push) Successful in 1m21s
Reviewed-on: #18
Reviewed-by: Dominik Säume <dominik.saeume@hmmh.de>
2024-10-24 09:02:39 +00:00
49244526ef PMT-40: Write Tests for Endpoint Implementation
All checks were successful
Quality Check / Validate OAS (push) Successful in 52s
Quality Check / Validate OAS (pull_request) Successful in 1m6s
Quality Check / Linting (push) Successful in 2m8s
Quality Check / Linting (pull_request) Successful in 2m14s
Quality Check / Testing (push) Successful in 2m30s
Quality Check / Static Analysis (push) Successful in 2m34s
Quality Check / Testing (pull_request) Successful in 2m26s
Quality Check / Static Analysis (pull_request) Successful in 2m29s
2024-10-24 10:31:09 +02:00
6b430ae251 PMT-40: Fix Endpoint 2024-10-24 10:30:56 +02:00
Rajbir Singh
096c25e33b PMT-40: Implement Endpoint
All checks were successful
Quality Check / Validate OAS (push) Successful in 53s
Quality Check / Validate OAS (pull_request) Successful in 1m3s
Quality Check / Linting (push) Successful in 2m12s
Quality Check / Linting (pull_request) Successful in 2m13s
Quality Check / Testing (push) Successful in 2m26s
Quality Check / Testing (pull_request) Successful in 2m23s
Quality Check / Static Analysis (push) Successful in 2m33s
Quality Check / Static Analysis (pull_request) Successful in 2m28s
Co-authored-by: Dominik Säume <dominik.saeume@hmmh.de>
2024-10-24 09:49:53 +02:00
Rajbir Singh
79ab6f7f48 PMT-40: define Endpoint 2024-10-24 09:44:46 +02:00
4 changed files with 161 additions and 0 deletions

View file

@ -112,6 +112,31 @@ components:
plannedEnd:
type: string
format: date-time
Project:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
goal:
type: string
customerId:
type: integer
format: int64
administratorId:
type: integer
format: int64
start:
type: string
format: date-time
plannedEnd:
type: string
format: date-time
realEnd:
type: string
format: date-time
AddEmployeeDTO:
type: object
properties:
@ -160,6 +185,13 @@ components:
type: array
items:
$ref: "#/components/schemas/Employee"
EmployeeProjectsDTO:
type: object
properties:
projects:
type: array
items:
$ref: '#/components/schemas/Project'
responses:
Unauthorized:
description: "Unauthorized"
@ -416,3 +448,27 @@ paths:
$ref: '#/components/responses/NotFound'
500:
$ref: "#/components/responses/InternalError"
/employye/{id}/projects:
get:
description: "getAllProjects"
operationId: "Get a List of all Projects from a specific Employee"
parameters:
- in: path
name: id
schema:
type: integer
format: int64
required: true
responses:
200:
content:
application/json:
schema:
$ref: "#/components/schemas/EmployeeProjectsDTO"
description: 'Get a List of all Projects from a specific Employee'
401:
$ref: "#/components/responses/Unauthorized"
404:
$ref: '#/components/responses/NotFound'
500:
$ref: '#/components/responses/InternalError'

View file

@ -3,6 +3,7 @@ package de.hmmh.pmt;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.hmmh.pmt.db.*;
import de.hmmh.pmt.db.Project;
import de.hmmh.pmt.dtos.*;
import de.hmmh.pmt.employee.ApiClientFactory;
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
@ -237,4 +238,22 @@ public class ApiController implements DefaultApi {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Override
public ResponseEntity<EmployeeProjectsDTO> getAListOfAllProjectsFromASpecificEmployee(Long id) {
ApiTools.CheckEmployeeRecord employeeRecord = apiTools.checkEmployeeExists(id);
if (employeeRecord.status() != HttpStatus.OK) {
return new ResponseEntity<>(employeeRecord.status());
}
List<Allocation> allocationsByEmployee = allocationRepository.findAllByEmployeeId(id);
EmployeeProjectsDTO response = new EmployeeProjectsDTO();
response.setProjects(new ArrayList<>());
for (Allocation allocation : allocationsByEmployee) {
response.addProjectsItem(mapper.mapProject(allocation.getProject()));
}
return ResponseEntity.ok(response);
}
}

View file

@ -82,4 +82,16 @@ public class Mapper {
project.setPlannedEnd(dto.getPlannedEnd());
return project;
}
public de.hmmh.pmt.dtos.Project mapProject(Project project){
de.hmmh.pmt.dtos.Project dto = new de.hmmh.pmt.dtos.Project();
dto.setId(project.getId());
dto.setName(project.getName());
dto.setGoal(project.getGoal());
dto.setCustomerId(project.getCustomerId());
dto.setAdministratorId(project.getAdministratorId());
dto.setStart(project.getStart());
dto.setPlannedEnd(project.getPlannedEnd());
dto.setRealEnd(project.getRealEnd());
return dto;
}
}

View file

@ -0,0 +1,74 @@
package de.hmmh.pmt.project;
import de.hmmh.pmt.IntegrationTest;
import de.hmmh.pmt.db.Allocation;
import de.hmmh.pmt.db.Project;
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
import java.util.List;
import java.util.Map;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasSize;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class GetAllProjectsByEmployeeTest extends IntegrationTest {
@Test
void successfullyGetAllProjectsByEmployee() throws Exception {
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
.thenReturn(new EmployeeResponseDTO());
Map<String, Project> allProjects = createTestProjectData();
Map<String, Allocation> allAllocations = createTestAllocationData(allProjects);
List<Allocation> allocations = allAllocations
.values()
.stream()
.filter(allocation -> allocation.getEmployeeId().equals(TEST_EMPLOYEE_A_ID))
.toList();
mvc
.perform(get(baseUri + "/employye/" + TEST_EMPLOYEE_A_ID + "/projects"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.projects", hasSize(allocations.size())))
.andExpect(jsonPath("$.projects[*].id").exists())
.andExpect(jsonPath("$.projects[*].name").exists())
.andExpect(jsonPath("$.projects[*].goal").exists())
.andExpect(jsonPath("$.projects[*].customerId").exists())
.andExpect(jsonPath("$.projects[*].administratorId").exists())
.andExpect(jsonPath("$.projects[*].plannedEnd").exists())
.andExpect(jsonPath("$.projects[*].realEnd").exists());
}
@Test
void shouldReturnEmptyListWhenNoAllocationsFound() throws Exception {
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
.thenReturn(new EmployeeResponseDTO());
createTestProjectData();
mvc
.perform(get(baseUri + "/employye/" + TEST_EMPLOYEE_A_ID + "/projects"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.projects", empty()));
}
@Test
void shouldReturnNotFoundWhenEmployeeDoesNotExist() throws Exception {
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
.thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));
mvc
.perform(get(baseUri + "/employye/0/projects"))
.andExpect(status().isNotFound());
}
}