Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ public Mentee create(final Mentee mentee) {
memberId = memberMapper.addMember(mentee);
}

if (findById(memberId).isEmpty()) {
final var existing = findById(memberId);
if (existing.isEmpty()) {
insertMenteeDetails(mentee, memberId);
} else {
updateMenteeDetails(mentee, memberId);
final var profileStatus =
mentee.getProfileStatus() != null
? mentee.getProfileStatus()
: existing.get().getProfileStatus();
updateMenteeDetails(mentee, memberId, profileStatus);
}

jdbc.update(SQL_DELETE_TECH_AREAS, memberId);
Expand All @@ -108,7 +113,11 @@ public Mentee update(final Long id, final Mentee mentee) {
validate(mentee);
memberMapper.updateMember(mentee, id);

updateMenteeDetails(mentee, id);
final var profileStatus =
mentee.getProfileStatus() != null
? mentee.getProfileStatus()
: findById(id).map(Mentee::getProfileStatus).orElse(ProfileStatus.PENDING);
updateMenteeDetails(mentee, id, profileStatus);

jdbc.update(SQL_DELETE_TECH_AREAS, id);
jdbc.update(SQL_DELETE_LANGUAGES, id);
Expand Down Expand Up @@ -186,8 +195,8 @@ public Mentee updateProfileStatus(final Long menteeId, final ProfileStatus statu
() -> new MenteeNotSavedException("Mentee not found after status update: " + menteeId));
}

private void updateMenteeDetails(final Mentee mentee, final Long memberId) {
final var profileStatus = mentee.getProfileStatus();
private void updateMenteeDetails(
final Mentee mentee, final Long memberId, final ProfileStatus profileStatus) {
final var skills = mentee.getSkills();
jdbc.update(
SQL_UPDATE_MENTEE,
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/wcc/platform/service/MenteeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ private Mentee createOrUpdateMentee(final Mentee mentee) {
}

private Mentee handleMenteeWithId(final Mentee mentee) {
if (menteeRepository.findById(mentee.getId()).isPresent()) {
final var existingMentee = menteeRepository.findById(mentee.getId());
if (existingMentee.isPresent()) {
mentee.setMemberTypes(mergeMemberTypes(existingMentee.get().getMemberTypes()));
return menteeRepository.update(mentee.getId(), mentee);
}

Expand Down
Loading