diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsApi.java b/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsApi.java index b6d19e4f..a152eebc 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsApi.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsApi.java @@ -46,18 +46,4 @@ NewsDetailResponse getDetailNews( @Parameter(in = ParameterIn.PATH, description = "뉴스 ID", required = true) Long newsId ); - - @Operation( - summary = "최근 읽은 뉴스 조회", - description = "가장 최근에 읽은 3개의 뉴스를 조회합니다.", - security = {@SecurityRequirement(name = "access_token")}, - tags = {"news"} - ) - @ApiResponse( - responseCode = "200", - description = "요청에 성공하였습니다." - ) - List getReadNews(); - - } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsController.java index 0f50123a..84407564 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsController.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/news/api/NewsController.java @@ -2,9 +2,7 @@ import com.rollthedice.backend.domain.news.dto.response.NewsDetailResponse; import com.rollthedice.backend.domain.news.dto.response.NewsResponse; -import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse; import com.rollthedice.backend.domain.news.service.NewsService; -import com.rollthedice.backend.domain.news.service.ReadNewsService; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -17,7 +15,6 @@ @RequestMapping("news") public class NewsController implements NewsApi { private final NewsService newsService; - private final ReadNewsService readNewsService; @ResponseStatus(HttpStatus.OK) @GetMapping("") @@ -28,13 +25,8 @@ public List getNews(final Pageable pageable) { @ResponseStatus(HttpStatus.OK) @GetMapping("/{newsId}") + @Override public NewsDetailResponse getDetailNews(final @PathVariable Long newsId) { return newsService.getDetailNews(newsId); } - - @ResponseStatus(HttpStatus.OK) - @GetMapping("/viewed-history") - public List getReadNews() { - return readNewsService.getReadNews(); - } } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/ReadNewsRepository.java b/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/ReadNewsRepository.java index 0dec52dc..c1c49b32 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/ReadNewsRepository.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/news/repository/ReadNewsRepository.java @@ -1,7 +1,7 @@ package com.rollthedice.backend.domain.news.repository; import com.rollthedice.backend.domain.member.entity.Member; -import com.rollthedice.backend.domain.news.entity.ReadNews; +import com.rollthedice.backend.domain.readNews.entity.ReadNews; import com.rollthedice.backend.domain.statistics.repository.ReadNewsCustomRepository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/NewsService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/NewsService.java index bb3136c1..8dac390a 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/NewsService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/NewsService.java @@ -4,7 +4,7 @@ import com.rollthedice.backend.domain.member.entity.Member; import com.rollthedice.backend.domain.news.dto.response.NewsDetailResponse; import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse; -import com.rollthedice.backend.domain.news.entity.ReadNews; +import com.rollthedice.backend.domain.readNews.entity.ReadNews; import com.rollthedice.backend.domain.news.exception.NewsNotFoundException; import com.rollthedice.backend.domain.news.repository.ReadNewsRepository; import com.rollthedice.backend.global.oauth2.service.AuthService; @@ -30,11 +30,11 @@ @RequiredArgsConstructor public class NewsService { private final AuthService authService; + private final BookmarkService bookmarkService; private final ContentProducer contentProducer; private final NewsRepository newsRepository; private final ReadNewsRepository readNewsRepository; private final NewsMapper newsMapper; - private final BookmarkService bookmarkService; @Transactional diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/api/ReadNewsApi.java b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/api/ReadNewsApi.java new file mode 100644 index 00000000..59aff96e --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/api/ReadNewsApi.java @@ -0,0 +1,22 @@ +package com.rollthedice.backend.domain.readNews.api; + +import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; + +import java.util.List; + +public interface ReadNewsApi { + @Operation( + summary = "최근 읽은 뉴스 조회", + description = "가장 최근에 읽은 3개의 뉴스를 조회합니다.", + security = {@SecurityRequirement(name = "access_token")}, + tags = {"news"} + ) + @ApiResponse( + responseCode = "200", + description = "요청에 성공하였습니다." + ) + List getReadNews(); +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/api/ReadNewsController.java b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/api/ReadNewsController.java new file mode 100644 index 00000000..e32da2b7 --- /dev/null +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/api/ReadNewsController.java @@ -0,0 +1,27 @@ +package com.rollthedice.backend.domain.readNews.api; + +import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse; +import com.rollthedice.backend.domain.readNews.service.ReadNewsService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequiredArgsConstructor +@RequestMapping("read-news") +public class ReadNewsController implements ReadNewsApi { + + private final ReadNewsService readNewsService; + + @ResponseStatus(HttpStatus.OK) + @GetMapping("/viewed-history") + @Override + public List getReadNews() { + return readNewsService.getReadNews(); + } +} diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/entity/ReadNews.java b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/entity/ReadNews.java similarity index 87% rename from backend/core/src/main/java/com/rollthedice/backend/domain/news/entity/ReadNews.java rename to backend/core/src/main/java/com/rollthedice/backend/domain/readNews/entity/ReadNews.java index 03abeb91..012fb466 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/entity/ReadNews.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/entity/ReadNews.java @@ -1,6 +1,7 @@ -package com.rollthedice.backend.domain.news.entity; +package com.rollthedice.backend.domain.readNews.entity; import com.rollthedice.backend.domain.member.entity.Member; +import com.rollthedice.backend.domain.news.entity.News; import com.rollthedice.backend.global.config.BaseTimeEntity; import jakarta.persistence.*; import lombok.AccessLevel; diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/ReadNewsService.java b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/service/ReadNewsService.java similarity index 79% rename from backend/core/src/main/java/com/rollthedice/backend/domain/news/service/ReadNewsService.java rename to backend/core/src/main/java/com/rollthedice/backend/domain/readNews/service/ReadNewsService.java index c2618ff0..78795df1 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/news/service/ReadNewsService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/readNews/service/ReadNewsService.java @@ -1,9 +1,10 @@ -package com.rollthedice.backend.domain.news.service; +package com.rollthedice.backend.domain.readNews.service; import com.rollthedice.backend.domain.member.entity.Member; import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse; -import com.rollthedice.backend.domain.news.entity.ReadNews; +import com.rollthedice.backend.domain.readNews.entity.ReadNews; import com.rollthedice.backend.domain.news.repository.ReadNewsRepository; +import com.rollthedice.backend.domain.news.service.NewsService; import com.rollthedice.backend.global.oauth2.service.AuthService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -21,6 +22,6 @@ public class ReadNewsService { public List getReadNews() { Member member = authService.getMember(); List readNews = readNewsReository.getTop3ByMemberOrderByCreatedAtDesc(member); - return newsService.getNewsByReadNews(readNews.stream().map(r -> r.getNews()).collect(Collectors.toList())); + return newsService.getNewsByReadNews(readNews.stream().map(ReadNews::getNews).collect(Collectors.toList())); } } diff --git a/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/repository/ReadNewsCustomRepositoryImpl.java b/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/repository/ReadNewsCustomRepositoryImpl.java index 8fe479f3..7e42c6c4 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/repository/ReadNewsCustomRepositoryImpl.java +++ b/backend/core/src/main/java/com/rollthedice/backend/domain/statistics/repository/ReadNewsCustomRepositoryImpl.java @@ -7,7 +7,7 @@ import java.time.LocalDate; import static com.rollthedice.backend.domain.news.entity.QNews.news; -import static com.rollthedice.backend.domain.news.entity.QReadNews.readNews; +import static com.rollthedice.backend.domain.readNews.entity.QReadNews.readNews; @RequiredArgsConstructor public class ReadNewsCustomRepositoryImpl implements ReadNewsCustomRepository { diff --git a/backend/core/src/test/java/com/rollthedice/backend/domain/news/api/NewsControllerTest.java b/backend/core/src/test/java/com/rollthedice/backend/domain/news/api/NewsControllerTest.java index 200419be..056cb0f4 100644 --- a/backend/core/src/test/java/com/rollthedice/backend/domain/news/api/NewsControllerTest.java +++ b/backend/core/src/test/java/com/rollthedice/backend/domain/news/api/NewsControllerTest.java @@ -3,7 +3,7 @@ import com.rollthedice.backend.domain.news.exception.NewsNotFoundException; import com.rollthedice.backend.domain.news.repository.NewsRepository; import com.rollthedice.backend.domain.news.service.NewsService; -import com.rollthedice.backend.domain.news.service.ReadNewsService; +import com.rollthedice.backend.domain.readNews.service.ReadNewsService; import com.rollthedice.backend.global.BaseControllerTest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -25,10 +25,6 @@ class NewsControllerTest extends BaseControllerTest { @MockBean private NewsService newsService; - @MockBean - private ReadNewsService readNewsService; - @MockBean - private NewsRepository newsRepository; @Test @DisplayName("News 전체 조회 API가 수행되는가") @@ -76,18 +72,4 @@ void getDetailNewsNotFound() throws Exception { perform.andExpect(status().isNotFound()) .andExpect(jsonPath(ERROR_MESSAGE, NEWS_NOT_FOUND_ERROR.getErrorMessage()).exists()); } - - @Test - @DisplayName("조회한 News 전체 조회 API가 수행되는가") - void getReadNews() throws Exception{ - //when - final ResultActions perform = mockMvc.perform( - get("/news/viewed-history") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken) - ).andDo(print()); - - //then - perform.andExpect(status().isOk()); - } } diff --git a/backend/core/src/test/java/com/rollthedice/backend/domain/news/service/NewsServiceTest.java b/backend/core/src/test/java/com/rollthedice/backend/domain/news/service/NewsServiceTest.java index 0ebf8b3b..0ab9133e 100644 --- a/backend/core/src/test/java/com/rollthedice/backend/domain/news/service/NewsServiceTest.java +++ b/backend/core/src/test/java/com/rollthedice/backend/domain/news/service/NewsServiceTest.java @@ -16,7 +16,6 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; @@ -33,7 +32,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.BDDMockito.given; -@Slf4j @DisplayName("NewsService의") @ExtendWith(MockitoExtension.class) class NewsServiceTest extends LoginTest { @@ -44,11 +42,7 @@ class NewsServiceTest extends LoginTest { @MockBean private NewsRepository newsRepository; @MockBean - private BookmarkRepository bookmarkRepository; - @MockBean private ReadNewsRepository readNewsRepository; - @Mock - private NewsMapper newsMapper; private News news; @@ -87,7 +81,7 @@ void getNews() { } @Test - @DisplayName("뉴스를 상세조회할 수 있는가") + @DisplayName("뉴스를 상세 조회할 수 있는가") void getDetailNews() { //given NewsDetailResponse expect = NEWS_DETAIL_RESPONSE(); diff --git a/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/ReadNewsFixture.java b/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/ReadNewsFixture.java new file mode 100644 index 00000000..96b77256 --- /dev/null +++ b/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/ReadNewsFixture.java @@ -0,0 +1,23 @@ +package com.rollthedice.backend.domain.readNews; + +import com.rollthedice.backend.domain.member.entity.Member; +import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse; +import com.rollthedice.backend.domain.readNews.entity.ReadNews; + +import static com.rollthedice.backend.domain.news.NewsFixture.NEWS; + +public class ReadNewsFixture { + public static ReadNews READ_NEWS(Member member) { + return ReadNews.builder() + .member(member) + .news(NEWS(member)) + .build(); + } + + public static ReadNewsResponse READ_NEWS_RESPONSE() { + return ReadNewsResponse.builder() + .id(1L) + .title("임연지 대통령 되다.") + .build(); + } +} diff --git a/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/api/ReadNewsControllerTest.java b/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/api/ReadNewsControllerTest.java new file mode 100644 index 00000000..78e7653e --- /dev/null +++ b/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/api/ReadNewsControllerTest.java @@ -0,0 +1,35 @@ +package com.rollthedice.backend.domain.readNews.api; + +import com.rollthedice.backend.domain.readNews.service.ReadNewsService; +import com.rollthedice.backend.global.BaseControllerTest; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.ResultActions; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@DisplayName("ReadNewsController의 ") +@WebMvcTest(ReadNewsController.class) +class ReadNewsControllerTest extends BaseControllerTest { + @MockBean + private ReadNewsService readNewsService; + + @Test + @DisplayName("조회한 News 전체 조회 API가 수행되는가") + void getReadNews() throws Exception{ + //when + final ResultActions perform = mockMvc.perform( + get("/read-news/viewed-history") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + accessToken) + ).andDo(print()); + + //then + perform.andExpect(status().isOk()); + } +} diff --git a/backend/core/src/test/java/com/rollthedice/backend/domain/news/repository/ReadNewsRepositoryTest.java b/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/repository/ReadNewsRepositoryTest.java similarity index 88% rename from backend/core/src/test/java/com/rollthedice/backend/domain/news/repository/ReadNewsRepositoryTest.java rename to backend/core/src/test/java/com/rollthedice/backend/domain/readNews/repository/ReadNewsRepositoryTest.java index 5427888c..5e2bf860 100644 --- a/backend/core/src/test/java/com/rollthedice/backend/domain/news/repository/ReadNewsRepositoryTest.java +++ b/backend/core/src/test/java/com/rollthedice/backend/domain/readNews/repository/ReadNewsRepositoryTest.java @@ -1,10 +1,12 @@ -package com.rollthedice.backend.domain.news.repository; +package com.rollthedice.backend.domain.readNews.repository; import com.rollthedice.backend.domain.member.entity.Member; import com.rollthedice.backend.domain.member.repository.MemberRepository; import com.rollthedice.backend.domain.news.entity.News; import com.rollthedice.backend.domain.news.entity.NewsCategory; -import com.rollthedice.backend.domain.news.entity.ReadNews; +import com.rollthedice.backend.domain.news.repository.NewsRepository; +import com.rollthedice.backend.domain.news.repository.ReadNewsRepository; +import com.rollthedice.backend.domain.readNews.entity.ReadNews; import com.rollthedice.backend.support.RepositoryTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -18,7 +20,7 @@ @DisplayName("ReadNewsRepository의 ") @RepositoryTest -public class ReadNewsRepositoryTest { +class ReadNewsRepositoryTest { @Autowired private ReadNewsRepository readNewsRepository; @Autowired