Skip to content

Commit

Permalink
Merge pull request #75 from Leets-Official/feat/#72/멤버-리스트-반환-수정-및-멤버…
Browse files Browse the repository at this point in the history
…-상세-조회-추가

Feat #75 멤버 리스트 반환 수정 및 멤버 상세 조회 추가
  • Loading branch information
huncozyboy authored Nov 23, 2024
2 parents 90bc02e + 96292f8 commit 327a913
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 7 deletions.
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,14 @@ public record AdminResponse(
LocalDateTime modifiedAt
) {
}

public record UserResponse(
Integer id,
String name,
String email,
String studentId,
String department,
List<Integer> cardinals,
Position position
) {
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package leets.weeth.domain.user.application.mapper;

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

@Mappings({
// 상세 데이터 매핑
})
UserResponse toUserResponse(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();

UserResponse 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 @@ -106,14 +106,30 @@ 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()
.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));
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,8 @@
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.dto.response.UserResponseDto.UserResponse;
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 +60,16 @@ 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<UserResponse> findUser(@RequestParam Long userId) {
return CommonResponse.createSuccess(
USER_DETAILS_SUCCESS.getMessage(), userUseCase.findUserDetails(userId)
);
}

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

0 comments on commit 327a913

Please sign in to comment.