Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 가려진 응원톡 전체 조회하기 #235

Merged
merged 15 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']

== 게임 API

=== 게임 상세 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Zena0128 marked this conversation as resolved.
Show resolved Hide resolved
mvc.pattern(HttpMethod.POST, "/games/*/timelines/**"),
mvc.pattern(HttpMethod.POST, "/games/{gameId}/lineup-players/{lineupPlayerId}/**")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CheerTalkResponse.ForSpectator> getCheerTalksByGameId(final Long gameId,
final PageRequestDto pageRequest) {
List<CheerTalk> cheerTalks = cheerTalkDynamicRepository.findByGameIdOrderByStartTime(
gameId, pageRequest.cursor(), pageRequest.size()
);
public List<CheerTalkResponse.ForSpectator> getCheerTalksByGameId(final Long gameId,
final PageRequestDto pageRequest) {
List<CheerTalk> cheerTalks = cheerTalkDynamicRepository.findByGameIdOrderByStartTime(
gameId, pageRequest.cursor(), pageRequest.size()
);

List<CheerTalkResponse.ForSpectator> responses = cheerTalks.stream()
.map(CheerTalkResponse.ForSpectator::new)
.collect(Collectors.toList());
List<CheerTalkResponse.ForSpectator> responses = cheerTalks.stream()
.map(CheerTalkResponse.ForSpectator::new)
.collect(Collectors.toList());

Collections.reverse(responses);
return responses;
}
Collections.reverse(responses);
return responses;
}

public List<CheerTalkResponse.Reported> getReportedCheerTalksByLeagueId(final Long leagueId,
final PageRequestDto pageRequest,
final Member manager) {
League league = entityUtils.getEntity(leagueId, League.class);
public List<CheerTalkResponse.Reported> 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<CheerTalk> reportedCheerTalks = cheerTalkDynamicRepository.findReportedCheerTalksByLeagueId(
leagueId, pageRequest.cursor(), pageRequest.size()
);
List<CheerTalk> 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<CheerTalkResponse.Blocked> 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<CheerTalk> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ public ResponseEntity<List<CheerTalkResponse.Reported>> getAllReportedCheerTalks
Member member) {
return ResponseEntity.ok(cheerTalkQueryService.getReportedCheerTalksByLeagueId(leagueId, pageRequest, member));
}

@GetMapping("/leagues/{leagueId}/cheer-talks/blocked")
public ResponseEntity<List<CheerTalkResponse.Blocked>> 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 @@ -8,4 +8,6 @@ public interface CheerTalkDynamicRepository {
List<CheerTalk> findByGameIdOrderByStartTime(Long gameId, Long cursor, Integer size);

List<CheerTalk> findReportedCheerTalksByLeagueId(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
);
}

private List<CheerTalk> applyPagination(JPAQuery<CheerTalk> query, Long cursor, Integer size) {
return query
.where(getPaginationConditions(cursor))
Expand Down
Loading
Loading