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

Feat #75 멤버 리스트 반환 수정 및 멤버 상세 조회 추가 #75

Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1bc59b2
refactor: AdminSummaryResponse 생성해서 dto 축소
huncozyboy Nov 20, 2024
a52ae3c
refactor: 축소된 내용 mapper 구현
huncozyboy Nov 20, 2024
039144a
refactor: AdminSummaryResponse에 findAllByAdmin 적용하도록 UserUseCase 변경
huncozyboy Nov 20, 2024
7c39040
refactor: UserUseCaseImplcaseimpl에서 toSummary로 매핑
huncozyboy Nov 20, 2024
7aaabc8
refactor: 컨트롤러에서 적용
huncozyboy Nov 20, 2024
70dd74b
refactor: 불필요한 import문 삭제
huncozyboy Nov 20, 2024
a185775
refactor: 불필요한 import문 삭제
huncozyboy Nov 20, 2024
54aea74
feat: 특정 회원 상세정보 조회 성공 메세지 추가
huncozyboy Nov 20, 2024
e1c831e
feat: toAdminResponse 매퍼 구현
huncozyboy Nov 20, 2024
c84d593
feat: findUserDetails UseCase 구현
huncozyboy Nov 20, 2024
dd90a36
feat: findUserDetails 메서드 구현
huncozyboy Nov 20, 2024
7d2eee8
feat: 어드민용 특정 멤버 상세 조회 컨트롤러 추가
huncozyboy Nov 20, 2024
95e0f35
refactor: 어드민이 아닌 사용자 관련 컨트롤러를 수정하기 위해서 변경 내용 롤백
huncozyboy Nov 20, 2024
1b453a2
refactor: 상세조회, 멤버 기수별로 리스트 조회 UserMapper 구현
huncozyboy Nov 20, 2024
0e250b7
feat: SummaryResponse dto 추가
huncozyboy Nov 20, 2024
8fe021b
feat: findAllUser, findUserDetails 메서드 추가
huncozyboy Nov 20, 2024
d924c65
feat: findAllUser, findUserDetails 메서드 UserUseCaseImpl에서 구현
huncozyboy Nov 20, 2024
1d7ae00
refactor: 동아리 멤버 전체조회 및 특정 멤버 상세조회 컨트롤러 구현
huncozyboy Nov 20, 2024
ea78f3f
refactor: 유저가 존재하는지 중복된 검증 삭제
huncozyboy Nov 22, 2024
0022c77
refactor: 기존 컨트롤러 형식과 통일
huncozyboy Nov 22, 2024
80719a5
feat: UserResponse dto 추가
huncozyboy Nov 22, 2024
4b07c39
refactor: findUserDetails이 UserResponse 사용하도록 수정
huncozyboy Nov 22, 2024
07017c8
refactor: UserResponse 매퍼 사용하도록 추가
huncozyboy Nov 22, 2024
4325ae8
refactor: UserUseCaseImpl에서 findUserDetails 올바르게 매핑되도록 수정
huncozyboy Nov 22, 2024
7f755dd
refactor: 특정 멤버 상세조회 반환 dto 컨트롤러에서 수정
huncozyboy Nov 22, 2024
96292f8
refactor: 기수 리스트와 요약 정보 두개의 스트림 사용해서 중복 호출 제거
huncozyboy Nov 23, 2024
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 @@ -30,7 +30,12 @@ public record Response(
Role role
) {
}

public record SummaryResponse(
Integer id,
String name,
List<Integer> cardinals,
String department
) {}
public record AdminResponse(
Integer id,
String name,
Expand All @@ -50,5 +55,4 @@ public record AdminResponse(
LocalDateTime modifiedAt
) {
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package leets.weeth.domain.user.application.mapper;

import leets.weeth.domain.user.application.dto.response.UserResponseDto.SummaryResponse;
import leets.weeth.domain.user.domain.entity.User;
import leets.weeth.domain.user.domain.entity.enums.Department;
import org.mapstruct.*;
Expand All @@ -26,7 +27,15 @@ public interface UserMapper {
// 수정: 출석률, 출석 횟수, 결석 횟수 매핑 추후 추가 예정
})
AdminResponse toAdminResponse(User user);
@Mappings({
@Mapping(target = "department", expression = "java( toString(user.getDepartment()) )")
})
SummaryResponse toSummaryResponse(User user);

@Mappings({
// 상세 데이터 매핑
})
Response toResponse(User user);
default String toString(Department department) {
return department.getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ public interface UserUseCase {

Map<Integer, List<Response>> findAll();

Map<Integer, List<SummaryResponse>> findAllUser();

List<AdminResponse> findAllByAdmin();

Response findUserDetails(Long userId);

void update(Update dto, Long userId);

void accept(Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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.exception.UserNotFoundException;
import leets.weeth.domain.user.application.mapper.UserMapper;
import leets.weeth.domain.user.domain.entity.User;
import leets.weeth.domain.user.domain.service.UserDeleteService;
Expand Down Expand Up @@ -106,14 +107,33 @@ public Map<Integer, List<Response>> findAll() {
.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()
.flatMap(user -> Stream.concat(
user.getCardinals().stream()
.map(cardinal -> new AbstractMap.SimpleEntry<>(cardinal, mapper.toSummaryResponse(user))), // 기수별 Map
Stream.of(new AbstractMap.SimpleEntry<>(0, mapper.toSummaryResponse(user))) // 모든 기수는 cardinal 0에 저장
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapper.toSummaryResponse(user)을 반복적으로 사용하게 되는데 이부분을 한번만 호출하는건 어떨까요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 로직은 기존에 구현되어있던 로직과 동일한 형태로 작성했는데, 수정하지 않은 이유는 mapper.toSummaryResponse가 동일한 user 객체를 받아온다는 가정이므로 여러번 호출하더라도 성능저하가 되지 않는다고 판단했었고, 각 스트림 역할을 명확하게 읽을 수 있어 가독성이 더 좋을거같다는 생각을 했는데 어떻게 생각하시나요 ??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

구글링 해보니 동일한 객체를 반환하는 메서드를 반복적으로 호출하는 것만으로도 오버헤드가 발생되네요
해당 내용도 수정하겠습니다

))
.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 Response findUserDetails(Long userId) {
User user = userGetService.find(userId);
if (user == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userGetService.find() 메서드 내부에서 null 체킹을 해서 예외를 던져주고 있기 때문에 useCase 단에서 따로 체크는 하지 않아도 될 것 같아요!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 해당 로직 확인하여 수정했습니다

throw new UserNotFoundException();
}
return mapper.toResponse(user);
}
@Override
public Response find(Long userId) {
return mapper.to(userGetService.find(userId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public enum ResponseMessage {
// UserAdminController 관련
USER_FIND_ALL_SUCCESS("관리자가 모든 회원 정보를 성공적으로 조회했습니다."),
USER_DETAILS_SUCCESS("특정 회원의 상세 정보를 성공적으로 조회했습니다."),
USER_ACCEPT_SUCCESS("회원 가입 승인이 성공적으로 처리되었습니다."),
USER_BAN_SUCCESS("회원이 성공적으로 차단되었습니다."),
USER_ROLE_UPDATE_SUCCESS("회원의 역할이 성공적으로 수정되었습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import leets.weeth.domain.user.application.dto.response.UserResponseDto.SummaryResponse;
import leets.weeth.domain.user.application.usecase.UserManageUseCase;
import leets.weeth.domain.user.application.usecase.UserUseCase;
import leets.weeth.domain.user.domain.service.UserGetService;
Expand Down Expand Up @@ -58,10 +59,17 @@ public CommonResponse<Boolean> checkEmail(@RequestParam String email) {

@GetMapping("/all")
@Operation(summary="동아리 멤버 전체 조회(전체/기수별)")
public CommonResponse<Map<Integer, List<Response>>> findAll() {
return CommonResponse.createSuccess(USER_FIND_ALL_SUCCESS.getMessage(), userUseCase.findAll());
public CommonResponse<Map<Integer, List<SummaryResponse>>> findAllUser() {
return CommonResponse.createSuccess(USER_FIND_ALL_SUCCESS.getMessage(), userUseCase.findAllUser());
}
@GetMapping("/details")
@Operation(summary = "특정 멤버 상세 조회")
public CommonResponse<Response> findUser(@RequestParam Long userId) {
return CommonResponse.createSuccess(
USER_DETAILS_SUCCESS.getMessage(),
userUseCase.findUserDetails(userId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

의도된 줄바꿈일까요? 길이가 길지 않아서 기존 코드 형식과 통일해도 괜찮을 것 같아요!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

미처 확인하지 못했던 부분입니다
가독성 위해서 다른 컨트롤러 형식들과 통일하겠습니다

);
}

@GetMapping
@Operation(summary="내 정보 조회")
public CommonResponse<Response> find(@Parameter(hidden = true) @CurrentUser Long userId) {
Expand Down
Loading