-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refactor #89 UserUseCase 분리 및 리프레시 토큰 수정 #89
Open
hyxklee
wants to merge
3
commits into
develop
Choose a base branch
from
refactor/#74/UserUsecase-분리
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "refactor/#74/UserUsecase-\uBD84\uB9AC"
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 29 additions & 1 deletion
30
src/main/java/leets/weeth/domain/user/application/usecase/UserManageUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,38 @@ | ||
package leets.weeth.domain.user.application.usecase; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import leets.weeth.domain.user.application.dto.request.UserRequestDto; | ||
import leets.weeth.domain.user.application.dto.response.UserResponseDto; | ||
import leets.weeth.global.auth.jwt.application.dto.JwtDto; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static leets.weeth.domain.user.application.dto.request.UserRequestDto.refreshRequest; | ||
|
||
public interface UserManageUseCase { | ||
JwtDto refresh(HttpServletRequest request); | ||
|
||
UserResponseDto.Response find(Long userId); | ||
|
||
Map<Integer, List<UserResponseDto.Response>> findAll(); | ||
|
||
Map<Integer, List<UserResponseDto.SummaryResponse>> findAllUser(); | ||
|
||
List<UserResponseDto.AdminResponse> findAllByAdmin(); | ||
|
||
UserResponseDto.UserResponse findUserDetails(Long userId); | ||
|
||
void update(UserRequestDto.Update dto, Long userId); | ||
|
||
void accept(Long userId); | ||
|
||
void update(Long userId, String role); | ||
|
||
void leave(Long userId); | ||
|
||
void ban(Long userId); | ||
|
||
void applyOB(Long userId, Integer cardinal); | ||
|
||
void reset(Long userId); | ||
} |
157 changes: 147 additions & 10 deletions
157
src/main/java/leets/weeth/domain/user/application/usecase/UserManageUseCaseImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,166 @@ | ||
package leets.weeth.domain.user.application.usecase; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.transaction.Transactional; | ||
import leets.weeth.domain.attendance.domain.service.AttendanceSaveService; | ||
import leets.weeth.domain.schedule.domain.entity.Meeting; | ||
import leets.weeth.domain.schedule.domain.service.MeetingGetService; | ||
import leets.weeth.domain.user.application.exception.StudentIdExistsException; | ||
import leets.weeth.domain.user.application.exception.TelExistsException; | ||
import leets.weeth.domain.user.application.mapper.UserMapper; | ||
import leets.weeth.domain.user.domain.entity.User; | ||
import leets.weeth.domain.user.domain.service.UserDeleteService; | ||
import leets.weeth.domain.user.domain.service.UserGetService; | ||
import leets.weeth.domain.user.domain.service.UserSaveService; | ||
import leets.weeth.domain.user.domain.service.UserUpdateService; | ||
import leets.weeth.global.auth.jwt.application.dto.JwtDto; | ||
import leets.weeth.global.auth.jwt.application.usecase.JwtManageUseCase; | ||
import leets.weeth.global.auth.jwt.service.JwtRedisService; | ||
import leets.weeth.global.auth.kakao.KakaoAuthService; | ||
import leets.weeth.global.auth.kakao.dto.KakaoTokenResponse; | ||
import leets.weeth.global.auth.kakao.dto.KakaoUserInfoResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import static leets.weeth.domain.user.application.dto.request.UserRequestDto.refreshRequest; | ||
import java.util.AbstractMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static leets.weeth.domain.user.application.dto.request.UserRequestDto.*; | ||
import static leets.weeth.domain.user.application.dto.response.UserResponseDto.*; | ||
import static leets.weeth.domain.user.domain.entity.enums.LoginStatus.LOGIN; | ||
import static leets.weeth.domain.user.domain.entity.enums.LoginStatus.REGISTER; | ||
import static leets.weeth.domain.user.domain.entity.enums.Status.ACTIVE; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class UserManageUseCaseImpl implements UserManageUseCase { | ||
private final JwtManageUseCase jwtManageUseCase; | ||
|
||
private final UserGetService userGetService; | ||
private final UserUpdateService userUpdateService; | ||
private final UserDeleteService userDeleteService; | ||
|
||
private final AttendanceSaveService attendanceSaveService; | ||
private final MeetingGetService meetingGetService; | ||
private final JwtRedisService jwtRedisService; | ||
|
||
private final UserMapper mapper; | ||
private final PasswordEncoder passwordEncoder; | ||
|
||
@Override | ||
public Map<Integer, List<Response>> findAll() { | ||
return userGetService.findAllByStatus(ACTIVE).stream() | ||
.flatMap(user -> Stream.concat( | ||
user.getCardinals().stream() | ||
.map(cardinal -> new AbstractMap.SimpleEntry<>(cardinal, mapper.to(user))), // 기수별 Map | ||
Stream.of(new AbstractMap.SimpleEntry<>(0, mapper.to(user))) // 모든 기수는 cardinal 0에 저장 | ||
)) | ||
.collect(Collectors.groupingBy(Map.Entry::getKey, // key = 기수, value = 유저 정보 | ||
Collectors.mapping(Map.Entry::getValue, Collectors.toList()))); | ||
} | ||
|
||
@Override | ||
public Map<Integer, List<SummaryResponse>> findAllUser() { | ||
return userGetService.findAllByStatus(ACTIVE).stream() | ||
.map(user -> new AbstractMap.SimpleEntry<>(user.getCardinals(), mapper.toSummaryResponse(user))) | ||
.flatMap(entry -> Stream.concat( | ||
entry.getKey().stream().map(cardinal -> new AbstractMap.SimpleEntry<>(cardinal, entry.getValue())), // 기수별 Map | ||
Stream.of(new AbstractMap.SimpleEntry<>(0, entry.getValue())) // 모든 기수는 cardinal 0에 저장 | ||
)) | ||
.collect(Collectors.groupingBy( | ||
Map.Entry::getKey, // key = 기수 | ||
Collectors.mapping(Map.Entry::getValue, Collectors.toList()) // value = 요약 정보 리스트 | ||
)); | ||
} | ||
|
||
@Override | ||
public List<AdminResponse> findAllByAdmin() { | ||
return userGetService.findAll().stream() | ||
.map(mapper::toAdminResponse) | ||
.toList(); | ||
} | ||
|
||
@Override | ||
public UserResponse findUserDetails(Long userId) { | ||
User user = userGetService.find(userId); | ||
return mapper.toUserResponse(user); | ||
} | ||
|
||
@Override | ||
public Response find(Long userId) { | ||
return mapper.to(userGetService.find(userId)); | ||
} | ||
|
||
@Override | ||
public void update(Update dto, Long userId) { | ||
validate(dto, userId); | ||
User user = userGetService.find(userId); | ||
userUpdateService.update(user, dto, passwordEncoder); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void accept(Long userId) { | ||
User user = userGetService.find(userId); | ||
|
||
if (user.isInactive()) { | ||
userUpdateService.accept(user); | ||
List<Meeting> meetings = meetingGetService.find(user.getCardinals().get(0)); | ||
attendanceSaveService.save(user, meetings); | ||
} | ||
} | ||
|
||
@Override | ||
public void update(Long userId, String role) { | ||
User user = userGetService.find(userId); | ||
userUpdateService.update(user, role); | ||
jwtRedisService.updateRole(user.getId(), role); | ||
} | ||
|
||
@Override | ||
public void leave(Long userId) { | ||
User user = userGetService.find(userId); | ||
// 탈퇴하는 경우 리프레시 토큰 삭제 | ||
jwtRedisService.delete(user.getId()); | ||
userDeleteService.leave(user); | ||
} | ||
|
||
@Override | ||
public void ban(Long userId) { | ||
User user = userGetService.find(userId); | ||
jwtRedisService.delete(user.getId()); | ||
userDeleteService.ban(user); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public JwtDto refresh(HttpServletRequest request) { | ||
public void applyOB(Long userId, Integer cardinal) { | ||
User user = userGetService.find(userId); | ||
|
||
JwtDto token = jwtManageUseCase.reIssueToken(request); | ||
if (user.notContains(cardinal)) { | ||
if (user.isCurrent(cardinal)) { | ||
user.initAttendance(); | ||
List<Meeting> meetings = meetingGetService.find(cardinal); | ||
attendanceSaveService.save(user, meetings); | ||
} | ||
|
||
userUpdateService.applyOB(user, cardinal); | ||
} | ||
} | ||
|
||
@Override | ||
public void reset(Long userId) { | ||
User user = userGetService.find(userId); | ||
userUpdateService.reset(user, passwordEncoder); | ||
} | ||
|
||
log.info("RefreshToken 발급 완료: {}", token); | ||
return new JwtDto(token.accessToken(), token.refreshToken()); | ||
private void validate(Update dto, Long userId) { | ||
if (userGetService.validateStudentId(dto.studentId(), userId)) | ||
throw new StudentIdExistsException(); | ||
if (userGetService.validateTel(dto.tel(), userId)) | ||
throw new TelExistsException(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생많으셨습니다 어드민 페이지에서 관리할 수 있는 정보(회원조회, 가입 승인, 유저 추방, 관리자 승격 + 강등, 다음 기수도 진행, 비번 초기화)들은 PR에 적어주셨듯이 어드민 기준이기 때문에 userManageUseCase라는 이름과 별도로 구성한 목적에 맞다고 판단이 드는데, 동아리 멤버 전체 조회라던지 내 정보와 관련된 부분도 userManageUseCase로 들어가는 것은 추가적인 고민이 필요해보입니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 조회같은 부분은 manage 말고 UserUseCase에 들어가야 한다고 생각합니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그러면 admin 관련한 메서드만 Manage에 넣도록 하겟습니당