From 61d3f70661d0e61d2b1b3e8b048bb6e17a01c529 Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Mon, 23 Sep 2024 14:27:36 +0900 Subject: [PATCH 01/16] =?UTF-8?q?[FEAT]=20=EC=9D=91=EC=9B=90=ED=86=A1=20?= =?UTF-8?q?=EA=B0=80=EB=A6=AC=EA=B8=B0/=EA=B0=80=EB=A6=AC=EA=B8=B0=20?= =?UTF-8?q?=ED=95=B4=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84=20?= =?UTF-8?q?#231?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/CheerTalkService.java | 67 +++++++++++++++++++ .../command/cheertalk/domain/CheerTalk.java | 4 ++ .../exception/CheerTalkErrorMessages.java | 2 + .../presentation/CheerTalkController.java | 17 +++++ .../server/command/report/domain/Report.java | 6 ++ .../report/exception/ReportErrorMessage.java | 3 + 6 files changed, 99 insertions(+) diff --git a/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java b/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java index 16552ecf..1744abf8 100644 --- a/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java +++ b/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java @@ -2,23 +2,38 @@ import static com.sports.server.command.cheertalk.exception.CheerTalkErrorMessages.CHEER_TALK_CONTAINS_BAD_WORD; +import com.sports.server.auth.exception.AuthorizationErrorMessages; import com.sports.server.command.cheertalk.domain.CheerTalk; import com.sports.server.command.cheertalk.domain.CheerTalkRepository; import com.sports.server.command.cheertalk.domain.LanguageFilter; import com.sports.server.command.cheertalk.dto.CheerTalkRequest; +import com.sports.server.command.cheertalk.exception.CheerTalkErrorMessages; +import com.sports.server.command.league.domain.League; +import com.sports.server.command.member.domain.Member; +import com.sports.server.command.report.domain.Report; +import com.sports.server.command.report.domain.ReportRepository; +import com.sports.server.command.report.domain.ReportState; +import com.sports.server.command.report.exception.ReportErrorMessage; +import com.sports.server.common.application.EntityUtils; import com.sports.server.common.exception.CustomException; +import com.sports.server.common.exception.UnauthorizedException; +import com.sports.server.query.repository.CheerTalkDynamicRepository; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.security.Key; + @Service @Transactional @RequiredArgsConstructor public class CheerTalkService { private final CheerTalkRepository cheerTalkRepository; + private final ReportRepository reportRepository; private final LanguageFilter languageFilter; + private final EntityUtils entityUtils; public void register(final CheerTalkRequest cheerTalkRequest) { validateContent(cheerTalkRequest.content()); @@ -31,4 +46,56 @@ private void validateContent(final String content) { throw new CustomException(HttpStatus.BAD_REQUEST, CHEER_TALK_CONTAINS_BAD_WORD); } } + + public void block(final Long leagueId, final Long cheerTalkId, final Member manager) { + checkPermission(leagueId, manager); + + CheerTalk cheerTalk = entityUtils.getEntity(cheerTalkId, CheerTalk.class); + if (cheerTalk.isBlocked()) { + throw new CustomException(HttpStatus.BAD_REQUEST, CheerTalkErrorMessages.CHEER_TALK_ALREADY_BLOCKED); + } + + Report report = checkReportPendingAndGetReport(cheerTalk); + report.updateToValid(); // 해당 cheerTalk도 같이 block + + } + + public void unblock(final Long leagueId, final Long cheerTalkId, final Member manager) { + checkPermission(leagueId, manager); + + CheerTalk cheerTalk = entityUtils.getEntity(cheerTalkId, CheerTalk.class); + if (!cheerTalk.isBlocked()) { + throw new CustomException(HttpStatus.BAD_REQUEST, CheerTalkErrorMessages.CHEER_TALK_ALREADY_UNBLOCKED); + } + + Report report = checkReportValidAndGetReport(cheerTalk); + report.updateToInvalid(); // 해당 cheerTalk도 같이 unblock + } + + private void checkPermission(final Long leagueId, final Member manager) { + + League league = entityUtils.getEntity(leagueId, League.class); + + if (!league.isManagedBy(manager)) { + throw new UnauthorizedException(AuthorizationErrorMessages.PERMISSION_DENIED); + } + } + + private Report checkReportPendingAndGetReport(CheerTalk cheerTalk) { + Report report = reportRepository.findByCheerTalk(cheerTalk) + .orElseThrow(() -> new CustomException(HttpStatus.NOT_FOUND, ReportErrorMessage.REPORT_NOT_EXIST)); + if (!report.getState().equals(ReportState.PENDING)) { + throw new CustomException(HttpStatus.BAD_REQUEST, ReportErrorMessage.REPORT_NOT_PENDING); + } + return report; + } + + private Report checkReportValidAndGetReport(CheerTalk cheerTalk) { + Report report = reportRepository.findByCheerTalk(cheerTalk) + .orElseThrow(() -> new CustomException(HttpStatus.NOT_FOUND, ReportErrorMessage.REPORT_NOT_EXIST)); + if (!report.getState().equals(ReportState.VALID)) { + throw new CustomException(HttpStatus.BAD_REQUEST, ReportErrorMessage.REPORT_NOT_VALID); + } + return report; + } } diff --git a/src/main/java/com/sports/server/command/cheertalk/domain/CheerTalk.java b/src/main/java/com/sports/server/command/cheertalk/domain/CheerTalk.java index 342f5324..e21b5f50 100644 --- a/src/main/java/com/sports/server/command/cheertalk/domain/CheerTalk.java +++ b/src/main/java/com/sports/server/command/cheertalk/domain/CheerTalk.java @@ -35,6 +35,10 @@ public void block() { this.isBlocked = true; } + public void unblock() { + this.isBlocked = false; + } + public CheerTalk(final String content, final Long gameTeamId) { this.createdAt = LocalDateTime.now(); this.content = content; diff --git a/src/main/java/com/sports/server/command/cheertalk/exception/CheerTalkErrorMessages.java b/src/main/java/com/sports/server/command/cheertalk/exception/CheerTalkErrorMessages.java index 5a4a19e6..b9dd36e7 100644 --- a/src/main/java/com/sports/server/command/cheertalk/exception/CheerTalkErrorMessages.java +++ b/src/main/java/com/sports/server/command/cheertalk/exception/CheerTalkErrorMessages.java @@ -2,4 +2,6 @@ public class CheerTalkErrorMessages { public static final String CHEER_TALK_CONTAINS_BAD_WORD = "댓글에 욕설이 포함되어 있어 저장할 수 없습니다."; + public static final String CHEER_TALK_ALREADY_BLOCKED = "이미 가려진 채팅입니다."; + public static final String CHEER_TALK_ALREADY_UNBLOCKED = "이미 신고 취소된 채팅입니다."; } diff --git a/src/main/java/com/sports/server/command/cheertalk/presentation/CheerTalkController.java b/src/main/java/com/sports/server/command/cheertalk/presentation/CheerTalkController.java index c62f1431..0089ea25 100644 --- a/src/main/java/com/sports/server/command/cheertalk/presentation/CheerTalkController.java +++ b/src/main/java/com/sports/server/command/cheertalk/presentation/CheerTalkController.java @@ -2,6 +2,7 @@ import com.sports.server.command.cheertalk.application.CheerTalkService; import com.sports.server.command.cheertalk.dto.CheerTalkRequest; +import com.sports.server.command.member.domain.Member; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -18,4 +19,20 @@ public ResponseEntity register(@RequestBody @Valid final CheerTalkRequest cheerTalkService.register(cheerTalkRequest); return ResponseEntity.ok(null); } + + @PatchMapping("/cheer-talks/{leagueId}/{cheerTalkId}/block") + public ResponseEntity block(@PathVariable Long leagueId, + @PathVariable Long cheerTalkId, + final Member manager) { + cheerTalkService.block(leagueId, cheerTalkId, manager); + return ResponseEntity.ok().build(); + } + + @PatchMapping("/cheer-talks/{leagueId}/{cheerTalkId}/unblock") + public ResponseEntity unblock(@PathVariable Long leagueId, + @PathVariable Long cheerTalkId, + final Member manager) { + cheerTalkService.unblock(leagueId, cheerTalkId, manager); + return ResponseEntity.ok().build(); + } } diff --git a/src/main/java/com/sports/server/command/report/domain/Report.java b/src/main/java/com/sports/server/command/report/domain/Report.java index 29765dc0..11cc6b17 100644 --- a/src/main/java/com/sports/server/command/report/domain/Report.java +++ b/src/main/java/com/sports/server/command/report/domain/Report.java @@ -60,7 +60,13 @@ public void updateToValid() { cheerTalk.block(); } + public void updateToInvalid() { + this.state = ReportState.INVALID; + cheerTalk.unblock(); + } + public void updateToPending() { this.state = ReportState.PENDING; } + } diff --git a/src/main/java/com/sports/server/command/report/exception/ReportErrorMessage.java b/src/main/java/com/sports/server/command/report/exception/ReportErrorMessage.java index 72586f05..4e4b0000 100644 --- a/src/main/java/com/sports/server/command/report/exception/ReportErrorMessage.java +++ b/src/main/java/com/sports/server/command/report/exception/ReportErrorMessage.java @@ -8,4 +8,7 @@ public class ReportErrorMessage { public static final String INVALID_REPORT_BLOCKED_CHEER_TALK = "이미 블락된 응원톡은 신고할 수 없습니다."; public static final String REPORT_CHECK_SERVER_ERROR = "신고 검사 서버에 문제가 발생했습니다"; + public static final String REPORT_NOT_EXIST = "해당 응원톡에 대한 신고가 존재하지 않습니다."; + public static final String REPORT_NOT_PENDING = "대기 상태가 아닌 신고는 유효 처리할 수 없습니다."; + public static final String REPORT_NOT_VALID = "유효하지 않은 신고는 무효 처리할 수 없습니다."; } From 3ae269fdabe643e0f83d70bbc152305b0a3f26e1 Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Mon, 23 Sep 2024 14:27:56 +0900 Subject: [PATCH 02/16] =?UTF-8?q?[TEST]=20=EC=9D=91=EC=9B=90=ED=86=A1=20?= =?UTF-8?q?=EA=B0=80=EB=A6=AC=EA=B8=B0/=EA=B0=80=EB=A6=AC=EA=B8=B0=20?= =?UTF-8?q?=ED=95=B4=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20#231?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/CheerTalkServiceTest.java | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/sports/server/command/cheertalk/application/CheerTalkServiceTest.java b/src/test/java/com/sports/server/command/cheertalk/application/CheerTalkServiceTest.java index 026fc572..ecee3f6c 100644 --- a/src/test/java/com/sports/server/command/cheertalk/application/CheerTalkServiceTest.java +++ b/src/test/java/com/sports/server/command/cheertalk/application/CheerTalkServiceTest.java @@ -1,21 +1,41 @@ package com.sports.server.command.cheertalk.application; import com.sports.server.command.cheertalk.dto.CheerTalkRequest; +import com.sports.server.command.member.domain.Member; +import com.sports.server.common.application.EntityUtils; import com.sports.server.common.exception.CustomException; import com.sports.server.support.ServiceTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.jdbc.Sql; import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertThrows; - +@Sql("/cheer-talk-fixture.sql") public class CheerTalkServiceTest extends ServiceTest { @Autowired private CheerTalkService cheerTalkService; + @Autowired + private EntityUtils entityUtils; + + private Long managerId; + private Long leagueId; + private Member manager; + + @BeforeEach + void setUp() { + managerId = 1L; + leagueId = 1L; + manager = entityUtils.getEntity(1L, Member.class); + } + @ParameterizedTest @ValueSource(strings = {"ㅅㅂ", "개새", "ㅆㅂ"}) void 욕설이_포함된_응원톡을_저장하려고_하면_예외가_발생한다(String content) { @@ -40,4 +60,23 @@ public class CheerTalkServiceTest extends ServiceTest { .doesNotThrowAnyException(); } + @Test + void 이미_가려진_응원톡을_다시_가리려고_하면_예외가_발생한다() { + // given + Long cheerTalkId = 14L; + + // when & then + assertThatThrownBy(() -> cheerTalkService.block(leagueId, cheerTalkId, manager)) + .isInstanceOf(CustomException.class); + } + + @Test + void 이미_가리기_취소된_응원톡을_다시_가리기_취소하려고_하면_예외가_발생한다() { + // given + Long cheerTalkId = 1L; + + // when & then + assertThatThrownBy(() -> cheerTalkService.unblock(leagueId, cheerTalkId, manager)) + .isInstanceOf(CustomException.class); + } } From df66d7d986676def5bba6a7ae59ddddd38eba4ff Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Mon, 23 Sep 2024 14:28:23 +0900 Subject: [PATCH 03/16] =?UTF-8?q?[DOCS]=20=EC=9D=91=EC=9B=90=ED=86=A1=20?= =?UTF-8?q?=EA=B0=80=EB=A6=AC=EA=B8=B0/=EA=B0=80=EB=A6=AC=EA=B8=B0=20?= =?UTF-8?q?=ED=95=B4=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EB=AC=B8=EC=84=9C?= =?UTF-8?q?=ED=99=94=20#231?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/api.adoc | 8 + src/main/resources/static/docs/api.html | 301 ++++++++++++++++-- .../acceptance/CheerTalkAcceptanceTest.java | 63 ++++ .../presentation/CheerTalkControllerTest.java | 53 +++ src/test/resources/cheer-talk-fixture.sql | 3 +- 5 files changed, 406 insertions(+), 22 deletions(-) diff --git a/src/docs/asciidoc/api.adoc b/src/docs/asciidoc/api.adoc index aa3b04c1..15947753 100644 --- a/src/docs/asciidoc/api.adoc +++ b/src/docs/asciidoc/api.adoc @@ -20,6 +20,14 @@ 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-controller-test/신고된_응원톡을_가린다[snippets='http-request,path-parameters,http-response'] + +=== 가려진 응원톡을 가리기 취소하기 + +operation::cheer-talk-controller-test/가려진_응원톡을_가리기_취소한다[snippets='http-request,path-parameters,http-response'] + == 게임 API === 게임 상세 조회 diff --git a/src/main/resources/static/docs/api.html b/src/main/resources/static/docs/api.html index b22c8662..b2f590ea 100644 --- a/src/main/resources/static/docs/api.html +++ b/src/main/resources/static/docs/api.html @@ -451,6 +451,9 @@

훕치치 서버 API 문서

  • 게임 API @@ -717,6 +720,268 @@

    +

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

    +
    +

    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

    +
    +
    +
    PATCH /cheer-talks/1/1/block HTTP/1.1
    +Content-Type: application/json
    +Host: www.api.hufstreaming.site
    +Cookie: HCC_SES=temp-cookie
    +
    +
    +
    +
    +

    Path parameters

    + + ++++ + + + + + + + + + + + + + + + + +
    Table 1. /cheer-talks/{leagueId}/{cheerTalkId}/block
    ParameterDescription

    leagueId

    리그의 ID

    cheerTalkId

    응원톡의 ID

    +
    +
    +

    HTTP response

    +
    +
    +
    HTTP/1.1 200 OK
    +Vary: Origin
    +Vary: Access-Control-Request-Method
    +Vary: Access-Control-Request-Headers
    +
    +
    +
    +
    +
    +

    가려진 응원톡을 가리기 취소하기

    +
    +

    HTTP request

    +
    +
    +
    PATCH /cheer-talks/1/1/unblock HTTP/1.1
    +Content-Type: application/json
    +Host: www.api.hufstreaming.site
    +Cookie: HCC_SES=temp-cookie
    +
    +
    +
    +
    +

    Path parameters

    + + ++++ + + + + + + + + + + + + + + + + +
    Table 1. /cheer-talks/{leagueId}/{cheerTalkId}/unblock
    ParameterDescription

    leagueId

    리그의 ID

    cheerTalkId

    응원톡의 ID

    +
    +
    +

    HTTP response

    +
    +
    +
    HTTP/1.1 200 OK
    +Vary: Origin
    +Vary: Access-Control-Request-Method
    +Vary: Access-Control-Request-Headers
    +
    +
    +
    +
    @@ -1939,19 +2203,14 @@

    organizationId

    -

    Number

    -

    조직 id

    - -

    name

    String

    대회 이름

    maxRound

    -

    String

    -

    대회 진행 라운드 수

    +

    Number

    +

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

    startAt

    @@ -1986,14 +2245,14 @@

    PUT /leagues/5124 HTTP/1.1
     Content-Type: application/json
    -Content-Length: 166
    +Content-Length: 165
     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-22T18:02:36.84967",
    +  "endAt" : "2024-09-22T18:02:36.849675",
       "maxRound" : "16강"
     }
    @@ -2873,12 +3132,12 @@

    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 eb75eae7..ec2192d9 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 @@ -1,6 +1,7 @@ package com.sports.server.command.cheertalk.acceptance; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; import com.sports.server.command.cheertalk.dto.CheerTalkRequest; import com.sports.server.support.AcceptanceTest; @@ -10,7 +11,9 @@ import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; +import org.springframework.test.context.jdbc.Sql; +@Sql("/cheer-talk-fixture.sql") public class CheerTalkAcceptanceTest extends AcceptanceTest { @Test @@ -32,4 +35,64 @@ public class CheerTalkAcceptanceTest extends AcceptanceTest { //then assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()); } + + @Test + void 신고_대기중인_응원톡을_가린다() { + // given + Long leagueId = 1L; + Long cheerTalkId = 1L; + + configureMockJwtForEmail("john@example.com"); + + // when + ExtractableResponse patchResponse = RestAssured.given().log().all() + .when() + .cookie(COOKIE_NAME, mockToken) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .patch("/cheer-talks/{leagueId}/{cheerTalkId}/block", leagueId, cheerTalkId) + .then().log().all() + .extract(); + + // then + // 가려진 응원톡 전체조회 기능 머지 후 테스트 추가 예정 +// ExtractableResponse getResponse = RestAssured.given().log().all() +// .when() +// .contentType(MediaType.APPLICATION_JSON_VALUE) +// .get("") +// .then().log().all() +// .extract(); + assertAll( + () -> assertThat(patchResponse.statusCode()).isEqualTo(HttpStatus.OK.value()) + ); + } + + @Test + void 가려진_응원톡을_가리기_취소한다() { + // given + Long leagueId = 1L; + Long cheerTalkId = 14L; + + configureMockJwtForEmail("john@example.com"); + + // when + ExtractableResponse patchResponse = RestAssured.given().log().all() + .when() + .cookie(COOKIE_NAME, mockToken) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .patch("/cheer-talks/{leagueId}/{cheerTalkId}/unblock", leagueId, cheerTalkId) + .then().log().all() + .extract(); + + // then + // 리그의 응원톡 전체조회 기능 머지 후 테스트 추가 예정 +// ExtractableResponse getResponse = RestAssured.given().log().all() +// .when() +// .contentType(MediaType.APPLICATION_JSON_VALUE) +// .get("/leagues/{leagueId}/cheer-talks", leagueId) +// .then().log().all() +// .extract(); + assertAll( + () -> assertThat(patchResponse.statusCode()).isEqualTo(HttpStatus.OK.value()) + ); + } } diff --git a/src/test/java/com/sports/server/command/cheertalk/presentation/CheerTalkControllerTest.java b/src/test/java/com/sports/server/command/cheertalk/presentation/CheerTalkControllerTest.java index 0056cd62..3aded8cf 100644 --- a/src/test/java/com/sports/server/command/cheertalk/presentation/CheerTalkControllerTest.java +++ b/src/test/java/com/sports/server/command/cheertalk/presentation/CheerTalkControllerTest.java @@ -1,12 +1,16 @@ package com.sports.server.command.cheertalk.presentation; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.patch; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; +import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; +import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.sports.server.command.cheertalk.dto.CheerTalkRequest; import com.sports.server.support.DocumentationTest; +import jakarta.servlet.http.Cookie; import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.restdocs.payload.JsonFieldType; @@ -33,4 +37,53 @@ class CheerTalkControllerTest extends DocumentationTest { ) )); } + + @Test + void 신고된_응원톡을_가린다() throws Exception { + // given + Long leagueId = 1L; + Long cheerTalkId = 1L; + + Cookie cookie = new Cookie(COOKIE_NAME, "temp-cookie"); + + // when + ResultActions result = mockMvc.perform(patch("/cheer-talks/{leagueId}/{cheerTalkId}/block", leagueId, cheerTalkId) + .contentType(MediaType.APPLICATION_JSON) + .cookie(cookie) + ); + + // then + result.andExpect((status().isOk())) + .andDo(restDocsHandler.document( + pathParameters( + parameterWithName("leagueId").description("리그의 ID"), + parameterWithName("cheerTalkId").description("응원톡의 ID") + ) + )); + } + + @Test + void 가려진_응원톡을_가리기_취소한다() throws Exception { + // given + Long leagueId = 1L; + Long cheerTalkId = 1L; + + Cookie cookie = new Cookie(COOKIE_NAME, "temp-cookie"); + + + // when + ResultActions result = mockMvc.perform(patch("/cheer-talks/{leagueId}/{cheerTalkId}/unblock", leagueId, cheerTalkId) + .contentType(MediaType.APPLICATION_JSON) + .cookie(cookie) + ); + + // then + result.andExpect((status().isOk())) + .andDo(restDocsHandler.document( + pathParameters( + parameterWithName("leagueId").description("리그의 ID"), + parameterWithName("cheerTalkId").description("응원톡의 ID") + ) + )); + } } diff --git a/src/test/resources/cheer-talk-fixture.sql b/src/test/resources/cheer-talk-fixture.sql index b3a73c2d..b4f1a714 100644 --- a/src/test/resources/cheer-talk-fixture.sql +++ b/src/test/resources/cheer-talk-fixture.sql @@ -61,5 +61,6 @@ VALUES (15, '2023-01-01 12:30:00', '응원톡15', false, 3), INSERT INTO reports(id, cheer_talk_id, reported_at, state) VALUES (1, 1, '2023-01-01 12:30:00', 'PENDING'), - (2, 18, '2023-01-01 12:30:00', 'PENDING'); + (2, 18, '2023-01-01 12:30:00', 'PENDING'), + (3, 14, '2023-01-01 12:30:00', 'VALID'); SET foreign_key_checks = 1; From ff98d1a0f9caba3eee1a6c963afad972ef891ff4 Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Mon, 23 Sep 2024 18:23:19 +0900 Subject: [PATCH 04/16] =?UTF-8?q?[CHORE]=20security=20config=EC=97=90=20?= =?UTF-8?q?=EC=97=94=EB=93=9C=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sports/server/auth/config/SecurityConfig.java | 3 ++- 1 file changed, 2 insertions(+), 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 26e49f9e..7bd3fc1e 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,8 @@ SecurityFilterChain filterChain(HttpSecurity http, MvcRequestMatcher.Builder mvc 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}/**") + mvc.pattern(HttpMethod.POST, "/games/{gameId}/lineup-players/{lineupPlayerId}/**"), + mvc.pattern(HttpMethod.PATCH, "/cheer-talks/{leagueId}/{cheerTalkId}/**") ) .authenticated() .anyRequest().permitAll() From 19cb2b59c7729241d6c15da8af0d83f6ac219b02 Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Tue, 24 Sep 2024 21:44:11 +0900 Subject: [PATCH 05/16] =?UTF-8?q?[REFACTOR]=20RequestMapping=EC=97=90=20?= =?UTF-8?q?=EA=B3=B5=ED=86=B5=EB=90=98=EB=8A=94=20=EC=97=94=EB=93=9C?= =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EC=B6=94=EA=B0=80=20#231?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/cheertalk/presentation/CheerTalkController.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sports/server/command/cheertalk/presentation/CheerTalkController.java b/src/main/java/com/sports/server/command/cheertalk/presentation/CheerTalkController.java index 0089ea25..db1b4248 100644 --- a/src/main/java/com/sports/server/command/cheertalk/presentation/CheerTalkController.java +++ b/src/main/java/com/sports/server/command/cheertalk/presentation/CheerTalkController.java @@ -10,17 +10,18 @@ @RestController @RequiredArgsConstructor +@RequestMapping("/cheer-talks") public class CheerTalkController { private final CheerTalkService cheerTalkService; - @PostMapping("/cheer-talks") + @PostMapping public ResponseEntity register(@RequestBody @Valid final CheerTalkRequest cheerTalkRequest) { cheerTalkService.register(cheerTalkRequest); return ResponseEntity.ok(null); } - @PatchMapping("/cheer-talks/{leagueId}/{cheerTalkId}/block") + @PatchMapping("/{leagueId}/{cheerTalkId}/block") public ResponseEntity block(@PathVariable Long leagueId, @PathVariable Long cheerTalkId, final Member manager) { From ac2620fdee4c651331c542cb428f0793562599b5 Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Tue, 24 Sep 2024 21:45:32 +0900 Subject: [PATCH 06/16] =?UTF-8?q?[FIX]=20=EC=9D=91=EC=9B=90=ED=86=A1=20?= =?UTF-8?q?=EA=B0=80=EB=A6=AC=EA=B1=B0=EB=82=98=20=ED=95=B4=EC=A0=9C?= =?UTF-8?q?=ED=95=A0=20=EB=95=8C=20=EC=8B=A0=EA=B3=A0=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=20=EC=97=86=EC=96=B4=EB=8F=84=20=EA=B0=80=EB=8A=A5=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=20#231?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/CheerTalkService.java | 31 +++++-------------- .../server/command/report/domain/Report.java | 2 -- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java b/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java index 1744abf8..7bdb7580 100644 --- a/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java +++ b/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java @@ -23,7 +23,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.security.Key; +import java.util.Optional; @Service @Transactional @@ -55,9 +55,9 @@ public void block(final Long leagueId, final Long cheerTalkId, final Member mana throw new CustomException(HttpStatus.BAD_REQUEST, CheerTalkErrorMessages.CHEER_TALK_ALREADY_BLOCKED); } - Report report = checkReportPendingAndGetReport(cheerTalk); - report.updateToValid(); // 해당 cheerTalk도 같이 block - + Optional report = reportRepository.findByCheerTalk(cheerTalk); + report.ifPresent(Report::updateToValid); + cheerTalk.block(); } public void unblock(final Long leagueId, final Long cheerTalkId, final Member manager) { @@ -68,8 +68,9 @@ public void unblock(final Long leagueId, final Long cheerTalkId, final Member ma throw new CustomException(HttpStatus.BAD_REQUEST, CheerTalkErrorMessages.CHEER_TALK_ALREADY_UNBLOCKED); } - Report report = checkReportValidAndGetReport(cheerTalk); - report.updateToInvalid(); // 해당 cheerTalk도 같이 unblock + Optional report = reportRepository.findByCheerTalk(cheerTalk); + report.ifPresent(Report::updateToInvalid); + cheerTalk.unblock(); } private void checkPermission(final Long leagueId, final Member manager) { @@ -80,22 +81,4 @@ private void checkPermission(final Long leagueId, final Member manager) { throw new UnauthorizedException(AuthorizationErrorMessages.PERMISSION_DENIED); } } - - private Report checkReportPendingAndGetReport(CheerTalk cheerTalk) { - Report report = reportRepository.findByCheerTalk(cheerTalk) - .orElseThrow(() -> new CustomException(HttpStatus.NOT_FOUND, ReportErrorMessage.REPORT_NOT_EXIST)); - if (!report.getState().equals(ReportState.PENDING)) { - throw new CustomException(HttpStatus.BAD_REQUEST, ReportErrorMessage.REPORT_NOT_PENDING); - } - return report; - } - - private Report checkReportValidAndGetReport(CheerTalk cheerTalk) { - Report report = reportRepository.findByCheerTalk(cheerTalk) - .orElseThrow(() -> new CustomException(HttpStatus.NOT_FOUND, ReportErrorMessage.REPORT_NOT_EXIST)); - if (!report.getState().equals(ReportState.VALID)) { - throw new CustomException(HttpStatus.BAD_REQUEST, ReportErrorMessage.REPORT_NOT_VALID); - } - return report; - } } diff --git a/src/main/java/com/sports/server/command/report/domain/Report.java b/src/main/java/com/sports/server/command/report/domain/Report.java index 11cc6b17..70b202a9 100644 --- a/src/main/java/com/sports/server/command/report/domain/Report.java +++ b/src/main/java/com/sports/server/command/report/domain/Report.java @@ -57,12 +57,10 @@ public boolean isUnchecked() { public void updateToValid() { this.state = ReportState.VALID; - cheerTalk.block(); } public void updateToInvalid() { this.state = ReportState.INVALID; - cheerTalk.unblock(); } public void updateToPending() { From 62c714e8e49dcda901bac010881feb1636d8738e Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Tue, 24 Sep 2024 21:46:34 +0900 Subject: [PATCH 07/16] =?UTF-8?q?[REFACTOR]=20report=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=20=EC=83=81=ED=83=9C=20=ED=99=95=EC=9D=B8=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C=20#231?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/cheertalk/application/CheerTalkService.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java b/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java index 7bdb7580..519f5f52 100644 --- a/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java +++ b/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java @@ -51,9 +51,6 @@ public void block(final Long leagueId, final Long cheerTalkId, final Member mana checkPermission(leagueId, manager); CheerTalk cheerTalk = entityUtils.getEntity(cheerTalkId, CheerTalk.class); - if (cheerTalk.isBlocked()) { - throw new CustomException(HttpStatus.BAD_REQUEST, CheerTalkErrorMessages.CHEER_TALK_ALREADY_BLOCKED); - } Optional report = reportRepository.findByCheerTalk(cheerTalk); report.ifPresent(Report::updateToValid); @@ -64,9 +61,6 @@ public void unblock(final Long leagueId, final Long cheerTalkId, final Member ma checkPermission(leagueId, manager); CheerTalk cheerTalk = entityUtils.getEntity(cheerTalkId, CheerTalk.class); - if (!cheerTalk.isBlocked()) { - throw new CustomException(HttpStatus.BAD_REQUEST, CheerTalkErrorMessages.CHEER_TALK_ALREADY_UNBLOCKED); - } Optional report = reportRepository.findByCheerTalk(cheerTalk); report.ifPresent(Report::updateToInvalid); From 2aa029afd087766e88af9f55a866456f2d3836c9 Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Tue, 24 Sep 2024 21:59:26 +0900 Subject: [PATCH 08/16] =?UTF-8?q?[FIX]=20=EC=9D=B4=EB=AF=B8=20=EA=B0=80?= =?UTF-8?q?=EB=A0=A4=EC=A7=84/=EA=B0=80=EB=A6=AC=EA=B8=B0=20=EC=B7=A8?= =?UTF-8?q?=EC=86=8C=EB=90=9C=20=EC=9D=91=EC=9B=90=ED=86=A1=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=B4=EC=84=9C=20=EC=98=88=EC=99=B8=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=EC=8B=9C=ED=82=A4=EC=A7=80=20=EC=95=8A=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?#231?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/CheerTalkErrorMessages.java | 2 -- .../acceptance/CheerTalkAcceptanceTest.java | 2 +- .../application/CheerTalkServiceTest.java | 20 ------------------- 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/src/main/java/com/sports/server/command/cheertalk/exception/CheerTalkErrorMessages.java b/src/main/java/com/sports/server/command/cheertalk/exception/CheerTalkErrorMessages.java index b9dd36e7..5a4a19e6 100644 --- a/src/main/java/com/sports/server/command/cheertalk/exception/CheerTalkErrorMessages.java +++ b/src/main/java/com/sports/server/command/cheertalk/exception/CheerTalkErrorMessages.java @@ -2,6 +2,4 @@ public class CheerTalkErrorMessages { public static final String CHEER_TALK_CONTAINS_BAD_WORD = "댓글에 욕설이 포함되어 있어 저장할 수 없습니다."; - public static final String CHEER_TALK_ALREADY_BLOCKED = "이미 가려진 채팅입니다."; - public static final String CHEER_TALK_ALREADY_UNBLOCKED = "이미 신고 취소된 채팅입니다."; } 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 ec2192d9..4097a9af 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 @@ -37,7 +37,7 @@ public class CheerTalkAcceptanceTest extends AcceptanceTest { } @Test - void 신고_대기중인_응원톡을_가린다() { + void 응원톡을_가린다() { // given Long leagueId = 1L; Long cheerTalkId = 1L; diff --git a/src/test/java/com/sports/server/command/cheertalk/application/CheerTalkServiceTest.java b/src/test/java/com/sports/server/command/cheertalk/application/CheerTalkServiceTest.java index ecee3f6c..66b450b7 100644 --- a/src/test/java/com/sports/server/command/cheertalk/application/CheerTalkServiceTest.java +++ b/src/test/java/com/sports/server/command/cheertalk/application/CheerTalkServiceTest.java @@ -59,24 +59,4 @@ void setUp() { assertThatCode(() -> cheerTalkService.register(cheerTalkRequest)) .doesNotThrowAnyException(); } - - @Test - void 이미_가려진_응원톡을_다시_가리려고_하면_예외가_발생한다() { - // given - Long cheerTalkId = 14L; - - // when & then - assertThatThrownBy(() -> cheerTalkService.block(leagueId, cheerTalkId, manager)) - .isInstanceOf(CustomException.class); - } - - @Test - void 이미_가리기_취소된_응원톡을_다시_가리기_취소하려고_하면_예외가_발생한다() { - // given - Long cheerTalkId = 1L; - - // when & then - assertThatThrownBy(() -> cheerTalkService.unblock(leagueId, cheerTalkId, manager)) - .isInstanceOf(CustomException.class); - } } From 24df89e9b7a38db4f77eb19f35742cffe3e7b776 Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Tue, 24 Sep 2024 22:21:05 +0900 Subject: [PATCH 09/16] =?UTF-8?q?[FIX]=20Report=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=88=84=EB=9D=BD=EB=90=9C=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84=20=EC=B6=94=EA=B0=80=20#231?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sports/server/command/report/domain/Report.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/sports/server/command/report/domain/Report.java b/src/main/java/com/sports/server/command/report/domain/Report.java index 70b202a9..11cc6b17 100644 --- a/src/main/java/com/sports/server/command/report/domain/Report.java +++ b/src/main/java/com/sports/server/command/report/domain/Report.java @@ -57,10 +57,12 @@ public boolean isUnchecked() { public void updateToValid() { this.state = ReportState.VALID; + cheerTalk.block(); } public void updateToInvalid() { this.state = ReportState.INVALID; + cheerTalk.unblock(); } public void updateToPending() { From ecad95f636c43874ae9a4b14f4720c3a8bdfc6f5 Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Tue, 24 Sep 2024 22:22:51 +0900 Subject: [PATCH 10/16] =?UTF-8?q?[DOCS]=20=ED=94=BC=EB=93=9C=EB=B0=B1=20?= =?UTF-8?q?=EB=B0=9B=EC=9C=BC=EB=A9=B0=20=EC=88=98=EC=A0=95=ED=95=9C=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=20=EB=AC=B8=EC=84=9C=ED=99=94=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20#231?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/api.adoc | 4 +-- .../presentation/CheerTalkController.java | 2 +- src/main/resources/static/docs/api.html | 34 +++++++++---------- .../presentation/CheerTalkControllerTest.java | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/docs/asciidoc/api.adoc b/src/docs/asciidoc/api.adoc index 15947753..70bfed67 100644 --- a/src/docs/asciidoc/api.adoc +++ b/src/docs/asciidoc/api.adoc @@ -20,9 +20,9 @@ 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-controller-test/신고된_응원톡을_가린다[snippets='http-request,path-parameters,http-response'] +operation::cheer-talk-controller-test/응원톡을_가린다[snippets='http-request,path-parameters,http-response'] === 가려진 응원톡을 가리기 취소하기 diff --git a/src/main/java/com/sports/server/command/cheertalk/presentation/CheerTalkController.java b/src/main/java/com/sports/server/command/cheertalk/presentation/CheerTalkController.java index db1b4248..9c3d5fef 100644 --- a/src/main/java/com/sports/server/command/cheertalk/presentation/CheerTalkController.java +++ b/src/main/java/com/sports/server/command/cheertalk/presentation/CheerTalkController.java @@ -29,7 +29,7 @@ public ResponseEntity block(@PathVariable Long leagueId, return ResponseEntity.ok().build(); } - @PatchMapping("/cheer-talks/{leagueId}/{cheerTalkId}/unblock") + @PatchMapping("{leagueId}/{cheerTalkId}/unblock") public ResponseEntity unblock(@PathVariable Long leagueId, @PathVariable Long cheerTalkId, final Member manager) { diff --git a/src/main/resources/static/docs/api.html b/src/main/resources/static/docs/api.html index b2f590ea..ca1b2e88 100644 --- a/src/main/resources/static/docs/api.html +++ b/src/main/resources/static/docs/api.html @@ -452,7 +452,7 @@

    훕치치 서버 API 문서

  • 응원톡 저장
  • 응원톡 조회
  • 신고된 리그의 응원톡 전체 조회
  • -
  • 신고된 응원톡 가리기
  • +
  • 응원톡 가리기
  • 가려진 응원톡을 가리기 취소하기
  • @@ -881,9 +881,9 @@

    -

    신고된 응원톡 가리기

    +

    응원톡 가리기

    -

    HTTP request

    +

    HTTP request

    PATCH /cheer-talks/1/1/block HTTP/1.1
    @@ -894,7 +894,7 @@ 

    -

    Path parameters

    +

    Path parameters

    @@ -920,7 +920,7 @@

    -

    HTTP response

    +

    HTTP response

    @@ -2245,14 +2245,14 @@

    PUT /leagues/5124 HTTP/1.1
     Content-Type: application/json
    -Content-Length: 165
    +Content-Length: 166
     Host: www.api.hufstreaming.site
     Cookie: HCC_SES=temp-cookie
     
     {
       "name" : "훕치치배 망고 빨리먹기 대회",
    -  "startAt" : "2024-09-22T18:02:36.84967",
    -  "endAt" : "2024-09-22T18:02:36.849675",
    +  "startAt" : "2024-09-24T22:21:56.796529",
    +  "endAt" : "2024-09-24T22:21:56.796533",
       "maxRound" : "16강"
     }
    @@ -3132,12 +3132,12 @@

    diff --git a/src/test/java/com/sports/server/command/cheertalk/presentation/CheerTalkControllerTest.java b/src/test/java/com/sports/server/command/cheertalk/presentation/CheerTalkControllerTest.java index 3aded8cf..31ca5bb3 100644 --- a/src/test/java/com/sports/server/command/cheertalk/presentation/CheerTalkControllerTest.java +++ b/src/test/java/com/sports/server/command/cheertalk/presentation/CheerTalkControllerTest.java @@ -39,7 +39,7 @@ class CheerTalkControllerTest extends DocumentationTest { } @Test - void 신고된_응원톡을_가린다() throws Exception { + void 응원톡을_가린다() throws Exception { // given Long leagueId = 1L; Long cheerTalkId = 1L; From 8064ebd51028c6046f104bef3b97042884d36215 Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Wed, 25 Sep 2024 18:37:51 +0900 Subject: [PATCH 11/16] =?UTF-8?q?[TEST]=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD=20#231?= 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 | 46 +++++++++---------- .../acceptance/CheerTalkAcceptanceTest.java | 2 +- .../presentation/CheerTalkControllerTest.java | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/docs/asciidoc/api.adoc b/src/docs/asciidoc/api.adoc index f9ab0c30..2ce44ee9 100644 --- a/src/docs/asciidoc/api.adoc +++ b/src/docs/asciidoc/api.adoc @@ -24,9 +24,9 @@ operation::cheer-talk-query-controller-test/리그의_신고된_응원톡을_조 operation::cheer-talk-controller-test/응원톡을_가린다[snippets='http-request,path-parameters,http-response'] -=== 가려진 응원톡을 가리기 취소하기 +=== 응원톡을 가리기 취소하기 -operation::cheer-talk-controller-test/가려진_응원톡을_가리기_취소한다[snippets='http-request,path-parameters,http-response'] +operation::cheer-talk-controller-test/응원톡을_가리기_취소한다[snippets='http-request,path-parameters,http-response'] == 게임 API diff --git a/src/main/resources/static/docs/api.html b/src/main/resources/static/docs/api.html index b1818a7a..183a394e 100644 --- a/src/main/resources/static/docs/api.html +++ b/src/main/resources/static/docs/api.html @@ -453,7 +453,7 @@

    훕치치 서버 API 문서

  • 응원톡 조회
  • 신고된 리그의 응원톡 전체 조회
  • 응원톡 가리기
  • -
  • 가려진 응원톡을 가리기 취소하기
  • +
  • 응원톡을 가리기 취소하기
  • 게임 API @@ -934,9 +934,9 @@

    -

    가려진 응원톡을 가리기 취소하기

    +

    응원톡을 가리기 취소하기

    -

    HTTP request

    +

    HTTP request

    PATCH /cheer-talks/1/1/unblock HTTP/1.1
    @@ -947,7 +947,7 @@ 

    -

    Path parameters

    +

    Path parameters

  • Table 1. /cheer-talks/{leagueId}/{cheerTalkId}/block
    @@ -973,7 +973,7 @@

    @@ -2261,14 +2261,14 @@

    PUT /leagues/5124 HTTP/1.1
     Content-Type: application/json
    -Content-Length: 165
    +Content-Length: 166
     Host: www.api.hufstreaming.site
     Cookie: HCC_SES=temp-cookie
     
     {
       "name" : "훕치치배 망고 빨리먹기 대회",
    -  "startAt" : "2024-09-24T22:21:56.796529",
    -  "endAt" : "2024-09-24T22:21:56.796533",
    +  "startAt" : "2024-09-25T18:00:36.135448",
    +  "endAt" : "2024-09-25T18:00:36.135453",
       "maxRound" : "16강"
     }
    @@ -3148,12 +3148,12 @@

    @@ -4491,7 +4491,7 @@

    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 4097a9af..f1feb99f 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 @@ -67,7 +67,7 @@ public class CheerTalkAcceptanceTest extends AcceptanceTest { } @Test - void 가려진_응원톡을_가리기_취소한다() { + void 응원톡을_가리기_취소한다() { // given Long leagueId = 1L; Long cheerTalkId = 14L; diff --git a/src/test/java/com/sports/server/command/cheertalk/presentation/CheerTalkControllerTest.java b/src/test/java/com/sports/server/command/cheertalk/presentation/CheerTalkControllerTest.java index 31ca5bb3..36d2e9bf 100644 --- a/src/test/java/com/sports/server/command/cheertalk/presentation/CheerTalkControllerTest.java +++ b/src/test/java/com/sports/server/command/cheertalk/presentation/CheerTalkControllerTest.java @@ -63,7 +63,7 @@ class CheerTalkControllerTest extends DocumentationTest { } @Test - void 가려진_응원톡을_가리기_취소한다() throws Exception { + void 응원톡을_가리기_취소한다() throws Exception { // given Long leagueId = 1L; Long cheerTalkId = 1L; From 02919e6a5ce38f2707cae6034708f3c1afd66ad0 Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Wed, 25 Sep 2024 18:40:23 +0900 Subject: [PATCH 12/16] =?UTF-8?q?[REFACTOR]=20=EC=A4=91=EB=B3=B5=EB=90=98?= =?UTF-8?q?=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0=20#231?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cheertalk/application/CheerTalkService.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java b/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java index 519f5f52..83f6b3cd 100644 --- a/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java +++ b/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java @@ -53,8 +53,11 @@ public void block(final Long leagueId, final Long cheerTalkId, final Member mana CheerTalk cheerTalk = entityUtils.getEntity(cheerTalkId, CheerTalk.class); Optional report = reportRepository.findByCheerTalk(cheerTalk); - report.ifPresent(Report::updateToValid); - cheerTalk.block(); + if (report.isPresent()) { + report.get().updateToValid(); + } else { + cheerTalk.block(); + } } public void unblock(final Long leagueId, final Long cheerTalkId, final Member manager) { @@ -63,8 +66,11 @@ public void unblock(final Long leagueId, final Long cheerTalkId, final Member ma CheerTalk cheerTalk = entityUtils.getEntity(cheerTalkId, CheerTalk.class); Optional report = reportRepository.findByCheerTalk(cheerTalk); - report.ifPresent(Report::updateToInvalid); - cheerTalk.unblock(); + if (report.isPresent()) { + report.get().updateToInvalid(); + } else { + cheerTalk.unblock(); + } } private void checkPermission(final Long leagueId, final Member manager) { From 240a9a3a824f24d4543ea61458f490616e672191 Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Wed, 25 Sep 2024 20:23:05 +0900 Subject: [PATCH 13/16] =?UTF-8?q?[TEST]=20=EC=B6=94=ED=9B=84=20=EB=B0=98?= =?UTF-8?q?=EC=98=81=ED=95=B4=EC=95=BC=20=ED=95=98=EB=8A=94=20=EC=82=AC?= =?UTF-8?q?=ED=95=AD=EC=97=90=20todo=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/cheertalk/acceptance/CheerTalkAcceptanceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f1feb99f..84e51bb6 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 @@ -54,7 +54,7 @@ public class CheerTalkAcceptanceTest extends AcceptanceTest { .extract(); // then - // 가려진 응원톡 전체조회 기능 머지 후 테스트 추가 예정 + // todo : 가려진 응원톡 전체조회 기능 머지 후 테스트 추가 예정 // ExtractableResponse getResponse = RestAssured.given().log().all() // .when() // .contentType(MediaType.APPLICATION_JSON_VALUE) From cd00368198458f1dce00c7f13911d27f99980d08 Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Wed, 25 Sep 2024 22:06:57 +0900 Subject: [PATCH 14/16] =?UTF-8?q?[REFACTOR]=20=EC=97=AD=ED=95=A0=20?= =?UTF-8?q?=EB=AA=85=ED=99=95=ED=95=B4=EC=A7=80=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD=20#23?= =?UTF-8?q?1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cheertalk/application/CheerTalkService.java | 9 +++------ .../command/report/application/ReportProcessor.java | 2 +- .../sports/server/command/report/domain/Report.java | 11 +++++------ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java b/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java index 83f6b3cd..40d9afee 100644 --- a/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java +++ b/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java @@ -54,7 +54,7 @@ public void block(final Long leagueId, final Long cheerTalkId, final Member mana Optional report = reportRepository.findByCheerTalk(cheerTalk); if (report.isPresent()) { - report.get().updateToValid(); + report.get().accept(); } else { cheerTalk.block(); } @@ -66,11 +66,8 @@ public void unblock(final Long leagueId, final Long cheerTalkId, final Member ma CheerTalk cheerTalk = entityUtils.getEntity(cheerTalkId, CheerTalk.class); Optional report = reportRepository.findByCheerTalk(cheerTalk); - if (report.isPresent()) { - report.get().updateToInvalid(); - } else { - cheerTalk.unblock(); - } + report.ifPresent(Report::cancel); + cheerTalk.unblock(); } private void checkPermission(final Long leagueId, final Member manager) { diff --git a/src/main/java/com/sports/server/command/report/application/ReportProcessor.java b/src/main/java/com/sports/server/command/report/application/ReportProcessor.java index 355ce4cc..767abd84 100644 --- a/src/main/java/com/sports/server/command/report/application/ReportProcessor.java +++ b/src/main/java/com/sports/server/command/report/application/ReportProcessor.java @@ -26,7 +26,7 @@ public void check(CheerTalk cheerTalk, Report report) { } if (cachedBadWords.contains(cheerTalk.getContent())) { - report.updateToValid(); + report.accept(); return; } report.updateToPending(); diff --git a/src/main/java/com/sports/server/command/report/domain/Report.java b/src/main/java/com/sports/server/command/report/domain/Report.java index 11cc6b17..5d24fa5a 100644 --- a/src/main/java/com/sports/server/command/report/domain/Report.java +++ b/src/main/java/com/sports/server/command/report/domain/Report.java @@ -55,18 +55,17 @@ public boolean isUnchecked() { return this.state == ReportState.UNCHECKED; } - public void updateToValid() { + public void accept() { this.state = ReportState.VALID; cheerTalk.block(); } - public void updateToInvalid() { - this.state = ReportState.INVALID; - cheerTalk.unblock(); - } - public void updateToPending() { this.state = ReportState.PENDING; } + public void cancel() { + this.state = ReportState.INVALID; + } + } From 2908950212d1a6850842daeae8e18020292bb473 Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Wed, 25 Sep 2024 22:26:35 +0900 Subject: [PATCH 15/16] =?UTF-8?q?[DOCS]=20LocalDateTime.now()=20=EB=8C=80?= =?UTF-8?q?=EC=8B=A0=20=EA=B3=A0=EC=A0=95=20=EC=8B=9C=EA=B0=84=EB=8C=80=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/static/docs/api.html | 113 +++++------------- .../game/presentation/GameControllerTest.java | 4 +- .../presentation/LeagueControllerTest.java | 8 +- .../LeagueQueryControllerTest.java | 17 +-- 4 files changed, 47 insertions(+), 95 deletions(-) diff --git a/src/main/resources/static/docs/api.html b/src/main/resources/static/docs/api.html index 185fe8e5..22cd7f75 100644 --- a/src/main/resources/static/docs/api.html +++ b/src/main/resources/static/docs/api.html @@ -510,6 +510,7 @@

    훕치치 서버 API 문서

  • 득점 타임라인 생성
  • 교체 타임라인 생성
  • 게임 진행 타임라인 생성
  • +
  • 승부차기 타임라인 생성
  • 게임의 타임라인 조회
  • 타임라인 삭제
  • @@ -1860,7 +1861,7 @@

    POST /leagues/1/games HTTP/1.1
     Content-Type: application/json
    -Content-Length: 212
    +Content-Length: 205
     Host: www.api.hufstreaming.site
     Cookie: HCC_SES=temp-cookie
     
    @@ -1869,7 +1870,7 @@ 

    PUT /leagues/1/1 HTTP/1.1
     Content-Type: application/json
    -Content-Length: 172
    +Content-Length: 165
     Host: www.api.hufstreaming.site
     Cookie: HCC_SES=temp-cookie
     
    @@ -1929,7 +1930,7 @@ 

    @@ -2040,66 +2041,18 @@

    라인업 선수 주장으로 등록

    Table 1. /cheer-talks/{leagueId}/{cheerTalkId}/unblock
    - ---- - - - - - - - - - - - - - - - - - - - - -
    Table 1. /games/{gameId}/{gameTeamId}/lineup-players/{lineupPlayerId}/captain/register
    ParameterDescription

    gameId

    게임의 ID

    gameTeamId

    게임팀의 ID

    lineupPlayerId

    라인업 선수의 ID

    +
    +

    Snippet path-parameters not found for operation::game-controller-test/라인업_선수를_주장으로_등록한다

    +

    라인업 선수 주장에서 해제

    Path parameters

    - - ---- - - - - - - - - - - - - - - - - - - - - -
    Table 1. /games/{gameId}/{gameTeamId}/lineup-players/{lineupPlayerId}/captain/revoke
    ParameterDescription

    gameId

    게임의 ID

    gameTeamId

    게임팀의 ID

    lineupPlayerId

    라인업 선수의 ID

    +
    +

    Snippet path-parameters not found for operation::game-controller-test/라인업_선수를_주장에서_해제한다

    +
    @@ -2237,16 +2190,15 @@

    POST /leagues HTTP/1.1
     Content-Type: application/json
    -Content-Length: 150
    +Content-Length: 136
     Host: www.api.hufstreaming.site
     Cookie: HCC_SES=temp-cookie
     
     {
    -  "organizationId" : 1,
       "name" : "우물정 제기차기 대회",
       "maxRound" : 4,
    -  "startAt" : "2024-09-25T18:00:36.111058",
    -  "endAt" : "2024-09-25T18:00:36.111061"
    +  "startAt" : "2024-09-11T12:00:00",
    +  "endAt" : "2024-09-11T12:00:00"
     }
    @@ -2268,19 +2220,14 @@

    organizationId

    -

    Number

    -

    조직 id

    - -

    name

    String

    대회 이름

    maxRound

    -

    String

    -

    대회 진행 라운드 수

    +

    Number

    +

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

    startAt

    @@ -2315,14 +2262,14 @@

    PUT /leagues/5124 HTTP/1.1
     Content-Type: application/json
    -Content-Length: 166
    +Content-Length: 152
     Host: www.api.hufstreaming.site
     Cookie: HCC_SES=temp-cookie
     
     {
       "name" : "훕치치배 망고 빨리먹기 대회",
    -  "startAt" : "2024-09-25T18:00:36.135448",
    -  "endAt" : "2024-09-25T18:00:36.135453",
    +  "startAt" : "2024-09-11T12:00:00",
    +  "endAt" : "2024-09-11T12:00:00",
       "maxRound" : "16강"
     }
    @@ -3194,7 +3141,7 @@

    @@ -4646,7 +4593,7 @@

    diff --git a/src/test/java/com/sports/server/command/game/presentation/GameControllerTest.java b/src/test/java/com/sports/server/command/game/presentation/GameControllerTest.java index e7ddc5bf..f40de42a 100644 --- a/src/test/java/com/sports/server/command/game/presentation/GameControllerTest.java +++ b/src/test/java/com/sports/server/command/game/presentation/GameControllerTest.java @@ -108,7 +108,7 @@ public class GameControllerTest extends DocumentationTest { Long idOfTeam1 = 1L; Long idOfTeam2 = 2L; GameRequestDto.Register requestDto = new GameRequestDto.Register("경기 이름", "16강", "경기전", "SCHEDULED", - LocalDateTime.now(), idOfTeam1, idOfTeam2, "videoId"); + LocalDateTime.of(2024, 9, 11, 12, 0, 0), idOfTeam1, idOfTeam2, "videoId"); Cookie cookie = new Cookie(COOKIE_NAME, "temp-cookie"); @@ -151,7 +151,7 @@ public class GameControllerTest extends DocumentationTest { Long leagueId = 1L; Long gameId = 1L; GameRequestDto.Update requestDto = new GameRequestDto.Update( - "게임 이름", "16강", "전반전", "PLAYING", LocalDateTime.now(), "videoId" + "게임 이름", "16강", "전반전", "PLAYING", LocalDateTime.of(2024, 9, 11, 12, 0, 0), "videoId" ); doNothing().when(gameService).updateGame(anyLong(), anyLong(), any(GameRequestDto.Update.class), any(Member.class)); diff --git a/src/test/java/com/sports/server/command/league/presentation/LeagueControllerTest.java b/src/test/java/com/sports/server/command/league/presentation/LeagueControllerTest.java index ba6a90cf..9d5d27e9 100644 --- a/src/test/java/com/sports/server/command/league/presentation/LeagueControllerTest.java +++ b/src/test/java/com/sports/server/command/league/presentation/LeagueControllerTest.java @@ -30,7 +30,8 @@ class LeagueControllerTest extends DocumentationTest { @Test void 리그를_생성한다() throws Exception { // given - LeagueRequestDto.Register request = new LeagueRequestDto.Register("우물정 제기차기 대회", 4, LocalDateTime.now(), LocalDateTime.now()); + LocalDateTime fixedDateTime = LocalDateTime.of(2024, 9, 11, 12, 0, 0); + LeagueRequestDto.Register request = new LeagueRequestDto.Register("우물정 제기차기 대회", 4, fixedDateTime, fixedDateTime); doNothing().when(leagueService).register(any(Member.class), any(LeagueRequestDto.Register.class)); @@ -85,8 +86,9 @@ class LeagueControllerTest extends DocumentationTest { void 리그를_수정한다() throws Exception { // given Long leagueId = 5124L; - LeagueRequestDto.Update request = new LeagueRequestDto.Update("훕치치배 망고 빨리먹기 대회", LocalDateTime.now(), - LocalDateTime.now(), "16강"); + LocalDateTime fixedDateTime = LocalDateTime.of(2024, 9, 11, 12, 0, 0); + LeagueRequestDto.Update request = new LeagueRequestDto.Update("훕치치배 망고 빨리먹기 대회", fixedDateTime, + fixedDateTime, "16강"); doNothing().when(leagueService).update(any(Member.class), any(LeagueRequestDto.Update.class), anyLong()); diff --git a/src/test/java/com/sports/server/query/presentation/LeagueQueryControllerTest.java b/src/test/java/com/sports/server/query/presentation/LeagueQueryControllerTest.java index 42c49cda..db61a0ed 100644 --- a/src/test/java/com/sports/server/query/presentation/LeagueQueryControllerTest.java +++ b/src/test/java/com/sports/server/query/presentation/LeagueQueryControllerTest.java @@ -216,14 +216,16 @@ public class LeagueQueryControllerTest extends DocumentationTest { new GameTeamResponse(2L, "서어 뼤데뻬", "이미지 이미지", 1) ); + LocalDateTime fixedDateTime = LocalDateTime.of(2024, 9, 11, 12, 0, 0); + // 진행 중인 경기만 List inProgressGames = List.of( - new GameDetailResponse(1L, "PLAYING", LocalDateTime.now(), gameTeams) + new GameDetailResponse(1L, "PLAYING", fixedDateTime, gameTeams) ); List responses = List.of( - new LeagueResponseWithInProgressGames(1L, "삼건물 대회", "진행 중", 2, "16강", LocalDateTime.now(), - LocalDateTime.now(), inProgressGames)); + new LeagueResponseWithInProgressGames(1L, "삼건물 대회", "진행 중", 2, "16강", fixedDateTime, + fixedDateTime, inProgressGames)); Cookie cookie = new Cookie(COOKIE_NAME, "temp-cookie"); @@ -275,11 +277,12 @@ public class LeagueQueryControllerTest extends DocumentationTest { void 매니저가_생성한_모든_리그를_조회한다() throws Exception { // given + LocalDateTime fixedDateTime = LocalDateTime.of(2024, 9, 11, 12, 0, 0); List responses = List.of( - new LeagueResponseToManage(1L, "삼건물 대회", "진행 중", 2, "16강", LocalDateTime.now(), - LocalDateTime.now()), - new LeagueResponseToManage(2L, "탁구 대회", "시작 전", 2, "16강", LocalDateTime.now(), - LocalDateTime.now())); + new LeagueResponseToManage(1L, "삼건물 대회", "진행 중", 2, "16강", fixedDateTime, + fixedDateTime), + new LeagueResponseToManage(2L, "탁구 대회", "시작 전", 2, "16강", fixedDateTime, + fixedDateTime)); Cookie cookie = new Cookie(COOKIE_NAME, "temp-cookie"); From e53bfc69bf2a973cb7ca96b6d60acc4736d48083 Mon Sep 17 00:00:00 2001 From: Zena0128 <0128ja@gmail.com> Date: Thu, 26 Sep 2024 15:04:49 +0900 Subject: [PATCH 16/16] =?UTF-8?q?[REFACTOR]=20PermissionValidator=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20#231?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cheertalk/application/CheerTalkService.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java b/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java index 40d9afee..fbf41f0a 100644 --- a/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java +++ b/src/main/java/com/sports/server/command/cheertalk/application/CheerTalkService.java @@ -15,6 +15,7 @@ import com.sports.server.command.report.domain.ReportState; import com.sports.server.command.report.exception.ReportErrorMessage; import com.sports.server.common.application.EntityUtils; +import com.sports.server.common.application.PermissionValidator; import com.sports.server.common.exception.CustomException; import com.sports.server.common.exception.UnauthorizedException; import com.sports.server.query.repository.CheerTalkDynamicRepository; @@ -48,7 +49,8 @@ private void validateContent(final String content) { } public void block(final Long leagueId, final Long cheerTalkId, final Member manager) { - checkPermission(leagueId, manager); + League league = entityUtils.getEntity(leagueId, League.class); + PermissionValidator.checkPermission(league, manager); CheerTalk cheerTalk = entityUtils.getEntity(cheerTalkId, CheerTalk.class); @@ -61,7 +63,8 @@ public void block(final Long leagueId, final Long cheerTalkId, final Member mana } public void unblock(final Long leagueId, final Long cheerTalkId, final Member manager) { - checkPermission(leagueId, manager); + League league = entityUtils.getEntity(leagueId, League.class); + PermissionValidator.checkPermission(league, manager); CheerTalk cheerTalk = entityUtils.getEntity(cheerTalkId, CheerTalk.class); @@ -69,13 +72,4 @@ public void unblock(final Long leagueId, final Long cheerTalkId, final Member ma report.ifPresent(Report::cancel); cheerTalk.unblock(); } - - private void checkPermission(final Long leagueId, final Member manager) { - - League league = entityUtils.getEntity(leagueId, League.class); - - if (!league.isManagedBy(manager)) { - throw new UnauthorizedException(AuthorizationErrorMessages.PERMISSION_DENIED); - } - } }