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 @@ -226,6 +226,9 @@ public GetRecentUploadTodoResponse getRecentUploadTodo(long userId, long targetI
String redisKey = REDIS_KEY_PREFIX + userId;
String seenValue = (String) redisTemplate.opsForHash().get(redisKey, String.valueOf(targetId));

User target = userRepository.findById(targetId)
.orElseThrow(() -> new UserException(NOT_FOUND_USER));

//target의 최근 24시간 내 등록된 할 일(오래된 순) 조회
List<Todo> recentTodos = todoRepository.findAllRecentTodosByUserId(
targetId, now().minusHours(24), TodoStatus.GIVEN_UP
Expand All @@ -246,20 +249,20 @@ targetId, now().minusHours(24), TodoStatus.GIVEN_UP
if (latestIndex == -1 || latestIndex == recentTodos.size() - 1){
Todo first = recentTodos.get(0);
if (latestIndex == -1) redisTemplate.opsForHash().put(redisKey, String.valueOf(targetId), String.valueOf(first.getId()));
return GetRecentUploadTodoResponse.from(now(), first, null, getNextId(recentTodos, 0), recentTodos.size(), awsS3Service);
return GetRecentUploadTodoResponse.from(now(), target.getProfileImageKey(), first, null, getNextId(recentTodos, 0), recentTodos.size(), awsS3Service);
}
//유효한 본 이력이고 아직 가장 최신 할 일을 조회하지 않은 경우
else {
Todo next = recentTodos.get(latestIndex + 1);
redisTemplate.opsForHash().put(redisKey, String.valueOf(targetId), String.valueOf(next.getId()));
return GetRecentUploadTodoResponse.from(now(), next, recentTodos.get(latestIndex).getId(), getNextId(recentTodos, latestIndex + 1), recentTodos.size(), awsS3Service);
return GetRecentUploadTodoResponse.from(now(), target.getProfileImageKey(), next, recentTodos.get(latestIndex).getId(), getNextId(recentTodos, latestIndex + 1), recentTodos.size(), awsS3Service);
}
}
//Redis 에 이 전에 본 이력이 없는 경우
else {
Todo first = recentTodos.get(0);
redisTemplate.opsForHash().put(redisKey, String.valueOf(targetId), String.valueOf(first.getId()));
return GetRecentUploadTodoResponse.from(now(), first, null, getNextId(recentTodos, 0), recentTodos.size(), awsS3Service);
return GetRecentUploadTodoResponse.from(now(), target.getProfileImageKey(), first, null, getNextId(recentTodos, 0), recentTodos.size(), awsS3Service);

}
}
Expand All @@ -274,9 +277,6 @@ targetId, now().minusHours(24), TodoStatus.GIVEN_UP
throw new TodoException(TodoErrorCode.NOT_FOUND_TODO);
}

User target = userRepository.findById(targetId)
.orElseThrow(() -> new UserException(NOT_FOUND_USER));

if(!Objects.equals(recentTodos.get(currentIndex).getUser(), target)) {
throw new TodoException(NOT_TARGET_TODO);
}
Expand All @@ -289,7 +289,7 @@ targetId, now().minusHours(24), TodoStatus.GIVEN_UP

Long prevId = currentIndex > 0 ? recentTodos.get(currentIndex - 1).getId() : null;
Long nextId = getNextId(recentTodos, currentIndex);
return GetRecentUploadTodoResponse.from(now(), recentTodos.get(currentIndex), prevId, nextId, recentTodos.size(), awsS3Service);
return GetRecentUploadTodoResponse.from(now(), target.getProfileImageKey() ,recentTodos.get(currentIndex), prevId, nextId, recentTodos.size(), awsS3Service);
}

private Long getNextId(List<Todo> todos, int index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

public record GetRecentUploadTodoResponse(
String title,
String profileImage,
String startImage,
String endImage,
LocalTime challengeTime,
Expand All @@ -19,9 +20,10 @@ public record GetRecentUploadTodoResponse(
Long prevId,
int totalCount
) {
public static GetRecentUploadTodoResponse from(LocalDateTime now, Todo todo, Long prevId, Long nextId, int totalCount, AwsS3Service awsS3Service) {
public static GetRecentUploadTodoResponse from(LocalDateTime now,String profileImage, Todo todo, Long prevId, Long nextId, int totalCount, AwsS3Service awsS3Service) {
return new GetRecentUploadTodoResponse(
todo.getTitle(),
awsS3Service.generateGetPresignedUrl(profileImage),
awsS3Service.generateGetPresignedUrl(todo.getStartImage()),
awsS3Service.generateGetPresignedUrl(todo.getEndImage()),
todo.getChallengeTime(),
Expand Down