-
Notifications
You must be signed in to change notification settings - Fork 1
[WTH-68] 출석 dto에 출석코드 추가 #229
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
The head ref may contain hidden characters: "WTH-68-Weeth-\uCD9C\uC11D-dto\uC5D0-\uCD9C\uC11D\uCF54\uB4DC-\uCD94\uAC00"
Conversation
🚀 분석 요약Walkthrough어드민 사용자에게만 출석 코드를 노출하기 위한 기능이 추가되었습니다. 새로운 Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant AttendanceUseCaseImpl
participant AttendanceMapper
participant DTO
Client->>AttendanceUseCaseImpl: find(User)
alt User.role == ADMIN
AttendanceUseCaseImpl->>AttendanceMapper: toAdminResponse(user, attendance)
AttendanceMapper->>DTO: Main(code=meeting.code, ...)
DTO-->>AttendanceUseCaseImpl: Main with code
else User.role != ADMIN
AttendanceUseCaseImpl->>AttendanceMapper: toMainDto(user, attendance)
AttendanceMapper->>DTO: Main(code=null, ...)
DTO-->>AttendanceUseCaseImpl: Main without code
end
AttendanceUseCaseImpl-->>Client: AttendanceDTO.Main
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/test/java/leets/weeth/domain/attendance/test/fixture/AttendanceTestFixture.java (1)
29-46: 코드 중복을 줄이기 위한 리팩터링을 권장합니다.
createAdminUserWithAttendances와createActiveUserWithAttendances(lines 49-66) 메서드가 거의 동일한 로직을 포함하고 있습니다. 호출하는 사용자 생성 메서드만 다를 뿐, 나머지 reflection을 통한 초기화 및 출석 추가 로직이 중복됩니다.다음과 같이 공통 로직을 추출하여 중복을 제거할 수 있습니다:
+ private static User createUserWithAttendances(User user, List<Meeting> meetings) { + if (user.getAttendances() == null) { + try { + java.lang.reflect.Field f = user.getClass().getDeclaredField("attendances"); + f.setAccessible(true); + f.set(user, new java.util.ArrayList<>()); + } catch (Exception ignore) {} + } + if (meetings != null) { + for (Meeting meeting : meetings) { + Attendance attendance = createAttendance(meeting, user); + user.add(attendance); + } + } + return user; + } + public static User createAdminUserWithAttendances(String name, List<Meeting> meetings) { User user = createAdminUser(name); - - if (user.getAttendances() == null) { - try { - java.lang.reflect.Field f = user.getClass().getDeclaredField("attendances"); - f.setAccessible(true); - f.set(user, new java.util.ArrayList<>()); - } catch (Exception ignore) {} - } - if (meetings != null) { - for (Meeting meeting : meetings) { - Attendance attendance = createAttendance(meeting, user); - user.add(attendance); - } - } - return user; + return createUserWithAttendances(user, meetings); } public static User createActiveUserWithAttendances(String name, List<Meeting> meetings) { User user = createActiveUser(name); - - if (user.getAttendances() == null) { - try { - java.lang.reflect.Field f = user.getClass().getDeclaredField("attendances"); - f.setAccessible(true); - f.set(user, new java.util.ArrayList<>()); - } catch (Exception ignore) {} - } - if (meetings != null) { - for (Meeting meeting : meetings) { - Attendance attendance = createAttendance(meeting, user); - user.add(attendance); - } - } - return user; + return createUserWithAttendances(user, meetings); }src/test/java/leets/weeth/domain/attendance/application/mapper/AttendanceMapperTest.java (1)
24-25: 매퍼 초기화 패턴을 단순화할 수 있습니다.
@InjectMocks는 일반적으로 목(mock) 객체를 주입할 때 사용되지만, 여기서는Mappers.getMapper()로 실제 구현체를 생성하고 있습니다. MapStruct 테스트에서는 보통 애노테이션 없이 필드 초기화만 사용합니다.다음과 같이 단순화할 수 있습니다:
- @InjectMocks - private final AttendanceMapper attendanceMapper = Mappers.getMapper(AttendanceMapper.class); + private final AttendanceMapper attendanceMapper = Mappers.getMapper(AttendanceMapper.class);그리고
@ExtendWith(MockitoExtension.class)도 실제로 목을 사용하지 않는다면 제거할 수 있습니다.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/main/java/leets/weeth/domain/attendance/application/dto/AttendanceDTO.java(2 hunks)src/main/java/leets/weeth/domain/attendance/application/mapper/AttendanceMapper.java(1 hunks)src/main/java/leets/weeth/domain/attendance/application/usecase/AttendanceUseCaseImpl.java(2 hunks)src/test/java/leets/weeth/domain/attendance/application/mapper/AttendanceMapperTest.java(2 hunks)src/test/java/leets/weeth/domain/attendance/test/fixture/AttendanceTestFixture.java(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/test/java/leets/weeth/domain/attendance/application/mapper/AttendanceMapperTest.java (1)
src/test/java/leets/weeth/domain/attendance/test/fixture/AttendanceTestFixture.java (1)
AttendanceTestFixture(16-125)
🔇 Additional comments (7)
src/main/java/leets/weeth/domain/attendance/application/mapper/AttendanceMapper.java (2)
17-17: 명시적인 ignore 설정이 좋습니다.
toMainDto에서code필드를 명시적으로ignore하여 일반 사용자에게는 출석 코드가 노출되지 않도록 의도를 명확히 했습니다.
24-33: ADMIN 사용자를 위한 매핑 메서드가 올바르게 추가되었습니다.
toAdminResponse메서드가attendance.meeting.code를 매핑하여 관리자에게만 출석 코드를 노출하도록 구현되었습니다.toMainDto와 매핑 설정이 거의 동일하지만, MapStruct의 제약으로 인해 이러한 중복은 불가피합니다.src/main/java/leets/weeth/domain/attendance/application/usecase/AttendanceUseCaseImpl.java (1)
70-74: 역할 기반 분기 로직이 올바르게 구현되었습니다.ADMIN 역할을 가진 사용자에게는
toAdminResponse를 통해 출석 코드가 포함된 DTO를 반환하고, 일반 사용자에게는toMainDto를 사용하는 분기 처리가 정확합니다. 상수를 먼저 비교하는 패턴(Role.ADMIN == user.getRole())도 NPE 방지를 위한 좋은 관행입니다.src/main/java/leets/weeth/domain/attendance/application/dto/AttendanceDTO.java (1)
17-18: DTO에 출석 코드 필드가 올바르게 추가되었습니다.
code필드가Integer타입으로 추가되었고, Swagger 문서화를 통해 어드민 전용 필드임을 명확히 표시했습니다.src/test/java/leets/weeth/domain/attendance/test/fixture/AttendanceTestFixture.java (1)
25-27: 어드민 사용자 생성 헬퍼가 추가되었습니다.테스트에서 ADMIN 역할을 가진 사용자를 생성할 수 있는 헬퍼 메서드가 추가되어 어드민 관련 테스트 시나리오를 지원합니다.
src/test/java/leets/weeth/domain/attendance/application/mapper/AttendanceMapperTest.java (2)
130-147: 일반 사용자의 코드 필드 null 처리가 올바르게 검증되었습니다.
toMainDto를 통해 일반 사용자의 DTO를 생성할 때code필드가 null로 매핑되는지 확인하는 테스트가 추가되어 권한에 따른 필드 노출 제어가 올바르게 동작하는지 검증합니다.
149-169: 어드민 사용자의 코드 포함 여부가 올바르게 검증되었습니다.
toAdminResponse를 통해 관리자의 DTO를 생성할 때 출석 코드가 정확히 포함되는지 확인하는 테스트가 추가되었습니다. 다만, 기존 null 안전성 테스트(lines 115-128)는toMainDto만 검증하므로,toAdminResponse에 대한 null 안전성도 확인하는 것이 좋습니다.
toAdminResponse에 대한 null 안전성 테스트를 추가하는 것을 권장합니다:@Test @DisplayName("null 안전성 테스트: toAdminResponse에서 todayAttendance가 null이면 필드는 null로 매핑") void nullSafety_toAdminResponse_whenTodayAttendanceNull() { // given User adminUser = createAdminUser("관리자"); // when AttendanceDTO.Main main = attendanceMapper.toAdminResponse(adminUser, null); // then assertThat(main).isNotNull(); assertThat(main.code()).isNull(); assertThat(main.title()).isNull(); assertThat(main.start()).isNull(); assertThat(main.end()).isNull(); assertThat(main.location()).isNull(); }
| @Mapping(target = "location", source = "attendance.meeting.location"), | ||
| }) | ||
| AttendanceDTO.Main toMainDto(User user, Attendance attendance); | ||
|
|
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.
ignore 옵션으로 , ROLE별로 매핑되는 필드를 조절할 수 있군요! 좋은 설계같습니다
| assertThat(main.end()).isEqualTo(meeting.getEnd()); | ||
| assertThat(main.location()).isEqualTo(meeting.getLocation()); | ||
| } | ||
| } |
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.
테스트도 케이스별로 보기좋게 잘 작성해주신 것 같아요 !! 굳굳
seokjun01
left a comment
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.
작성된 코드 잘 보았습니다 고생하셨습니다~~
jj0526
left a comment
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 내용
🔍 PR 세부사항
📸 관련 스크린샷
📝 주의사항
✅ 체크리스트
Summary by CodeRabbit
릴리스 노트
New Features
Tests