Skip to content

Commit

Permalink
refactor: modify response field
Browse files Browse the repository at this point in the history
  • Loading branch information
aiaiaiai1 committed Nov 27, 2024
1 parent af7a920 commit 4eaaf2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public WorkoutConfirmationOrObjectionResponse(
this.isObjection = isObjection;
}

public static WorkoutConfirmationOrObjectionResponse workoutConfirmation(User loginedUser, WorkoutHistory workoutHistory, String workoutConfirmationImageUrl) {
public static WorkoutConfirmationOrObjectionResponse workoutConfirmation(User loginedUser, Objection objection, WorkoutHistory workoutHistory, String workoutConfirmationImageUrl) {
User user = workoutHistory.getWorker().getUser();
LocalDateTime createdAt = workoutHistory.getCreatedAt();
return WorkoutConfirmationOrObjectionResponse.builder()
.workoutConfirmationId(workoutHistory.getWorkoutConfirmation().getId())
.objectionId(null)
.objectionId(getObjectId(objection))
.nickname(user.getNickname())
.profileImageUrl(user.getProfileImageName())
.workoutConfirmationImageUrl(workoutConfirmationImageUrl)
Expand All @@ -53,6 +53,13 @@ public static WorkoutConfirmationOrObjectionResponse workoutConfirmation(User lo
.build();
}

private static Long getObjectId(Objection objection) {
if (objection == null) {
return null;
}
return objection.getId();
}

public static WorkoutConfirmationOrObjectionResponse objection(User loginedUser, Objection objection, User objectionTargetUser) {
LocalDateTime createdAt = objection.getCreatedAt();
return WorkoutConfirmationOrObjectionResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public List<WorkoutConfirmationOrObjectionResponse> getWorkoutConfirmations(User
WorkoutHistory workoutHistory = workoutHistoryRepository.getByWorkoutHistoryId(dto.getId());
WorkoutConfirmation workoutConfirmation = workoutHistory.getWorkoutConfirmation();
String imagePresignedUrl = s3Service.getPresignedUrl(ImageUse.WORKOUT_CONFIRMATION, workoutConfirmation.getFilename());
Objection objection = objectionRepository.findByWorkoutConfirmationId(workoutConfirmation.getId()).orElseGet(null);
responses.add(WorkoutConfirmationOrObjectionResponse.workoutConfirmation(loginedUser, workoutHistory, imagePresignedUrl));
}
if (dto.getType().equals("objection")) {
Expand All @@ -188,8 +189,7 @@ public List<WorkoutConfirmationOrObjectionResponse> getWorkoutConfirmations(User
return responses;
}

public WorkoutConfirmationDetailResponse getWorkoutConfirmation(User loginedUser, Long workspaceId, Long
workoutConfirmationId) {
public WorkoutConfirmationDetailResponse getWorkoutConfirmation(User loginedUser, Long workspaceId, Long workoutConfirmationId) {
Workspace workspace = workspaceRepository.getWorkspaceById(workspaceId);
validateIfWorkerIsInWorkspace(loginedUser.getId(), workspace.getId());
WorkoutHistory workoutHistory = workoutHistoryRepository.getByWorkoutConfirmationId(workoutConfirmationId);
Expand Down

0 comments on commit 4eaaf2d

Please sign in to comment.