Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -9,6 +9,7 @@
import com.pinback.api.user.dto.request.UpdateUserJobRequest;
import com.pinback.application.user.dto.response.UserHasJobInfoResponse;
import com.pinback.application.user.dto.response.UserJobInfoResponse;
import com.pinback.application.user.dto.response.UserPropertyResponse;
import com.pinback.application.user.port.in.UserManagementPort;
import com.pinback.domain.user.entity.User;
import com.pinback.shared.annotation.CurrentUser;
Expand Down Expand Up @@ -42,4 +43,12 @@ public ResponseDto<UserHasJobInfoResponse> getUserJob(
UserHasJobInfoResponse response = userManagementPort.getUserJobInfo(user);
return ResponseDto.ok(response);
}

@GetMapping("/properties")
public ResponseDto<UserPropertyResponse> getUserProperty(
@Parameter(hidden = true) @CurrentUser User user
) {
UserPropertyResponse response = userManagementPort.getUserProperty(user);
return ResponseDto.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ public Mono<GoogleLoginResponseV3> getInfoAndTokenV3(String email, String pictur

saveRefreshTokenToRedis(updatedUser.getId(), refreshToken);

String jobRole = updatedUser.hasJob() ? updatedUser.getJob().getValue() : null;

return Mono.just(GoogleLoginResponseV3.loggedIn(
updatedUser.hasJob(), updatedUser.getId(), updatedUser.getEmail(), accessToken,
updatedUser.hasJob(), jobRole, updatedUser.getId(), updatedUser.getEmail(), accessToken,
refreshToken
));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
public record GoogleLoginResponseV3(
boolean isUser,
boolean hasJob,
String jobRole,
UUID userId,
String email,
String accessToken,
String refreshToken
) {
public static GoogleLoginResponseV3 loggedIn(boolean hasJob, UUID userId, String email, String accessToken,
public static GoogleLoginResponseV3 loggedIn(boolean hasJob, String jobRole, UUID userId, String email,
String accessToken,
String refreshToken) {
return new GoogleLoginResponseV3(true, hasJob, userId, email, accessToken, refreshToken);
return new GoogleLoginResponseV3(true, hasJob, jobRole, userId, email, accessToken, refreshToken);
}

public static GoogleLoginResponseV3 tempLogin(UUID userId, String email) {
return new GoogleLoginResponseV3(false, false, userId, email, null, null);
return new GoogleLoginResponseV3(false, false, null, userId, email, null, null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.pinback.application.user.dto.response;

import java.util.UUID;

public record UserPropertyResponse(
UUID userId,
String jobRole
) {
public static UserPropertyResponse of(UUID id, String jobRole) {
return new UserPropertyResponse(id, jobRole);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.pinback.application.user.dto.response.UserInfoResponse;
import com.pinback.application.user.dto.response.UserJobInfoResponse;
import com.pinback.application.user.dto.response.UserProfileInfoResponse;
import com.pinback.application.user.dto.response.UserPropertyResponse;
import com.pinback.application.user.dto.response.UserRemindInfoResponse;
import com.pinback.domain.user.entity.User;

Expand All @@ -24,4 +25,6 @@ public interface UserManagementPort {
UserJobInfoResponse updateUserJobInfo(User user, UpdateUserJobCommand command);

UserHasJobInfoResponse getUserJobInfo(User user);

UserPropertyResponse getUserProperty(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.pinback.application.user.dto.response.UserInfoResponse;
import com.pinback.application.user.dto.response.UserJobInfoResponse;
import com.pinback.application.user.dto.response.UserProfileInfoResponse;
import com.pinback.application.user.dto.response.UserPropertyResponse;
import com.pinback.application.user.dto.response.UserRemindInfoResponse;
import com.pinback.application.user.port.in.UserManagementPort;
import com.pinback.application.user.port.out.AcornServicePort;
Expand Down Expand Up @@ -96,6 +97,14 @@ public UserHasJobInfoResponse getUserJobInfo(User user) {

}

@Override
@Transactional(readOnly = true)
public UserPropertyResponse getUserProperty(User user) {
User getUser = userGetServicePort.findById(user.getId());

return UserPropertyResponse.of(getUser.getId(), getUser.getJob().getValue());
}
Comment on lines +100 to +106
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check how other methods handle potentially null job field
rg -n -A3 -B3 'getJob\(\)' --type=java

# Check the hasJob() method implementation
ast-grep --pattern $'public boolean hasJob() {
  $$$
}'

Repository: Pinback-Team/pinback-server

Length of output: 6183


Potential NullPointerException when user has no job set.

The job field is nullable (confirmed by the hasJob() method in User.java). Calling getUser.getJob().getValue() on line 105 will throw a NullPointerException for users who haven't set their job role.

Other query methods in the codebase handle this consistently: AuthUsecase.java (line 170) uses updatedUser.hasJob() ? updatedUser.getJob().getValue() : null, and GetSharedArticleUsecase.java (line 30) explicitly checks if (user.getJob() == null) before access.

Proposed fix with null-safe handling
 `@Override`
 `@Transactional`(readOnly = true)
 public UserPropertyResponse getUserProperty(User user) {
     User getUser = userGetServicePort.findById(user.getId());
-
-    return UserPropertyResponse.of(getUser.getId(), getUser.getJob().getValue());
+    String jobRole = getUser.getJob() != null ? getUser.getJob().getValue() : null;
+    return UserPropertyResponse.of(getUser.getId(), jobRole);
 }
📝 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.

Suggested change
@Override
@Transactional(readOnly = true)
public UserPropertyResponse getUserProperty(User user) {
User getUser = userGetServicePort.findById(user.getId());
return UserPropertyResponse.of(getUser.getId(), getUser.getJob().getValue());
}
`@Override`
`@Transactional`(readOnly = true)
public UserPropertyResponse getUserProperty(User user) {
User getUser = userGetServicePort.findById(user.getId());
String jobRole = getUser.getJob() != null ? getUser.getJob().getValue() : null;
return UserPropertyResponse.of(getUser.getId(), jobRole);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@application/src/main/java/com/pinback/application/user/usecase/UserManagementUsecase.java`
around lines 100 - 106, getUserProperty in UserManagementUsecase calls
getUser.getJob().getValue() which can NPE when job is null; change this to
obtain the user via userGetServicePort.findById(user.getId()) and pass a
null-safe job value to UserPropertyResponse.of by checking User.hasJob() (or
user.getJob() != null) and using job.getValue() only when present, otherwise
pass null, mirroring the pattern used in AuthUsecase and
GetSharedArticleUsecase.


private LocalDateTime getRemindDateTime(LocalDateTime now, LocalTime remindDefault) {
LocalDateTime remindDate = now.plusDays(1L);

Expand Down
Loading