-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
12 changed files
with
404 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 59 additions & 44 deletions
103
src/main/java/com/sports/server/query/application/CheerTalkQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,91 @@ | ||
package com.sports.server.query.application; | ||
|
||
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.query.dto.response.CheerTalkResponse; | ||
import com.sports.server.query.dto.response.CheerTalkResponse.ForManager; | ||
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 EntityUtils entityUtils; | ||
|
||
private final GameQueryRepository gameQueryRepository; | ||
public List<CheerTalkResponse.ForSpectator> getCheerTalksByGameId(final Long gameId, | ||
final PageRequestDto pageRequest) { | ||
List<CheerTalk> cheerTalks = cheerTalkDynamicRepository.findByGameIdOrderByStartTime( | ||
gameId, pageRequest.cursor(), pageRequest.size() | ||
); | ||
|
||
private final EntityUtils entityUtils; | ||
List<CheerTalkResponse.ForSpectator> responses = cheerTalks.stream() | ||
.map(CheerTalkResponse.ForSpectator::new) | ||
.collect(Collectors.toList()); | ||
|
||
public List<CheerTalkResponse.ForSpectator> getCheerTalksByGameId(final Long gameId, | ||
final PageRequestDto pageRequest) { | ||
List<CheerTalk> cheerTalks = cheerTalkDynamicRepository.findByGameIdOrderByStartTime( | ||
gameId, pageRequest.cursor(), pageRequest.size() | ||
); | ||
Collections.reverse(responses); | ||
return responses; | ||
} | ||
|
||
List<CheerTalkResponse.ForSpectator> responses = cheerTalks.stream() | ||
.map(CheerTalkResponse.ForSpectator::new) | ||
.collect(Collectors.toList()); | ||
public List<CheerTalkResponse.ForManager> 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<CheerTalk> reportedCheerTalks = cheerTalkDynamicRepository.findReportedCheerTalksByLeagueId( | ||
leagueId, pageRequest.cursor(), pageRequest.size() | ||
); | ||
|
||
public List<CheerTalkResponse.ForManager> 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<CheerTalk> reportedCheerTalks = cheerTalkDynamicRepository.findReportedCheerTalksByLeagueId( | ||
leagueId, pageRequest.cursor(), pageRequest.size() | ||
); | ||
public List<CheerTalkResponse.ForManager> 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<CheerTalk> cheerTalks = cheerTalkDynamicRepository.findUnblockedCheerTalksByLeagueId( | ||
leagueId, pageRequest.cursor(), pageRequest.size() | ||
); | ||
|
||
public List<CheerTalkResponse.ForManager> getUnblockedCheerTalksByLeagueId(Long leagueId, | ||
PageRequestDto pageRequest, | ||
Member manager) { | ||
League league = entityUtils.getEntity(leagueId, League.class); | ||
PermissionValidator.checkPermission(league, manager); | ||
return cheerTalks.stream() | ||
.map(cheerTalk -> new CheerTalkResponse.ForManager(cheerTalk, | ||
gameQueryRepository.findByGameTeamIdWithLeague(cheerTalk.getGameTeamId()))).toList(); | ||
} | ||
|
||
List<CheerTalk> cheerTalks = cheerTalkDynamicRepository.findUnblockedCheerTalksByLeagueId( | ||
leagueId, pageRequest.cursor(), pageRequest.size() | ||
); | ||
public List<CheerTalkResponse.ForManager> getBlockedCheerTalksByLeagueId(final Long leagueId, | ||
final PageRequestDto pageable, | ||
final Member member) { | ||
League league = entityUtils.getEntity(leagueId, League.class); | ||
|
||
return cheerTalks.stream() | ||
.map(cheerTalk -> new ForManager(cheerTalk, | ||
gameQueryRepository.findByGameTeamIdWithLeague(cheerTalk.getGameTeamId()))).toList(); | ||
} | ||
PermissionValidator.checkPermission(league, member); | ||
|
||
List<CheerTalk> blockedCheerTalks = cheerTalkDynamicRepository.findBlockedCheerTalksByLeagueId( | ||
leagueId, pageable.cursor(), pageable.size()); | ||
|
||
return blockedCheerTalks.stream() | ||
.map(cheerTalk -> new CheerTalkResponse.ForManager(cheerTalk, | ||
gameQueryRepository.findByGameTeamIdWithLeague(cheerTalk.getGameTeamId()))).toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ public class CheerTalkAcceptanceTest extends AcceptanceTest { | |
Long leagueId = 1L; | ||
Long cheerTalkId = 1L; | ||
|
||
configureMockJwtForEmail("[email protected]"); | ||
configureMockJwtForEmail(MOCK_EMAIL); | ||
|
||
// when | ||
ExtractableResponse<Response> patchResponse = RestAssured.given().log().all() | ||
|
@@ -72,7 +72,7 @@ public class CheerTalkAcceptanceTest extends AcceptanceTest { | |
Long leagueId = 1L; | ||
Long cheerTalkId = 14L; | ||
|
||
configureMockJwtForEmail("[email protected]"); | ||
configureMockJwtForEmail(MOCK_EMAIL); | ||
|
||
// when | ||
ExtractableResponse<Response> patchResponse = RestAssured.given().log().all() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,7 +164,7 @@ class GetCommentsTest { | |
// given | ||
Long leagueId = 1L; | ||
|
||
configureMockJwtForEmail("[email protected]"); | ||
configureMockJwtForEmail(MOCK_EMAIL); | ||
|
||
// when | ||
ExtractableResponse<Response> response = RestAssured.given().log().all() | ||
|
@@ -194,7 +194,7 @@ class GetCommentsTest { | |
// given | ||
Long leagueId = 1L; | ||
|
||
configureMockJwtForEmail("[email protected]"); | ||
configureMockJwtForEmail(MOCK_EMAIL); | ||
|
||
// when | ||
ExtractableResponse<Response> response = RestAssured.given().log().all() | ||
|
@@ -223,4 +223,30 @@ class GetCommentsTest { | |
.containsOnly(false) | ||
); | ||
} | ||
|
||
@Test | ||
void 리그의_가려진_응원톡을_조회한다() throws Exception { | ||
// given | ||
Long leagueId = 1L; | ||
|
||
configureMockJwtForEmail(MOCK_EMAIL); | ||
|
||
// when | ||
ExtractableResponse<Response> 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<CheerTalkResponse.ForManager> actual = toResponses(response, CheerTalkResponse.ForManager.class); | ||
assertAll( | ||
() -> assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()), | ||
() -> assertThat(actual).map(CheerTalkResponse.ForManager::cheerTalkId) | ||
.containsExactly(19L, 14L), | ||
() -> assertThat(actual).map(CheerTalkResponse.ForManager::content).containsExactly("응원톡17", "블락된 응원톡") | ||
); | ||
} | ||
} |
Oops, something went wrong.