diff --git a/src/main/java/com/stempo/api/domain/application/service/AchievementService.java b/src/main/java/com/stempo/api/domain/application/service/AchievementService.java index 7cd984b..01dbbbd 100644 --- a/src/main/java/com/stempo/api/domain/application/service/AchievementService.java +++ b/src/main/java/com/stempo/api/domain/application/service/AchievementService.java @@ -3,14 +3,14 @@ import com.stempo.api.domain.presentation.dto.request.AchievementRequestDto; import com.stempo.api.domain.presentation.dto.request.AchievementUpdateRequestDto; import com.stempo.api.domain.presentation.dto.response.AchievementResponseDto; - -import java.util.List; +import com.stempo.api.global.common.dto.PagedResponseDto; +import org.springframework.data.domain.Pageable; public interface AchievementService { Long registerAchievement(AchievementRequestDto requestDto); - List getAchievements(); + PagedResponseDto getAchievements(Pageable pageable); Long updateAchievement(Long achievementId, AchievementUpdateRequestDto requestDto); diff --git a/src/main/java/com/stempo/api/domain/application/service/AchievementServiceImpl.java b/src/main/java/com/stempo/api/domain/application/service/AchievementServiceImpl.java index 209c4f2..88181d4 100644 --- a/src/main/java/com/stempo/api/domain/application/service/AchievementServiceImpl.java +++ b/src/main/java/com/stempo/api/domain/application/service/AchievementServiceImpl.java @@ -7,12 +7,13 @@ import com.stempo.api.domain.presentation.dto.request.AchievementRequestDto; import com.stempo.api.domain.presentation.dto.request.AchievementUpdateRequestDto; import com.stempo.api.domain.presentation.dto.response.AchievementResponseDto; +import com.stempo.api.global.common.dto.PagedResponseDto; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import java.util.List; - @Service @RequiredArgsConstructor public class AchievementServiceImpl implements AchievementService { @@ -27,11 +28,9 @@ public Long registerAchievement(AchievementRequestDto requestDto) { } @Override - public List getAchievements() { - List achievements = repository.findAll(); - return achievements.stream() - .map(AchievementResponseDto::toDto) - .toList(); + public PagedResponseDto getAchievements(Pageable pageable) { + Page achievements = repository.findAll(pageable); + return new PagedResponseDto<>(achievements.map(AchievementResponseDto::toDto)); } @Override diff --git a/src/main/java/com/stempo/api/domain/application/service/ArticleService.java b/src/main/java/com/stempo/api/domain/application/service/ArticleService.java index a9cb916..c3487f8 100644 --- a/src/main/java/com/stempo/api/domain/application/service/ArticleService.java +++ b/src/main/java/com/stempo/api/domain/application/service/ArticleService.java @@ -4,14 +4,14 @@ import com.stempo.api.domain.presentation.dto.request.ArticleUpdateRequestDto; import com.stempo.api.domain.presentation.dto.response.ArticleDetailsResponseDto; import com.stempo.api.domain.presentation.dto.response.ArticleResponseDto; - -import java.util.List; +import com.stempo.api.global.common.dto.PagedResponseDto; +import org.springframework.data.domain.Pageable; public interface ArticleService { Long registerArticle(ArticleRequestDto requestDto); - List getArticles(); + PagedResponseDto getArticles(Pageable pageable); ArticleDetailsResponseDto getArticle(Long articleId); diff --git a/src/main/java/com/stempo/api/domain/application/service/ArticleServiceImpl.java b/src/main/java/com/stempo/api/domain/application/service/ArticleServiceImpl.java index 7b44d37..93fbd22 100644 --- a/src/main/java/com/stempo/api/domain/application/service/ArticleServiceImpl.java +++ b/src/main/java/com/stempo/api/domain/application/service/ArticleServiceImpl.java @@ -6,11 +6,12 @@ import com.stempo.api.domain.presentation.dto.request.ArticleUpdateRequestDto; import com.stempo.api.domain.presentation.dto.response.ArticleDetailsResponseDto; import com.stempo.api.domain.presentation.dto.response.ArticleResponseDto; +import com.stempo.api.global.common.dto.PagedResponseDto; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import java.util.List; - @Service @RequiredArgsConstructor public class ArticleServiceImpl implements ArticleService { @@ -24,11 +25,9 @@ public Long registerArticle(ArticleRequestDto requestDto) { } @Override - public List getArticles() { - List
articles = repository.findAll(); - return articles.stream() - .map(ArticleResponseDto::toDto) - .toList(); + public PagedResponseDto getArticles(Pageable pageable) { + Page
articles = repository.findAll(pageable); + return new PagedResponseDto<>(articles.map(ArticleResponseDto::toDto)); } @Override diff --git a/src/main/java/com/stempo/api/domain/application/service/BoardService.java b/src/main/java/com/stempo/api/domain/application/service/BoardService.java index 679f794..4c2ba6c 100644 --- a/src/main/java/com/stempo/api/domain/application/service/BoardService.java +++ b/src/main/java/com/stempo/api/domain/application/service/BoardService.java @@ -4,14 +4,14 @@ import com.stempo.api.domain.presentation.dto.request.BoardRequestDto; import com.stempo.api.domain.presentation.dto.request.BoardUpdateRequestDto; import com.stempo.api.domain.presentation.dto.response.BoardResponseDto; - -import java.util.List; +import com.stempo.api.global.common.dto.PagedResponseDto; +import org.springframework.data.domain.Pageable; public interface BoardService { - + Long registerBoard(BoardRequestDto requestDto); - List getBoardsByCategory(BoardCategory category); + PagedResponseDto getBoardsByCategory(BoardCategory category, Pageable pageable); Long updateBoard(Long boardId, BoardUpdateRequestDto requestDto); diff --git a/src/main/java/com/stempo/api/domain/application/service/BoardServiceImpl.java b/src/main/java/com/stempo/api/domain/application/service/BoardServiceImpl.java index b4703b6..9d0d9d0 100644 --- a/src/main/java/com/stempo/api/domain/application/service/BoardServiceImpl.java +++ b/src/main/java/com/stempo/api/domain/application/service/BoardServiceImpl.java @@ -7,12 +7,13 @@ import com.stempo.api.domain.presentation.dto.request.BoardRequestDto; import com.stempo.api.domain.presentation.dto.request.BoardUpdateRequestDto; import com.stempo.api.domain.presentation.dto.response.BoardResponseDto; +import com.stempo.api.global.common.dto.PagedResponseDto; import com.stempo.api.global.exception.PermissionDeniedException; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import java.util.List; - @Service @RequiredArgsConstructor public class BoardServiceImpl implements BoardService { @@ -29,12 +30,10 @@ public Long registerBoard(BoardRequestDto requestDto) { } @Override - public List getBoardsByCategory(BoardCategory category) { + public PagedResponseDto getBoardsByCategory(BoardCategory category, Pageable pageable) { validateAccessPermissionForSuggestion(category); - List boards = repository.findByCategory(category); - return boards.stream() - .map(BoardResponseDto::toDto) - .toList(); + Page boards = repository.findByCategory(category, pageable); + return new PagedResponseDto<>(boards.map(BoardResponseDto::toDto)); } @Override diff --git a/src/main/java/com/stempo/api/domain/application/service/UserAchievementService.java b/src/main/java/com/stempo/api/domain/application/service/UserAchievementService.java index ed19684..33ac3a0 100644 --- a/src/main/java/com/stempo/api/domain/application/service/UserAchievementService.java +++ b/src/main/java/com/stempo/api/domain/application/service/UserAchievementService.java @@ -1,12 +1,12 @@ package com.stempo.api.domain.application.service; import com.stempo.api.domain.presentation.dto.response.UserAchievementResponseDto; - -import java.util.List; +import com.stempo.api.global.common.dto.PagedResponseDto; +import org.springframework.data.domain.Pageable; public interface UserAchievementService { Long registerUserAchievement(Long achievementId); - List getUserAchievements(); + PagedResponseDto getUserAchievements(Pageable pageable); } diff --git a/src/main/java/com/stempo/api/domain/application/service/UserAchievementServiceImpl.java b/src/main/java/com/stempo/api/domain/application/service/UserAchievementServiceImpl.java index 6e9670a..c4e480b 100644 --- a/src/main/java/com/stempo/api/domain/application/service/UserAchievementServiceImpl.java +++ b/src/main/java/com/stempo/api/domain/application/service/UserAchievementServiceImpl.java @@ -4,12 +4,16 @@ import com.stempo.api.domain.domain.model.UserAchievement; import com.stempo.api.domain.domain.repository.AchievementRepository; import com.stempo.api.domain.domain.repository.UserAchievementRepository; -import com.stempo.api.domain.persistence.entity.UserAchievementEntity; import com.stempo.api.domain.presentation.dto.response.UserAchievementResponseDto; +import com.stempo.api.global.common.dto.PagedResponseDto; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Objects; import java.util.Optional; @Service @@ -23,7 +27,8 @@ public class UserAchievementServiceImpl implements UserAchievementService { @Override public Long registerUserAchievement(Long achievementId) { String deviceTag = userService.getCurrentDeviceTag(); - Optional existingUserAchievement = userAchievementRepository.findByDeviceTagAndAchievementId(deviceTag, achievementId); + Optional existingUserAchievement = + userAchievementRepository.findByDeviceTagAndAchievementId(deviceTag, achievementId); if (existingUserAchievement.isPresent()) { return existingUserAchievement.get().getId(); @@ -34,16 +39,20 @@ public Long registerUserAchievement(Long achievementId) { } @Override - public List getUserAchievements() { + public PagedResponseDto getUserAchievements(Pageable pageable) { String deviceTag = userService.getCurrentDeviceTag(); - List userAchievements = userAchievementRepository.findByDeviceTag(deviceTag); - return userAchievements.stream() - .map(this::getUserAchievementResponseDto) - .toList(); + Page achievements = achievementRepository.findAll(pageable); + List userAchievementDtos = getUserAchievementResponseDtos(achievements, deviceTag); + return new PagedResponseDto<>(new PageImpl<>(userAchievementDtos, pageable, userAchievementDtos.size())); } - private UserAchievementResponseDto getUserAchievementResponseDto(UserAchievementEntity ua) { - Achievement achievement = achievementRepository.findByIdOrThrow(ua.getAchievementId()); - return UserAchievementResponseDto.toDto(achievement); + private List getUserAchievementResponseDtos(Page achievements, String deviceTag) { + return achievements.stream() + .map(achievement -> userAchievementRepository.findByDeviceTagAndAchievementId(deviceTag, achievement.getId()) + .map(userAchievement -> UserAchievementResponseDto.toDto(achievement, userAchievement.getCreatedAt())) + .orElse(null) + ) + .filter(Objects::nonNull) + .toList(); } } diff --git a/src/main/java/com/stempo/api/domain/application/service/VideoService.java b/src/main/java/com/stempo/api/domain/application/service/VideoService.java index 74d6f1f..f8fb399 100644 --- a/src/main/java/com/stempo/api/domain/application/service/VideoService.java +++ b/src/main/java/com/stempo/api/domain/application/service/VideoService.java @@ -4,14 +4,14 @@ import com.stempo.api.domain.presentation.dto.request.VideoUpdateRequestDto; import com.stempo.api.domain.presentation.dto.response.VideoDetailsResponseDto; import com.stempo.api.domain.presentation.dto.response.VideoResponseDto; - -import java.util.List; +import com.stempo.api.global.common.dto.PagedResponseDto; +import org.springframework.data.domain.Pageable; public interface VideoService { Long registerVideo(VideoRequestDto requestDto); - List getVideos(); + PagedResponseDto getVideos(Pageable pageable); VideoDetailsResponseDto getVideo(Long videoId); diff --git a/src/main/java/com/stempo/api/domain/application/service/VideoServiceImpl.java b/src/main/java/com/stempo/api/domain/application/service/VideoServiceImpl.java index f85dc54..e564a70 100644 --- a/src/main/java/com/stempo/api/domain/application/service/VideoServiceImpl.java +++ b/src/main/java/com/stempo/api/domain/application/service/VideoServiceImpl.java @@ -6,11 +6,12 @@ import com.stempo.api.domain.presentation.dto.request.VideoUpdateRequestDto; import com.stempo.api.domain.presentation.dto.response.VideoDetailsResponseDto; import com.stempo.api.domain.presentation.dto.response.VideoResponseDto; +import com.stempo.api.global.common.dto.PagedResponseDto; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import java.util.List; - @Service @RequiredArgsConstructor public class VideoServiceImpl implements VideoService { @@ -24,11 +25,9 @@ public Long registerVideo(VideoRequestDto requestDto) { } @Override - public List getVideos() { - List