Skip to content

Commit 1f0e932

Browse files
authored
Merge pull request #497 from bounswe/refactor/492-mentorship-parameter-update
feat(mentorship): add motivation field to mentorship requests and res…
2 parents 2a5ac66 + 610132e commit 1f0e932

File tree

11 files changed

+237
-57
lines changed

11 files changed

+237
-57
lines changed

apps/jobboard-backend/src/main/java/org/bounswe/jobboardbackend/mentorship/controller/MentorshipController.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,26 +139,26 @@ public ResponseEntity<List<MentorshipDetailsDTO>> getMyMentorshipDetails(
139139

140140

141141
@GetMapping("/requests/{requestId}")
142-
public ResponseEntity<MentorshipRequestDTO> getMentorshipRequest(
142+
public ResponseEntity<MentorshipRequestResponseDTO> getMentorshipRequest(
143143
@PathVariable Long requestId,
144144
Authentication auth
145145
) {
146146
UserDetailsImpl userDetails = (UserDetailsImpl) auth.getPrincipal();
147-
MentorshipRequestDTO request = mentorshipService.getMentorshipRequest(requestId, userDetails.getId());
147+
MentorshipRequestResponseDTO request = mentorshipService.getMentorshipRequest(requestId, userDetails.getId());
148148
return new ResponseEntity<>(request, HttpStatus.OK);
149149
}
150150

151151

152152
@PatchMapping("/requests/{requestId}/respond")
153-
public ResponseEntity<MentorshipRequestDTO> respondToMentorshipRequest(
153+
public ResponseEntity<MentorshipRequestResponseDTO> respondToMentorshipRequest(
154154
@PathVariable Long requestId,
155155
@Valid @RequestBody RespondToRequestDTO responseDTO,
156156
Authentication auth
157157
) {
158158
UserDetailsImpl userDetails = (UserDetailsImpl) auth.getPrincipal();
159-
MentorshipRequestDTO updatedRequest = mentorshipService.respondToMentorshipRequest(
159+
MentorshipRequestResponseDTO updatedRequest = mentorshipService.respondToMentorshipRequest(
160160
requestId,
161-
responseDTO.accept(),
161+
responseDTO,
162162
userDetails.getId()
163163
);
164164
return new ResponseEntity<>(updatedRequest, HttpStatus.OK);

apps/jobboard-backend/src/main/java/org/bounswe/jobboardbackend/mentorship/dto/CreateMentorshipRequestDTO.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33

44

5+
import jakarta.validation.constraints.NotBlank;
56
import jakarta.validation.constraints.NotNull;
67

78
public record CreateMentorshipRequestDTO(
8-
@NotNull Long mentorId
9+
@NotNull Long mentorId,
10+
@NotBlank String motivation
911
) {}

apps/jobboard-backend/src/main/java/org/bounswe/jobboardbackend/mentorship/dto/MentorshipRequestDTO.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ public record MentorshipRequestDTO(
77
String requesterId,
88
String mentorId,
99
String status,
10-
LocalDateTime createdAt
10+
LocalDateTime createdAt,
11+
String motivation
1112
) {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.bounswe.jobboardbackend.mentorship.dto;
2+
3+
import java.time.LocalDateTime;
4+
5+
public record MentorshipRequestResponseDTO(
6+
String id,
7+
String requesterId,
8+
String mentorId,
9+
String status,
10+
LocalDateTime createdAt,
11+
String motivation,
12+
String responseMessage
13+
) {}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.bounswe.jobboardbackend.mentorship.dto;
22

3+
import jakarta.validation.constraints.NotBlank;
34
import jakarta.validation.constraints.NotNull;
45

56
public record RespondToRequestDTO(
6-
@NotNull Boolean accept
7-
) {}
7+
@NotNull Boolean accept,
8+
@NotBlank String responseMessage
9+
) {}

apps/jobboard-backend/src/main/java/org/bounswe/jobboardbackend/mentorship/model/MentorshipRequest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
@Entity
1111
@Data
12+
@Table(name = "mentorship_request")
1213
public class MentorshipRequest {
1314
@Id
1415
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -27,12 +28,20 @@ public class MentorshipRequest {
2728

2829
private LocalDateTime createdAt;
2930

30-
public void accept() {
31+
@Column(nullable = false, columnDefinition = "TEXT DEFAULT 'Not provided'")
32+
private String motivation;
33+
34+
@Column
35+
private String responseMessage;
36+
37+
public void accept(String message) {
3138
this.status = RequestStatus.ACCEPTED;
39+
this.responseMessage = message;
3240
}
3341

34-
public void decline() {
42+
public void decline(String message) {
3543
this.status = RequestStatus.DECLINED;
44+
this.responseMessage = message;
3645
}
3746

3847

apps/jobboard-backend/src/main/java/org/bounswe/jobboardbackend/mentorship/service/MentorshipService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public interface MentorshipService {
2222
MentorProfileDTO updateMentorProfile(Long userId, UpdateMentorProfileDTO updateDTO);
2323
void deleteMentorProfile(Long userId);
2424
MentorshipRequestDTO createMentorshipRequest(CreateMentorshipRequestDTO requestDTO, Long jobSeekerId);
25-
MentorshipRequestDTO respondToMentorshipRequest(Long requestId, boolean accept, Long mentorId);
25+
MentorshipRequestResponseDTO respondToMentorshipRequest(Long requestId, RespondToRequestDTO respondToRequestDTO, Long mentorId);
2626
void rateMentor(CreateRatingDTO ratingDTO, Long jobSeekerId);
27-
MentorshipRequestDTO getMentorshipRequest(Long requestId, Long userId);
27+
MentorshipRequestResponseDTO getMentorshipRequest(Long requestId, Long userId);
2828
void completeMentorship(Long resumeReviewId, Authentication auth);
2929
void closeMentorship(Long resumeReviewId, Authentication auth);
3030
List<MentorshipRequestDTO> getMentorshipRequestsOfMentor(Long mentorId, Long userId);

apps/jobboard-backend/src/main/java/org/bounswe/jobboardbackend/mentorship/service/MentorshipServiceImpl.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ public MentorshipRequestDTO createMentorshipRequest(CreateMentorshipRequestDTO r
251251
newRequest.setRequester(jobSeeker);
252252
newRequest.setStatus(RequestStatus.PENDING);
253253
newRequest.setCreatedAt(LocalDateTime.now());
254+
newRequest.setMotivation(requestDTO.motivation());
254255
MentorshipRequest savedRequest = mentorshipRequestRepository.save(newRequest);
255256

256257
// Trigger notification
@@ -261,7 +262,7 @@ public MentorshipRequestDTO createMentorshipRequest(CreateMentorshipRequestDTO r
261262

262263
@Override
263264
@Transactional
264-
public MentorshipRequestDTO respondToMentorshipRequest(Long requestId, boolean accept, Long mentorId) {
265+
public MentorshipRequestResponseDTO respondToMentorshipRequest(Long requestId, RespondToRequestDTO respondToRequestDTO, Long mentorId) {
265266
MentorshipRequest request = mentorshipRequestRepository.findById(requestId)
266267
.orElseThrow(() -> new HandleException(ErrorCode.REQUEST_NOT_FOUND, "Request not found"));
267268

@@ -273,9 +274,11 @@ public MentorshipRequestDTO respondToMentorshipRequest(Long requestId, boolean a
273274
throw new HandleException(ErrorCode.REQUEST_ALREADY_PROCESSED, "This request has already been responded to.");
274275
}
275276

276-
if (accept) {
277277

278-
request.accept();
278+
279+
if (respondToRequestDTO.accept()) {
280+
281+
request.accept(respondToRequestDTO.responseMessage());
279282

280283
ResumeReview review = new ResumeReview();
281284
review.setJobSeeker(request.getRequester());
@@ -295,14 +298,14 @@ public MentorshipRequestDTO respondToMentorshipRequest(Long requestId, boolean a
295298
// notificationService.notifyUser(request.getRequester(), "Your request was accepted!"); // (Future implementation)
296299

297300
} else {
298-
request.decline();
301+
request.decline(respondToRequestDTO.responseMessage());
299302

300303
// Trigger notification
301304
// notificationService.notifyUser(request.getRequester(), "Your request was declined."); // (Future implementation)
302305
}
303306

304307
MentorshipRequest updatedRequest = mentorshipRequestRepository.save(request);
305-
return toMentorshipRequestDTO(updatedRequest);
308+
return toMentorshipRequestResponseDTO(updatedRequest);
306309
}
307310

308311
@Override
@@ -339,7 +342,7 @@ public void rateMentor(CreateRatingDTO ratingDTO, Long jobSeekerId) {
339342

340343
@Override
341344
@Transactional(readOnly = true)
342-
public MentorshipRequestDTO getMentorshipRequest(Long requestId, Long userId) {
345+
public MentorshipRequestResponseDTO getMentorshipRequest(Long requestId, Long userId) {
343346

344347

345348

@@ -352,7 +355,7 @@ public MentorshipRequestDTO getMentorshipRequest(Long requestId, Long userId) {
352355
if (!userId.equals(mentorId) && !userId.equals(requesterId)) {
353356
throw new HandleException(ErrorCode.UNAUTHORIZED_REVIEW_ACCESS, "User is not authorized to see this request");
354357
}
355-
return toMentorshipRequestDTO(request);
358+
return toMentorshipRequestResponseDTO(request);
356359
}
357360

358361
@Override
@@ -500,7 +503,20 @@ private MentorshipRequestDTO toMentorshipRequestDTO(MentorshipRequest request) {
500503
request.getRequester().getId().toString(),
501504
request.getMentor().getId().toString(),
502505
request.getStatus().name(),
503-
request.getCreatedAt()
506+
request.getCreatedAt(),
507+
request.getMotivation()
508+
);
509+
}
510+
511+
private MentorshipRequestResponseDTO toMentorshipRequestResponseDTO(MentorshipRequest request) {
512+
return new MentorshipRequestResponseDTO(
513+
request.getId().toString(),
514+
request.getRequester().getId().toString(),
515+
request.getMentor().getId().toString(),
516+
request.getStatus().name(),
517+
request.getCreatedAt(),
518+
request.getMotivation(),
519+
request.getResponseMessage()
504520
);
505521
}
506522

apps/jobboard-backend/src/test/java/org/bounswe/jobboardbackend/mentorship/controller/MentorshipControllerTest.java

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.springframework.security.core.Authentication;
1212
import org.springframework.web.multipart.MultipartFile;
1313

14+
import java.time.LocalDateTime;
1415
import java.util.List;
1516

1617
import static org.junit.jupiter.api.Assertions.*;
@@ -263,43 +264,57 @@ void getMentorshipRequest_usesAuthenticatedUserId() {
263264
when(auth.getPrincipal()).thenReturn(principal);
264265
when(principal.getId()).thenReturn(99L);
265266

266-
MentorshipRequestDTO dto = mock(MentorshipRequestDTO.class);
267+
MentorshipRequestResponseDTO dto = new MentorshipRequestResponseDTO(
268+
"50",
269+
"10",
270+
"99",
271+
"PENDING",
272+
LocalDateTime.now(),
273+
"Because I want to learn",
274+
""
275+
);
267276

268277
when(mentorshipService.getMentorshipRequest(requestId, 99L))
269278
.thenReturn(dto);
270279

271-
ResponseEntity<MentorshipRequestDTO> response =
280+
ResponseEntity<MentorshipRequestResponseDTO> response =
272281
mentorshipController.getMentorshipRequest(requestId, auth);
273282

274283
assertEquals(HttpStatus.OK, response.getStatusCode());
275284
assertSame(dto, response.getBody());
285+
276286
verify(mentorshipService).getMentorshipRequest(requestId, 99L);
287+
verifyNoMoreInteractions(mentorshipService);
277288
}
278289

290+
279291
@Test
280-
void respondToMentorshipRequest_usesAcceptFlagAndUserId() {
292+
void respondToMentorshipRequest_usesAuthenticatedUserIdAndDelegatesToService() {
281293
Long requestId = 60L;
294+
282295
Authentication auth = mock(Authentication.class);
283296
UserDetailsImpl principal = mock(UserDetailsImpl.class);
284297
when(auth.getPrincipal()).thenReturn(principal);
285298
when(principal.getId()).thenReturn(11L);
286299

287-
RespondToRequestDTO responseDTO = mock(RespondToRequestDTO.class);
288-
when(responseDTO.accept()).thenReturn(true);
289-
290-
MentorshipRequestDTO returned = mock(MentorshipRequestDTO.class);
300+
RespondToRequestDTO dto =
301+
new RespondToRequestDTO(true, "Happy to mentor you.");
291302

292-
when(mentorshipService.respondToMentorshipRequest(requestId, true, 11L))
293-
.thenReturn(returned);
303+
MentorshipRequestResponseDTO serviceResult = mock(MentorshipRequestResponseDTO.class);
304+
when(mentorshipService.respondToMentorshipRequest(requestId, dto, 11L))
305+
.thenReturn(serviceResult);
294306

295-
ResponseEntity<MentorshipRequestDTO> response =
296-
mentorshipController.respondToMentorshipRequest(requestId, responseDTO, auth);
307+
ResponseEntity<MentorshipRequestResponseDTO> response =
308+
mentorshipController.respondToMentorshipRequest(requestId, dto, auth);
297309

298310
assertEquals(HttpStatus.OK, response.getStatusCode());
299-
assertSame(returned, response.getBody());
300-
verify(mentorshipService).respondToMentorshipRequest(requestId, true, 11L);
311+
assertSame(serviceResult, response.getBody());
312+
313+
verify(mentorshipService).respondToMentorshipRequest(requestId, dto, 11L);
314+
verifyNoMoreInteractions(mentorshipService);
301315
}
302316

317+
303318
// ----------------------------------------------------------------------
304319
// Rating endpoint
305320
// ----------------------------------------------------------------------

apps/jobboard-backend/src/test/java/org/bounswe/jobboardbackend/mentorship/repository/MentorshipRepositoriesTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ private MentorshipRequest buildAndPersistMentorshipRequest(MentorProfile mentor,
6969
request.setRequester(mentee);
7070
request.setStatus(RequestStatus.PENDING);
7171
request.setCreatedAt(LocalDateTime.now());
72+
request.setMotivation("Test motivation");
7273

7374
entityManager.persist(mentee);
7475
entityManager.persist(request);
7576
return request;
7677
}
7778

79+
7880
private ResumeReview buildAndPersistResumeReview(MentorshipRequest request,
7981
MentorProfile mentor,
8082
User mentee) {

0 commit comments

Comments
 (0)