From 771b9b2b3b533a54473860ac3d18c93aa91bfa04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=9C=EA=B4=80=ED=9D=AC?= <85067003+limehee@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:53:18 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=82=B4=20=EC=9E=AC=ED=99=9C=20?= =?UTF-8?q?=EC=9A=B4=EB=8F=99=20=EA=B8=B0=EB=A1=9D=20=ED=86=B5=EA=B3=84=20?= =?UTF-8?q?API=20=EC=B6=94=EA=B0=80=20=EC=99=84=EB=A3=8C=20(#49)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/AchievementDeletedEvent.java | 15 --- .../event/AchievementEventDispatcher.java | 24 ----- .../event/AchievementEventProcessor.java | 8 -- .../AchievementEventProcessorRegistry.java | 21 ----- .../event/AchievementUpdatedEvent.java | 15 --- .../event/UserAchievementEventProcessor.java | 29 ------ .../service/AchievementService.java | 18 ---- .../service/AchievementServiceImpl.java | 58 ------------ .../application/service/ArticleService.java | 21 ----- .../service/ArticleServiceImpl.java | 58 ------------ .../application/service/BoardService.java | 2 +- .../application/service/BoardServiceImpl.java | 6 +- .../application/service/HomeworkService.java | 2 +- .../service/HomeworkServiceImpl.java | 2 +- .../application/service/RecordService.java | 3 + .../service/RecordServiceImpl.java | 49 ++++++++++ .../service/UserAchievementService.java | 12 --- .../service/UserAchievementServiceImpl.java | 61 ------------ .../application/service/VideoService.java | 21 ----- .../application/service/VideoServiceImpl.java | 58 ------------ .../api/domain/domain/model/Achievement.java | 35 ------- .../api/domain/domain/model/Article.java | 39 -------- .../stempo/api/domain/domain/model/Board.java | 5 - .../domain/domain/model/UserAchievement.java | 35 ------- .../stempo/api/domain/domain/model/Video.java | 39 -------- .../repository/AchievementRepository.java | 14 --- .../domain/repository/ArticleRepository.java | 14 --- .../domain/repository/BoardRepository.java | 2 + .../domain/repository/RecordRepository.java | 4 + .../repository/UserAchievementRepository.java | 17 ---- .../domain/repository/VideoRepository.java | 14 --- .../persistence/entity/AchievementEntity.java | 42 --------- .../persistence/entity/ArticleEntity.java | 46 --------- .../persistence/entity/BoardEntity.java | 3 - .../persistence/entity/RecordEntity.java | 4 +- .../entity/UploadedFileEntity.java | 3 - .../entity/UserAchievementEntity.java | 41 -------- .../domain/persistence/entity/UserEntity.java | 4 - .../persistence/entity/VideoEntity.java | 46 --------- .../mappper/AchievementMapper.java | 29 ------ .../persistence/mappper/ArticleMapper.java | 32 ------- .../persistence/mappper/BoardMapper.java | 2 - .../mappper/UserAchievementMapper.java | 28 ------ .../persistence/mappper/VideoMapper.java | 32 ------- .../repository/AchievementJpaRepository.java | 23 ----- .../repository/AchievementRepositoryImpl.java | 40 -------- .../repository/ArticleJpaRepository.java | 22 ----- .../repository/ArticleRepositoryImpl.java | 40 -------- .../repository/BoardJpaRepository.java | 12 --- .../repository/BoardRepositoryImpl.java | 8 +- .../repository/RecordJpaRepository.java | 10 ++ .../repository/RecordRepositoryImpl.java | 10 ++ .../UserAchievementJpaRepository.java | 14 --- .../UserAchievementRepositoryImpl.java | 48 ---------- .../repository/VideoJpaRepository.java | 22 ----- .../repository/VideoRepositoryImpl.java | 39 -------- .../presentation/AchievementController.java | 83 ----------------- .../presentation/ArticleController.java | 93 ------------------- .../domain/presentation/AuthController.java | 2 +- .../domain/presentation/BoardController.java | 4 +- .../domain/presentation/FileController.java | 4 +- .../presentation/HomeworkController.java | 4 +- .../domain/presentation/RecordController.java | 11 ++- .../domain/presentation/RhythmController.java | 2 +- .../UserAchievementController.java | 55 ----------- .../domain/presentation/VideoController.java | 93 ------------------- .../dto/request/AchievementRequestDto.java | 32 ------- .../request/AchievementUpdateRequestDto.java | 19 ---- .../dto/request/ArticleRequestDto.java | 36 ------- .../dto/request/ArticleUpdateRequestDto.java | 22 ----- .../dto/request/VideoRequestDto.java | 36 ------- .../dto/request/VideoUpdateRequestDto.java | 22 ----- .../dto/response/AchievementResponseDto.java | 24 ----- .../response/ArticleDetailsResponseDto.java | 28 ------ .../dto/response/ArticleResponseDto.java | 26 ------ .../response/RecordStatisticsResponseDto.java | 21 +++++ .../response/UserAchievementResponseDto.java | 26 ------ .../dto/response/VideoDetailsResponseDto.java | 28 ------ .../dto/response/VideoResponseDto.java | 26 ------ .../api/global/config/SecurityConfig.java | 4 +- .../global/{common => }/dto/ApiResponse.java | 2 +- .../{common => }/dto/ErrorResponse.java | 2 +- .../{common => }/dto/PagedResponseDto.java | 2 +- .../handler/GlobalExceptionHandler.java | 4 +- .../stempo/api/global/util/ResponseUtil.java | 2 +- src/main/resources/db/data.sql | 59 ------------ 86 files changed, 139 insertions(+), 1934 deletions(-) delete mode 100644 src/main/java/com/stempo/api/domain/application/event/AchievementDeletedEvent.java delete mode 100644 src/main/java/com/stempo/api/domain/application/event/AchievementEventDispatcher.java delete mode 100644 src/main/java/com/stempo/api/domain/application/event/AchievementEventProcessor.java delete mode 100644 src/main/java/com/stempo/api/domain/application/event/AchievementEventProcessorRegistry.java delete mode 100644 src/main/java/com/stempo/api/domain/application/event/AchievementUpdatedEvent.java delete mode 100644 src/main/java/com/stempo/api/domain/application/event/UserAchievementEventProcessor.java delete mode 100644 src/main/java/com/stempo/api/domain/application/service/AchievementService.java delete mode 100644 src/main/java/com/stempo/api/domain/application/service/AchievementServiceImpl.java delete mode 100644 src/main/java/com/stempo/api/domain/application/service/ArticleService.java delete mode 100644 src/main/java/com/stempo/api/domain/application/service/ArticleServiceImpl.java delete mode 100644 src/main/java/com/stempo/api/domain/application/service/UserAchievementService.java delete mode 100644 src/main/java/com/stempo/api/domain/application/service/UserAchievementServiceImpl.java delete mode 100644 src/main/java/com/stempo/api/domain/application/service/VideoService.java delete mode 100644 src/main/java/com/stempo/api/domain/application/service/VideoServiceImpl.java delete mode 100644 src/main/java/com/stempo/api/domain/domain/model/Achievement.java delete mode 100644 src/main/java/com/stempo/api/domain/domain/model/Article.java delete mode 100644 src/main/java/com/stempo/api/domain/domain/model/UserAchievement.java delete mode 100644 src/main/java/com/stempo/api/domain/domain/model/Video.java delete mode 100644 src/main/java/com/stempo/api/domain/domain/repository/AchievementRepository.java delete mode 100644 src/main/java/com/stempo/api/domain/domain/repository/ArticleRepository.java delete mode 100644 src/main/java/com/stempo/api/domain/domain/repository/UserAchievementRepository.java delete mode 100644 src/main/java/com/stempo/api/domain/domain/repository/VideoRepository.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/entity/AchievementEntity.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/entity/ArticleEntity.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/entity/UserAchievementEntity.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/entity/VideoEntity.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/mappper/AchievementMapper.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/mappper/ArticleMapper.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/mappper/UserAchievementMapper.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/mappper/VideoMapper.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/repository/AchievementJpaRepository.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/repository/AchievementRepositoryImpl.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/repository/ArticleJpaRepository.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/repository/ArticleRepositoryImpl.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/repository/UserAchievementJpaRepository.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/repository/UserAchievementRepositoryImpl.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/repository/VideoJpaRepository.java delete mode 100644 src/main/java/com/stempo/api/domain/persistence/repository/VideoRepositoryImpl.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/AchievementController.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/ArticleController.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/UserAchievementController.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/VideoController.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/request/AchievementRequestDto.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/request/AchievementUpdateRequestDto.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/request/ArticleRequestDto.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/request/ArticleUpdateRequestDto.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/request/VideoRequestDto.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/request/VideoUpdateRequestDto.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/response/AchievementResponseDto.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/response/ArticleDetailsResponseDto.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/response/ArticleResponseDto.java create mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/response/RecordStatisticsResponseDto.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/response/UserAchievementResponseDto.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/response/VideoDetailsResponseDto.java delete mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/response/VideoResponseDto.java rename src/main/java/com/stempo/api/global/{common => }/dto/ApiResponse.java (95%) rename src/main/java/com/stempo/api/global/{common => }/dto/ErrorResponse.java (93%) rename src/main/java/com/stempo/api/global/{common => }/dto/PagedResponseDto.java (97%) delete mode 100644 src/main/resources/db/data.sql diff --git a/src/main/java/com/stempo/api/domain/application/event/AchievementDeletedEvent.java b/src/main/java/com/stempo/api/domain/application/event/AchievementDeletedEvent.java deleted file mode 100644 index 415b44b..0000000 --- a/src/main/java/com/stempo/api/domain/application/event/AchievementDeletedEvent.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.stempo.api.domain.application.event; - -import lombok.Getter; -import org.springframework.context.ApplicationEvent; - -@Getter -public class AchievementDeletedEvent extends ApplicationEvent { - - private final Long achievementId; - - public AchievementDeletedEvent(Object source, Long achievementId) { - super(source); - this.achievementId = achievementId; - } -} diff --git a/src/main/java/com/stempo/api/domain/application/event/AchievementEventDispatcher.java b/src/main/java/com/stempo/api/domain/application/event/AchievementEventDispatcher.java deleted file mode 100644 index 941bd45..0000000 --- a/src/main/java/com/stempo/api/domain/application/event/AchievementEventDispatcher.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.stempo.api.domain.application.event; - -import lombok.RequiredArgsConstructor; -import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Component -@RequiredArgsConstructor -public class AchievementEventDispatcher { - - private final List processors; - - @EventListener - public void handleAchievementDeletedEvent(AchievementDeletedEvent event) { - processors.forEach(processor -> processor.processAchievementDeleted(event.getAchievementId())); - } - - @EventListener - public void handleAchievementUpdatedEvent(AchievementUpdatedEvent event) { - processors.forEach(processor -> processor.processAchievementUpdated(event.getAchievementId())); - } -} diff --git a/src/main/java/com/stempo/api/domain/application/event/AchievementEventProcessor.java b/src/main/java/com/stempo/api/domain/application/event/AchievementEventProcessor.java deleted file mode 100644 index 487e659..0000000 --- a/src/main/java/com/stempo/api/domain/application/event/AchievementEventProcessor.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.stempo.api.domain.application.event; - -public interface AchievementEventProcessor { - - void processAchievementDeleted(Long achievementId); - - void processAchievementUpdated(Long achievementId); -} diff --git a/src/main/java/com/stempo/api/domain/application/event/AchievementEventProcessorRegistry.java b/src/main/java/com/stempo/api/domain/application/event/AchievementEventProcessorRegistry.java deleted file mode 100644 index eda0b45..0000000 --- a/src/main/java/com/stempo/api/domain/application/event/AchievementEventProcessorRegistry.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.stempo.api.domain.application.event; - -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -@Component -public class AchievementEventProcessorRegistry { - - private final List processors = new ArrayList<>(); - - public void register(AchievementEventProcessor processor) { - processors.add(processor); - } - - public List getProcessors() { - return Collections.unmodifiableList(processors); - } -} diff --git a/src/main/java/com/stempo/api/domain/application/event/AchievementUpdatedEvent.java b/src/main/java/com/stempo/api/domain/application/event/AchievementUpdatedEvent.java deleted file mode 100644 index 81da03e..0000000 --- a/src/main/java/com/stempo/api/domain/application/event/AchievementUpdatedEvent.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.stempo.api.domain.application.event; - -import lombok.Getter; -import org.springframework.context.ApplicationEvent; - -@Getter -public class AchievementUpdatedEvent extends ApplicationEvent { - - private final Long achievementId; - - public AchievementUpdatedEvent(Object source, Long achievementId) { - super(source); - this.achievementId = achievementId; - } -} diff --git a/src/main/java/com/stempo/api/domain/application/event/UserAchievementEventProcessor.java b/src/main/java/com/stempo/api/domain/application/event/UserAchievementEventProcessor.java deleted file mode 100644 index fa93b30..0000000 --- a/src/main/java/com/stempo/api/domain/application/event/UserAchievementEventProcessor.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.stempo.api.domain.application.event; - -import com.stempo.api.domain.domain.model.UserAchievement; -import com.stempo.api.domain.domain.repository.UserAchievementRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Component -@RequiredArgsConstructor -public class UserAchievementEventProcessor implements AchievementEventProcessor { - - private final UserAchievementRepository userAchievementRepository; - - @Override - @Transactional - public void processAchievementDeleted(Long achievementId) { - List achievements = userAchievementRepository.findByAchievementId(achievementId); - achievements.forEach(UserAchievement::delete); - userAchievementRepository.saveAll(achievements); - } - - @Override - public void processAchievementUpdated(Long achievementId) { - // do nothing - } -} 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 deleted file mode 100644 index 01dbbbd..0000000 --- a/src/main/java/com/stempo/api/domain/application/service/AchievementService.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.stempo.api.domain.application.service; - -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 org.springframework.data.domain.Pageable; - -public interface AchievementService { - - Long registerAchievement(AchievementRequestDto requestDto); - - PagedResponseDto getAchievements(Pageable pageable); - - Long updateAchievement(Long achievementId, AchievementUpdateRequestDto requestDto); - - Long deleteAchievement(Long achievementId); -} 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 deleted file mode 100644 index 3201b3e..0000000 --- a/src/main/java/com/stempo/api/domain/application/service/AchievementServiceImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.stempo.api.domain.application.service; - -import com.stempo.api.domain.application.event.AchievementDeletedEvent; -import com.stempo.api.domain.application.event.AchievementUpdatedEvent; -import com.stempo.api.domain.domain.model.Achievement; -import com.stempo.api.domain.domain.repository.AchievementRepository; -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 org.springframework.transaction.annotation.Transactional; - -@Service -@RequiredArgsConstructor -public class AchievementServiceImpl implements AchievementService { - - private final AchievementRepository repository; - private final ApplicationEventPublisher eventPublisher; - - @Override - @Transactional - public Long registerAchievement(AchievementRequestDto requestDto) { - Achievement achievement = AchievementRequestDto.toDomain(requestDto); - return repository.save(achievement).getId(); - } - - @Override - @Transactional(readOnly = true) - public PagedResponseDto getAchievements(Pageable pageable) { - Page achievements = repository.findAll(pageable); - return new PagedResponseDto<>(achievements.map(AchievementResponseDto::toDto)); - } - - @Override - @Transactional - public Long updateAchievement(Long achievementId, AchievementUpdateRequestDto requestDto) { - Achievement achievement = repository.findByIdOrThrow(achievementId); - achievement.update(requestDto); - repository.save(achievement); - eventPublisher.publishEvent(new AchievementUpdatedEvent(this, achievement.getId())); - return achievement.getId(); - } - - @Override - @Transactional - public Long deleteAchievement(Long achievementId) { - Achievement achievement = repository.findByIdOrThrow(achievementId); - achievement.delete(); - repository.save(achievement); - eventPublisher.publishEvent(new AchievementDeletedEvent(this, achievement.getId())); - return achievement.getId(); - } -} 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 deleted file mode 100644 index c3487f8..0000000 --- a/src/main/java/com/stempo/api/domain/application/service/ArticleService.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.stempo.api.domain.application.service; - -import com.stempo.api.domain.presentation.dto.request.ArticleRequestDto; -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 org.springframework.data.domain.Pageable; - -public interface ArticleService { - - Long registerArticle(ArticleRequestDto requestDto); - - PagedResponseDto getArticles(Pageable pageable); - - ArticleDetailsResponseDto getArticle(Long articleId); - - Long updateArticle(Long articleId, ArticleUpdateRequestDto requestDto); - - Long deleteArticle(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 deleted file mode 100644 index 5f9d390..0000000 --- a/src/main/java/com/stempo/api/domain/application/service/ArticleServiceImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.stempo.api.domain.application.service; - -import com.stempo.api.domain.domain.model.Article; -import com.stempo.api.domain.domain.repository.ArticleRepository; -import com.stempo.api.domain.presentation.dto.request.ArticleRequestDto; -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 org.springframework.transaction.annotation.Transactional; - -@Service -@RequiredArgsConstructor -public class ArticleServiceImpl implements ArticleService { - - private final ArticleRepository repository; - - @Override - @Transactional - public Long registerArticle(ArticleRequestDto requestDto) { - Article article = ArticleRequestDto.toDomain(requestDto); - return repository.save(article).getId(); - } - - @Override - @Transactional(readOnly = true) - public PagedResponseDto getArticles(Pageable pageable) { - Page
articles = repository.findAll(pageable); - return new PagedResponseDto<>(articles.map(ArticleResponseDto::toDto)); - } - - @Override - @Transactional(readOnly = true) - public ArticleDetailsResponseDto getArticle(Long articleId) { - Article article = repository.findByIdOrThrow(articleId); - return ArticleDetailsResponseDto.toDto(article); - } - - @Override - @Transactional - public Long updateArticle(Long articleId, ArticleUpdateRequestDto requestDto) { - Article article = repository.findByIdOrThrow(articleId); - article.update(requestDto); - return repository.save(article).getId(); - } - - @Override - @Transactional - public Long deleteArticle(Long articleId) { - Article article = repository.findByIdOrThrow(articleId); - article.delete(); - return repository.save(article).getId(); - } -} 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 4c2ba6c..98a964b 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,7 +4,7 @@ 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.dto.PagedResponseDto; import org.springframework.data.domain.Pageable; public interface BoardService { 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 6b7981d..c2eb179 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,7 +7,7 @@ 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.dto.PagedResponseDto; import com.stempo.api.global.exception.PermissionDeniedException; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -55,8 +55,8 @@ public Long deleteBoard(Long boardId) { User user = userService.getCurrentUser(); Board board = repository.findByIdOrThrow(boardId); board.validateAccessPermission(user); - board.delete(); - return repository.save(board).getId(); + repository.delete(board); + return board.getId(); } private void validateAccessPermissionForSuggestion(BoardCategory category) { diff --git a/src/main/java/com/stempo/api/domain/application/service/HomeworkService.java b/src/main/java/com/stempo/api/domain/application/service/HomeworkService.java index d1cba45..d54489a 100644 --- a/src/main/java/com/stempo/api/domain/application/service/HomeworkService.java +++ b/src/main/java/com/stempo/api/domain/application/service/HomeworkService.java @@ -3,7 +3,7 @@ import com.stempo.api.domain.presentation.dto.request.HomeworkRequestDto; import com.stempo.api.domain.presentation.dto.request.HomeworkUpdateRequestDto; import com.stempo.api.domain.presentation.dto.response.HomeworkResponseDto; -import com.stempo.api.global.common.dto.PagedResponseDto; +import com.stempo.api.global.dto.PagedResponseDto; import org.springframework.data.domain.Pageable; public interface HomeworkService { diff --git a/src/main/java/com/stempo/api/domain/application/service/HomeworkServiceImpl.java b/src/main/java/com/stempo/api/domain/application/service/HomeworkServiceImpl.java index fce2157..7a1de4b 100644 --- a/src/main/java/com/stempo/api/domain/application/service/HomeworkServiceImpl.java +++ b/src/main/java/com/stempo/api/domain/application/service/HomeworkServiceImpl.java @@ -5,7 +5,7 @@ import com.stempo.api.domain.presentation.dto.request.HomeworkRequestDto; import com.stempo.api.domain.presentation.dto.request.HomeworkUpdateRequestDto; import com.stempo.api.domain.presentation.dto.response.HomeworkResponseDto; -import com.stempo.api.global.common.dto.PagedResponseDto; +import com.stempo.api.global.dto.PagedResponseDto; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; diff --git a/src/main/java/com/stempo/api/domain/application/service/RecordService.java b/src/main/java/com/stempo/api/domain/application/service/RecordService.java index a3adfb9..e12f1dd 100644 --- a/src/main/java/com/stempo/api/domain/application/service/RecordService.java +++ b/src/main/java/com/stempo/api/domain/application/service/RecordService.java @@ -2,6 +2,7 @@ import com.stempo.api.domain.presentation.dto.request.RecordRequestDto; import com.stempo.api.domain.presentation.dto.response.RecordResponseDto; +import com.stempo.api.domain.presentation.dto.response.RecordStatisticsResponseDto; import java.time.LocalDate; import java.util.List; @@ -11,4 +12,6 @@ public interface RecordService { String record(RecordRequestDto requestDto); List getRecordsByDateRange(LocalDate startDate, LocalDate endDate); + + RecordStatisticsResponseDto getRecordStatistics(); } diff --git a/src/main/java/com/stempo/api/domain/application/service/RecordServiceImpl.java b/src/main/java/com/stempo/api/domain/application/service/RecordServiceImpl.java index a584e41..82b091e 100644 --- a/src/main/java/com/stempo/api/domain/application/service/RecordServiceImpl.java +++ b/src/main/java/com/stempo/api/domain/application/service/RecordServiceImpl.java @@ -4,12 +4,15 @@ import com.stempo.api.domain.domain.repository.RecordRepository; import com.stempo.api.domain.presentation.dto.request.RecordRequestDto; import com.stempo.api.domain.presentation.dto.response.RecordResponseDto; +import com.stempo.api.domain.presentation.dto.response.RecordStatisticsResponseDto; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.DayOfWeek; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.temporal.TemporalAdjusters; import java.util.ArrayList; import java.util.List; @@ -56,4 +59,50 @@ public List getRecordsByDateRange(LocalDate startDate, LocalD } return combinedRecords; } + + @Override + @Transactional(readOnly = true) + public RecordStatisticsResponseDto getRecordStatistics() { + String deviceTag = userService.getCurrentDeviceTag(); + + LocalDateTime todayStartDateTime = LocalDate.now().atStartOfDay(); + LocalDateTime todayEndDateTime = todayStartDateTime.plusDays(1); + LocalDateTime weekStartDateTime = LocalDate.now() + .with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)) + .atStartOfDay(); + + // 오늘의 훈련 횟수 계산 + int todayWalkTrainingCount = recordRepository.countByDeviceTagAndCreatedAtBetween( + deviceTag, todayStartDateTime, todayEndDateTime); + + // 이번 주 훈련 횟수 계산 (월요일부터 오늘까지) + int weeklyWalkTrainingCount = recordRepository.countByDeviceTagAndCreatedAtBetween( + deviceTag, weekStartDateTime, todayEndDateTime); + + // 연속된 훈련 일수 계산 + int consecutiveWalkTrainingDays = calculateConsecutiveTrainingDays(deviceTag); + + return RecordStatisticsResponseDto.of(todayWalkTrainingCount, weeklyWalkTrainingCount, consecutiveWalkTrainingDays); + } + + private int calculateConsecutiveTrainingDays(String deviceTag) { + List createdDates = recordRepository.findCreatedAtByDeviceTagOrderByCreatedAtDesc(deviceTag); + int consecutiveDays = 0; + LocalDate previousDate = null; + + for (LocalDateTime createdAt : createdDates) { + LocalDate recordDate = createdAt.toLocalDate(); + + // 첫 기록이거나, 이전 기록이 하루 전날이면 연속으로 카운트 + if (previousDate == null || previousDate.minusDays(1).isEqual(recordDate)) { + consecutiveDays++; + previousDate = recordDate; + } else { + // 연속된 날짜가 아니면 중단 + break; + } + } + return consecutiveDays; + } + } 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 deleted file mode 100644 index 33ac3a0..0000000 --- a/src/main/java/com/stempo/api/domain/application/service/UserAchievementService.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.stempo.api.domain.application.service; - -import com.stempo.api.domain.presentation.dto.response.UserAchievementResponseDto; -import com.stempo.api.global.common.dto.PagedResponseDto; -import org.springframework.data.domain.Pageable; - -public interface UserAchievementService { - - Long registerUserAchievement(Long achievementId); - - 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 deleted file mode 100644 index 6eac51c..0000000 --- a/src/main/java/com/stempo/api/domain/application/service/UserAchievementServiceImpl.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.stempo.api.domain.application.service; - -import com.stempo.api.domain.domain.model.Achievement; -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.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 org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.Objects; -import java.util.Optional; - -@Service -@RequiredArgsConstructor -public class UserAchievementServiceImpl implements UserAchievementService { - - private final UserService userService; - private final UserAchievementRepository userAchievementRepository; - private final AchievementRepository achievementRepository; - - @Override - @Transactional - public Long registerUserAchievement(Long achievementId) { - String deviceTag = userService.getCurrentDeviceTag(); - Optional existingUserAchievement = - userAchievementRepository.findByDeviceTagAndAchievementId(deviceTag, achievementId); - - if (existingUserAchievement.isPresent()) { - return existingUserAchievement.get().getId(); - } - - UserAchievement userAchievement = UserAchievement.create(achievementId, deviceTag); - return userAchievementRepository.save(userAchievement).getId(); - } - - @Override - @Transactional(readOnly = true) - public PagedResponseDto getUserAchievements(Pageable pageable) { - String deviceTag = userService.getCurrentDeviceTag(); - Page achievements = achievementRepository.findAll(pageable); - List userAchievementDtos = getUserAchievementResponseDtos(achievements, deviceTag); - return new PagedResponseDto<>(new PageImpl<>(userAchievementDtos, pageable, userAchievementDtos.size())); - } - - 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 deleted file mode 100644 index f8fb399..0000000 --- a/src/main/java/com/stempo/api/domain/application/service/VideoService.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.stempo.api.domain.application.service; - -import com.stempo.api.domain.presentation.dto.request.VideoRequestDto; -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 org.springframework.data.domain.Pageable; - -public interface VideoService { - - Long registerVideo(VideoRequestDto requestDto); - - PagedResponseDto getVideos(Pageable pageable); - - VideoDetailsResponseDto getVideo(Long videoId); - - Long updateVideo(Long videoId, VideoUpdateRequestDto requestDto); - - Long deleteVideo(Long id); -} 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 deleted file mode 100644 index 785a70b..0000000 --- a/src/main/java/com/stempo/api/domain/application/service/VideoServiceImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.stempo.api.domain.application.service; - -import com.stempo.api.domain.domain.model.Video; -import com.stempo.api.domain.domain.repository.VideoRepository; -import com.stempo.api.domain.presentation.dto.request.VideoRequestDto; -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 org.springframework.transaction.annotation.Transactional; - -@Service -@RequiredArgsConstructor -public class VideoServiceImpl implements VideoService { - - private final VideoRepository repository; - - @Override - @Transactional - public Long registerVideo(VideoRequestDto requestDto) { - Video video = VideoRequestDto.toDomain(requestDto); - return repository.save(video).getId(); - } - - @Override - @Transactional(readOnly = true) - public PagedResponseDto getVideos(Pageable pageable) { - Page