ApiException → 글로벌 핸들러 처리list)public Page<TaskResponse> list(String scope, TaskStatus status, Long userId, int page, int size) {
if (userId == null) throw new ApiException(ErrorCode.UNAUTHORIZED, "로그인이 필요합니다.");
if (scope == null || scope.isBlank()) scope = "all";
Pageable pageable = PageRequest.of(
Math.max(page, 0),
Math.min(Math.max(size, 1), 100),
Sort.by(Sort.Direction.DESC, "createdAt")
);
UserEntity me = userRepository.findById(userId)
.orElseThrow(() -> new ApiException(ErrorCode.UNAUTHORIZED, "사용자가 존재하지 않습니다."));
Long myDeptId = me.getDepartment().getId();
Page<TaskEntity> result;
switch (scope) {
case "all" -> result = (status == null)
? taskRepository.findAllVisibleForUser(userId, myDeptId, pageable)
: taskRepository.findAllVisibleForUserByStatus(userId, myDeptId, status, pageable);
case "public" -> result = (status == null)
? taskRepository.findPublicOnly(pageable)
: taskRepository.findPublicOnlyByStatus(status, pageable);
case "team" -> result = (status == null)
? taskRepository.findTeamVisibleForUser(userId, myDeptId, pageable)
: taskRepository.findTeamVisibleForUserByStatus(userId, myDeptId, status, pageable);
case "created" -> result = (status == null)
? taskRepository.findByIsDeletedFalseAndCreatedBy_Id(userId, pageable)
: taskRepository.findByIsDeletedFalseAndCreatedBy_IdAndStatus(userId, status, pageable);
case "assigned" -> result = (status == null)
? taskRepository.findByIsDeletedFalseAndAssignee_Id(userId, pageable)
: taskRepository.findByIsDeletedFalseAndAssignee_IdAndStatus(userId, status, pageable);
default -> throw new ApiException(ErrorCode.BAD_REQUEST, "scope 값이 올바르지 않습니다. (all|public|team|created|assigned)");
}
return result.map(t -> {
long cnt = attachmentService.countActiveByTask(t.getId());
return TaskResponse.from(t, cnt);
});
}
설명 + 포인트
401 UNAUTHORIZEDall400 BAD_REQUEST보안/최적화 포인트
흐름도