Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add getPlacementSummaryById #974

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tcs-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.transformuk.hee.tis</groupId>
<artifactId>tcs-client</artifactId>
<version>6.2.0</version>
<version>6.2.1</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class TcsServiceImpl extends AbstractClientService {
private static final String API_TRAINER_APPROVAL = "/api/trainer-approvals";
private static final String API_PERSON_TRAINER_APPROVALS = "/api/people/%d/trainer-approvals";
private static final String API_PLACEMENT = "/api/placement/";
private static final String API_PLACEMENT_SUMMARY = "/api/placements/%d/summary";
private static final String API_PLACEMENTS = "/api/placements/";
private static final String API_POSTS = "/api/posts/";
private static final String API_PLACEMENT_COMMENT = "/api/placementComment/";
Expand Down Expand Up @@ -377,6 +378,13 @@ public PlacementDetailsDTO getPlacementById(Long id) {
}).getBody();
}

public PlacementSummaryDTO getPlacementSummaryById(Long id) {
String uri = String.format(API_PLACEMENT_SUMMARY, id);
return tcsRestTemplate.exchange(serviceUrl + uri,
HttpMethod.GET, null, new ParameterizedTypeReference<PlacementSummaryDTO>() {
}).getBody();
}

public PostDTO getPostById(Long id) {
return tcsRestTemplate.exchange(serviceUrl + API_POSTS + id,
HttpMethod.GET, null, new ParameterizedTypeReference<PostDTO>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,23 @@ public void getPlacementForTraineeShouldReturnResponse() {
assertThat("Unexpected placement DTO.", returnDtos.get(0), is(dto));
}

@Test
public void getPlacementSummaryByIdShouldReturnResponse() {
PlacementSummaryDTO dto = new PlacementSummaryDTO();
dto.setPlacementId(1L);
dto.setTraineeId(2L);

ResponseEntity<PlacementSummaryDTO> response = ResponseEntity.ok(dto);
when(restTemplateMock.exchange(anyString(), eq(HttpMethod.GET), eq(null), any(
ParameterizedTypeReference.class))).thenReturn(response);

// When.
PlacementSummaryDTO returnDto = testObj.getPlacementSummaryById(2L);
// Then.
assertThat("Unexpected placement ID", returnDto.getPlacementId(), is(1L));
assertThat("Unexpected placement trainee ID", returnDto.getTraineeId(), is(2L));
}

@Test
public void getProgrammeMembershipDetailsByIds() {
ProgrammeMembershipCurriculaDTO dto = new ProgrammeMembershipCurriculaDTO();
Expand Down
2 changes: 1 addition & 1 deletion tcs-persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<description>A module containing the model and persistence layer for TCS</description>
<groupId>uk.nhs.tis</groupId>
<artifactId>tcs-persistence</artifactId>
<version>2.28.0</version>
<version>2.29.0</version>
<dependencies>
<dependency>
<groupId>com.transformuk.hee.tis</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class SqlQuerySupplier {
public static final String SEARCH_POST_VIEW = "queries/searchPostView.sql";
public static final String TRAINEE_PLACEMENT_SUMMARY = "queries/placementSummaryForTrainee.sql";
public static final String PLACEMENT_DETAILS = "queries/placementDetails.sql";
public static final String PLACEMENT_SUMMARY = "queries/placementSummary.sql";
public static final String PLACEMENT_SUPERVISOR = "queries/placementSupervisor.sql";
public static final String POST_PLACEMENT_SUMMARY = "queries/placementSummaryForPost.sql";
public static final String PERSON_PLACEMENT_EMPLOYINGBODY = "queries/personPlacementEmployingBody.sql";
Expand Down
16 changes: 16 additions & 0 deletions tcs-persistence/src/main/resources/queries/placementSummary.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SELECT p.*, s.name primarySpecialtyName, c.forenames, c.legalforenames, c.surname, c.legalsurname, c.id traineeId, c.email, p.id placementId, ps.placementSpecialtyType, po.nationalPostNumber
FROM Placement p
LEFT JOIN PlacementSpecialty ps
ON p.id = ps.placementId
LEFT JOIN Specialty s
ON s.id = ps.specialtyId
LEFT JOIN ContactDetails c
ON c.id = p.traineeId
LEFT JOIN Post po
ON po.id = p.postId
WHERE
-- TODO: uncomment this when changes to the FE adds a specialty on creation
-- "ps.placementSpecialtyType = :specialtyType
-- AND
p.id = :id
ORDER BY dateTo DESC
4 changes: 2 additions & 2 deletions tcs-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.transformuk.hee.tis</groupId>
<artifactId>tcs-service</artifactId>
<version>6.32.1</version>
<version>6.33.0</version>

<dependencies>
<dependency>
Expand Down Expand Up @@ -81,7 +81,7 @@
<dependency>
<groupId>uk.nhs.tis</groupId>
<artifactId>tcs-persistence</artifactId>
<version>2.28.0</version>
<version>2.29.0</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.transformuk.hee.tis.tcs.api.dto.PlacementDTO;
import com.transformuk.hee.tis.tcs.api.dto.PlacementDetailsDTO;
import com.transformuk.hee.tis.tcs.api.dto.PlacementEsrEventDto;
import com.transformuk.hee.tis.tcs.api.dto.PlacementSummaryDTO;
import com.transformuk.hee.tis.tcs.api.dto.validation.Create;
import com.transformuk.hee.tis.tcs.api.dto.validation.Update;
import com.transformuk.hee.tis.tcs.service.api.decorator.PlacementDetailsDecorator;
import com.transformuk.hee.tis.tcs.service.api.decorator.PlacementSummaryDecorator;
import com.transformuk.hee.tis.tcs.service.api.util.HeaderUtil;
import com.transformuk.hee.tis.tcs.service.api.util.PaginationUtil;
import com.transformuk.hee.tis.tcs.service.api.validation.PlacementValidator;
Expand All @@ -22,6 +24,7 @@
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.time.LocalDate;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -66,17 +69,20 @@ public class PlacementResource {
private final PlacementService placementService;
private final PlacementValidator placementValidator;
private final PlacementDetailsDecorator placementDetailsDecorator;
private final PlacementSummaryDecorator placementSummaryDecorator;
private final PlacementPlannerServiceImp placementPlannerService;
private final PermissionService permissionService;

public PlacementResource(final PlacementService placementService,
final PlacementValidator placementValidator,
final PlacementDetailsDecorator placementDetailsDecorator,
final PlacementSummaryDecorator placementSummaryDecorator,
PlacementPlannerServiceImp placementPlannerService,
PermissionService permissionService) {
this.placementService = placementService;
this.placementValidator = placementValidator;
this.placementDetailsDecorator = placementDetailsDecorator;
this.placementSummaryDecorator = placementSummaryDecorator;
this.placementPlannerService = placementPlannerService;
this.permissionService = permissionService;
}
Expand Down Expand Up @@ -170,6 +176,21 @@ public ResponseEntity<PlacementDetailsDTO> getPlacement(@PathVariable final Long
Optional.ofNullable(placementDetailsDecorator.decorate(placementDetailsDTO)));
}

/**
* GET /placements/{id}/summary : get the summary of the "id" placement.
*
* @param id the id of the placementSummaryDTO to retrieve
* @return the ResponseEntity with status 200 (OK) and the placement in body
*/
@GetMapping("/placements/{id}/summary")
@PreAuthorize("hasAuthority('tcs:view:entities')")
public ResponseEntity<PlacementSummaryDTO> getPlacementSummary(@PathVariable final Long id) {
log.debug("REST request to get Placement Summary : {}", id);
final List<PlacementSummaryDTO> placementSummaryDtoList = placementService.getSummary(id);
return ResponseUtil.wrapOrNotFound(
Optional.ofNullable(placementSummaryDecorator.decorate(placementSummaryDtoList).get(0)));
}

/**
* DELETE /placements/:id : delete the "id" placement.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ public interface PlacementService {
*/
PlacementDetailsDTO getDetails(Long id);

/**
* Get a list containing at most a single placement summary given the placement ID
*
* @param id the placement ID
* @return the placement summary if found
*/
List<PlacementSummaryDTO> getSummary(Long id);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a "list" 😬


/**
* Updates an existing placement
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,24 @@ public PlacementDetailsDTO getDetails(final Long id) {
return placementDetailsDTO;
}

@Transactional(readOnly = true)
@Override
public List<PlacementSummaryDTO> getSummary(final Long placementId) {
final String query = sqlQuerySupplier.getQuery(SqlQuerySupplier.PLACEMENT_SUMMARY);
List<PlacementSummaryDTO> resultList;

Map<String, Object> params = Maps.newHashMap();
params.put("id", placementId);
PlacementRowMapper placementRowMapper = new PlacementRowMapper();
resultList = namedParameterJdbcTemplate.query(query, params, placementRowMapper);
resultList
.forEach(p -> p.setPlacementStatus(getPlacementStatus(p.getDateFrom(), p.getDateTo())));
resultList = filterPlacements(resultList);

populateEsrEventsForPlacementSummary(resultList);
return resultList;
}

/**
* Delete the placement by id.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.transformuk.hee.tis.tcs.service.api.decorator.AsyncReferenceService;
import com.transformuk.hee.tis.tcs.service.api.decorator.PersonBasicDetailsRepositoryAccessor;
import com.transformuk.hee.tis.tcs.service.api.decorator.PlacementDetailsDecorator;
import com.transformuk.hee.tis.tcs.service.api.decorator.PlacementSummaryDecorator;
import com.transformuk.hee.tis.tcs.service.api.validation.PlacementValidator;
import com.transformuk.hee.tis.tcs.service.exception.ExceptionTranslator;
import com.transformuk.hee.tis.tcs.service.model.ContactDetails;
Expand Down Expand Up @@ -202,6 +203,8 @@ public class PlacementResourceIntTest {

private PlacementDetailsDecorator placementDetailsDecorator;

private PlacementSummaryDecorator placementSummaryDecorator;

private MockMvc restPlacementMockMvc;

private PlacementDetails placementDetails;
Expand Down Expand Up @@ -292,9 +295,10 @@ public void setup() {
personRepository, placementRepository, specialtyRepository);
placementDetailsDecorator = new PlacementDetailsDecorator(asyncReferenceService,
asyncPersonBasicDetailsRepository, postRepository);
placementSummaryDecorator = new PlacementSummaryDecorator(asyncReferenceService);
final PlacementResource placementResource = new PlacementResource(placementService,
placementValidator, placementDetailsDecorator, placementPlannerServiceImp,
permissionService);
placementValidator, placementDetailsDecorator, placementSummaryDecorator,
placementPlannerServiceImp, permissionService);
this.restPlacementMockMvc = MockMvcBuilders.standaloneSetup(placementResource)
.setCustomArgumentResolvers(pageableArgumentResolver)
.setControllerAdvice(exceptionTranslator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.transformuk.hee.tis.tcs.api.dto.PlacementEsrEventDto;
import com.transformuk.hee.tis.tcs.api.enumeration.LifecycleState;
import com.transformuk.hee.tis.tcs.service.api.decorator.PlacementDetailsDecorator;
import com.transformuk.hee.tis.tcs.service.api.decorator.PlacementSummaryDecorator;
import com.transformuk.hee.tis.tcs.service.api.validation.PlacementValidator;
import com.transformuk.hee.tis.tcs.service.dto.placementmanager.PersonDTO;
import com.transformuk.hee.tis.tcs.service.dto.placementmanager.PlacementDTO;
Expand Down Expand Up @@ -89,6 +90,8 @@ public class PlacementResourceTest {
@MockBean
private PlacementDetailsDecorator placementDetailsDecoratorMock;
@MockBean
private PlacementSummaryDecorator placementSummaryDecoratorMock;
@MockBean
private PlacementPlannerServiceImp placementPlannerServiceMock;
@MockBean
private PermissionService permissionServiceMock;
Expand All @@ -106,7 +109,8 @@ public class PlacementResourceTest {
@Before
public void setup() {
placementResource = new PlacementResource(placementServiceMock, placementValidatorMock,
placementDetailsDecoratorMock, placementPlannerServiceMock, permissionServiceMock);
placementDetailsDecoratorMock, placementSummaryDecoratorMock,
placementPlannerServiceMock, permissionServiceMock);
mockMvc = MockMvcBuilders.standaloneSetup(placementResource).build();

setupData();
Expand Down