From 5b5be5a77c8b4544e1ee07a75c55583c98f6e6db 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: Wed, 24 Jul 2024 22:11:12 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=AC=ED=99=9C=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A0=9C=EA=B3=B5=20=EC=99=84=EB=A3=8C=20?= =?UTF-8?q?(#21)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/service/ArticleService.java | 21 +++++ .../service/ArticleServiceImpl.java | 53 +++++++++++++ .../application/service/VideoService.java | 3 + .../application/service/VideoServiceImpl.java | 21 +++-- .../api/domain/domain/model/Article.java | 39 +++++++++ .../stempo/api/domain/domain/model/Video.java | 16 ++-- .../domain/repository/ArticleRepository.java | 14 ++++ .../persistence/mappper/ArticleMapper.java | 32 ++++++++ .../repository/ArticleJpaRepository.java | 22 ++++++ .../repository/ArticleRepositoryImpl.java | 42 ++++++++++ .../repository/VideoJpaRepository.java | 6 ++ .../repository/VideoRepositoryImpl.java | 2 +- .../presentation/ArticleController.java | 79 +++++++++++++++++++ .../domain/presentation/VideoController.java | 21 ++++- .../dto/request/ArticleRequestDto.java | 36 +++++++++ .../dto/request/ArticleUpdateRequestDto.java | 22 ++++++ .../dto/request/VideoRequestDto.java | 4 +- .../dto/request/VideoUpdateRequestDto.java | 4 +- .../response/ArticleDetailsResponseDto.java | 28 +++++++ .../dto/response/ArticleResponseDto.java | 26 ++++++ .../dto/response/VideoDetailsResponseDto.java | 28 +++++++ .../dto/response/VideoResponseDto.java | 2 - 22 files changed, 495 insertions(+), 26 deletions(-) create mode 100644 src/main/java/com/stempo/api/domain/application/service/ArticleService.java create mode 100644 src/main/java/com/stempo/api/domain/application/service/ArticleServiceImpl.java create mode 100644 src/main/java/com/stempo/api/domain/domain/model/Article.java create mode 100644 src/main/java/com/stempo/api/domain/domain/repository/ArticleRepository.java create mode 100644 src/main/java/com/stempo/api/domain/persistence/mappper/ArticleMapper.java create mode 100644 src/main/java/com/stempo/api/domain/persistence/repository/ArticleJpaRepository.java create mode 100644 src/main/java/com/stempo/api/domain/persistence/repository/ArticleRepositoryImpl.java create mode 100644 src/main/java/com/stempo/api/domain/presentation/ArticleController.java create mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/request/ArticleRequestDto.java create mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/request/ArticleUpdateRequestDto.java create mode 100644 src/main/java/com/stempo/api/domain/presentation/dto/response/ArticleDetailsResponseDto.java create 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/VideoDetailsResponseDto.java 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 new file mode 100644 index 00000000..a9cb9167 --- /dev/null +++ b/src/main/java/com/stempo/api/domain/application/service/ArticleService.java @@ -0,0 +1,21 @@ +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 java.util.List; + +public interface ArticleService { + + Long registerArticle(ArticleRequestDto requestDto); + + List getArticles(); + + 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 new file mode 100644 index 00000000..7b44d37b --- /dev/null +++ b/src/main/java/com/stempo/api/domain/application/service/ArticleServiceImpl.java @@ -0,0 +1,53 @@ +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 lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class ArticleServiceImpl implements ArticleService { + + private final ArticleRepository repository; + + @Override + public Long registerArticle(ArticleRequestDto requestDto) { + Article article = ArticleRequestDto.toDomain(requestDto); + return repository.save(article).getId(); + } + + @Override + public List getArticles() { + List
articles = repository.findAll(); + return articles.stream() + .map(ArticleResponseDto::toDto) + .toList(); + } + + @Override + public ArticleDetailsResponseDto getArticle(Long articleId) { + Article article = repository.findByIdOrThrow(articleId); + return ArticleDetailsResponseDto.toDto(article); + } + + @Override + public Long updateArticle(Long articleId, ArticleUpdateRequestDto requestDto) { + Article article = repository.findByIdOrThrow(articleId); + article.update(requestDto); + return repository.save(article).getId(); + } + + @Override + 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/VideoService.java b/src/main/java/com/stempo/api/domain/application/service/VideoService.java index d5562850..74d6f1fb 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 @@ -2,6 +2,7 @@ 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 java.util.List; @@ -12,6 +13,8 @@ public interface VideoService { List getVideos(); + 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 index b6852e64..f85dc541 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 @@ -4,6 +4,7 @@ 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 lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -14,33 +15,39 @@ @RequiredArgsConstructor public class VideoServiceImpl implements VideoService { - private final VideoRepository videoRepository; + private final VideoRepository repository; @Override public Long registerVideo(VideoRequestDto requestDto) { Video video = VideoRequestDto.toDomain(requestDto); - return videoRepository.save(video).getId(); + return repository.save(video).getId(); } @Override public List getVideos() { - List