Skip to content

Commit

Permalink
[MERGE] 메인 브랜치와 병합
Browse files Browse the repository at this point in the history
  • Loading branch information
Zena0128 committed Sep 23, 2024
2 parents 47a0149 + 22870d7 commit 81dbec7
Show file tree
Hide file tree
Showing 35 changed files with 928 additions and 188 deletions.
8 changes: 8 additions & 0 deletions src/docs/asciidoc/api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ operation::cheer-talk-controller-test/응원톡을_저장한다[snippets='http-r

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 Expand Up @@ -46,6 +50,10 @@ operation::game-query-controller-test/출전_선수를_조회한다[snippets='ht

operation::game-controller-test/경기를_등록한다[snippets='http-request,path-parameters,http-response']

=== 게임 수정

operation::game-controller-test/경기를_수정한다[snippets='http-request,path-parameters,http-response']

== 라인업 API

=== 라인업 선수 선발로 변경
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ SecurityFilterChain filterChain(HttpSecurity http, MvcRequestMatcher.Builder mvc
mvc.pattern(HttpMethod.GET, "/members/info"),
mvc.pattern(HttpMethod.POST, "/leagues"),
mvc.pattern(HttpMethod.PUT, "/leagues/{leagueId}"),
mvc.pattern(HttpMethod.PUT, "/leagues/{leagueId}/{gameId}"),
mvc.pattern(HttpMethod.POST, "/leagues/*/teams"),
mvc.pattern(HttpMethod.POST, "/leagues/{leagueId}/teams"),
mvc.pattern(HttpMethod.PUT, "/leagues/{leagueId}/teams/{teamId}"),
mvc.pattern(HttpMethod.DELETE, "/leagues/{leagueId}/teams/{teamId}"),
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, "/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 @@ -31,6 +31,10 @@ public boolean isBlocked() {
return isBlocked;
}

public void block() {
this.isBlocked = true;
}

public CheerTalk(final String content, final Long gameTeamId) {
this.createdAt = LocalDateTime.now();
this.content = content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.sports.server.auth.exception.AuthorizationErrorMessages;
import com.sports.server.command.game.domain.Game;
import com.sports.server.command.game.domain.GameRepository;
import com.sports.server.command.game.domain.GameState;
import com.sports.server.command.game.domain.GameTeam;
import com.sports.server.command.game.dto.GameRequestDto;
import com.sports.server.command.league.domain.League;
import com.sports.server.command.league.domain.Round;
import com.sports.server.command.leagueteam.domain.LeagueTeam;
import com.sports.server.command.member.domain.Member;
import com.sports.server.command.sport.domain.Sport;
Expand Down Expand Up @@ -69,4 +71,19 @@ private League getLeagueAndCheckPermission(final Long leagueId, final Member man

return league;
}

@Transactional
public void updateGame(Long leagueId, Long gameId, GameRequestDto.Update request, Member manager) {
League league = entityUtils.getEntity(leagueId, League.class);
if (!league.isManagedBy(manager)) {
throw new UnauthorizedException(AuthorizationErrorMessages.PERMISSION_DENIED);
}
Game game = entityUtils.getEntity(gameId, Game.class);
game.updateName(request.name());
game.updateStartTime(request.startTime());
game.updateVideoId(request.videoId());
game.updateGameQuarter(request.quarter());
game.updateState(GameState.from(request.state()));
game.updateRound(Round.from(request.round()));
}
}
33 changes: 33 additions & 0 deletions src/main/java/com/sports/server/command/game/domain/Game.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sports.server.command.game.domain;

import com.sports.server.command.game.dto.GameRequestDto;
import com.sports.server.command.league.domain.League;
import com.sports.server.command.league.domain.Round;
import com.sports.server.command.member.domain.Member;
Expand All @@ -23,6 +24,7 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;
import org.springframework.http.HttpStatus;

@Entity
Expand Down Expand Up @@ -114,6 +116,37 @@ public void cancelScore(LineupPlayer scorer) {
scoredTeam.cancelScore();
}

public void updateName(String name) {
if (StringUtils.hasText(name)) {
this.name = name;
}
}

public void updateStartTime(LocalDateTime startTime) {
this.startTime = startTime;
}

public void updateVideoId(String videoId) {
if (StringUtils.hasText(videoId)) {
this.videoId = videoId;
}
}

public void updateGameQuarter(String gameQuarter) {
if (StringUtils.hasText(gameQuarter)) {
this.gameQuarter = gameQuarter;
}
}

public void updateState(GameState state) {
this.state = state;
}

public void updateRound(Round round) {
this.round = round;
}


public Game(Sport sport, Member manager, League league, String name, LocalDateTime startTime,
String videoId, String gameQuarter, GameState state, Round round) {
this.sport = sport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ public Game toEntity(Sport sport, Member manager, League league) {
Round.from(round));
}
}
}

public record Update(
String name,
String round,
String quarter,
String state,
LocalDateTime startTime,
String videoId
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
import java.net.URI;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -53,6 +49,15 @@ public ResponseEntity<Void> registerGame(@PathVariable final Long leagueId,
return ResponseEntity.created(URI.create("")).build();
}

@PutMapping("/leagues/{leagueId}/{gameId}")
public ResponseEntity<Void> updateGame(@PathVariable final Long leagueId,
@PathVariable final Long gameId,
@RequestBody final GameRequestDto.Update requestDto,
final Member member) {
gameService.updateGame(leagueId, gameId, requestDto, member);
return ResponseEntity.ok().build();
}

@PatchMapping("/games/{gameId}/{gameTeamId}/lineup-players/{lineupPlayerId}/captain/register")
public ResponseEntity<Void> changePlayerToCaptain(@PathVariable final Long gameId,
@PathVariable final Long lineupPlayerId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.sports.server.command.report.application;

import com.sports.server.command.cheertalk.domain.CheerTalk;
import com.sports.server.command.report.domain.Report;
import com.sports.server.common.application.TextFileProcessor;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional
public class ReportProcessor {

private final TextFileProcessor textFileProcessor;
private static final String FILE_NAME = "static/extra_bad_words.txt";
private static final String DELIM = ",";

private Set<String> cachedBadWords;

public void check(CheerTalk cheerTalk, Report report) {

if (cachedBadWords == null) {
cachedBadWords = textFileProcessor.readFile(FILE_NAME, DELIM);
}

if (cachedBadWords.contains(cheerTalk.getContent())) {
report.updateToValid();
return;
}
report.updateToPending();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,13 @@ private void validateBlockedCheerTalk(CheerTalk cheerTalk) {
public boolean isUnchecked() {
return this.state == ReportState.UNCHECKED;
}

public void updateToValid() {
this.state = ReportState.VALID;
cheerTalk.block();
}

public void updateToPending() {
this.state = ReportState.PENDING;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.sports.server.command.report.infrastructure;

import com.sports.server.command.cheertalk.domain.CheerTalk;
import com.sports.server.command.report.application.ReportProcessor;
import com.sports.server.command.report.domain.Report;
import com.sports.server.command.report.domain.ReportEvent;
import com.sports.server.command.report.exception.ReportErrorMessage;
import com.sports.server.common.exception.CustomException;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;
Expand All @@ -16,7 +13,7 @@
@RequiredArgsConstructor
public class ReportEventHandler {

private final ReportCheckClient reportCheckClient;
private final ReportProcessor reportProcessor;

@TransactionalEventListener
@Async("asyncThreadPool")
Expand All @@ -29,16 +26,32 @@ public void handle(ReportEvent event) {

private void checkReport(Report report) {
CheerTalk cheerTalk = report.getCheerTalk();
ReportCheckRequest request = new ReportCheckRequest(
cheerTalk.getContent(), cheerTalk.getId(), report.getId()
);
ResponseEntity<Void> response = reportCheckClient.check(request);
validateResponse(response);
reportProcessor.check(cheerTalk, report);
}

private void validateResponse(ResponseEntity<Void> response) {
if (response.getStatusCode().is5xxServerError()) {
throw new CustomException(HttpStatus.INTERNAL_SERVER_ERROR, ReportErrorMessage.REPORT_CHECK_SERVER_ERROR);
}
}
// 추후 람다로 이전 시 필요한 메서드들

// @TransactionalEventListener
// @Async("asyncThreadPool")
// public void handle(ReportEvent event) {
// Report report = event.report();
// if (report.isUnchecked()) {
// checkReport(report);
// }
// }
//
// private void checkReport(Report report) {
// CheerTalk cheerTalk = report.getCheerTalk();
// ReportCheckRequest request = new ReportCheckRequest(
// cheerTalk.getContent(), cheerTalk.getId(), report.getId()
// );
// ResponseEntity<Void> response = reportCheckClient.check(request);
// validateResponse(response);
// }
//
// private void validateResponse(ResponseEntity<Void> response) {
// if (response.getStatusCode().is5xxServerError()) {
// throw new CustomException(HttpStatus.INTERNAL_SERVER_ERROR, ReportErrorMessage.REPORT_CHECK_SERVER_ERROR);
// }
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.sports.server.common.application;

import com.sports.server.common.exception.CustomException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

@Service
public class TextFileProcessor {

public Set<String> readFile(String fileName, String delim) {
ClassPathResource resource = new ClassPathResource(fileName);

Set<String> resultSet = new HashSet<>();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8))) {

String line;
while ((line = reader.readLine()) != null) {
String[] tokens = line.split(delim);
for (String token : tokens) {
resultSet.add(token.replaceAll("^[\\s'\"]+|[\\s'\"]+$", ""));
}
}
} catch (IOException e) {
throw new CustomException(HttpStatus.INTERNAL_SERVER_ERROR, "파일을 읽어들이는 도중 예외가 발생했습니다.");
}
return resultSet;
}

}

Loading

0 comments on commit 81dbec7

Please sign in to comment.