From 1f1178a3e872d0e817d1bc306d9a854b056d43a1 Mon Sep 17 00:00:00 2001 From: fingersdanny Date: Sun, 22 Sep 2024 15:29:45 +0900 Subject: [PATCH 01/13] =?UTF-8?q?[FEAT]=20=EA=B0=80=EB=A0=A4=EC=A7=84=20?= =?UTF-8?q?=EC=9D=91=EC=9B=90=ED=86=A1=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/CheerTalkQueryService.java | 75 ++++++----- .../query/dto/response/CheerTalkResponse.java | 117 ++++++++++-------- .../CheerTalkDynamicRepository.java | 2 + .../CheerTalkDynamicRepositoryImpl.java | 12 ++ 4 files changed, 129 insertions(+), 77 deletions(-) diff --git a/src/main/java/com/sports/server/query/application/CheerTalkQueryService.java b/src/main/java/com/sports/server/query/application/CheerTalkQueryService.java index 00c81a18..50d09f72 100644 --- a/src/main/java/com/sports/server/query/application/CheerTalkQueryService.java +++ b/src/main/java/com/sports/server/query/application/CheerTalkQueryService.java @@ -2,6 +2,7 @@ import com.sports.server.auth.exception.AuthorizationErrorMessages; import com.sports.server.command.cheertalk.domain.CheerTalk; +import com.sports.server.command.game.domain.GameTeam; import com.sports.server.command.league.domain.League; import com.sports.server.command.member.domain.Member; import com.sports.server.common.application.EntityUtils; @@ -22,42 +23,60 @@ @Transactional(readOnly = true) public class CheerTalkQueryService { - private final CheerTalkDynamicRepository cheerTalkDynamicRepository; + private final CheerTalkDynamicRepository cheerTalkDynamicRepository; - private final GameQueryRepository gameQueryRepository; + private final GameQueryRepository gameQueryRepository; - private final EntityUtils entityUtils; + private final EntityUtils entityUtils; - public List getCheerTalksByGameId(final Long gameId, - final PageRequestDto pageRequest) { - List cheerTalks = cheerTalkDynamicRepository.findByGameIdOrderByStartTime( - gameId, pageRequest.cursor(), pageRequest.size() - ); + public List getCheerTalksByGameId(final Long gameId, + final PageRequestDto pageRequest) { + List cheerTalks = cheerTalkDynamicRepository.findByGameIdOrderByStartTime( + gameId, pageRequest.cursor(), pageRequest.size() + ); - List responses = cheerTalks.stream() - .map(CheerTalkResponse.ForSpectator::new) - .collect(Collectors.toList()); + List responses = cheerTalks.stream() + .map(CheerTalkResponse.ForSpectator::new) + .collect(Collectors.toList()); - Collections.reverse(responses); - return responses; - } + Collections.reverse(responses); + return responses; + } - public List getReportedCheerTalksByLeagueId(final Long leagueId, - final PageRequestDto pageRequest, - final Member manager) { - League league = entityUtils.getEntity(leagueId, League.class); + public List getReportedCheerTalksByLeagueId(final Long leagueId, + final PageRequestDto pageRequest, + final Member manager) { + League league = entityUtils.getEntity(leagueId, League.class); - if (!league.isManagedBy(manager)) { - throw new UnauthorizedException(AuthorizationErrorMessages.PERMISSION_DENIED); - } + if (!league.isManagedBy(manager)) { + throw new UnauthorizedException(AuthorizationErrorMessages.PERMISSION_DENIED); + } - List reportedCheerTalks = cheerTalkDynamicRepository.findReportedCheerTalksByLeagueId( - leagueId, pageRequest.cursor(), pageRequest.size() - ); + List reportedCheerTalks = cheerTalkDynamicRepository.findReportedCheerTalksByLeagueId( + leagueId, pageRequest.cursor(), pageRequest.size() + ); - return reportedCheerTalks.stream() - .map(cheerTalk -> new CheerTalkResponse.Reported(cheerTalk, - gameQueryRepository.findByIdWithLeague(cheerTalk.getGameTeamId()))).toList(); - } + return reportedCheerTalks.stream() + .map(cheerTalk -> new CheerTalkResponse.Reported(cheerTalk, + gameQueryRepository.findByIdWithLeague(cheerTalk.getGameTeamId()))).toList(); + } + public List getBlockedCheerTalksByLeagueId(final Long leagueId, + final PageRequestDto pageable, + final Member member) { + League league = entityUtils.getEntity(leagueId, League.class); + + if (!league.isManagedBy(member)) { + throw new UnauthorizedException(AuthorizationErrorMessages.PERMISSION_DENIED); + } + + List blockedCheerTalks = cheerTalkDynamicRepository.findBlockedCheerTalksByLeagueId( + leagueId, pageable.cursor(), pageable.size()); + + return blockedCheerTalks.stream() + .map(cheerTalk -> { + GameTeam gameTeam = entityUtils.getEntity(cheerTalk.getGameTeamId(), GameTeam.class); + return new CheerTalkResponse.Blocked(cheerTalk, gameTeam.getGame()); + }).toList(); + } } diff --git a/src/main/java/com/sports/server/query/dto/response/CheerTalkResponse.java b/src/main/java/com/sports/server/query/dto/response/CheerTalkResponse.java index 17204cd7..dd671ef6 100644 --- a/src/main/java/com/sports/server/query/dto/response/CheerTalkResponse.java +++ b/src/main/java/com/sports/server/query/dto/response/CheerTalkResponse.java @@ -5,57 +5,76 @@ import java.time.LocalDateTime; public class CheerTalkResponse { - public record ForSpectator( - Long cheerTalkId, - String content, - Long gameTeamId, - LocalDateTime createdAt, - Boolean isBlocked - ) { - public ForSpectator(CheerTalk cheerTalk) { - this( - cheerTalk.getId(), - checkCheerTalkIsBlocked(cheerTalk), - cheerTalk.getGameTeamId(), - cheerTalk.getCreatedAt(), - cheerTalk.isBlocked() - ); - } + public record ForSpectator( + Long cheerTalkId, + String content, + Long gameTeamId, + LocalDateTime createdAt, + Boolean isBlocked + ) { + public ForSpectator(CheerTalk cheerTalk) { + this( + cheerTalk.getId(), + checkCheerTalkIsBlocked(cheerTalk), + cheerTalk.getGameTeamId(), + cheerTalk.getCreatedAt(), + cheerTalk.isBlocked() + ); + } - private static String checkCheerTalkIsBlocked(CheerTalk cheerTalk) { - if (cheerTalk.isBlocked()) { - return null; - } - return cheerTalk.getContent(); - } - } - - public record Reported( - Long cheerTalkId, - Long gameId, - Long leagueId, - String content, - Long gameTeamId, - LocalDateTime createdAt, - Boolean isBlocked, - String gameName, - String leagueName - ) { - public Reported(CheerTalk cheerTalk, Game game) { - this( - cheerTalk.getId(), - game.getId(), - game.getLeague().getId(), - cheerTalk.getContent(), - cheerTalk.getGameTeamId(), - cheerTalk.getCreatedAt(), - cheerTalk.isBlocked(), - game.getName(), - game.getLeague().getName() - ); - } - } + private static String checkCheerTalkIsBlocked(CheerTalk cheerTalk) { + if (cheerTalk.isBlocked()) { + return null; + } + return cheerTalk.getContent(); + } + } + public record Reported( + Long cheerTalkId, + Long gameId, + Long leagueId, + String content, + Long gameTeamId, + LocalDateTime createdAt, + Boolean isBlocked, + String gameName, + String leagueName + ) { + public Reported(CheerTalk cheerTalk, Game game) { + this( + cheerTalk.getId(), + game.getId(), + game.getLeague().getId(), + cheerTalk.getContent(), + cheerTalk.getGameTeamId(), + cheerTalk.getCreatedAt(), + cheerTalk.isBlocked(), + game.getName(), + game.getLeague().getName() + ); + } + } + public record Blocked( + Long cheerTalkId, + Long gameId, + Long LeagueId, + String content, + LocalDateTime createdAt, + String gameName, + String leagueName + ) { + public Blocked(CheerTalk cheerTalk, Game game) { + this( + cheerTalk.getId(), + game.getId(), + game.getLeague().getId(), + cheerTalk.getContent(), + cheerTalk.getCreatedAt(), + game.getName(), + game.getLeague().getName()); + } + } } diff --git a/src/main/java/com/sports/server/query/repository/CheerTalkDynamicRepository.java b/src/main/java/com/sports/server/query/repository/CheerTalkDynamicRepository.java index bd5c6705..6fa22594 100644 --- a/src/main/java/com/sports/server/query/repository/CheerTalkDynamicRepository.java +++ b/src/main/java/com/sports/server/query/repository/CheerTalkDynamicRepository.java @@ -8,4 +8,6 @@ public interface CheerTalkDynamicRepository { List findByGameIdOrderByStartTime(Long gameId, Long cursor, Integer size); List findReportedCheerTalksByLeagueId(Long leagueId, Long cursor, Integer size); + + List findBlockedCheerTalksByLeagueId(Long leagueId, Long cursor, Integer size); } diff --git a/src/main/java/com/sports/server/query/repository/CheerTalkDynamicRepositoryImpl.java b/src/main/java/com/sports/server/query/repository/CheerTalkDynamicRepositoryImpl.java index 56c66224..09d48caf 100644 --- a/src/main/java/com/sports/server/query/repository/CheerTalkDynamicRepositoryImpl.java +++ b/src/main/java/com/sports/server/query/repository/CheerTalkDynamicRepositoryImpl.java @@ -44,6 +44,18 @@ public List findReportedCheerTalksByLeagueId(Long leagueId, Long curs ); } + @Override + public List findBlockedCheerTalksByLeagueId(Long leagueId, Long cursor, Integer size) { + return applyPagination( + queryFactory.selectFrom(cheerTalk) + .join(gameTeam).on(cheerTalk.gameTeamId.eq(gameTeam.id)) + .where(cheerTalk.isBlocked.eq(true)) + .where(gameTeam.game.league.id.eq(leagueId)), + cursor, + size + ); + } + private List applyPagination(JPAQuery query, Long cursor, Integer size) { return query .where(getPaginationConditions(cursor)) From e7b12045dc87329589ea7ea0086f1f9cd52aedcf Mon Sep 17 00:00:00 2001 From: fingersdanny Date: Sun, 22 Sep 2024 15:31:58 +0900 Subject: [PATCH 02/13] =?UTF-8?q?[FEAT]=20API=20endpoint=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../query/presentation/CheerTalkQueryController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/sports/server/query/presentation/CheerTalkQueryController.java b/src/main/java/com/sports/server/query/presentation/CheerTalkQueryController.java index a58e704e..b539f887 100644 --- a/src/main/java/com/sports/server/query/presentation/CheerTalkQueryController.java +++ b/src/main/java/com/sports/server/query/presentation/CheerTalkQueryController.java @@ -31,4 +31,12 @@ public ResponseEntity> getAllReportedCheerTalks Member member) { return ResponseEntity.ok(cheerTalkQueryService.getReportedCheerTalksByLeagueId(leagueId, pageRequest, member)); } + + @GetMapping("/leagues/{leagueId}/cheer-talks/blocked") + public ResponseEntity> getAllBlockedCheerTalks( + @PathVariable final Long leagueId, + @ModelAttribute final PageRequestDto pageable, + Member member) { + return ResponseEntity.ok(cheerTalkQueryService.getBlockedCheerTalksByLeagueId(leagueId, pageable, member)); + } } From 491858d766795fae8e3854f1c18f05497243b876 Mon Sep 17 00:00:00 2001 From: fingersdanny Date: Sun, 22 Sep 2024 15:55:40 +0900 Subject: [PATCH 03/13] =?UTF-8?q?[REFACTOR]=20=EB=82=B4=EB=B6=80=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EC=9E=90=EB=B0=94=20=EC=BB=A8=EB=B2=A4?= =?UTF-8?q?=EC=85=98=EC=97=90=20=EB=A7=9E=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sports/server/query/dto/response/CheerTalkResponse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sports/server/query/dto/response/CheerTalkResponse.java b/src/main/java/com/sports/server/query/dto/response/CheerTalkResponse.java index dd671ef6..fe3489c8 100644 --- a/src/main/java/com/sports/server/query/dto/response/CheerTalkResponse.java +++ b/src/main/java/com/sports/server/query/dto/response/CheerTalkResponse.java @@ -59,7 +59,7 @@ public Reported(CheerTalk cheerTalk, Game game) { public record Blocked( Long cheerTalkId, Long gameId, - Long LeagueId, + Long leagueId, String content, LocalDateTime createdAt, String gameName, From 51149c3a998d01338a15c0711f27b4e3cfce297c Mon Sep 17 00:00:00 2001 From: fingersdanny Date: Sun, 22 Sep 2024 15:56:42 +0900 Subject: [PATCH 04/13] =?UTF-8?q?[TEST]=20=EA=B0=80=EB=A0=A4=EC=A7=84=20?= =?UTF-8?q?=EC=9D=91=EC=9B=90=ED=86=A1=20=EC=A0=84=EC=B2=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CheerTalkQueryServiceTest.java | 198 +++++++++++------- src/test/resources/cheer-talk-fixture.sql | 3 +- 2 files changed, 128 insertions(+), 73 deletions(-) diff --git a/src/test/java/com/sports/server/query/application/CheerTalkQueryServiceTest.java b/src/test/java/com/sports/server/query/application/CheerTalkQueryServiceTest.java index 9caf4fa9..4902e9e9 100644 --- a/src/test/java/com/sports/server/query/application/CheerTalkQueryServiceTest.java +++ b/src/test/java/com/sports/server/query/application/CheerTalkQueryServiceTest.java @@ -12,6 +12,8 @@ import com.sports.server.query.dto.response.CheerTalkResponse; import com.sports.server.support.ServiceTest; import java.util.List; + +import org.assertj.core.api.ThrowableAssert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; @@ -22,76 +24,128 @@ @Sql("/cheer-talk-fixture.sql") public class CheerTalkQueryServiceTest extends ServiceTest { - @Autowired - private CheerTalkQueryService cheerTalkQueryService; - - @Autowired - private EntityUtils entityUtils; - - @Nested - @DisplayName("신고된 응원톡을 조회할 때") - class TestFindReportedCheerTalksByLeagueId { - - private PageRequestDto pageRequestDto; - - private Member manager; - - @BeforeEach - void setUp() { - pageRequestDto = new PageRequestDto( - null, 10 - ); - manager = entityUtils.getEntity(1L, Member.class); - } - - @Test - void 신고된_응원톡만_조회된다() { - // given - Long leagueId = 1L; - Long reportedCheerTalkId = 1L; - - // when - List results = cheerTalkQueryService.getReportedCheerTalksByLeagueId( - leagueId, pageRequestDto, manager); - - // then - assertAll( - () -> assertThat(results.size()).isEqualTo(1), - () -> assertThat(results.get(0).cheerTalkId()).isEqualTo(reportedCheerTalkId) - ); - } - - @Test - void 해당_리그의_응원톡만_조회된다() { - // given - Long leagueId = 1L; - - // when - List responses = cheerTalkQueryService.getReportedCheerTalksByLeagueId( - leagueId, pageRequestDto, manager); - - // then - assertThat( - responses.stream() - .map(CheerTalkResponse.Reported::leagueId).toList() - ).containsOnly(leagueId); - } - - @Test - void 리그의_매니저가_아닌_경우_예외가_발생한다() { - // given - Long leagueId = 1L; - Member invalidManager = entityUtils.getEntity(2L, Member.class); - - // when & then - assertThatThrownBy(() -> cheerTalkQueryService.getReportedCheerTalksByLeagueId( - leagueId, pageRequestDto, invalidManager)) - .hasMessage(AuthorizationErrorMessages.PERMISSION_DENIED) - .isInstanceOf(UnauthorizedException.class); - } - - - } - - + @Autowired + private CheerTalkQueryService cheerTalkQueryService; + + @Autowired + private EntityUtils entityUtils; + + @Nested + @DisplayName("신고된 응원톡을 조회할 때") + class TestFindReportedCheerTalksByLeagueId { + + private PageRequestDto pageRequestDto; + + private Member manager; + + @BeforeEach + void setUp() { + pageRequestDto = new PageRequestDto( + null, 10 + ); + manager = entityUtils.getEntity(1L, Member.class); + } + + @Test + void 신고된_응원톡만_조회된다() { + // given + Long leagueId = 1L; + Long reportedCheerTalkId = 1L; + + // when + List results = cheerTalkQueryService.getReportedCheerTalksByLeagueId( + leagueId, pageRequestDto, manager); + + // then + assertAll( + () -> assertThat(results.size()).isEqualTo(1), + () -> assertThat(results.get(0).cheerTalkId()).isEqualTo(reportedCheerTalkId) + ); + } + + @Test + void 해당_리그의_응원톡만_조회된다() { + // given + Long leagueId = 1L; + + // when + List responses = cheerTalkQueryService.getReportedCheerTalksByLeagueId( + leagueId, pageRequestDto, manager); + + // then + assertThat( + responses.stream() + .map(CheerTalkResponse.Reported::leagueId).toList() + ).containsOnly(leagueId); + } + + @Test + void 리그의_매니저가_아닌_경우_예외가_발생한다() { + // given + Long leagueId = 1L; + Member invalidManager = entityUtils.getEntity(2L, Member.class); + + // when & then + assertThatThrownBy(() -> cheerTalkQueryService.getReportedCheerTalksByLeagueId( + leagueId, pageRequestDto, invalidManager)) + .hasMessage(AuthorizationErrorMessages.PERMISSION_DENIED) + .isInstanceOf(UnauthorizedException.class); + } + + } + + @Nested + @DisplayName("가려진 응원톡 전체 조회") + class TestFindBlockedCheerTalksByLeagueId { + private PageRequestDto pageRequestDto = new PageRequestDto(null, 10); + private Member manager = entityUtils.getEntity(1L, Member.class); + + @Test + void 가려진_응원톡만_조회된다() throws Exception { + // given + Long leagueId = 1L; + Long blockedCheerTalkId = 19L; + + // when + List responses = cheerTalkQueryService.getBlockedCheerTalksByLeagueId( + leagueId, pageRequestDto, manager); + + // then + assertAll( + () -> assertThat(responses.size()).isEqualTo(1), + () -> assertThat( + responses.stream().map(CheerTalkResponse.Blocked::cheerTalkId).toList()).containsExactly( + blockedCheerTalkId) + ); + } + + @Test + void 해당_리그의_응원톡만_조회된다() { + // given + Long leagueId = 1L; + + // when + List responses = cheerTalkQueryService.getBlockedCheerTalksByLeagueId( + leagueId, pageRequestDto, manager); + + // then + assertThat(responses.stream().map(CheerTalkResponse.Blocked::leagueId).toList()).containsOnly(leagueId); + } + + @Test + void 리그의_매니저가_아닌_경우_예외가_발생한다() { + // given + Long leagueId = 1L; + Member invalidManager = entityUtils.getEntity(2L, Member.class); + + // when + ThrowableAssert.ThrowingCallable actual = () -> cheerTalkQueryService.getBlockedCheerTalksByLeagueId( + leagueId, pageRequestDto, invalidManager); + + // when & then + assertThatThrownBy(actual) + .isInstanceOf(UnauthorizedException.class) + .hasMessage(AuthorizationErrorMessages.PERMISSION_DENIED); + } + } } diff --git a/src/test/resources/cheer-talk-fixture.sql b/src/test/resources/cheer-talk-fixture.sql index b3a73c2d..5c04d0fc 100644 --- a/src/test/resources/cheer-talk-fixture.sql +++ b/src/test/resources/cheer-talk-fixture.sql @@ -56,7 +56,8 @@ INSERT INTO `cheer_talks` (id, `created_at`, `content`, `is_blocked`, `game_team VALUES (15, '2023-01-01 12:30:00', '응원톡15', false, 3), (16, '2023-01-01 12:30:00', '응원톡16', false, 4), (17, '2023-01-01 12:30:00', '응원톡16', false, 5), - (18, '2023-01-01 12:30:00', '응원톡16', false, 6); -- 신고된 응원톡 + (18, '2023-01-01 12:30:00', '응원톡16', false, 6), -- 신고된 응원톡 + (19, '2032-01-01 12:30:12', '응원톡17', true, 3); INSERT INTO reports(id, cheer_talk_id, reported_at, state) From 66c6f0dc948ac194ba58f3f2249b11ec82a4532e Mon Sep 17 00:00:00 2001 From: fingersdanny Date: Sun, 22 Sep 2024 16:40:12 +0900 Subject: [PATCH 05/13] =?UTF-8?q?[TEST]=20=EB=AC=B8=EC=84=9C=ED=99=94=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CheerTalkQueryControllerTest.java | 279 ++++++++++-------- 1 file changed, 160 insertions(+), 119 deletions(-) diff --git a/src/test/java/com/sports/server/query/presentation/CheerTalkQueryControllerTest.java b/src/test/java/com/sports/server/query/presentation/CheerTalkQueryControllerTest.java index 6a4ab9b3..5ffb79b8 100644 --- a/src/test/java/com/sports/server/query/presentation/CheerTalkQueryControllerTest.java +++ b/src/test/java/com/sports/server/query/presentation/CheerTalkQueryControllerTest.java @@ -1,132 +1,173 @@ package com.sports.server.query.presentation; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.BDDMockito.*; +import static org.mockito.Mockito.anyLong; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; +import static org.springframework.restdocs.payload.PayloadDocumentation.*; +import static org.springframework.restdocs.request.RequestDocumentation.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; -import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; -import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; -import static org.springframework.restdocs.request.RequestDocumentation.queryParameters; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import com.sports.server.command.member.domain.Member; -import com.sports.server.common.dto.PageRequestDto; -import com.sports.server.query.dto.response.CheerTalkResponse; -import com.sports.server.support.DocumentationTest; -import jakarta.servlet.http.Cookie; import java.time.LocalDateTime; import java.util.List; + import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.test.web.servlet.ResultActions; -public class CheerTalkQueryControllerTest extends DocumentationTest { +import com.sports.server.command.member.domain.Member; +import com.sports.server.common.dto.PageRequestDto; +import com.sports.server.query.dto.response.CheerTalkResponse; +import com.sports.server.support.DocumentationTest; - @Test - void 응원톡을_조회한다() throws Exception { - - //given - Long gameId = 1L; - - PageRequestDto pageRequestDto = new PageRequestDto(1L, 2); - - LocalDateTime createdAt = LocalDateTime.of(2024, 1, 21, 11, 46, 0); - List response = List.of( - new CheerTalkResponse.ForSpectator( - 2L, "응원해요", 1L, createdAt, false - ), - new CheerTalkResponse.ForSpectator( - 3L, "파이팅", 2L, createdAt, false - ) - ); - - given(cheerTalkQueryService.getCheerTalksByGameId(gameId, pageRequestDto)) - .willReturn(response); - - // when - ResultActions result = mockMvc.perform(get("/games/{gameId}/cheer-talks", gameId) - .queryParam("cursor", String.valueOf(1)) - .queryParam("size", String.valueOf(2)) - .contentType(MediaType.APPLICATION_JSON) - ); - - result.andExpect((status().isOk())) - .andDo(restDocsHandler.document( - queryParameters( - parameterWithName("cursor").description("마지막 응원톡의 ID"), - parameterWithName("size").description("조회하고자 하는 응원톡의 개수") - ), - pathParameters( - parameterWithName("gameId").description("게임의 ID") - ), - responseFields( - fieldWithPath("[].cheerTalkId").type(JsonFieldType.NUMBER).description("응원톡의 ID"), - fieldWithPath("[].content").type(JsonFieldType.STRING).description("응원톡의 내용"), - fieldWithPath("[].gameTeamId").type(JsonFieldType.NUMBER) - .description("응원톡에 해당하는 게임팀의 ID"), - fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("생성된 날짜 및 시각"), - fieldWithPath("[].isBlocked").type(JsonFieldType.BOOLEAN).description("응원톡의 블락 여부") - ) - )); - } - - @Test - void 리그의_신고된_응원톡을_조회한다() throws Exception { - //given - Long leagueId = 1L; - - PageRequestDto pageRequestDto = new PageRequestDto(1L, 2); - - LocalDateTime createdAt = LocalDateTime.of(2024, 1, 21, 11, 46, 0); - List response = List.of( - new CheerTalkResponse.Reported( - 2L, 1L, 1L, "응원해요", 1L, createdAt, false, "게임 이름", "리그 이름" - ), - new CheerTalkResponse.Reported( - 3L, 1L, 1L, "파이팅", 2L, createdAt, false, "게임 이름", "리그 이름" - ) - ); - - given(cheerTalkQueryService.getReportedCheerTalksByLeagueId( - eq(leagueId), - eq(pageRequestDto), - any(Member.class)) - ).willReturn(response); - - // when - ResultActions result = mockMvc.perform(get("/leagues/{leagueId}/cheer-talks/reported", leagueId) - .queryParam("cursor", String.valueOf(1)) - .queryParam("size", String.valueOf(2)) - .contentType(MediaType.APPLICATION_JSON) - .cookie(new Cookie(COOKIE_NAME, "temp-cookie")) - ); - - result.andExpect((status().isOk())) - .andDo(restDocsHandler.document( - queryParameters( - parameterWithName("cursor").description("마지막 응원톡의 ID"), - parameterWithName("size").description("조회하고자 하는 응원톡의 개수") - ), - pathParameters( - parameterWithName("leagueId").description("리그의 ID") - ), - responseFields( - fieldWithPath("[].cheerTalkId").type(JsonFieldType.NUMBER).description("응원톡의 ID"), - fieldWithPath("[].gameId").type(JsonFieldType.NUMBER).description("응원톡이 등록된 게임의 ID"), - fieldWithPath("[].leagueId").type(JsonFieldType.NUMBER).description("응원톡이 등록된 리그의 ID"), - fieldWithPath("[].content").type(JsonFieldType.STRING).description("응원톡의 내용"), - fieldWithPath("[].gameTeamId").type(JsonFieldType.NUMBER) - .description("응원톡에 해당하는 게임팀의 ID"), - fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("생성된 날짜 및 시각"), - fieldWithPath("[].isBlocked").type(JsonFieldType.BOOLEAN).description("응원톡의 블락 여부"), - fieldWithPath("[].gameName").type(JsonFieldType.STRING).description("응원톡이 등록된 게임의 이름"), - fieldWithPath("[].leagueName").type(JsonFieldType.STRING).description("응원톡이 등록된 리그의 이름") - ) - )); - } +import jakarta.servlet.http.Cookie; + +public class CheerTalkQueryControllerTest extends DocumentationTest { + @Test + void 응원톡을_조회한다() throws Exception { + + //given + Long gameId = 1L; + + PageRequestDto pageRequestDto = new PageRequestDto(1L, 2); + + LocalDateTime createdAt = LocalDateTime.of(2024, 1, 21, 11, 46, 0); + List response = List.of( + new CheerTalkResponse.ForSpectator( + 2L, "응원해요", 1L, createdAt, false + ), + new CheerTalkResponse.ForSpectator( + 3L, "파이팅", 2L, createdAt, false + ) + ); + + given(cheerTalkQueryService.getCheerTalksByGameId(gameId, pageRequestDto)) + .willReturn(response); + + // when + ResultActions result = mockMvc.perform(get("/games/{gameId}/cheer-talks", gameId) + .queryParam("cursor", String.valueOf(1)) + .queryParam("size", String.valueOf(2)) + .contentType(MediaType.APPLICATION_JSON) + ); + + result.andExpect((status().isOk())) + .andDo(restDocsHandler.document( + queryParameters( + parameterWithName("cursor").description("마지막 응원톡의 ID"), + parameterWithName("size").description("조회하고자 하는 응원톡의 개수") + ), + pathParameters( + parameterWithName("gameId").description("게임의 ID") + ), + responseFields( + fieldWithPath("[].cheerTalkId").type(JsonFieldType.NUMBER).description("응원톡의 ID"), + fieldWithPath("[].content").type(JsonFieldType.STRING).description("응원톡의 내용"), + fieldWithPath("[].gameTeamId").type(JsonFieldType.NUMBER) + .description("응원톡에 해당하는 게임팀의 ID"), + fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("생성된 날짜 및 시각"), + fieldWithPath("[].isBlocked").type(JsonFieldType.BOOLEAN).description("응원톡의 블락 여부") + ) + )); + } + + @Test + void 리그의_신고된_응원톡을_조회한다() throws Exception { + //given + Long leagueId = 1L; + + PageRequestDto pageRequestDto = new PageRequestDto(1L, 2); + + LocalDateTime createdAt = LocalDateTime.of(2024, 1, 21, 11, 46, 0); + List response = List.of( + new CheerTalkResponse.Reported( + 2L, 1L, 1L, "응원해요", 1L, createdAt, false, "게임 이름", "리그 이름" + ), + new CheerTalkResponse.Reported( + 3L, 1L, 1L, "파이팅", 2L, createdAt, false, "게임 이름", "리그 이름" + ) + ); + + given(cheerTalkQueryService.getReportedCheerTalksByLeagueId( + eq(leagueId), + eq(pageRequestDto), + any(Member.class)) + ).willReturn(response); + + // when + ResultActions result = mockMvc.perform(get("/leagues/{leagueId}/cheer-talks/reported", leagueId) + .queryParam("cursor", String.valueOf(1)) + .queryParam("size", String.valueOf(2)) + .contentType(MediaType.APPLICATION_JSON) + .cookie(new Cookie(COOKIE_NAME, "temp-cookie")) + ); + + result.andExpect((status().isOk())) + .andDo(restDocsHandler.document( + queryParameters( + parameterWithName("cursor").description("마지막 응원톡의 ID"), + parameterWithName("size").description("조회하고자 하는 응원톡의 개수") + ), + pathParameters( + parameterWithName("leagueId").description("리그의 ID") + ), + responseFields( + fieldWithPath("[].cheerTalkId").type(JsonFieldType.NUMBER).description("응원톡의 ID"), + fieldWithPath("[].gameId").type(JsonFieldType.NUMBER).description("응원톡이 등록된 게임의 ID"), + fieldWithPath("[].leagueId").type(JsonFieldType.NUMBER).description("응원톡이 등록된 리그의 ID"), + fieldWithPath("[].content").type(JsonFieldType.STRING).description("응원톡의 내용"), + fieldWithPath("[].gameTeamId").type(JsonFieldType.NUMBER) + .description("응원톡에 해당하는 게임팀의 ID"), + fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("생성된 날짜 및 시각"), + fieldWithPath("[].isBlocked").type(JsonFieldType.BOOLEAN).description("응원톡의 블락 여부"), + fieldWithPath("[].gameName").type(JsonFieldType.STRING).description("응원톡이 등록된 게임의 이름"), + fieldWithPath("[].leagueName").type(JsonFieldType.STRING).description("응원톡이 등록된 리그의 이름") + ) + )); + } + + @Test + void 리그의_가려진_응원톡을_조회한다() throws Exception { + // given + Long leagueId = 1L; + LocalDateTime createdAt = LocalDateTime.of(2024, 1, 21, 11, 46, 0); + List responses = List.of( + new CheerTalkResponse.Blocked(2L, 1L, 1L, "미안하다이거보여주려고어그로끌었다", createdAt, "제 1경기 학츄핑 vs 하츄핑", + "매봉역 배 타코 빨리 먹기 대작전"), + new CheerTalkResponse.Blocked(3L, 1L, 1L, "이학을국회로", createdAt, "제 2경기 학츄핑 vs 시진핑", + "매봉역 배 타코 빨리 먹기 대작전")); + + doReturn(responses).when(cheerTalkQueryService) + .getBlockedCheerTalksByLeagueId(anyLong(), any(PageRequestDto.class), any(Member.class)); + + // when + ResultActions result = mockMvc.perform( + get("/leagues/{leagueId}/cheer-talks/blocked", leagueId) + .contentType(MediaType.APPLICATION_JSON) + .queryParam("cursor", String.valueOf(1)) + .queryParam("size", String.valueOf(2)) + .cookie(new Cookie(COOKIE_NAME, "temp-cookie"))); + + // then + result.andExpect((status().isOk())) + .andDo(restDocsHandler.document( + queryParameters( + parameterWithName("cursor").description("마지막 응원톡의 ID"), + parameterWithName("size").description("조회하고자 하는 응원톡의 개수") + ), + pathParameters( + parameterWithName("leagueId").description("리그의 ID") + ), + responseFields( + fieldWithPath("[].cheerTalkId").type(JsonFieldType.NUMBER).description("응원톡의 ID"), + fieldWithPath("[].gameId").type(JsonFieldType.NUMBER).description("응원톡이 등록된 게임의 ID"), + fieldWithPath("[].leagueId").type(JsonFieldType.NUMBER).description("응원톡이 등록된 리그의 ID"), + fieldWithPath("[].content").type(JsonFieldType.STRING).description("응원톡의 내용"), + fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("생성된 날짜 및 시각"), + fieldWithPath("[].gameName").type(JsonFieldType.STRING).description("응원톡이 등록된 게임의 이름"), + fieldWithPath("[].leagueName").type(JsonFieldType.STRING).description("응원톡이 등록된 리그의 이름") + ))); + } } From 151e940d22f0273a6ad4d33f25b75e2b56ca0add Mon Sep 17 00:00:00 2001 From: fingersdanny Date: Sun, 22 Sep 2024 16:40:48 +0900 Subject: [PATCH 06/13] =?UTF-8?q?[FIX]=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95=20-=20BeforeEa?= =?UTF-8?q?ch=EB=A1=9C=20=EC=A1=B0=ED=9A=8C=ED=95=B4=EC=98=A4=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/CheerTalkQueryServiceTest.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/sports/server/query/application/CheerTalkQueryServiceTest.java b/src/test/java/com/sports/server/query/application/CheerTalkQueryServiceTest.java index 4902e9e9..c0ca5f83 100644 --- a/src/test/java/com/sports/server/query/application/CheerTalkQueryServiceTest.java +++ b/src/test/java/com/sports/server/query/application/CheerTalkQueryServiceTest.java @@ -97,14 +97,20 @@ void setUp() { @Nested @DisplayName("가려진 응원톡 전체 조회") class TestFindBlockedCheerTalksByLeagueId { - private PageRequestDto pageRequestDto = new PageRequestDto(null, 10); - private Member manager = entityUtils.getEntity(1L, Member.class); + private PageRequestDto pageRequestDto; + private Member manager; + + @BeforeEach + void setUp() { + pageRequestDto = new PageRequestDto(null, 10); + manager = entityUtils.getEntity(1L, Member.class); + } @Test void 가려진_응원톡만_조회된다() throws Exception { // given Long leagueId = 1L; - Long blockedCheerTalkId = 19L; + List blockedCheerTalkIds = List.of(19L, 14L); // when List responses = cheerTalkQueryService.getBlockedCheerTalksByLeagueId( @@ -112,10 +118,9 @@ class TestFindBlockedCheerTalksByLeagueId { // then assertAll( - () -> assertThat(responses.size()).isEqualTo(1), + () -> assertThat(responses.size()).isEqualTo(2), () -> assertThat( - responses.stream().map(CheerTalkResponse.Blocked::cheerTalkId).toList()).containsExactly( - blockedCheerTalkId) + responses.stream().map(CheerTalkResponse.Blocked::cheerTalkId).toList()).containsAll(blockedCheerTalkIds) ); } From 1de9b9d062f141da7f16e508e8bffbe034c382b0 Mon Sep 17 00:00:00 2001 From: fingersdanny Date: Sun, 22 Sep 2024 16:41:09 +0900 Subject: [PATCH 07/13] =?UTF-8?q?[FEAT]=20SecurityConfig=EC=97=90=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=EB=90=98=EB=8A=94=20API=20=EA=B2=BD=EB=A1=9C?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/sports/server/auth/config/SecurityConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/sports/server/auth/config/SecurityConfig.java b/src/main/java/com/sports/server/auth/config/SecurityConfig.java index 26e49f9e..eae7d660 100644 --- a/src/main/java/com/sports/server/auth/config/SecurityConfig.java +++ b/src/main/java/com/sports/server/auth/config/SecurityConfig.java @@ -50,6 +50,7 @@ SecurityFilterChain filterChain(HttpSecurity http, MvcRequestMatcher.Builder mvc mvc.pattern(HttpMethod.POST, "/leagues/{leagueId}/teams/{teamId}/delete-logo"), mvc.pattern(HttpMethod.GET, "/leagues/{leagueId}/cheer-talks/reported"), mvc.pattern(HttpMethod.POST, "/leagues/{leagueId}/games"), + mvc.pattern(HttpMethod.POST, "/leagues/{leagueId}/cheer-talks/blocked"), mvc.pattern(HttpMethod.POST, "/games/*/timelines/**"), mvc.pattern(HttpMethod.POST, "/games/{gameId}/lineup-players/{lineupPlayerId}/**") ) From 1af5e93bd0d19531ff88703f01f794e0ddbc377d Mon Sep 17 00:00:00 2001 From: fingersdanny Date: Sun, 22 Sep 2024 16:44:55 +0900 Subject: [PATCH 08/13] =?UTF-8?q?[REFACTOR]=20=EC=9D=B8=EC=88=98=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=97=90=EC=84=9C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EB=90=98=EB=8A=94=20SQL=20=EC=88=98=EC=A0=95=20-=20em?= =?UTF-8?q?ail=EC=9D=84=20john.doe@example.com=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=ED=86=B5=EC=9D=BC=20-=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=9D=B8=EC=88=98=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CheerTalkQueryAcceptanceTest.java | 28 ++++++++++++++++++- src/test/resources/cheer-talk-fixture.sql | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/sports/server/query/acceptance/CheerTalkQueryAcceptanceTest.java b/src/test/java/com/sports/server/query/acceptance/CheerTalkQueryAcceptanceTest.java index 3e300638..bd0db2cb 100644 --- a/src/test/java/com/sports/server/query/acceptance/CheerTalkQueryAcceptanceTest.java +++ b/src/test/java/com/sports/server/query/acceptance/CheerTalkQueryAcceptanceTest.java @@ -163,7 +163,7 @@ class GetCommentsTest { // given Long leagueId = 1L; - configureMockJwtForEmail("john@example.com"); + configureMockJwtForEmail(MOCK_EMAIL); // when ExtractableResponse response = RestAssured.given().log().all() @@ -186,4 +186,30 @@ class GetCommentsTest { .containsExactly("응원톡1") ); } + + @Test + void 리그의_가려진_응원톡을_조회한다() throws Exception { + // given + Long leagueId = 1L; + + configureMockJwtForEmail(MOCK_EMAIL); + + // when + ExtractableResponse response = RestAssured.given().log().all() + .when() + .cookie(COOKIE_NAME, mockToken) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .get("/leagues/{leagueId}/cheer-talks/blocked", leagueId) + .then().log().all() + .extract(); + + // then + List actual = toResponses(response, CheerTalkResponse.Blocked.class); + assertAll( + () -> assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()), + () -> assertThat(actual).map(CheerTalkResponse.Blocked::cheerTalkId) + .containsExactly(19L, 14L), + () -> assertThat(actual).map(CheerTalkResponse.Blocked::content).containsExactly("응원톡17", "블락된 응원톡") + ); + } } diff --git a/src/test/resources/cheer-talk-fixture.sql b/src/test/resources/cheer-talk-fixture.sql index 5c04d0fc..1b7a06cf 100644 --- a/src/test/resources/cheer-talk-fixture.sql +++ b/src/test/resources/cheer-talk-fixture.sql @@ -4,7 +4,7 @@ SET foreign_key_checks = 0; -- 농구 게임 (game_id = 1) 응원톡 픽스처 INSERT INTO members (id, organization_id, email, password, is_manager, last_login) -VALUES (1, 1, 'john@example.com', '$2a$10$yviVCR3GmaU6cPJT.8vaMOwph9WzbX6wtn9iERu3148ZP8XlKbakO', true, +VALUES (1, 1, 'john.doe@example.com', '$2a$10$yviVCR3GmaU6cPJT.8vaMOwph9WzbX6wtn9iERu3148ZP8XlKbakO', true, '2024-06-15 10:00:00'), (2, 1, 'jane@example.com', '$2a$10$yviVCR3GmaU6cPJT.8vaMOwph9WzbX6wtn9iERu3148ZP8XlKbakO', false, '2024-06-15 09:30:00'); From 44f9964fafdd5acb8e6bdf842805c652daa841a6 Mon Sep 17 00:00:00 2001 From: fingersdanny Date: Sun, 22 Sep 2024 17:24:50 +0900 Subject: [PATCH 09/13] =?UTF-8?q?[DOCS]=20API=20=EB=AA=85=EC=84=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/api.adoc | 4 + src/main/resources/static/docs/api.html | 346 ++++++++++++++++++++++-- 2 files changed, 328 insertions(+), 22 deletions(-) diff --git a/src/docs/asciidoc/api.adoc b/src/docs/asciidoc/api.adoc index aa3b04c1..365631c3 100644 --- a/src/docs/asciidoc/api.adoc +++ b/src/docs/asciidoc/api.adoc @@ -20,6 +20,10 @@ operation::cheer-talk-query-controller-test/응원톡을_조회한다[snippets=' operation::cheer-talk-query-controller-test/리그의_신고된_응원톡을_조회한다[snippets='http-request,query-parameters,path-parameters,http-response,response-fields'] +=== 가려진 리그의 응원톡 전체 조회 + +operation::cheer-talk-query-controller-test/리그의_가려진_응원톡을_조회한다[snippets='http-request,query-parameters,path-parameters,http-response,response-fields'] + == 게임 API === 게임 상세 조회 diff --git a/src/main/resources/static/docs/api.html b/src/main/resources/static/docs/api.html index b22c8662..3d46ed7e 100644 --- a/src/main/resources/static/docs/api.html +++ b/src/main/resources/static/docs/api.html @@ -451,6 +451,8 @@

훕치치 서버 API 문서

  • 게임 API @@ -717,6 +719,312 @@

    +

    신고된 리그의 응원톡 전체 조회

    +
    +

    HTTP request

    +
    +
    +
    GET /leagues/1/cheer-talks/reported?cursor=1&size=2 HTTP/1.1
    +Content-Type: application/json
    +Host: www.api.hufstreaming.site
    +Cookie: HCC_SES=temp-cookie
    +
    +
    +
    +
    +

    Query parameters

    + ++++ + + + + + + + + + + + + + + + + +
    ParameterDescription

    cursor

    마지막 응원톡의 ID

    size

    조회하고자 하는 응원톡의 개수

    +
    +
    +

    Path parameters

    + + ++++ + + + + + + + + + + + + +
    Table 1. /leagues/{leagueId}/cheer-talks/reported
    ParameterDescription

    leagueId

    리그의 ID

    +
    +
    +

    HTTP response

    +
    +
    +
    HTTP/1.1 200 OK
    +Vary: Origin
    +Vary: Access-Control-Request-Method
    +Vary: Access-Control-Request-Headers
    +Content-Type: application/json
    +Content-Length: 473
    +
    +[ {
    +  "cheerTalkId" : 2,
    +  "gameId" : 1,
    +  "leagueId" : 1,
    +  "content" : "응원해요",
    +  "gameTeamId" : 1,
    +  "createdAt" : "2024-01-21T11:46:00",
    +  "isBlocked" : false,
    +  "gameName" : "게임 이름",
    +  "leagueName" : "리그 이름"
    +}, {
    +  "cheerTalkId" : 3,
    +  "gameId" : 1,
    +  "leagueId" : 1,
    +  "content" : "파이팅",
    +  "gameTeamId" : 2,
    +  "createdAt" : "2024-01-21T11:46:00",
    +  "isBlocked" : false,
    +  "gameName" : "게임 이름",
    +  "leagueName" : "리그 이름"
    +} ]
    +
    +
    +
    +
    +

    Response fields

    + +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    PathTypeDescription

    [].cheerTalkId

    Number

    응원톡의 ID

    [].gameId

    Number

    응원톡이 등록된 게임의 ID

    [].leagueId

    Number

    응원톡이 등록된 리그의 ID

    [].content

    String

    응원톡의 내용

    [].gameTeamId

    Number

    응원톡에 해당하는 게임팀의 ID

    [].createdAt

    String

    생성된 날짜 및 시각

    [].isBlocked

    Boolean

    응원톡의 블락 여부

    [].gameName

    String

    응원톡이 등록된 게임의 이름

    [].leagueName

    String

    응원톡이 등록된 리그의 이름

    +
    + +
    +

    가려진 리그의 응원톡 전체 조회

    +
    +

    HTTP request

    +
    +
    +
    GET /leagues/1/cheer-talks/blocked?cursor=1&size=2 HTTP/1.1
    +Content-Type: application/json
    +Host: www.api.hufstreaming.site
    +Cookie: HCC_SES=temp-cookie
    +
    +
    +
    +
    +

    Query parameters

    + ++++ + + + + + + + + + + + + + + + + +
    ParameterDescription

    cursor

    마지막 응원톡의 ID

    size

    조회하고자 하는 응원톡의 개수

    +
    +
    +

    Path parameters

    + + ++++ + + + + + + + + + + + + +
    Table 1. /leagues/{leagueId}/cheer-talks/blocked
    ParameterDescription

    leagueId

    리그의 ID

    +
    +
    +

    HTTP response

    +
    +
    +
    HTTP/1.1 200 OK
    +Vary: Origin
    +Vary: Access-Control-Request-Method
    +Vary: Access-Control-Request-Headers
    +Content-Type: application/json
    +Content-Length: 539
    +
    +[ {
    +  "cheerTalkId" : 2,
    +  "gameId" : 1,
    +  "leagueId" : 1,
    +  "content" : "미안하다이거보여주려고어그로끌었다",
    +  "createdAt" : "2024-01-21T11:46:00",
    +  "gameName" : "제 1경기 학츄핑 vs 하츄핑",
    +  "leagueName" : "매봉역 배 타코 빨리 먹기 대작전"
    +}, {
    +  "cheerTalkId" : 3,
    +  "gameId" : 1,
    +  "leagueId" : 1,
    +  "content" : "이학을국회로",
    +  "createdAt" : "2024-01-21T11:46:00",
    +  "gameName" : "제 2경기 학츄핑 vs 시진핑",
    +  "leagueName" : "매봉역 배 타코 빨리 먹기 대작전"
    +} ]
    +
    +
    +
    +
    +

    Response fields

    + +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    PathTypeDescription

    [].cheerTalkId

    Number

    응원톡의 ID

    [].gameId

    Number

    응원톡이 등록된 게임의 ID

    [].leagueId

    Number

    응원톡이 등록된 리그의 ID

    [].content

    String

    응원톡의 내용

    [].createdAt

    String

    생성된 날짜 및 시각

    [].gameName

    String

    응원톡이 등록된 게임의 이름

    [].leagueName

    String

    응원톡이 등록된 리그의 이름

    +
    +
    @@ -1939,19 +2246,14 @@

    organizationId

    -

    Number

    -

    조직 id

    - -

    name

    String

    대회 이름

    maxRound

    -

    String

    -

    대회 진행 라운드 수

    +

    Number

    +

    대회 진행 라운드 수. 결승은 2

    startAt

    @@ -1986,14 +2288,14 @@

    PUT /leagues/5124 HTTP/1.1
     Content-Type: application/json
    -Content-Length: 166
    +Content-Length: 164
     Host: www.api.hufstreaming.site
     Cookie: HCC_SES=temp-cookie
     
     {
       "name" : "훕치치배 망고 빨리먹기 대회",
    -  "startAt" : "2024-09-18T18:41:01.856257",
    -  "endAt" : "2024-09-18T18:41:01.856261",
    +  "startAt" : "2024-09-22T17:24:33.910897",
    +  "endAt" : "2024-09-22T17:24:33.9109",
       "maxRound" : "16강"
     }
    @@ -2865,7 +3167,7 @@

    From 0a9219f99861460d08ed8bcde570510585e954c3 Mon Sep 17 00:00:00 2001 From: fingersdanny Date: Sun, 29 Sep 2024 17:17:41 +0900 Subject: [PATCH 10/13] =?UTF-8?q?[REFACTOR]=20Permission=20Validator=20?= =?UTF-8?q?=ED=99=9C=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/CheerTalkQueryService.java | 105 +++++++++--------- 1 file changed, 51 insertions(+), 54 deletions(-) diff --git a/src/main/java/com/sports/server/query/application/CheerTalkQueryService.java b/src/main/java/com/sports/server/query/application/CheerTalkQueryService.java index 34dfc6dd..f5dc3f42 100644 --- a/src/main/java/com/sports/server/query/application/CheerTalkQueryService.java +++ b/src/main/java/com/sports/server/query/application/CheerTalkQueryService.java @@ -1,94 +1,91 @@ package com.sports.server.query.application; -import com.sports.server.auth.exception.AuthorizationErrorMessages; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + import com.sports.server.command.cheertalk.domain.CheerTalk; import com.sports.server.command.league.domain.League; import com.sports.server.command.member.domain.Member; import com.sports.server.common.application.EntityUtils; +import com.sports.server.common.application.PermissionValidator; import com.sports.server.common.dto.PageRequestDto; -import com.sports.server.common.exception.UnauthorizedException; import com.sports.server.query.dto.response.CheerTalkResponse; import com.sports.server.query.repository.CheerTalkDynamicRepository; import com.sports.server.query.repository.GameQueryRepository; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; + import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @Transactional(readOnly = true) public class CheerTalkQueryService { - private final CheerTalkDynamicRepository cheerTalkDynamicRepository; + private final CheerTalkDynamicRepository cheerTalkDynamicRepository; - private final GameQueryRepository gameQueryRepository; + private final GameQueryRepository gameQueryRepository; - private final EntityUtils entityUtils; + private final EntityUtils entityUtils; - public List getCheerTalksByGameId(final Long gameId, - final PageRequestDto pageRequest) { - List cheerTalks = cheerTalkDynamicRepository.findByGameIdOrderByStartTime( - gameId, pageRequest.cursor(), pageRequest.size() - ); + public List getCheerTalksByGameId(final Long gameId, + final PageRequestDto pageRequest) { + List cheerTalks = cheerTalkDynamicRepository.findByGameIdOrderByStartTime( + gameId, pageRequest.cursor(), pageRequest.size() + ); - List responses = cheerTalks.stream() - .map(CheerTalkResponse.ForSpectator::new) - .collect(Collectors.toList()); + List responses = cheerTalks.stream() + .map(CheerTalkResponse.ForSpectator::new) + .collect(Collectors.toList()); - Collections.reverse(responses); - return responses; - } - - public List getReportedCheerTalksByLeagueId(final Long leagueId, - final PageRequestDto pageRequest, - final Member manager) { - League league = entityUtils.getEntity(leagueId, League.class); - PermissionValidator.checkPermission(league, manager); + Collections.reverse(responses); + return responses; + } - List reportedCheerTalks = cheerTalkDynamicRepository.findReportedCheerTalksByLeagueId( - leagueId, pageRequest.cursor(), pageRequest.size() - ); + public List getReportedCheerTalksByLeagueId(final Long leagueId, + final PageRequestDto pageRequest, + final Member manager) { + League league = entityUtils.getEntity(leagueId, League.class); + PermissionValidator.checkPermission(league, manager); - return reportedCheerTalks.stream() - .map(cheerTalk -> new CheerTalkResponse.ForManager(cheerTalk, - gameQueryRepository.findByGameTeamIdWithLeague(cheerTalk.getGameTeamId()))).toList(); - } + List reportedCheerTalks = cheerTalkDynamicRepository.findReportedCheerTalksByLeagueId( + leagueId, pageRequest.cursor(), pageRequest.size() + ); - public List getUnblockedCheerTalksByLeagueId(Long leagueId, - PageRequestDto pageRequest, - Member manager) { - League league = entityUtils.getEntity(leagueId, League.class); - PermissionValidator.checkPermission(league, manager); + return reportedCheerTalks.stream() + .map(cheerTalk -> new CheerTalkResponse.ForManager(cheerTalk, + gameQueryRepository.findByGameTeamIdWithLeague(cheerTalk.getGameTeamId()))).toList(); + } - List cheerTalks = cheerTalkDynamicRepository.findUnblockedCheerTalksByLeagueId( - leagueId, pageRequest.cursor(), pageRequest.size() - ); + public List getUnblockedCheerTalksByLeagueId(Long leagueId, + PageRequestDto pageRequest, + Member manager) { + League league = entityUtils.getEntity(leagueId, League.class); + PermissionValidator.checkPermission(league, manager); - return cheerTalks.stream() - .map(cheerTalk -> new ForManager(cheerTalk, - gameQueryRepository.findByGameTeamIdWithLeague(cheerTalk.getGameTeamId()))).toList(); - } + List cheerTalks = cheerTalkDynamicRepository.findUnblockedCheerTalksByLeagueId( + leagueId, pageRequest.cursor(), pageRequest.size() + ); + return cheerTalks.stream() + .map(cheerTalk -> new CheerTalkResponse.ForManager(cheerTalk, + gameQueryRepository.findByGameTeamIdWithLeague(cheerTalk.getGameTeamId()))).toList(); + } - public List getBlockedCheerTalksByLeagueId(final Long leagueId, + public List getBlockedCheerTalksByLeagueId(final Long leagueId, final PageRequestDto pageable, final Member member) { League league = entityUtils.getEntity(leagueId, League.class); - if (!league.isManagedBy(member)) { - throw new UnauthorizedException(AuthorizationErrorMessages.PERMISSION_DENIED); - } + PermissionValidator.checkPermission(league, member); List blockedCheerTalks = cheerTalkDynamicRepository.findBlockedCheerTalksByLeagueId( leagueId, pageable.cursor(), pageable.size()); return blockedCheerTalks.stream() - .map(cheerTalk -> { - GameTeam gameTeam = entityUtils.getEntity(cheerTalk.getGameTeamId(), GameTeam.class); - return new CheerTalkResponse.Blocked(cheerTalk, gameTeam.getGame()); - }).toList(); + .map(cheerTalk -> new CheerTalkResponse.ForManager(cheerTalk, + gameQueryRepository.findByGameTeamIdWithLeague(cheerTalk.getGameTeamId()))).toList(); } } From a978da4f1b11fa51952fbd07e7d99e3ecbce7971 Mon Sep 17 00:00:00 2001 From: fingersdanny Date: Sun, 29 Sep 2024 17:18:42 +0900 Subject: [PATCH 11/13] =?UTF-8?q?refactor=20:=20=EA=B3=B5=ED=86=B5?= =?UTF-8?q?=EB=90=9C=20=EC=9D=91=EB=8B=B5=EC=9C=BC=EB=A1=9C=20=EB=B0=94?= =?UTF-8?q?=EA=BE=B8=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20(ForManager)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/query/presentation/CheerTalkQueryController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sports/server/query/presentation/CheerTalkQueryController.java b/src/main/java/com/sports/server/query/presentation/CheerTalkQueryController.java index cb1a8233..b5bcd023 100644 --- a/src/main/java/com/sports/server/query/presentation/CheerTalkQueryController.java +++ b/src/main/java/com/sports/server/query/presentation/CheerTalkQueryController.java @@ -42,7 +42,7 @@ public ResponseEntity> getUnblockedCheerTalks } @GetMapping("/leagues/{leagueId}/cheer-talks/blocked") - public ResponseEntity> getAllBlockedCheerTalks( + public ResponseEntity> getAllBlockedCheerTalks( @PathVariable final Long leagueId, @ModelAttribute final PageRequestDto pageable, Member member) { From 59605200d1f02454073e4020d0077a05ee452b0f Mon Sep 17 00:00:00 2001 From: fingersdanny Date: Sun, 29 Sep 2024 17:19:14 +0900 Subject: [PATCH 12/13] =?UTF-8?q?fix=20:=20HttpMethod=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/sports/server/auth/config/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sports/server/auth/config/SecurityConfig.java b/src/main/java/com/sports/server/auth/config/SecurityConfig.java index 78808c7f..2963d91a 100644 --- a/src/main/java/com/sports/server/auth/config/SecurityConfig.java +++ b/src/main/java/com/sports/server/auth/config/SecurityConfig.java @@ -51,7 +51,7 @@ SecurityFilterChain filterChain(HttpSecurity http, MvcRequestMatcher.Builder mvc mvc.pattern(HttpMethod.POST, "/leagues/{leagueId}/teams/{teamId}/delete-logo"), mvc.pattern(HttpMethod.GET, "/leagues/{leagueId}/cheer-talks/**"), mvc.pattern(HttpMethod.POST, "/leagues/{leagueId}/games"), - mvc.pattern(HttpMethod.POST, "/leagues/{leagueId}/cheer-talks/blocked"), + mvc.pattern(HttpMethod.GET, "/leagues/{leagueId}/cheer-talks/blocked"), mvc.pattern(HttpMethod.POST, "/games/*/timelines/**"), mvc.pattern(HttpMethod.POST, "/games/{gameId}/lineup-players/{lineupPlayerId}/**"), mvc.pattern(HttpMethod.PATCH, "/cheer-talks/{leagueId}/{cheerTalkId}/**") From 6d7f9a572f82e14b4a2e214533cf4f53895f3463 Mon Sep 17 00:00:00 2001 From: fingersdanny Date: Sun, 29 Sep 2024 17:30:05 +0900 Subject: [PATCH 13/13] =?UTF-8?q?test=20:=20=EA=B9=A8=EC=A7=80=EB=8A=94=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EB=93=A4=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20-=20=EA=B6=8C=ED=95=9C=EC=9D=B4=20?= =?UTF-8?q?=EC=9E=88=EB=8A=94=20=EC=82=AC=EC=9A=A9=EC=9E=90=EB=8A=94=20MOC?= =?UTF-8?q?K=5FEMAIL=EB=A1=9C=20=ED=86=B5=EC=9D=BC=20-=20=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=EC=9D=B4=20=EC=97=86=EB=8A=94=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=EC=97=90=EB=9F=AC=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20-=20=EC=9D=91=EB=8B=B5=20DTO=20ForManager?= =?UTF-8?q?=EB=A1=9C=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../acceptance/CheerTalkAcceptanceTest.java | 4 +- .../CheerTalkQueryAcceptanceTest.java | 8 +- .../CheerTalkQueryServiceTest.java | 86 ++--- .../CheerTalkQueryControllerTest.java | 330 +++++++++--------- 4 files changed, 212 insertions(+), 216 deletions(-) diff --git a/src/test/java/com/sports/server/command/cheertalk/acceptance/CheerTalkAcceptanceTest.java b/src/test/java/com/sports/server/command/cheertalk/acceptance/CheerTalkAcceptanceTest.java index 84e51bb6..8f1280e8 100644 --- a/src/test/java/com/sports/server/command/cheertalk/acceptance/CheerTalkAcceptanceTest.java +++ b/src/test/java/com/sports/server/command/cheertalk/acceptance/CheerTalkAcceptanceTest.java @@ -42,7 +42,7 @@ public class CheerTalkAcceptanceTest extends AcceptanceTest { Long leagueId = 1L; Long cheerTalkId = 1L; - configureMockJwtForEmail("john@example.com"); + configureMockJwtForEmail(MOCK_EMAIL); // when ExtractableResponse patchResponse = RestAssured.given().log().all() @@ -72,7 +72,7 @@ public class CheerTalkAcceptanceTest extends AcceptanceTest { Long leagueId = 1L; Long cheerTalkId = 14L; - configureMockJwtForEmail("john@example.com"); + configureMockJwtForEmail(MOCK_EMAIL); // when ExtractableResponse patchResponse = RestAssured.given().log().all() diff --git a/src/test/java/com/sports/server/query/acceptance/CheerTalkQueryAcceptanceTest.java b/src/test/java/com/sports/server/query/acceptance/CheerTalkQueryAcceptanceTest.java index ecde88a8..bd684c31 100644 --- a/src/test/java/com/sports/server/query/acceptance/CheerTalkQueryAcceptanceTest.java +++ b/src/test/java/com/sports/server/query/acceptance/CheerTalkQueryAcceptanceTest.java @@ -194,7 +194,7 @@ class GetCommentsTest { // given Long leagueId = 1L; - configureMockJwtForEmail("john@example.com"); + configureMockJwtForEmail(MOCK_EMAIL); // when ExtractableResponse response = RestAssured.given().log().all() @@ -241,12 +241,12 @@ class GetCommentsTest { .extract(); // then - List actual = toResponses(response, CheerTalkResponse.Blocked.class); + List actual = toResponses(response, CheerTalkResponse.ForManager.class); assertAll( () -> assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()), - () -> assertThat(actual).map(CheerTalkResponse.Blocked::cheerTalkId) + () -> assertThat(actual).map(CheerTalkResponse.ForManager::cheerTalkId) .containsExactly(19L, 14L), - () -> assertThat(actual).map(CheerTalkResponse.Blocked::content).containsExactly("응원톡17", "블락된 응원톡") + () -> assertThat(actual).map(CheerTalkResponse.ForManager::content).containsExactly("응원톡17", "블락된 응원톡") ); } } diff --git a/src/test/java/com/sports/server/query/application/CheerTalkQueryServiceTest.java b/src/test/java/com/sports/server/query/application/CheerTalkQueryServiceTest.java index fd60ed44..f0b91c2f 100644 --- a/src/test/java/com/sports/server/query/application/CheerTalkQueryServiceTest.java +++ b/src/test/java/com/sports/server/query/application/CheerTalkQueryServiceTest.java @@ -97,14 +97,6 @@ class TestFindReportedCheerTalksByLeagueId { @Nested @DisplayName("가려진 응원톡 전체 조회") class TestFindBlockedCheerTalksByLeagueId { - private PageRequestDto pageRequestDto; - private Member manager; - - @BeforeEach - void setUp() { - pageRequestDto = new PageRequestDto(null, 10); - manager = entityUtils.getEntity(1L, Member.class); - } @Test void 가려진_응원톡만_조회된다() throws Exception { @@ -113,8 +105,45 @@ void setUp() { List blockedCheerTalkIds = List.of(19L, 14L); // when - List responses = cheerTalkQueryService.getBlockedCheerTalksByLeagueId( + List responses = cheerTalkQueryService.getBlockedCheerTalksByLeagueId( + leagueId, pageRequestDto, manager); + + // then + assertAll( + () -> assertThat(responses.size()).isEqualTo(2), + () -> assertThat( + responses.stream().map(CheerTalkResponse.ForManager::cheerTalkId).toList()).containsAll(blockedCheerTalkIds) + ); + } + + @Test + void 해당_리그의_응원톡만_조회된다() { + // given + Long leagueId = 1L; + + // when + List responses = cheerTalkQueryService.getBlockedCheerTalksByLeagueId( leagueId, pageRequestDto, manager); + + // then + assertThat(responses.stream().map(CheerTalkResponse.ForManager::leagueId).toList()).containsOnly(leagueId); + } + + @Test + void 리그의_매니저가_아닌_경우_예외가_발생한다() { + // given + Long leagueId = 1L; + Member invalidManager = entityUtils.getEntity(2L, Member.class); + + // when + ThrowableAssert.ThrowingCallable actual = () -> cheerTalkQueryService.getBlockedCheerTalksByLeagueId( + leagueId, pageRequestDto, invalidManager); + + // when & then + assertThatThrownBy(actual) + .isInstanceOf(UnauthorizedException.class); + } + } @Nested @DisplayName("블락되지 않은 리그의 응원톡을 전체 조회 할 때") class TestFindUnblockedCheerTalksByLeagueId { @@ -173,43 +202,4 @@ void setUp() { ).containsOnly(leagueId); } } - - - // then - assertAll( - () -> assertThat(responses.size()).isEqualTo(2), - () -> assertThat( - responses.stream().map(CheerTalkResponse.Blocked::cheerTalkId).toList()).containsAll(blockedCheerTalkIds) - ); - } - - @Test - void 해당_리그의_응원톡만_조회된다() { - // given - Long leagueId = 1L; - - // when - List responses = cheerTalkQueryService.getBlockedCheerTalksByLeagueId( - leagueId, pageRequestDto, manager); - - // then - assertThat(responses.stream().map(CheerTalkResponse.Blocked::leagueId).toList()).containsOnly(leagueId); - } - - @Test - void 리그의_매니저가_아닌_경우_예외가_발생한다() { - // given - Long leagueId = 1L; - Member invalidManager = entityUtils.getEntity(2L, Member.class); - - // when - ThrowableAssert.ThrowingCallable actual = () -> cheerTalkQueryService.getBlockedCheerTalksByLeagueId( - leagueId, pageRequestDto, invalidManager); - - // when & then - assertThatThrownBy(actual) - .isInstanceOf(UnauthorizedException.class) - .hasMessage(AuthorizationErrorMessages.PERMISSION_DENIED); - } - } } diff --git a/src/test/java/com/sports/server/query/presentation/CheerTalkQueryControllerTest.java b/src/test/java/com/sports/server/query/presentation/CheerTalkQueryControllerTest.java index a56e021c..bc86d257 100644 --- a/src/test/java/com/sports/server/query/presentation/CheerTalkQueryControllerTest.java +++ b/src/test/java/com/sports/server/query/presentation/CheerTalkQueryControllerTest.java @@ -1,9 +1,9 @@ package com.sports.server.query.presentation; - import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.*; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; @@ -16,9 +16,12 @@ import com.sports.server.common.dto.PageRequestDto; import com.sports.server.query.dto.response.CheerTalkResponse; import com.sports.server.support.DocumentationTest; + import jakarta.servlet.http.Cookie; + import java.time.LocalDateTime; import java.util.List; + import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.restdocs.payload.JsonFieldType; @@ -26,173 +29,173 @@ public class CheerTalkQueryControllerTest extends DocumentationTest { - @Test - void 응원톡을_조회한다() throws Exception { - - //given - Long gameId = 1L; - - PageRequestDto pageRequestDto = new PageRequestDto(1L, 2); - - LocalDateTime createdAt = LocalDateTime.of(2024, 1, 21, 11, 46, 0); - List response = List.of( - new CheerTalkResponse.ForSpectator( - 2L, "응원해요", 1L, createdAt, false - ), - new CheerTalkResponse.ForSpectator( - 3L, "파이팅", 2L, createdAt, false - ) - ); - - given(cheerTalkQueryService.getCheerTalksByGameId(gameId, pageRequestDto)) - .willReturn(response); - - // when - ResultActions result = mockMvc.perform(get("/games/{gameId}/cheer-talks", gameId) - .queryParam("cursor", String.valueOf(1)) - .queryParam("size", String.valueOf(2)) - .contentType(MediaType.APPLICATION_JSON) - ); - - result.andExpect((status().isOk())) - .andDo(restDocsHandler.document( - queryParameters( - parameterWithName("cursor").description("마지막 응원톡의 ID"), - parameterWithName("size").description("조회하고자 하는 응원톡의 개수") - ), - pathParameters( - parameterWithName("gameId").description("게임의 ID") - ), - responseFields( - fieldWithPath("[].cheerTalkId").type(JsonFieldType.NUMBER).description("응원톡의 ID"), - fieldWithPath("[].content").type(JsonFieldType.STRING).description("응원톡의 내용"), - fieldWithPath("[].gameTeamId").type(JsonFieldType.NUMBER) - .description("응원톡에 해당하는 게임팀의 ID"), - fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("생성된 날짜 및 시각"), - fieldWithPath("[].isBlocked").type(JsonFieldType.BOOLEAN).description("응원톡의 블락 여부") - ) - )); - } - - @Test - void 리그의_신고된_응원톡을_조회한다() throws Exception { - //given - Long leagueId = 1L; - - PageRequestDto pageRequestDto = new PageRequestDto(1L, 2); - - LocalDateTime createdAt = LocalDateTime.of(2024, 1, 21, 11, 46, 0); - List response = List.of( - new CheerTalkResponse.ForManager( - 2L, 1L, 1L, "응원해요", 1L, createdAt, false, "게임 이름", "리그 이름" - ), - new CheerTalkResponse.ForManager( - 3L, 1L, 1L, "파이팅", 2L, createdAt, false, "게임 이름", "리그 이름" - ) - ); - - given(cheerTalkQueryService.getReportedCheerTalksByLeagueId( - eq(leagueId), - eq(pageRequestDto), - any(Member.class)) - ).willReturn(response); - - // when - ResultActions result = mockMvc.perform(get("/leagues/{leagueId}/cheer-talks/reported", leagueId) - .queryParam("cursor", String.valueOf(1)) - .queryParam("size", String.valueOf(2)) - .contentType(MediaType.APPLICATION_JSON) - .cookie(new Cookie(COOKIE_NAME, "temp-cookie")) - ); - - result.andExpect((status().isOk())) - .andDo(restDocsHandler.document( - queryParameters( - parameterWithName("cursor").description("마지막 응원톡의 ID"), - parameterWithName("size").description("조회하고자 하는 응원톡의 개수") - ), - pathParameters( - parameterWithName("leagueId").description("리그의 ID") - ), - responseFields( - fieldWithPath("[].cheerTalkId").type(JsonFieldType.NUMBER).description("응원톡의 ID"), - fieldWithPath("[].gameId").type(JsonFieldType.NUMBER).description("응원톡이 등록된 게임의 ID"), - fieldWithPath("[].leagueId").type(JsonFieldType.NUMBER).description("응원톡이 등록된 리그의 ID"), - fieldWithPath("[].content").type(JsonFieldType.STRING).description("응원톡의 내용"), - fieldWithPath("[].gameTeamId").type(JsonFieldType.NUMBER) - .description("응원톡에 해당하는 게임팀의 ID"), - fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("생성된 날짜 및 시각"), - fieldWithPath("[].isBlocked").type(JsonFieldType.BOOLEAN).description("응원톡의 블락 여부"), - fieldWithPath("[].gameName").type(JsonFieldType.STRING).description("응원톡이 등록된 게임의 이름"), - fieldWithPath("[].leagueName").type(JsonFieldType.STRING).description("응원톡이 등록된 리그의 이름") - ) - )); - } - - @Test - void 리그의_차단되지_않은_응원톡을_조회한다() throws Exception { - //given - Long leagueId = 1L; - - PageRequestDto pageRequestDto = new PageRequestDto(1L, 2); - - LocalDateTime createdAt = LocalDateTime.of(2024, 1, 21, 11, 46, 0); - List response = List.of( - new CheerTalkResponse.ForManager( - 2L, 1L, 1L, "응원해요", 1L, createdAt, false, "게임 이름", "리그 이름" - ), - new CheerTalkResponse.ForManager( - 3L, 1L, 1L, "파이팅", 2L, createdAt, false, "게임 이름", "리그 이름" - ) - ); - - given(cheerTalkQueryService.getUnblockedCheerTalksByLeagueId( - eq(leagueId), - eq(pageRequestDto), - any(Member.class)) - ).willReturn(response); - - // when - ResultActions result = mockMvc.perform(get("/leagues/{leagueId}/cheer-talks", leagueId) - .queryParam("cursor", String.valueOf(1)) - .queryParam("size", String.valueOf(2)) - .contentType(MediaType.APPLICATION_JSON) - .cookie(new Cookie(COOKIE_NAME, "temp-cookie")) - ); - - result.andExpect((status().isOk())) - .andDo(restDocsHandler.document( - queryParameters( - parameterWithName("cursor").description("마지막 응원톡의 ID"), - parameterWithName("size").description("조회하고자 하는 응원톡의 개수") - ), - pathParameters( - parameterWithName("leagueId").description("리그의 ID") - ), - responseFields( - fieldWithPath("[].cheerTalkId").type(JsonFieldType.NUMBER).description("응원톡의 ID"), - fieldWithPath("[].gameId").type(JsonFieldType.NUMBER).description("응원톡이 등록된 게임의 ID"), - fieldWithPath("[].leagueId").type(JsonFieldType.NUMBER).description("응원톡이 등록된 리그의 ID"), - fieldWithPath("[].content").type(JsonFieldType.STRING).description("응원톡의 내용"), - fieldWithPath("[].gameTeamId").type(JsonFieldType.NUMBER) - .description("응원톡에 해당하는 게임팀의 ID"), - fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("생성된 날짜 및 시각"), - fieldWithPath("[].isBlocked").type(JsonFieldType.BOOLEAN).description("응원톡의 블락 여부"), - fieldWithPath("[].gameName").type(JsonFieldType.STRING).description("응원톡이 등록된 게임의 이름"), - fieldWithPath("[].leagueName").type(JsonFieldType.STRING).description("응원톡이 등록된 리그의 이름") - ) - )); - } + @Test + void 응원톡을_조회한다() throws Exception { + + //given + Long gameId = 1L; + + PageRequestDto pageRequestDto = new PageRequestDto(1L, 2); + + LocalDateTime createdAt = LocalDateTime.of(2024, 1, 21, 11, 46, 0); + List response = List.of( + new CheerTalkResponse.ForSpectator( + 2L, "응원해요", 1L, createdAt, false + ), + new CheerTalkResponse.ForSpectator( + 3L, "파이팅", 2L, createdAt, false + ) + ); + + given(cheerTalkQueryService.getCheerTalksByGameId(gameId, pageRequestDto)) + .willReturn(response); + + // when + ResultActions result = mockMvc.perform(get("/games/{gameId}/cheer-talks", gameId) + .queryParam("cursor", String.valueOf(1)) + .queryParam("size", String.valueOf(2)) + .contentType(MediaType.APPLICATION_JSON) + ); + + result.andExpect((status().isOk())) + .andDo(restDocsHandler.document( + queryParameters( + parameterWithName("cursor").description("마지막 응원톡의 ID"), + parameterWithName("size").description("조회하고자 하는 응원톡의 개수") + ), + pathParameters( + parameterWithName("gameId").description("게임의 ID") + ), + responseFields( + fieldWithPath("[].cheerTalkId").type(JsonFieldType.NUMBER).description("응원톡의 ID"), + fieldWithPath("[].content").type(JsonFieldType.STRING).description("응원톡의 내용"), + fieldWithPath("[].gameTeamId").type(JsonFieldType.NUMBER) + .description("응원톡에 해당하는 게임팀의 ID"), + fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("생성된 날짜 및 시각"), + fieldWithPath("[].isBlocked").type(JsonFieldType.BOOLEAN).description("응원톡의 블락 여부") + ) + )); + } + + @Test + void 리그의_신고된_응원톡을_조회한다() throws Exception { + //given + Long leagueId = 1L; + + PageRequestDto pageRequestDto = new PageRequestDto(1L, 2); + + LocalDateTime createdAt = LocalDateTime.of(2024, 1, 21, 11, 46, 0); + List response = List.of( + new CheerTalkResponse.ForManager( + 2L, 1L, 1L, "응원해요", 1L, createdAt, false, "게임 이름", "리그 이름" + ), + new CheerTalkResponse.ForManager( + 3L, 1L, 1L, "파이팅", 2L, createdAt, false, "게임 이름", "리그 이름" + ) + ); + + given(cheerTalkQueryService.getReportedCheerTalksByLeagueId( + eq(leagueId), + eq(pageRequestDto), + any(Member.class)) + ).willReturn(response); + + // when + ResultActions result = mockMvc.perform(get("/leagues/{leagueId}/cheer-talks/reported", leagueId) + .queryParam("cursor", String.valueOf(1)) + .queryParam("size", String.valueOf(2)) + .contentType(MediaType.APPLICATION_JSON) + .cookie(new Cookie(COOKIE_NAME, "temp-cookie")) + ); + + result.andExpect((status().isOk())) + .andDo(restDocsHandler.document( + queryParameters( + parameterWithName("cursor").description("마지막 응원톡의 ID"), + parameterWithName("size").description("조회하고자 하는 응원톡의 개수") + ), + pathParameters( + parameterWithName("leagueId").description("리그의 ID") + ), + responseFields( + fieldWithPath("[].cheerTalkId").type(JsonFieldType.NUMBER).description("응원톡의 ID"), + fieldWithPath("[].gameId").type(JsonFieldType.NUMBER).description("응원톡이 등록된 게임의 ID"), + fieldWithPath("[].leagueId").type(JsonFieldType.NUMBER).description("응원톡이 등록된 리그의 ID"), + fieldWithPath("[].content").type(JsonFieldType.STRING).description("응원톡의 내용"), + fieldWithPath("[].gameTeamId").type(JsonFieldType.NUMBER) + .description("응원톡에 해당하는 게임팀의 ID"), + fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("생성된 날짜 및 시각"), + fieldWithPath("[].isBlocked").type(JsonFieldType.BOOLEAN).description("응원톡의 블락 여부"), + fieldWithPath("[].gameName").type(JsonFieldType.STRING).description("응원톡이 등록된 게임의 이름"), + fieldWithPath("[].leagueName").type(JsonFieldType.STRING).description("응원톡이 등록된 리그의 이름") + ) + )); + } + + @Test + void 리그의_차단되지_않은_응원톡을_조회한다() throws Exception { + //given + Long leagueId = 1L; + + PageRequestDto pageRequestDto = new PageRequestDto(1L, 2); + + LocalDateTime createdAt = LocalDateTime.of(2024, 1, 21, 11, 46, 0); + List response = List.of( + new CheerTalkResponse.ForManager( + 2L, 1L, 1L, "응원해요", 1L, createdAt, false, "게임 이름", "리그 이름" + ), + new CheerTalkResponse.ForManager( + 3L, 1L, 1L, "파이팅", 2L, createdAt, false, "게임 이름", "리그 이름" + ) + ); + + given(cheerTalkQueryService.getUnblockedCheerTalksByLeagueId( + eq(leagueId), + eq(pageRequestDto), + any(Member.class)) + ).willReturn(response); + + // when + ResultActions result = mockMvc.perform(get("/leagues/{leagueId}/cheer-talks", leagueId) + .queryParam("cursor", String.valueOf(1)) + .queryParam("size", String.valueOf(2)) + .contentType(MediaType.APPLICATION_JSON) + .cookie(new Cookie(COOKIE_NAME, "temp-cookie")) + ); + + result.andExpect((status().isOk())) + .andDo(restDocsHandler.document( + queryParameters( + parameterWithName("cursor").description("마지막 응원톡의 ID"), + parameterWithName("size").description("조회하고자 하는 응원톡의 개수") + ), + pathParameters( + parameterWithName("leagueId").description("리그의 ID") + ), + responseFields( + fieldWithPath("[].cheerTalkId").type(JsonFieldType.NUMBER).description("응원톡의 ID"), + fieldWithPath("[].gameId").type(JsonFieldType.NUMBER).description("응원톡이 등록된 게임의 ID"), + fieldWithPath("[].leagueId").type(JsonFieldType.NUMBER).description("응원톡이 등록된 리그의 ID"), + fieldWithPath("[].content").type(JsonFieldType.STRING).description("응원톡의 내용"), + fieldWithPath("[].gameTeamId").type(JsonFieldType.NUMBER) + .description("응원톡에 해당하는 게임팀의 ID"), + fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("생성된 날짜 및 시각"), + fieldWithPath("[].isBlocked").type(JsonFieldType.BOOLEAN).description("응원톡의 블락 여부"), + fieldWithPath("[].gameName").type(JsonFieldType.STRING).description("응원톡이 등록된 게임의 이름"), + fieldWithPath("[].leagueName").type(JsonFieldType.STRING).description("응원톡이 등록된 리그의 이름") + ) + )); + } @Test void 리그의_가려진_응원톡을_조회한다() throws Exception { // given Long leagueId = 1L; LocalDateTime createdAt = LocalDateTime.of(2024, 1, 21, 11, 46, 0); - List responses = List.of( - new CheerTalkResponse.Blocked(2L, 1L, 1L, "미안하다이거보여주려고어그로끌었다", createdAt, "제 1경기 학츄핑 vs 하츄핑", + List responses = List.of( + new CheerTalkResponse.ForManager(2L, 1L, 1L, "미안하다이거보여주려고어그로끌었다", 1L, createdAt, true, "제 1경기 학츄핑 vs 하츄핑", "매봉역 배 타코 빨리 먹기 대작전"), - new CheerTalkResponse.Blocked(3L, 1L, 1L, "이학을국회로", createdAt, "제 2경기 학츄핑 vs 시진핑", + new CheerTalkResponse.ForManager(3L, 1L, 1L, "이학을국회로", 1L, createdAt, true, "제 2경기 학츄핑 vs 시진핑", "매봉역 배 타코 빨리 먹기 대작전")); doReturn(responses).when(cheerTalkQueryService) @@ -223,7 +226,10 @@ public class CheerTalkQueryControllerTest extends DocumentationTest { fieldWithPath("[].content").type(JsonFieldType.STRING).description("응원톡의 내용"), fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("생성된 날짜 및 시각"), fieldWithPath("[].gameName").type(JsonFieldType.STRING).description("응원톡이 등록된 게임의 이름"), - fieldWithPath("[].leagueName").type(JsonFieldType.STRING).description("응원톡이 등록된 리그의 이름") + fieldWithPath("[].leagueName").type(JsonFieldType.STRING).description("응원톡이 등록된 리그의 이름"), + fieldWithPath("[].gameTeamId").type(JsonFieldType.NUMBER) + .description("응원톡에 해당하는 게임팀의 ID"), + fieldWithPath("[].isBlocked").type(JsonFieldType.BOOLEAN).description("응원톡의 블락 여부") ))); } }