Skip to content

Commit

Permalink
Return business unit id in addNote response, when available.
Browse files Browse the repository at this point in the history
  • Loading branch information
RustyHMCTS committed Mar 18, 2024
1 parent eb49bb9 commit 1b7a1dc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/uk/gov/hmcts/opal/service/opal/NoteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public NoteDto saveNote(NoteDto noteDto) {
String postedBy = Optional.ofNullable(noteDto.getPostedBy())
.map(s -> StringUtils.substring(s, 0, 20)).orElse(null);
noteDto.setPostedBy(postedBy);
Short businessUnitId = noteDto.getBusinessUnitId();

return toNoteDto(noteRepository.save(toNoteEntity(noteDto)));
return toNoteDto(noteRepository.save(toNoteEntity(noteDto)), businessUnitId);
}

@Override
Expand All @@ -52,7 +53,7 @@ public List<NoteDto> searchNotes(NoteSearchDto criteria) {
ffq -> ffq.sortBy(dateSort).page(Pageable.unpaged()));

List<NoteDto> noteDtos = notesPage.getContent().stream()
.map(this::toNoteDto)
.map(entity -> toNoteDto(entity, null))
.collect(Collectors.toList());

return noteDtos;
Expand All @@ -70,12 +71,13 @@ public NoteEntity toNoteEntity(NoteDto noteDto) {
.build();
}

public NoteDto toNoteDto(NoteEntity entity) {
public NoteDto toNoteDto(NoteEntity entity, Short businessUnitId) {
return NoteDto.builder()
.noteId(entity.getNoteId()) // This will be the generated ID
.noteType(entity.getNoteType())
.associatedRecordType(entity.getAssociatedRecordType())
.associatedRecordId(entity.getAssociatedRecordId())
.businessUnitId(businessUnitId)
.noteText(entity.getNoteText())
.postedDate(entity.getPostedDate())
.postedBy(entity.getPostedBy())
Expand Down

0 comments on commit 1b7a1dc

Please sign in to comment.