-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] DTO 추가, 엔티티 변경 #7
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
Conversation
새로운 컬럼 추가입니다.
Api No.18 까지, 16번,17번 제외하고 Dto 추가 새로운 컬럼 추가입니다.
Api 32번,33번 제외하고 Dto 추가
Items, RentalHistory 에 있는 Status, Condition ENUM을 더 자연스럽게 개선했습니다.
gitignore에 gradle과 .idea를 추가했습니다.
📝 WalkthroughWalkthrough여러 도메인에서 요청/응답용 DTO 레코드들이 대거 추가되었고, 일부 엔티티에 필드가 추가되거나 이름이 수정되었으며 열거형(enum)이 추가·수정·교체되었습니다. 또한 IDE/컴파일러 설정과 .gitignore에 항목이 추가되었습니다. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: 10
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/java/ssurent/ssurentbe/domain/item/entity/Items.java (1)
32-38:⚠️ Potential issue | 🟡 Minor새 컬럼의
nullable = false제약 조건과 백필이 필요합니다.
condition컬럼이nullable = false없이 추가되었기 때문에 기존 레코드는 NULL 값을 가집니다.ItemResponse등의 API 응답 DTO에서Condition condition필드가 null 처리 없이 노출되므로 NPE 또는 응답 스키마 불일치로 이어질 수 있습니다.
BaseEntity의createdAt,updatedAt처럼 명시적인nullable = false제약을 추가하거나, 기존 레코드에 대한 백필(예: 기본값 설정)을 진행해야 합니다.
🤖 Fix all issues with AI agents
In @.idea/compiler.xml:
- Around line 15-20: The Gradle build is missing the Java compiler -parameters
flag causing mismatch with IDE settings; update build.gradle to configure all
JavaCompile tasks (use tasks.withType(JavaCompile).configureEach) and add the
'-parameters' argument to options.compilerArgs so the Gradle build and CI
produce parameter metadata consistent with the IDE; ensure this is applied for
all modules and commits the change.
In
`@src/main/java/ssurent/ssurentbe/domain/assists/dto/response/AdminAssistResponse.java`:
- Around line 3-7: Add a public static factory method named from to
AdminAssistResponse that accepts the corresponding entity (e.g., Assist assist)
and returns a new AdminAssistResponse populated from the entity's fields;
implement it as public static AdminAssistResponse from(Assist assist) { /* map
assist.getId(), assist.getName(), etc. */ } and include a null check if desired
to avoid NPEs.
In `@src/main/java/ssurent/ssurentbe/domain/item/dto/response/ItemResponse.java`:
- Around line 7-21: The ItemResponse.record declares itemId as String but
from(Items item) passes item.getId() (Long), causing a type mismatch; update the
from(Items item) method to convert the ID to a String (e.g.,
String.valueOf(item.getId()) or item.getId().toString()) when constructing the
new ItemResponse so the itemId parameter matches the record's String type and
consider null-safety if Items.getId() can be null.
In
`@src/main/java/ssurent/ssurentbe/domain/rental/dto/response/AdminUserRentalItemResponse.java`:
- Around line 5-9: The record AdminUserRentalItemResponse currently defines a
component named RentalId which makes the generated accessor/JSON field
"RentalId"; rename the component to rentalId (camelCase) in the record
declaration to match other DTOs and ensure JSON/serialization uses "rentalId",
then update any usages/constructors/serializers that reference
AdminUserRentalItemResponse.RentalId or the positional parameter order to use
the new rentalId component name.
In `@src/main/java/ssurent/ssurentbe/domain/rental/entity/RentalHistory.java`:
- Around line 47-49: 필드 overdue가 Boolean 래퍼 타입이라 언박싱 시 NPE 위험이 있으니 RentalHistory
엔티티의 private Boolean overdue를 primitive로 변경하여 기본값 false를 보장하세요; 즉 RentalHistory의
overdue를 private boolean overdue로 바꾸고 필요하면 `@Column`(name = "is_overdue", nullable
= false)로 null 불허 제약을 추가한 뒤 Lombok/수동 getter가 isOverdue() 시그니처를 내보내는지 확인하고 DTO
매핑 코드(또는 getOverdue() 사용처)가 isOverdue()로 맞춰지도록 관련 변환/참조를 수정하세요.
In `@src/main/java/ssurent/ssurentbe/domain/rental/enums/Status.java`:
- Around line 3-6: Status enum (Status.RENT/RETURN) is declared but never used;
update the service and mapping logic to set and persist these values: in the
rental flow implement or update methods like RentalService.rentItem(...) and
RentalService.returnItem(...) to assign RentalHistory.setStatus(Status.RENT) on
checkout and RentalHistory.setStatus(Status.RETURN) on checkin, save via
RentalHistoryRepository, and ensure AdminRentalHistoryResponse mapping (e.g., a
mapper or constructor that reads RentalHistory.getStatus()) returns the new enum
value; also add tests exercising both transitions and adjust any
DTOs/serializers to handle the Status enum.
In
`@src/main/java/ssurent/ssurentbe/domain/users/dto/request/AdminUserPenaltyCreateRequest.java`:
- Around line 6-10: AdminUserPenaltyCreateRequest currently accepts createdAt
from clients; remove the createdAt component from the record declaration
(AdminUserPenaltyCreateRequest) so clients no longer supply it, and update any
code that constructs or maps this DTO (controllers, mappers, tests) to stop
passing createdAt and instead let the server set creation time when assembling
the domain/entity (e.g., in the service or entity factory where the penalty is
persisted, populate createdAt via LocalDateTime.now() or database default).
Ensure any mapping functions or constructors that referenced
AdminUserPenaltyCreateRequest.createdAt are updated accordingly.
In
`@src/main/java/ssurent/ssurentbe/domain/users/dto/response/AdminUserDetailResponse.java`:
- Around line 18-28: AdminUserDetailResponse.from currently streams the
penalties list without null-check, causing NPE if penalties is null; update
AdminUserDetailResponse.from to defensively handle a null penalties parameter
(e.g., treat null as an empty list) before mapping with
UserPenaltyResponse::from so the constructor always receives a non-null list of
penalty DTOs; locate the from method in AdminUserDetailResponse and wrap or
replace the penalties usage with a safe fallback (e.g., Optional/Objects
null-check or Collections.emptyList()) prior to .stream()/mapping.
In
`@src/main/java/ssurent/ssurentbe/domain/users/dto/response/AdminUserResponse.java`:
- Around line 5-11: The AdminUserResponse record is missing the static factory
method from() for converting a User entity to this DTO; add a public static
AdminUserResponse from(User user) method (similar to AdminAssistResponse.from)
that constructs and returns a new AdminUserResponse by mapping the entity fields
(use user.getId(), user.getUserName(), user.getStudentNum(), user.getRole() or
the actual getter names on your User class) to the record components (userId,
userName, studentNum, role).
In
`@src/main/java/ssurent/ssurentbe/domain/users/dto/response/UserPenaltyResponse.java`:
- Around line 8-22: The record field userPenaltyId in UserPenaltyResponse is
declared as String but from(UserPenaltyLog) passes a Long
(userPenaltyLog.getId()), causing a type error; fix by converting the ID to a
String when constructing the record (e.g., call
String.valueOf(userPenaltyLog.getId()) or userPenaltyLog.getId().toString()) in
the UserPenaltyResponse.from method so the passed value matches the
userPenaltyId String type, keeping the rest of the return values (createdAt,
itemInfo, penaltyType) unchanged.
🧹 Nitpick comments (9)
src/main/java/ssurent/ssurentbe/domain/users/dto/request/AdminUserRoleUpdateRequest.java (1)
3-6: 요청 DTO에 입력 검증 추가 권장
userId/role이 비어 있거나 null이어도 통과합니다. 최소한 Bean Validation으로 공백/널을 막고, 가능하다면 역할은 도메인 Enum으로 제한하는 게 안전합니다.✅ 제안 변경 (Bean Validation 적용)
public record AdminUserRoleUpdateRequest( - String userId, - String role + `@jakarta.validation.constraints.NotBlank` String userId, + `@jakarta.validation.constraints.NotBlank` String role ) { }src/main/java/ssurent/ssurentbe/domain/users/dto/request/AdminUserStatusUpdateRequest.java (1)
3-5: status 값은 가능한 Enum으로 제한하세요.
String status는 오탈자/임의 값이 그대로 통과합니다. 기존 사용자 상태 Enum이 있다면 그 타입으로 받는 편이 더 안전합니다.♻️ 예시 변경안
-public record AdminUserStatusUpdateRequest( - String status -) { -} +public record AdminUserStatusUpdateRequest( + UserStatus status +) { +}.gitignore (1)
4-5: .idea/gradle 무시 규칙 정합성 정리 필요
.idea가 IntelliJ 섹션에 이미 있어 중복입니다. 한 곳으로 정리하는 게 깔끔합니다.gradle디렉터리를 무시한다면gradle/wrapper/gradle-wrapper.properties도 예외 처리하지 않으면 추후 변경이 누락될 수 있습니다.- 또한 이번 PR에
.idea/compiler.xml변경이 있어,.idea를 추적할지/무시할지 정책을 한쪽으로 맞추는 게 좋습니다.♻️ 정리 제안 (한 가지 옵션)
- gradle - .idea + gradle/ + !gradle/wrapper/gradle-wrapper.propertiessrc/main/java/ssurent/ssurentbe/domain/item/dto/request/AdminCategoryCreateRequest.java (1)
3-6: 입력 유효성 검증 누락
categoryName필드에@NotBlank또는@NotNull같은 Bean Validation 어노테이션이 없습니다. 빈 문자열이나 null 값으로 카테고리가 생성될 수 있습니다.♻️ 유효성 검증 추가 제안
package ssurent.ssurentbe.domain.item.dto.request; +import jakarta.validation.constraints.NotBlank; + public record AdminCategoryCreateRequest( - String categoryName + `@NotBlank`(message = "카테고리 이름은 필수입니다") + String categoryName ) { }src/main/java/ssurent/ssurentbe/domain/assists/dto/request/AdminAssistCreateRequest.java (1)
3-6: 입력 유효성 검증 누락
assistName필드에 유효성 검증 어노테이션이 없습니다.AdminCategoryCreateRequest와 동일하게@NotBlank추가를 권장합니다.♻️ 유효성 검증 추가 제안
package ssurent.ssurentbe.domain.assists.dto.request; +import jakarta.validation.constraints.NotBlank; + public record AdminAssistCreateRequest( - String assistName + `@NotBlank`(message = "조교 이름은 필수입니다") + String assistName ) { }src/main/java/ssurent/ssurentbe/domain/item/entity/Category.java (1)
23-24: 기존 코드 오타:isDelelted→isDeleted이번 변경 범위는 아니지만, Line 24의
isDelelted필드명에 오타가 있습니다. Lombok이 생성하는 getter 이름도isDelelted()가 되어 혼란을 줄 수 있으니, 이번 PR 또는 후속 작업에서 수정을 고려해 주세요.src/main/java/ssurent/ssurentbe/domain/item/dto/request/AdminItemUpdateRequest.java (1)
3-11: status는 String 대신 Status enum 사용을 권장합니다.
타입 안정성과 유효성 검증이 강화됩니다.♻️ 제안 수정안
+import ssurent.ssurentbe.domain.item.enums.Status; import java.util.List; public record AdminItemUpdateRequest( List<ItemUpdate> itemUpdates ) { public record ItemUpdate( Long itemId, - String status + Status status ){ } }src/main/java/ssurent/ssurentbe/domain/rental/dto/request/RentalExtendRequest.java (1)
5-8: 요청 DTO 입력 검증 추가 권장
rentalId공백/누락,dueDate누락을 초기에 차단하는 기본 검증이 없어서 컨트롤러 레벨에서 오류가 늦게 드러날 수 있습니다. Bean Validation 적용을 권장합니다.🔧 제안 변경안
+import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Future; import java.time.LocalDateTime; public record RentalExtendRequest( - String rentalId, - LocalDateTime dueDate + `@NotBlank` String rentalId, + `@NotNull` `@Future` LocalDateTime dueDate ) { }src/main/java/ssurent/ssurentbe/domain/rental/dto/response/RentalItemResponse.java (1)
14-21: DTO 매핑에서 null 방어와 중복 접근 최소화
rentalHistory또는itemId가 null이면 NPE가 즉시 발생합니다. DTO 매핑 진입점에서 최소한의 방어를 추가하고, 이미 가져온Items로 ID를 재사용하는 편이 명확합니다.♻️ 제안 변경안
import ssurent.ssurentbe.domain.item.entity.Items; import ssurent.ssurentbe.domain.rental.entity.RentalHistory; import java.time.LocalDateTime; +import java.util.Objects; public record RentalItemResponse( String rentalId, String itemId, String itemName, LocalDateTime dueDate ) { public static RentalItemResponse from(RentalHistory rentalHistory) { - Items items = rentalHistory.getItemId(); + Objects.requireNonNull(rentalHistory, "rentalHistory"); + Items items = Objects.requireNonNull(rentalHistory.getItemId(), "item"); String itemName = items.getName() + "(" + items.getItemNum() + ")"; return new RentalItemResponse( rentalHistory.getId(), - rentalHistory.getItemId().getId(), + items.getId(), itemName, rentalHistory.getDueDate() ); } }
src/main/java/ssurent/ssurentbe/domain/assists/dto/response/AdminAssistResponse.java
Show resolved
Hide resolved
src/main/java/ssurent/ssurentbe/domain/item/dto/response/ItemResponse.java
Show resolved
Hide resolved
src/main/java/ssurent/ssurentbe/domain/rental/dto/response/AdminUserRentalItemResponse.java
Show resolved
Hide resolved
src/main/java/ssurent/ssurentbe/domain/rental/entity/RentalHistory.java
Outdated
Show resolved
Hide resolved
| public enum Status { | ||
| ACTIVE, | ||
| OVERDUE, | ||
| INACTIVE | ||
| RENT, | ||
| RETURN | ||
| } |
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.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify Status enum constant updates
echo "=== Checking for references to old enum constants ==="
rg -n "Status\.(ACTIVE|OVERDUE|INACTIVE)" --type java
echo ""
echo "=== Checking for references to new enum constants ==="
rg -n "Status\.(RENT|RETURN)" --type java
echo ""
echo "=== Checking for Status enum import statements ==="
rg -n "import.*Status" --type java | head -20Repository: SSURENT/SSURENT-BE
Length of output: 2816
🏁 Script executed:
#!/bin/bash
# Check the users Status enum definition
echo "=== Users Status enum definition ==="
cat -n src/main/java/ssurent/ssurentbe/domain/users/enums/Status.java
echo ""
echo "=== RentalHistory entity to see Status usage ==="
cat -n src/main/java/ssurent/ssurentbe/domain/rental/entity/RentalHistory.java
echo ""
echo "=== AuthService.java around line 39 ==="
sed -n '35,45p' src/main/java/ssurent/ssurentbe/domain/users/service/AuthService.javaRepository: SSURENT/SSURENT-BE
Length of output: 2377
🏁 Script executed:
#!/bin/bash
# Check where rental Status is being used
echo "=== AdminRentalHistoryResponse (imports rental Status) ==="
cat -n src/main/java/ssurent/ssurentbe/domain/rental/dto/response/AdminRentalHistoryResponse.java
echo ""
echo "=== Search for RentalHistory instantiation with status field ==="
rg -n "RentalHistory.*builder\|\.status\(" --type java -A 2 -B 2 | head -50Repository: SSURENT/SSURENT-BE
Length of output: 696
🏁 Script executed:
#!/bin/bash
# Search for status field usage in rental domain
echo "=== Search for status assignments in rental domain ==="
rg -n "\.status\|status\s*=" src/main/java/ssurent/ssurentbe/domain/rental/ --type java
echo ""
echo "=== List rental domain files ==="
find src/main/java/ssurent/ssurentbe/domain/rental -name "*.java" -type fRepository: SSURENT/SSURENT-BE
Length of output: 966
🏁 Script executed:
#!/bin/bash
# Check if there are service classes in rental domain
echo "=== Find service/repository classes ==="
find src/main/java/ssurent/ssurentbe/domain/rental -name "*Service.java" -o -name "*Repository.java"
echo ""
echo "=== Search all files for Status.RENT or Status.RETURN ==="
rg -n "Status\.(RENT|RETURN)" --type javaRepository: SSURENT/SSURENT-BE
Length of output: 160
🏁 Script executed:
#!/bin/bash
# Check if rental service/repository might be in a different location
echo "=== Search entire codebase for Rental service/repository ==="
find src -name "*Rental*Service.java" -o -name "*Rental*Repository.java" 2>/dev/null
echo ""
echo "=== Verify the new Status enum constants are defined ==="
cat -n src/main/java/ssurent/ssurentbe/domain/rental/enums/Status.javaRepository: SSURENT/SSURENT-BE
Length of output: 314
기존 enum 상수 참조는 없으나, 새 상수의 사용처도 없어 구현 완성도 검토 필요
RENT/RETURN 상수는 정의되었으나, 코드베이스 전체에서 이들을 사용하는 부분이 없습니다. RentalHistory 엔티티의 status 필드와 AdminRentalHistoryResponse의 status 필드가 정의되어 있지만, 실제로 상태를 설정하고 관리하는 서비스 계층이 보이지 않습니다.
enum 정의 후 이를 활용한 비즈니스 로직(대여 시 RENT 설정, 반납 시 RETURN 설정 등)의 구현이 필요합니다.
🤖 Prompt for AI Agents
In `@src/main/java/ssurent/ssurentbe/domain/rental/enums/Status.java` around lines
3 - 6, Status enum (Status.RENT/RETURN) is declared but never used; update the
service and mapping logic to set and persist these values: in the rental flow
implement or update methods like RentalService.rentItem(...) and
RentalService.returnItem(...) to assign RentalHistory.setStatus(Status.RENT) on
checkout and RentalHistory.setStatus(Status.RETURN) on checkin, save via
RentalHistoryRepository, and ensure AdminRentalHistoryResponse mapping (e.g., a
mapper or constructor that reads RentalHistory.getStatus()) returns the new enum
value; also add tests exercising both transitions and adjust any
DTOs/serializers to handle the Status enum.
src/main/java/ssurent/ssurentbe/domain/users/dto/request/AdminUserPenaltyCreateRequest.java
Show resolved
Hide resolved
| public static AdminUserDetailResponse from(Users user, List<UserPenaltyLog> penalties) { | ||
| return new AdminUserDetailResponse( | ||
| user.getId(), | ||
| user.getName(), | ||
| user.getStudentNum(), | ||
| user.getRole().name(), | ||
| user.getStatus().name(), | ||
| user.getPhoneNum(), | ||
| penalties.stream() | ||
| .map(UserPenaltyResponse::from) | ||
| .toList() |
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.
penalties가 null이면 NPE가 발생합니다.
호출부에서 항상 빈 리스트를 보장하거나, 여기서 방어 처리를 넣어주세요.
🔧 제안 수정
public static AdminUserDetailResponse from(Users user, List<UserPenaltyLog> penalties) {
return new AdminUserDetailResponse(
user.getId(),
user.getName(),
user.getStudentNum(),
user.getRole().name(),
user.getStatus().name(),
user.getPhoneNum(),
- penalties.stream()
+ (penalties == null ? List.<UserPenaltyResponse>of() : penalties).stream()
.map(UserPenaltyResponse::from)
.toList()
);
}🤖 Prompt for AI Agents
In
`@src/main/java/ssurent/ssurentbe/domain/users/dto/response/AdminUserDetailResponse.java`
around lines 18 - 28, AdminUserDetailResponse.from currently streams the
penalties list without null-check, causing NPE if penalties is null; update
AdminUserDetailResponse.from to defensively handle a null penalties parameter
(e.g., treat null as an empty list) before mapping with
UserPenaltyResponse::from so the constructor always receives a non-null list of
penalty DTOs; locate the from method in AdminUserDetailResponse and wrap or
replace the penalties usage with a safe fallback (e.g., Optional/Objects
null-check or Collections.emptyList()) prior to .stream()/mapping.
| public record AdminUserResponse( | ||
| Long userId, | ||
| String userName, | ||
| String studentNum, | ||
| Role role | ||
| ) { | ||
| } |
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.
🛠️ Refactor suggestion | 🟠 Major
from() 정적 팩토리 메서드 누락
AdminAssistResponse와 마찬가지로, PR 목표에 명시된 엔티티 → 레코드 변환용 from() 메서드가 누락되었습니다.
♻️ from() 메서드 추가 제안
package ssurent.ssurentbe.domain.users.dto.response;
import ssurent.ssurentbe.domain.users.enums.Role;
+import ssurent.ssurentbe.domain.users.entity.Users;
public record AdminUserResponse(
Long userId,
String userName,
String studentNum,
Role role
) {
+ public static AdminUserResponse from(Users user) {
+ return new AdminUserResponse(
+ user.getId(),
+ user.getUserName(),
+ user.getStudentNum(),
+ user.getRole()
+ );
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public record AdminUserResponse( | |
| Long userId, | |
| String userName, | |
| String studentNum, | |
| Role role | |
| ) { | |
| } | |
| package ssurent.ssurentbe.domain.users.dto.response; | |
| import ssurent.ssurentbe.domain.users.enums.Role; | |
| import ssurent.ssurentbe.domain.users.entity.Users; | |
| public record AdminUserResponse( | |
| Long userId, | |
| String userName, | |
| String studentNum, | |
| Role role | |
| ) { | |
| public static AdminUserResponse from(Users user) { | |
| return new AdminUserResponse( | |
| user.getId(), | |
| user.getUserName(), | |
| user.getStudentNum(), | |
| user.getRole() | |
| ); | |
| } | |
| } |
🤖 Prompt for AI Agents
In
`@src/main/java/ssurent/ssurentbe/domain/users/dto/response/AdminUserResponse.java`
around lines 5 - 11, The AdminUserResponse record is missing the static factory
method from() for converting a User entity to this DTO; add a public static
AdminUserResponse from(User user) method (similar to AdminAssistResponse.from)
that constructs and returns a new AdminUserResponse by mapping the entity fields
(use user.getId(), user.getUserName(), user.getStudentNum(), user.getRole() or
the actual getter names on your User class) to the record components (userId,
userName, studentNum, role).
src/main/java/ssurent/ssurentbe/domain/users/dto/response/UserPenaltyResponse.java
Show resolved
Hide resolved
CromNEXT
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.
굿
Id String -> Long 타입 변경 from() 메서드 추가
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: 2
🤖 Fix all issues with AI agents
In
`@src/main/java/ssurent/ssurentbe/domain/rental/dto/response/AdminUserRentalItemResponse.java`:
- Around line 14-23: AdminUserRentalItemResponse.from currently calls
RentalHistory.getItemId() and immediately dereferences it
(Items.getName()/getItemNum()), which risks NPE; update
AdminUserRentalItemResponse.from to null-check rentalHistory.getItemId() and
produce a safe itemName (e.g., "Unknown Item" or empty values) when null,
ensuring the constructor still receives valid values; apply the same defensive
check/pattern to the similar factory in RentalItemResponse so both handle
nullable item relations safely; reference the methods/classes:
AdminUserRentalItemResponse.from, RentalHistory.getItemId, Items.getName,
Items.getItemNum, and RentalItemResponse when making the changes.
In
`@src/main/java/ssurent/ssurentbe/domain/users/dto/request/AdminUserPenaltyCreateRequest.java`:
- Line 4: The import of LocalDateTime in AdminUserPenaltyCreateRequest is unused
after removal of the createdAt field; remove the unused import statement (the
"import java.time.LocalDateTime;" line) from the AdminUserPenaltyCreateRequest
record to clean up the code and eliminate the unused-import warning.
🧹 Nitpick comments (4)
src/main/java/ssurent/ssurentbe/domain/rental/dto/request/RentalExtendRequest.java (1)
5-9: Bean Validation 어노테이션 추가를 권장합니다.요청 DTO에 유효성 검증 어노테이션이 없습니다.
rentalId와dueDate필드에@NotNull을 추가하고,dueDate에는@Future또는@FutureOrPresent를 추가하여 잘못된 데이터가 서비스 레이어에 도달하는 것을 방지하는 것이 좋습니다.♻️ 유효성 검증 어노테이션 추가 제안
package ssurent.ssurentbe.domain.rental.dto.request; import java.time.LocalDateTime; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.FutureOrPresent; public record RentalExtendRequest( - Long rentalId, - LocalDateTime dueDate + `@NotNull` Long rentalId, + `@NotNull` `@FutureOrPresent` LocalDateTime dueDate ) { }src/main/java/ssurent/ssurentbe/domain/rental/dto/response/RentalItemResponse.java (1)
14-22: 연관 엔티티 접근을 단일화하고 NPE 방어를 고려하세요.
rentalHistory.getItemId()를 두 번 호출하기보다items를 재사용하고, null 방어로 실패 원인을 명확히 하는 편이 안정적입니다.🔧 제안 변경(diff)
import ssurent.ssurentbe.domain.item.entity.Items; import ssurent.ssurentbe.domain.rental.entity.RentalHistory; import java.time.LocalDateTime; +import java.util.Objects; public record RentalItemResponse( Long rentalId, Long itemId, String itemName, LocalDateTime dueDate ) { public static RentalItemResponse from(RentalHistory rentalHistory) { - Items items = rentalHistory.getItemId(); + Objects.requireNonNull(rentalHistory, "rentalHistory"); + Items items = Objects.requireNonNull(rentalHistory.getItemId(), "items"); String itemName = items.getName() + "(" + items.getItemNum() + ")"; return new RentalItemResponse( rentalHistory.getId(), - rentalHistory.getItemId().getId(), + items.getId(), itemName, rentalHistory.getDueDate() ); } }src/main/java/ssurent/ssurentbe/domain/item/dto/response/CategoryResponse.java (1)
9-14: 선택 사항: null 입력에 대한 방어 코드 고려
from메서드에 nullcategory가 전달될 경우 NPE가 발생합니다. 서비스/컨트롤러 레이어에서 이미 null 체크가 이루어지고 있다면 무시해도 됩니다. 다만, 방어적 코딩 관점에서 명시적인 null 체크를 추가하는 것도 고려해 볼 수 있습니다.🛡️ 방어 코드 추가 예시
public static CategoryResponse from(Category category) { + if (category == null) { + throw new IllegalArgumentException("Category cannot be null"); + } return new CategoryResponse( category.getId(), category.getName() ); }src/main/java/ssurent/ssurentbe/domain/users/dto/request/AdminUserPenaltyCreateRequest.java (1)
6-9:penaltyType을PenaltyTypesenum으로 변경하세요
PenaltyTypesenum이 이미 존재하며UserPenaltyLog엔티티에서 사용 중입니다. 요청 DTO에서도String대신 enum 타입을 사용하면 타입 안전성을 확보할 수 있고, 유효하지 않은 값이 전달되는 것을 컴파일 타임에 방지할 수 있습니다. 엔티티와 DTO 간의 타입 일관성도 개선됩니다.import ssurent.ssurentbe.domain.users.enums.PenaltyTypes; public record AdminUserPenaltyCreateRequest ( String itemName, PenaltyTypes penaltyType ){ }
| public static AdminUserRentalItemResponse from(RentalHistory rentalHistory) { | ||
| Items items = rentalHistory.getItemId(); | ||
| String itemName = items.getName() + "(" + items.getItemNum() + ")"; | ||
| return new AdminUserRentalItemResponse( | ||
| rentalHistory.getId(), | ||
| rentalHistory.getRentalDate(), | ||
| rentalHistory.getReturnDate(), | ||
| itemName | ||
| ); | ||
| } |
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.
🧩 Analysis chain
🏁 Script executed:
fd -e java "RentalHistory\.java" --exec cat -n {} \;Repository: SSURENT/SSURENT-BE
Length of output: 1704
🏁 Script executed:
fd -e sql -e yml -e yaml | xargs grep -l "rental_history\|item_id" | head -10Repository: SSURENT/SSURENT-BE
Length of output: 44
🏁 Script executed:
rg "RentalHistory\." --type java -A 2 | head -50Repository: SSURENT/SSURENT-BE
Length of output: 44
🏁 Script executed:
rg "getItemId" --type java -B 2 -A 2Repository: SSURENT/SSURENT-BE
Length of output: 1930
🏁 Script executed:
rg "from\(RentalHistory" --type java -A 5 | grep -E "(from|getItemId|getName|getItem)"Repository: SSURENT/SSURENT-BE
Length of output: 1125
null 체크 추가 필수 - NPE 위험 확인됨
rentalHistory.getItemId()가 null을 반환할 경우 Line 17에서 NullPointerException이 발생합니다. RentalHistory 엔티티의 itemId 필드는 @ManyToOne 관계이며 nullable=false 제약이 없어 null 값이 가능합니다.
유사한 패턴이 RentalItemResponse에도 존재하므로 일괄 수정이 필요합니다:
🛡️ 방어적 null 체크 추가
public static AdminUserRentalItemResponse from(RentalHistory rentalHistory) {
Items items = rentalHistory.getItemId();
+ if (items == null) {
+ throw new IllegalArgumentException("RentalHistory must have an associated Item");
+ }
String itemName = items.getName() + "(" + items.getItemNum() + ")";
return new AdminUserRentalItemResponse(
rentalHistory.getId(),
rentalHistory.getRentalDate(),
rentalHistory.getReturnDate(),
itemName
);
}부가 사항: getItemId()가 실제로 Items 엔티티를 반환하므로 메서드명이 명확하지 않습니다.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public static AdminUserRentalItemResponse from(RentalHistory rentalHistory) { | |
| Items items = rentalHistory.getItemId(); | |
| String itemName = items.getName() + "(" + items.getItemNum() + ")"; | |
| return new AdminUserRentalItemResponse( | |
| rentalHistory.getId(), | |
| rentalHistory.getRentalDate(), | |
| rentalHistory.getReturnDate(), | |
| itemName | |
| ); | |
| } | |
| public static AdminUserRentalItemResponse from(RentalHistory rentalHistory) { | |
| Items items = rentalHistory.getItemId(); | |
| if (items == null) { | |
| throw new IllegalArgumentException("RentalHistory must have an associated Item"); | |
| } | |
| String itemName = items.getName() + "(" + items.getItemNum() + ")"; | |
| return new AdminUserRentalItemResponse( | |
| rentalHistory.getId(), | |
| rentalHistory.getRentalDate(), | |
| rentalHistory.getReturnDate(), | |
| itemName | |
| ); | |
| } |
🤖 Prompt for AI Agents
In
`@src/main/java/ssurent/ssurentbe/domain/rental/dto/response/AdminUserRentalItemResponse.java`
around lines 14 - 23, AdminUserRentalItemResponse.from currently calls
RentalHistory.getItemId() and immediately dereferences it
(Items.getName()/getItemNum()), which risks NPE; update
AdminUserRentalItemResponse.from to null-check rentalHistory.getItemId() and
produce a safe itemName (e.g., "Unknown Item" or empty values) when null,
ensuring the constructor still receives valid values; apply the same defensive
check/pattern to the similar factory in RentalItemResponse so both handle
nullable item relations safely; reference the methods/classes:
AdminUserRentalItemResponse.from, RentalHistory.getItemId, Items.getName,
Items.getItemNum, and RentalItemResponse when making the changes.
| package ssurent.ssurentbe.domain.users.dto.request; | ||
|
|
||
|
|
||
| import java.time.LocalDateTime; |
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.
사용하지 않는 import 제거 필요
LocalDateTime이 import되어 있지만 레코드 내에서 사용되지 않습니다. 이전 리뷰에서 createdAt 필드가 제거되면서 남은 것으로 보입니다.
🧹 수정 제안
package ssurent.ssurentbe.domain.users.dto.request;
-
-import java.time.LocalDateTime;
public record AdminUserPenaltyCreateRequest (
String itemName,
String penaltyType
){
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import java.time.LocalDateTime; | |
| package ssurent.ssurentbe.domain.users.dto.request; | |
| public record AdminUserPenaltyCreateRequest ( | |
| String itemName, | |
| String penaltyType | |
| ){ | |
| } |
🤖 Prompt for AI Agents
In
`@src/main/java/ssurent/ssurentbe/domain/users/dto/request/AdminUserPenaltyCreateRequest.java`
at line 4, The import of LocalDateTime in AdminUserPenaltyCreateRequest is
unused after removal of the createdAt field; remove the unused import statement
(the "import java.time.LocalDateTime;" line) from the
AdminUserPenaltyCreateRequest record to clean up the code and eliminate the
unused-import warning.
개요
PR 유형
어떤 변경 사항이 있나요?
PR Checklist
PR이 다음 요구 사항을 충족하는지 확인하세요.
🧩 작업 내용
Status 컬럼은 관리자나 서비스가 아이템을 '활성화' , '비활성화' 하기 위한 상태로 정의했고,
Condition 컬럼은 실제 사용자가 아이템을 대여하거나 반납했을때 아이템의 상태를 '보관중', '대여중'으로 상태 추적을 위해 정의했습니다.
Status 컬럼은 해당 대여내역이 '대여'인지, '반납'인지 여부를 관리하기 위해 동작하도록 정의했습니다.
is_overdue 컬럼은 만약 해당 대여내역이 가지고 있는 due_date 가 현재보다 지나, 연체가 된 상황일 경우 true가 되는 컬럼으로 해당 대여내역이 연체된 건인지, 아닌 건인지 판단하기 위해 사용됩니다.
📸 스크린샷(선택)
📣 To Reviewers
Summary by CodeRabbit
릴리스 노트
New Features
Bug Fixes