Skip to content

Commit

Permalink
Merge pull request #235 from hufscheer/feat/#195-blocked-cheertalk
Browse files Browse the repository at this point in the history
  • Loading branch information
hodadako authored Sep 29, 2024
2 parents 315b697 + 6d7f9a5 commit ba59e65
Show file tree
Hide file tree
Showing 12 changed files with 404 additions and 239 deletions.
4 changes: 4 additions & 0 deletions src/docs/asciidoc/api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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']

=== 응원톡 가리기

operation::cheer-talk-controller-test/응원톡을_가린다[snippets='http-request,path-parameters,http-response']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +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.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}/**")
Expand Down
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
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();
}
}
private static String checkCheerTalkIsBlocked(CheerTalk cheerTalk) {
if (cheerTalk.isBlocked()) {
return null;
}
return cheerTalk.getContent();
}
}

public record ForManager(
Long cheerTalkId,
Expand All @@ -55,7 +55,5 @@ public ForManager(CheerTalk cheerTalk, Game game) {
);
}
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ public ResponseEntity<List<CheerTalkResponse.ForManager>> getUnblockedCheerTalks
member) {
return ResponseEntity.ok(cheerTalkQueryService.getUnblockedCheerTalksByLeagueId(leagueId, pageRequest, member));
}

@GetMapping("/leagues/{leagueId}/cheer-talks/blocked")
public ResponseEntity<List<CheerTalkResponse.ForManager>> getAllBlockedCheerTalks(
@PathVariable final Long leagueId,
@ModelAttribute final PageRequestDto pageable,
Member member) {
return ResponseEntity.ok(cheerTalkQueryService.getBlockedCheerTalksByLeagueId(leagueId, pageable, member));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface CheerTalkDynamicRepository {
List<CheerTalk> findReportedCheerTalksByLeagueId(Long leagueId, Long cursor, Integer size);

List<CheerTalk> findUnblockedCheerTalksByLeagueId(Long leagueId, Long cursor, Integer size);

List<CheerTalk> findBlockedCheerTalksByLeagueId(Long leagueId, Long cursor, Integer size);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ public List<CheerTalk> findReportedCheerTalksByLeagueId(Long leagueId, Long curs
);
}

@Override
public List<CheerTalk> 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
);
}

@Override
public List<CheerTalk> findUnblockedCheerTalksByLeagueId(Long leagueId, Long cursor, Integer size) {
return applyPagination(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class GetCommentsTest {
// given
Long leagueId = 1L;

configureMockJwtForEmail("[email protected]");
configureMockJwtForEmail(MOCK_EMAIL);

// when
ExtractableResponse<Response> response = RestAssured.given().log().all()
Expand Down Expand Up @@ -194,7 +194,7 @@ class GetCommentsTest {
// given
Long leagueId = 1L;

configureMockJwtForEmail("[email protected]");
configureMockJwtForEmail(MOCK_EMAIL);

// when
ExtractableResponse<Response> response = RestAssured.given().log().all()
Expand Down Expand Up @@ -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", "블락된 응원톡")
);
}
}
Loading

0 comments on commit ba59e65

Please sign in to comment.