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