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

[BE] 비밀번호 마이그레이션 추가 #369

Merged
merged 2 commits into from
Sep 26, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ public ResponseEntity<Void> logout(@PathVariable String uuid) {
public MomoApiResponse<List<String>> findAttendeesOfMeeting(@PathVariable String uuid) {
return new MomoApiResponse<>(attendeeService.findAll(uuid));
}

/**
* TEMP: 비밀번호 마이그레이션 이후 삭제될 메서드입니다.
*/
@PostMapping("/api/v1/attendee/update-password")
public MomoApiResponse<Integer> updatePassword() {
return new MomoApiResponse<>(attendeeService.updateAllPassword());
}
}
4 changes: 4 additions & 0 deletions backend/src/main/java/kr/momo/domain/attendee/Attendee.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public boolean isNotHost() {
return !isHost();
}

public void updatePassword(String password) {
this.password = new AttendeePassword(password);
}

public void verifyPassword(AttendeeRawPassword rawPassword, PasswordEncoder passwordEncoder) {
password.verifyMatch(rawPassword, passwordEncoder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,23 @@ public List<String> findAll(String uuid) {
.map(Attendee::name)
.toList();
}

/**
* TEMP: 비밀번호 마이그레이션 이후 삭제될 메서드입니다.
*/
public Integer updateAllPassword() {
List<Attendee> attendees = attendeeRepository.findAll();
List<Attendee> rawAttendees = attendees.stream()
.filter(attendee -> attendee.getPassword().getPassword().length() < 15)
.toList();
rawAttendees.forEach(
attendee -> {
String rawPassword = attendee.getPassword().getPassword();
String encodedPassword = passwordEncoder.encode(rawPassword);
attendee.updatePassword(encodedPassword);
}
);
attendeeRepository.saveAll(rawAttendees);
return rawAttendees.size();
}
}