From 24057e5cc640cdcad4d74377760a0e9fdbfc32ff Mon Sep 17 00:00:00 2001 From: JunH Date: Thu, 20 Jul 2023 16:13:26 +0900 Subject: [PATCH 01/13] =?UTF-8?q?refactor:=20(#95)=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PostControllerIntegratedTest.java | 84 ------------------- .../post/integrated/IntegrationTest.java | 19 ----- 2 files changed, 103 deletions(-) delete mode 100644 backend/src/test/java/com/votogether/domain/post/controller/PostControllerIntegratedTest.java delete mode 100644 backend/src/test/java/com/votogether/domain/post/integrated/IntegrationTest.java diff --git a/backend/src/test/java/com/votogether/domain/post/controller/PostControllerIntegratedTest.java b/backend/src/test/java/com/votogether/domain/post/controller/PostControllerIntegratedTest.java deleted file mode 100644 index 33639987a..000000000 --- a/backend/src/test/java/com/votogether/domain/post/controller/PostControllerIntegratedTest.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.votogether.domain.post.controller; - -import static org.hamcrest.Matchers.startsWith; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import com.votogether.domain.member.entity.Gender; -import com.votogether.domain.member.entity.Member; -import com.votogether.domain.member.entity.SocialType; -import com.votogether.domain.post.dto.request.PostCreateRequest; -import com.votogether.domain.post.integrated.IntegrationTest; -import com.votogether.global.jwt.TokenProcessor; -import io.restassured.RestAssured; -import io.restassured.http.ContentType; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.time.LocalDateTime; -import java.util.List; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; - -class PostControllerIntegratedTest extends IntegrationTest { - - @Autowired - TokenProcessor tokenProcessor; - - @Test - @DisplayName("게시글을 등록한다") - void save() throws IOException { - // given - final Member member = Member.builder() - .gender(Gender.MALE) - .point(0) - .socialType(SocialType.KAKAO) - .nickname("user1") - .socialId("kakao@gmail.com") - .ageRange("30~39") - .birthday("0101") - .build(); - String token = tokenProcessor.generateToken(member); - - final List postOptionRequests = List.of("option1", "option2"); - - final PostCreateRequest postCreateRequest = PostCreateRequest.builder() - .title("title") - .content("content") - .postOptionContents(postOptionRequests) - .categoryIds(List.of(0L, 3L)) - .deadline(LocalDateTime.now()) - .build(); - - final String fileName1 = "testImage1.PNG"; - final String resultFileName1 = "testResultImage1.PNG"; - final String filePath1 = "src/test/resources/images/" + fileName1; - File file1 = new File(filePath1); - - final String fileName2 = "testImage2.PNG"; - final String resultFileName2 = "testResultImage2.PNG"; - final String filePath2 = "src/test/resources/images/" + fileName2; - File file2 = new File(filePath2); - - final ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JavaTimeModule()); - objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - - // when, then - RestAssured.given().log().all() - .contentType(ContentType.MULTIPART) - .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) - .multiPart("request", postCreateRequest, "application/json") - .multiPart("images", resultFileName1, new FileInputStream(file1), "image/png") - .multiPart("images", resultFileName2, new FileInputStream(file2), "image/png") - .when().post("/posts") - .then().log().all() - .statusCode(HttpStatus.CREATED.value()) - .header("Location", startsWith("/posts/")); - } - -} diff --git a/backend/src/test/java/com/votogether/domain/post/integrated/IntegrationTest.java b/backend/src/test/java/com/votogether/domain/post/integrated/IntegrationTest.java deleted file mode 100644 index 00c59cb31..000000000 --- a/backend/src/test/java/com/votogether/domain/post/integrated/IntegrationTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.votogether.domain.post.integrated; - -import io.restassured.RestAssured; -import org.junit.jupiter.api.BeforeEach; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.server.LocalServerPort; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class IntegrationTest { - - @LocalServerPort - int port; - - @BeforeEach - public void setUp() { - RestAssured.port = port; - } - -} From e65bfab56c88fa7e72f16eb9d14be34658b7c4a0 Mon Sep 17 00:00:00 2001 From: JunH Date: Thu, 20 Jul 2023 16:19:01 +0900 Subject: [PATCH 02/13] =?UTF-8?q?feat:=20(#95)=20=ED=95=B4=EB=8B=B9=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=A1=B0=EA=B8=B0=20=EB=A7=88?= =?UTF-8?q?=EA=B0=90=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/controller/PostController.java | 15 ++++++++++- .../votogether/domain/post/entity/Post.java | 3 +++ .../domain/post/service/PostService.java | 7 +++++ .../post/controller/PostControllerTest.java | 16 +++++++++++ .../domain/post/entity/PostTest.java | 27 +++++++++++++++---- .../domain/post/service/PostServiceTest.java | 26 ++++++++++++++++++ 6 files changed, 88 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/com/votogether/domain/post/controller/PostController.java b/backend/src/main/java/com/votogether/domain/post/controller/PostController.java index b90b6a7cd..a4f4449fe 100644 --- a/backend/src/main/java/com/votogether/domain/post/controller/PostController.java +++ b/backend/src/main/java/com/votogether/domain/post/controller/PostController.java @@ -16,6 +16,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +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.RequestMapping; @@ -62,7 +63,7 @@ public ResponseEntity save( } @Operation(summary = "게시글 투표 선택지 통계 조회", description = "게시글 특정 투표 선택지에 대한 통계를 조회한다.") - @ApiResponses({ + @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "게시글 투표 선택지 통계 조회 성공"), @ApiResponse(responseCode = "400", description = "게시글 투표 옵션이 게시글에 속하지 않아 조회 실패"), @ApiResponse(responseCode = "404", description = "존재하지 않는 게시글이거나 게시글 투표 옵션") @@ -76,5 +77,17 @@ public ResponseEntity getVoteOptionStatistics( return ResponseEntity.ok(response); } + @Operation(summary = "게시글 조기 마감", description = "게시글을 조기 마감한다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "201", description = "게시물이 조기 마감 되었습니다."), + @ApiResponse(responseCode = "400", description = "잘못된 입력입니다."), + @ApiResponse(responseCode = "500", description = "인터넷 서버 오류입니다.") + }) + @PatchMapping("/{id}/close") + public ResponseEntity postClosedEarly(@PathVariable final Long id) { + postService.postClosedEarlyById(id); + return ResponseEntity.ok().build(); + } + } diff --git a/backend/src/main/java/com/votogether/domain/post/entity/Post.java b/backend/src/main/java/com/votogether/domain/post/entity/Post.java index 695df4548..68b61aaaf 100644 --- a/backend/src/main/java/com/votogether/domain/post/entity/Post.java +++ b/backend/src/main/java/com/votogether/domain/post/entity/Post.java @@ -130,4 +130,7 @@ private void validatePostOption(PostOption postOption) { } } + public void closedEarly() { + this.deadline = LocalDateTime.now(); + } } diff --git a/backend/src/main/java/com/votogether/domain/post/service/PostService.java b/backend/src/main/java/com/votogether/domain/post/service/PostService.java index 1bdd91117..a19dd01a1 100644 --- a/backend/src/main/java/com/votogether/domain/post/service/PostService.java +++ b/backend/src/main/java/com/votogether/domain/post/service/PostService.java @@ -118,4 +118,11 @@ private String groupAgeRange(final String ageRange) { return ageRange; } + @Transactional + public void postClosedEarlyById(final Long id) { + final Post post = postRepository.findById(id) + .orElseThrow(() -> new IllegalArgumentException("해당 게시글은 존재하지 않습니다.")); + + post.closedEarly(); + } } diff --git a/backend/src/test/java/com/votogether/domain/post/controller/PostControllerTest.java b/backend/src/test/java/com/votogether/domain/post/controller/PostControllerTest.java index 93394a2b4..acd037662 100644 --- a/backend/src/test/java/com/votogether/domain/post/controller/PostControllerTest.java +++ b/backend/src/test/java/com/votogether/domain/post/controller/PostControllerTest.java @@ -117,4 +117,20 @@ void getVoteOptionStatistics() { assertThat(result).usingRecursiveComparison().isEqualTo(response); } + @Test + @DisplayName("게시글을 조기 마감 합니다") + void postClosedEarly() { + // given + long postId = 1L; + + // when + ExtractableResponse response = RestAssuredMockMvc.given().log().all() + .when().patch("/posts/" + postId + "/close") + .then().log().all() + .extract(); + + // then + assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()); + } + } diff --git a/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java b/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java index 759bbd785..bf81c808a 100644 --- a/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java +++ b/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java @@ -20,17 +20,17 @@ class PostTest { @DisplayName("여러 Category를 전달하면 Post와 매핑되어 PostOptions를 생성한다") void mapCategories() { // given - final Post post = Post.builder().build(); - final Category category1 = Category.builder().build(); - final Category category2 = Category.builder().build(); + Post post = Post.builder().build(); + Category category1 = Category.builder().build(); + Category category2 = Category.builder().build(); - final List categories = List.of(category1, category2); + List categories = List.of(category1, category2); // when post.mapCategories(categories); // then - final PostCategories actualPostCategories = post.getPostCategories(); + PostCategories actualPostCategories = post.getPostCategories(); assertThat(actualPostCategories.getPostCategories()).hasSize(2); } @@ -92,4 +92,21 @@ void isClosed() { ); } + @Test + @DisplayName("해당 게시글을 조기 마감 합니다.") + void closedEarly() { + // given + LocalDateTime deadline = LocalDateTime.of(2100, 1, 1, 0, 0); + Post post = Post.builder() + .deadline(deadline) + .build(); + + + // when + post.closedEarly(); + + // then + assertThat(post.getDeadline()).isBefore(deadline); + } + } diff --git a/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java b/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java index 457374ed8..6c0fc0b37 100644 --- a/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java +++ b/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java @@ -207,4 +207,30 @@ void getVoteOptionStatistics() { } } + @Test + @DisplayName("해당 게시글을 조기 마감 합니다") + void postClosedEarlyById() { + // given + Member writer = memberRepository.save(MemberFixtures.MALE_30); + LocalDateTime oldDeadline = LocalDateTime.of(2100, 7, 12, 0, 0); + Post post = postRepository.save( + Post.builder() + .member(writer) + .postBody(PostBody.builder().title("title").content("content").build()) + .deadline(oldDeadline) + .build() + ); + + Post findedPost = postRepository.findById(post.getId()).get(); + + // when + postService.postClosedEarlyById(post.getId()); + + // then + assertAll( + () -> assertThat(findedPost.getId()).isEqualTo(post.getId()), + () -> assertThat(findedPost.getDeadline()).isBefore(oldDeadline) + ); + } + } From 8ab5bf2bf919041397b9a43053bbadf01a8425f9 Mon Sep 17 00:00:00 2001 From: JunH Date: Fri, 21 Jul 2023 16:57:14 +0900 Subject: [PATCH 03/13] =?UTF-8?q?refactor:=20(#95)=20API=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EC=8B=9C,=20swagger=20=ED=91=9C=EC=8B=9C=EB=A5=BC?= =?UTF-8?q?=20201=EC=97=90=EC=84=9C=20200=EC=9C=BC=EB=A1=9C=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 --- .../com/votogether/domain/post/controller/PostController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/votogether/domain/post/controller/PostController.java b/backend/src/main/java/com/votogether/domain/post/controller/PostController.java index a4f4449fe..f7e939bca 100644 --- a/backend/src/main/java/com/votogether/domain/post/controller/PostController.java +++ b/backend/src/main/java/com/votogether/domain/post/controller/PostController.java @@ -79,7 +79,7 @@ public ResponseEntity getVoteOptionStatistics( @Operation(summary = "게시글 조기 마감", description = "게시글을 조기 마감한다.") @ApiResponses(value = { - @ApiResponse(responseCode = "201", description = "게시물이 조기 마감 되었습니다."), + @ApiResponse(responseCode = "200", description = "게시물이 조기 마감 되었습니다."), @ApiResponse(responseCode = "400", description = "잘못된 입력입니다."), @ApiResponse(responseCode = "500", description = "인터넷 서버 오류입니다.") }) From c1692e2fb23a954a31ef2ed2b9e0d95b0374936b Mon Sep 17 00:00:00 2001 From: JunH Date: Fri, 28 Jul 2023 14:40:22 +0900 Subject: [PATCH 04/13] =?UTF-8?q?refactor:=20(#95)=20swagger=20500=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=84=A4=EB=AA=85=EC=9D=80=20=EC=83=9D?= =?UTF-8?q?=EB=9E=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/votogether/domain/post/controller/PostController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/main/java/com/votogether/domain/post/controller/PostController.java b/backend/src/main/java/com/votogether/domain/post/controller/PostController.java index f7e939bca..a9549486d 100644 --- a/backend/src/main/java/com/votogether/domain/post/controller/PostController.java +++ b/backend/src/main/java/com/votogether/domain/post/controller/PostController.java @@ -80,8 +80,7 @@ public ResponseEntity getVoteOptionStatistics( @Operation(summary = "게시글 조기 마감", description = "게시글을 조기 마감한다.") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "게시물이 조기 마감 되었습니다."), - @ApiResponse(responseCode = "400", description = "잘못된 입력입니다."), - @ApiResponse(responseCode = "500", description = "인터넷 서버 오류입니다.") + @ApiResponse(responseCode = "400", description = "잘못된 입력입니다.") }) @PatchMapping("/{id}/close") public ResponseEntity postClosedEarly(@PathVariable final Long id) { From 03fd8bdc0f0d5c38986efd578743c1b3b6131bbb Mon Sep 17 00:00:00 2001 From: JunH Date: Fri, 28 Jul 2023 14:40:54 +0900 Subject: [PATCH 05/13] =?UTF-8?q?refactor:=20(#95)=20Post=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EB=A7=88=EC=A7=80=EB=A7=89=20=EC=A4=84=20?= =?UTF-8?q?=EA=B0=9C=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/votogether/domain/post/entity/Post.java | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/main/java/com/votogether/domain/post/entity/Post.java b/backend/src/main/java/com/votogether/domain/post/entity/Post.java index 68b61aaaf..e42e9b7d2 100644 --- a/backend/src/main/java/com/votogether/domain/post/entity/Post.java +++ b/backend/src/main/java/com/votogether/domain/post/entity/Post.java @@ -133,4 +133,5 @@ private void validatePostOption(PostOption postOption) { public void closedEarly() { this.deadline = LocalDateTime.now(); } + } From 7b5e0b73b2a7a74a6da582cd4e478e4937f56ff2 Mon Sep 17 00:00:00 2001 From: JunH Date: Fri, 28 Jul 2023 14:41:13 +0900 Subject: [PATCH 06/13] =?UTF-8?q?refactor:=20(#95)=20PostService=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=A7=88=EC=A7=80=EB=A7=89=20?= =?UTF-8?q?=EC=A4=84=20=EA=B0=9C=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/votogether/domain/post/service/PostService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/main/java/com/votogether/domain/post/service/PostService.java b/backend/src/main/java/com/votogether/domain/post/service/PostService.java index a19dd01a1..e746ab19a 100644 --- a/backend/src/main/java/com/votogether/domain/post/service/PostService.java +++ b/backend/src/main/java/com/votogether/domain/post/service/PostService.java @@ -125,4 +125,5 @@ public void postClosedEarlyById(final Long id) { post.closedEarly(); } + } From 9b775e36f7f90fcb13db213941cef397eb803370 Mon Sep 17 00:00:00 2001 From: JunH Date: Fri, 28 Jul 2023 14:59:40 +0900 Subject: [PATCH 07/13] =?UTF-8?q?refactor:=20(#95)=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?=EC=9E=90=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=EB=A7=8C=20=EC=A1=B0?= =?UTF-8?q?=EA=B8=B0=20=EB=A7=88=EA=B0=90=EC=9D=B4=20=EA=B0=80=EB=8A=A5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/controller/PostController.java | 7 ++++-- .../domain/post/service/PostService.java | 3 ++- .../domain/post/service/PostServiceTest.java | 25 ++++++++++++++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/votogether/domain/post/controller/PostController.java b/backend/src/main/java/com/votogether/domain/post/controller/PostController.java index f10adfde1..64176f766 100644 --- a/backend/src/main/java/com/votogether/domain/post/controller/PostController.java +++ b/backend/src/main/java/com/votogether/domain/post/controller/PostController.java @@ -99,8 +99,11 @@ public ResponseEntity getVoteOptionStatistics( @ApiResponse(responseCode = "400", description = "잘못된 입력입니다.") }) @PatchMapping("/{id}/close") - public ResponseEntity postClosedEarly(@PathVariable final Long id) { - postService.postClosedEarlyById(id); + public ResponseEntity postClosedEarly( + @PathVariable final Long id, + @Auth final Member loginMember + ) { + postService.postClosedEarlyById(id, loginMember); return ResponseEntity.ok().build(); } diff --git a/backend/src/main/java/com/votogether/domain/post/service/PostService.java b/backend/src/main/java/com/votogether/domain/post/service/PostService.java index 930f12b8d..1a656d7ee 100644 --- a/backend/src/main/java/com/votogether/domain/post/service/PostService.java +++ b/backend/src/main/java/com/votogether/domain/post/service/PostService.java @@ -136,10 +136,11 @@ private String groupAgeRange(final String ageRange) { } @Transactional - public void postClosedEarlyById(final Long id) { + public void postClosedEarlyById(final Long id, final Member loginMember) { final Post post = postRepository.findById(id) .orElseThrow(() -> new IllegalArgumentException("해당 게시글은 존재하지 않습니다.")); + post.validateWriter(loginMember); post.closedEarly(); } diff --git a/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java b/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java index 7bfc557cd..e79bec2cb 100644 --- a/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java +++ b/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java @@ -1,5 +1,6 @@ package com.votogether.domain.post.service; +import static com.votogether.fixtures.MemberFixtures.MALE_30; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertAll; @@ -342,7 +343,7 @@ void postClosedEarlyById() { Post findedPost = postRepository.findById(post.getId()).get(); // when - postService.postClosedEarlyById(post.getId()); + postService.postClosedEarlyById(post.getId(), writer); // then assertAll( @@ -351,4 +352,26 @@ void postClosedEarlyById() { ); } + @Test + @DisplayName("해당 게시글을 조기 마감할 시, 작성자가 아니면 예외를 던진다.") + void throwExceptionNotWriterPostClosedEarly() { + // given + Member writer = memberRepository.save(MemberFixtures.MALE_30.get()); + LocalDateTime oldDeadline = LocalDateTime.of(2100, 7, 12, 0, 0); + Post post = postRepository.save( + Post.builder() + .member(writer) + .postBody(PostBody.builder().title("title").content("content").build()) + .deadline(oldDeadline) + .build() + ); + + Post findedPost = postRepository.findById(post.getId()).get(); + + // when, then + assertThatThrownBy(() -> postService.postClosedEarlyById(findedPost.getId(), MemberFixtures.MALE_30.get())) + .isInstanceOf(BadRequestException.class) + .hasMessage("해당 게시글 작성자가 아닙니다."); + } + } From b4c9b438147976710e4b02953b777f332a4e6f68 Mon Sep 17 00:00:00 2001 From: JunH Date: Fri, 28 Jul 2023 16:26:05 +0900 Subject: [PATCH 08/13] =?UTF-8?q?refactor:=20(#95)=20=EC=A1=B0=EA=B8=B0=20?= =?UTF-8?q?=EB=A7=88=EA=B0=90=20=ED=95=A0=20=EC=8B=9C,=20=EB=B3=B8?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=8C=EC=8B=9C=EA=B8=80=EC=9D=B8=EC=A7=80,=20?= =?UTF-8?q?=EB=A7=88=EA=B0=90=EB=90=98=EC=A7=80=20=EC=95=8A=EC=9D=80=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EA=B8=80=EC=9D=B8=EC=A7=80,=20=EB=A7=88?= =?UTF-8?q?=EA=B0=90=20=EC=8B=9C=EA=B0=84=EA=B9=8C=EC=A7=80=20=EC=A0=88?= =?UTF-8?q?=EB=B0=98=20=EC=8B=9C=EA=B0=84=EC=9D=B4=20=EC=A7=80=EB=82=9C=20?= =?UTF-8?q?=EA=B2=83=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/entity/Member.java | 2 + .../votogether/domain/post/entity/Post.java | 21 ++++++-- .../post/exception/PostExceptionType.java | 2 + .../domain/post/service/PostService.java | 2 + .../domain/post/service/PostServiceTest.java | 51 ++++++++++++++++++- 5 files changed, 72 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/com/votogether/domain/member/entity/Member.java b/backend/src/main/java/com/votogether/domain/member/entity/Member.java index cb8c8c0f8..4ad48e35d 100644 --- a/backend/src/main/java/com/votogether/domain/member/entity/Member.java +++ b/backend/src/main/java/com/votogether/domain/member/entity/Member.java @@ -12,10 +12,12 @@ import jakarta.persistence.Id; import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; @NoArgsConstructor(access = AccessLevel.PROTECTED) +@EqualsAndHashCode(of = {"id"}) @Getter @Entity public class Member extends BaseEntity { diff --git a/backend/src/main/java/com/votogether/domain/post/entity/Post.java b/backend/src/main/java/com/votogether/domain/post/entity/Post.java index e9ee08961..95635c77a 100644 --- a/backend/src/main/java/com/votogether/domain/post/entity/Post.java +++ b/backend/src/main/java/com/votogether/domain/post/entity/Post.java @@ -18,7 +18,11 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; +import java.time.Duration; +import java.time.Instant; import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -104,7 +108,7 @@ public boolean hasPostOption(final PostOption postOption) { } public void validateWriter(final Member member) { - if (!Objects.equals(this.member.getId(), member.getId())) { + if (!Objects.equals(this.member, member)) { throw new BadRequestException(PostExceptionType.NOT_WRITER); } } @@ -124,15 +128,24 @@ public Vote makeVote(Member member, PostOption postOption) { .build(); } - private void validateDeadLine() { + public void validateDeadLine() { if (isClosed()) { - throw new IllegalStateException("게시글이 이미 마감되었습니다."); + throw new BadRequestException(PostExceptionType.POST_CLOSED); } } private void validatePostOption(PostOption postOption) { if (!hasPostOption(postOption)) { - throw new IllegalArgumentException("해당 게시글에서 존재하지 않는 선택지 입니다."); + throw new BadRequestException(PostExceptionType.POST_OPTION_NOT_FOUND); + } + } + + public void validateHalfDeadLine() { + final Duration betweenDuration = Duration.between(getCreatedAt(), this.deadline); + final LocalDateTime midpoint = getCreatedAt().plus(betweenDuration.dividedBy(2)); + + if (midpoint.isAfter(LocalDateTime.now())) { + throw new BadRequestException(PostExceptionType.POST_NOT_HALF_DEADLINE); } } diff --git a/backend/src/main/java/com/votogether/domain/post/exception/PostExceptionType.java b/backend/src/main/java/com/votogether/domain/post/exception/PostExceptionType.java index b7d39c4d5..846bec6dc 100644 --- a/backend/src/main/java/com/votogether/domain/post/exception/PostExceptionType.java +++ b/backend/src/main/java/com/votogether/domain/post/exception/PostExceptionType.java @@ -10,6 +10,8 @@ public enum PostExceptionType implements ExceptionType { POST_OPTION_NOT_FOUND(1001, "해당 게시글 투표 옵션이 존재하지 않습니다."), UNRELATED_POST_OPTION(1002, "게시글 투표 옵션이 게시글과 연관되어 있지 않습니다."), NOT_WRITER(1003, "해당 게시글 작성자가 아닙니다."), + POST_CLOSED(1004, "게시글이 이미 마감되었습니다."), + POST_NOT_HALF_DEADLINE(1005, "게시글이 마감 시간까지 절반의 시간 이상이 지나지 않으면 조기마감을 할 수 없습니다."), ; private final int code; diff --git a/backend/src/main/java/com/votogether/domain/post/service/PostService.java b/backend/src/main/java/com/votogether/domain/post/service/PostService.java index 1a656d7ee..d7e10fa10 100644 --- a/backend/src/main/java/com/votogether/domain/post/service/PostService.java +++ b/backend/src/main/java/com/votogether/domain/post/service/PostService.java @@ -141,6 +141,8 @@ public void postClosedEarlyById(final Long id, final Member loginMember) { .orElseThrow(() -> new IllegalArgumentException("해당 게시글은 존재하지 않습니다.")); post.validateWriter(loginMember); + post.validateDeadLine(); + post.validateHalfDeadLine(); post.closedEarly(); } diff --git a/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java b/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java index e79bec2cb..5715fae19 100644 --- a/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java +++ b/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java @@ -26,7 +26,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.time.Duration; import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; @@ -328,10 +330,10 @@ void getVoteOptionStatistics() { @Test @DisplayName("해당 게시글을 조기 마감 합니다") - void postClosedEarlyById() { + void postClosedEarlyById() throws InterruptedException { // given Member writer = memberRepository.save(MemberFixtures.MALE_30.get()); - LocalDateTime oldDeadline = LocalDateTime.of(2100, 7, 12, 0, 0); + LocalDateTime oldDeadline = LocalDateTime.now().plus(100, ChronoUnit.MILLIS); Post post = postRepository.save( Post.builder() .member(writer) @@ -341,6 +343,7 @@ void postClosedEarlyById() { ); Post findedPost = postRepository.findById(post.getId()).get(); + Thread.sleep(50); // when postService.postClosedEarlyById(post.getId(), writer); @@ -374,4 +377,48 @@ void throwExceptionNotWriterPostClosedEarly() { .hasMessage("해당 게시글 작성자가 아닙니다."); } + @Test + @DisplayName("해당 게시글을 조기 마감할 시, 마감이 된 게시글이면 예외를 던진다.") + void throwExceptionDeadLinePostClosedEarly() { + // given + Member writer = memberRepository.save(MemberFixtures.MALE_30.get()); + LocalDateTime oldDeadline = LocalDateTime.of(2000, 7, 12, 0, 0); + Post post = postRepository.save( + Post.builder() + .member(writer) + .postBody(PostBody.builder().title("title").content("content").build()) + .deadline(oldDeadline) + .build() + ); + + Post findedPost = postRepository.findById(post.getId()).get(); + + // when, then + assertThatThrownBy(() -> postService.postClosedEarlyById(findedPost.getId(), writer)) + .isInstanceOf(BadRequestException.class) + .hasMessage("게시글이 이미 마감되었습니다."); + } + + @Test + @DisplayName("해당 게시글을 조기 마감할 시, 마감 시간까지의 시간 중 반 이상이 지나지 않은 게시글이면 예외를 던진다.") + void throwExceptionHalfDeadLinePostClosedEarly() { + // given + Member writer = memberRepository.save(MemberFixtures.MALE_30.get()); + LocalDateTime oldDeadline = LocalDateTime.now().plusMinutes(1); + Post post = postRepository.save( + Post.builder() + .member(writer) + .postBody(PostBody.builder().title("title").content("content").build()) + .deadline(oldDeadline) + .build() + ); + + Post findedPost = postRepository.findById(post.getId()).get(); + + // when, then + assertThatThrownBy(() -> postService.postClosedEarlyById(findedPost.getId(), writer)) + .isInstanceOf(BadRequestException.class) + .hasMessage("게시글이 마감 시간까지 절반의 시간 이상이 지나지 않으면 조기마감을 할 수 없습니다."); + } + } From e0f49907e51d7d826f60fe9a15c4979a66ce94ee Mon Sep 17 00:00:00 2001 From: JunH Date: Sun, 30 Jul 2023 16:16:44 +0900 Subject: [PATCH 09/13] =?UTF-8?q?test:=20(#95)=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=20=EC=A1=B0=EA=B8=B0=20=EB=A7=88=EA=B0=90=20=EC=8B=9C?= =?UTF-8?q?,=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=A6=9D=EC=97=90?= =?UTF-8?q?=20=EB=8C=80=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/entity/PostTest.java | 97 ++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java b/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java index 0e27a2635..e4aa07ca4 100644 --- a/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java +++ b/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java @@ -1,13 +1,21 @@ package com.votogether.domain.post.entity; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatNoException; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertAll; import com.votogether.domain.category.entity.Category; +import com.votogether.domain.member.entity.Member; +import com.votogether.domain.post.exception.PostExceptionType; +import com.votogether.exception.BadRequestException; +import com.votogether.fixtures.MemberFixtures; import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.springframework.test.util.ReflectionTestUtils; class PostTest { @@ -29,6 +37,94 @@ void mapCategories() { assertThat(actualPostCategories.getPostCategories()).hasSize(2); } + @Test + @DisplayName("게시글의 작성자 여부에 따라 예외를 던질 지 결정한다.") + void throwExceptionIsWriter() { + // given + final Member writer = MemberFixtures.MALE_30.get(); + ReflectionTestUtils.setField(writer, "id", 1L); + + final Member newMember = MemberFixtures.FEMALE_30.get(); + ReflectionTestUtils.setField(newMember, "id", 2L); + + Post post1 = Post.builder() + .member(writer) + .build(); + + Post post2 = Post.builder() + .member(writer) + .build(); + + // when, then + assertAll( + () -> assertThatThrownBy(() -> post1.validateWriter(newMember)) + .isInstanceOf(BadRequestException.class) + .hasMessage(PostExceptionType.NOT_WRITER.getMessage()), + () -> assertThatNoException() + .isThrownBy(() -> post2.validateWriter(writer)) + ); + } + + @Test + @DisplayName("게시글의 마감 여부에 따라 예외를 던질 지 결정한다.") + void throwExceptionIsDeadlinePassed() { + // given + final Member writer = MemberFixtures.MALE_30.get(); + ReflectionTestUtils.setField(writer, "id", 1L); + + Post post1 = Post.builder() + .member(writer) + .deadline(LocalDateTime.of(2000, 1, 1, 1, 1)) + .build(); + + Post post2 = Post.builder() + .member(writer) + .deadline(LocalDateTime.of(9999, 1, 1, 1, 1)) + .build(); + + // when, then + assertAll( + () -> assertThatThrownBy(post1::validateDeadLine) + .isInstanceOf(BadRequestException.class) + .hasMessage(PostExceptionType.POST_CLOSED.getMessage()), + () -> assertThatNoException() + .isThrownBy(post2::validateDeadLine) + ); + } + + @Test + @DisplayName("게시글의 마감까지 절반의 시간을 넘겼는 지에 따라 예외를 던질 지 결정한다.") + void throwExceptionIsHalfToTheDeadline() { + // given + final Member writer = MemberFixtures.MALE_30.get(); + ReflectionTestUtils.setField(writer, "id", 1L); + + Post post1 = Post.builder() + .member(writer) + .deadline(LocalDateTime.of(9999, 1, 1, 1, 1)) + .build(); + ReflectionTestUtils.setField(post1, "createdAt", LocalDateTime.now()); + + Post post2 = Post.builder() + .member(writer) + .deadline(LocalDateTime.now().plus(100, ChronoUnit.MILLIS)) + .build(); + ReflectionTestUtils.setField(post2, "createdAt", LocalDateTime.now()); + + // when, then + assertAll( + () -> assertThatThrownBy(post1::validateHalfDeadLine) + .isInstanceOf(BadRequestException.class) + .hasMessage(PostExceptionType.POST_NOT_HALF_DEADLINE.getMessage()), + () -> { + Thread.sleep(50); + assertThatNoException() + .isThrownBy(post2::validateHalfDeadLine); + + } + ); + } + @Test @DisplayName("게시글의 마감 여부를 확인한다.") void isClosed() { @@ -61,7 +157,6 @@ void closedEarly() { .deadline(deadline) .build(); - // when post.closedEarly(); From bc66a7bea44e02d12612ab40732061116f3325cb Mon Sep 17 00:00:00 2001 From: JunH Date: Sun, 30 Jul 2023 16:18:23 +0900 Subject: [PATCH 10/13] =?UTF-8?q?refactor:=20(#95)=20PathVariable=20?= =?UTF-8?q?=EA=B0=92=EC=9D=B8=20id=EC=9D=98=20=EB=B3=80=EC=88=98=EB=AA=85?= =?UTF-8?q?=EC=9D=84=20postId=EB=A1=9C=20=EB=8D=94=20=EB=AA=85=ED=99=95?= =?UTF-8?q?=ED=95=98=EA=B2=8C=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../votogether/domain/post/controller/PostController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/com/votogether/domain/post/controller/PostController.java b/backend/src/main/java/com/votogether/domain/post/controller/PostController.java index 64176f766..a87cbb09a 100644 --- a/backend/src/main/java/com/votogether/domain/post/controller/PostController.java +++ b/backend/src/main/java/com/votogether/domain/post/controller/PostController.java @@ -98,12 +98,12 @@ public ResponseEntity getVoteOptionStatistics( @ApiResponse(responseCode = "200", description = "게시물이 조기 마감 되었습니다."), @ApiResponse(responseCode = "400", description = "잘못된 입력입니다.") }) - @PatchMapping("/{id}/close") + @PatchMapping("/{postId}/close") public ResponseEntity postClosedEarly( - @PathVariable final Long id, + @PathVariable final Long postId, @Auth final Member loginMember ) { - postService.postClosedEarlyById(id, loginMember); + postService.postClosedEarlyById(postId, loginMember); return ResponseEntity.ok().build(); } From 21d10f3b515b6b4afb53c6b45caaa779e13d33eb Mon Sep 17 00:00:00 2001 From: JunH Date: Sun, 30 Jul 2023 16:20:21 +0900 Subject: [PATCH 11/13] =?UTF-8?q?refactor:=20(#95)=20path=20parameter?= =?UTF-8?q?=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=EC=9D=98=20url=EC=9D=84?= =?UTF-8?q?=20=EB=8D=94=20=EC=A7=81=EA=B4=80=EC=A0=81=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../votogether/domain/post/controller/PostControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/test/java/com/votogether/domain/post/controller/PostControllerTest.java b/backend/src/test/java/com/votogether/domain/post/controller/PostControllerTest.java index 6d758df0c..fb0ae826b 100644 --- a/backend/src/test/java/com/votogether/domain/post/controller/PostControllerTest.java +++ b/backend/src/test/java/com/votogether/domain/post/controller/PostControllerTest.java @@ -158,7 +158,7 @@ void postClosedEarly() { // when ExtractableResponse response = RestAssuredMockMvc.given().log().all() - .when().patch("/posts/" + postId + "/close") + .when().patch("/posts/{postId}/close", postId) .then().log().all() .extract(); From 34e5aa78df080ab48ff4f0d36528dbc419081751 Mon Sep 17 00:00:00 2001 From: JunH Date: Sun, 30 Jul 2023 16:22:02 +0900 Subject: [PATCH 12/13] =?UTF-8?q?refactor:=20(#95)=20PostServiceTest?= =?UTF-8?q?=EC=9D=98=20=EC=BD=94=EB=93=9C=EC=97=90=EC=84=9C=20finded=20?= =?UTF-8?q?=EB=8B=A8=EC=96=B4=EB=A5=BC=20found=EB=A1=9C=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/service/PostServiceTest.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java b/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java index 5715fae19..f8a6e3e5a 100644 --- a/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java +++ b/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java @@ -342,7 +342,7 @@ void postClosedEarlyById() throws InterruptedException { .build() ); - Post findedPost = postRepository.findById(post.getId()).get(); + Post foundPost = postRepository.findById(post.getId()).get(); Thread.sleep(50); // when @@ -350,8 +350,8 @@ void postClosedEarlyById() throws InterruptedException { // then assertAll( - () -> assertThat(findedPost.getId()).isEqualTo(post.getId()), - () -> assertThat(findedPost.getDeadline()).isBefore(oldDeadline) + () -> assertThat(foundPost.getId()).isEqualTo(post.getId()), + () -> assertThat(foundPost.getDeadline()).isBefore(oldDeadline) ); } @@ -369,10 +369,10 @@ void throwExceptionNotWriterPostClosedEarly() { .build() ); - Post findedPost = postRepository.findById(post.getId()).get(); + Post foundPost = postRepository.findById(post.getId()).get(); // when, then - assertThatThrownBy(() -> postService.postClosedEarlyById(findedPost.getId(), MemberFixtures.MALE_30.get())) + assertThatThrownBy(() -> postService.postClosedEarlyById(foundPost.getId(), MemberFixtures.MALE_30.get())) .isInstanceOf(BadRequestException.class) .hasMessage("해당 게시글 작성자가 아닙니다."); } @@ -391,10 +391,10 @@ void throwExceptionDeadLinePostClosedEarly() { .build() ); - Post findedPost = postRepository.findById(post.getId()).get(); + Post foundPost = postRepository.findById(post.getId()).get(); // when, then - assertThatThrownBy(() -> postService.postClosedEarlyById(findedPost.getId(), writer)) + assertThatThrownBy(() -> postService.postClosedEarlyById(foundPost.getId(), writer)) .isInstanceOf(BadRequestException.class) .hasMessage("게시글이 이미 마감되었습니다."); } @@ -413,10 +413,10 @@ void throwExceptionHalfDeadLinePostClosedEarly() { .build() ); - Post findedPost = postRepository.findById(post.getId()).get(); + Post foundPost = postRepository.findById(post.getId()).get(); // when, then - assertThatThrownBy(() -> postService.postClosedEarlyById(findedPost.getId(), writer)) + assertThatThrownBy(() -> postService.postClosedEarlyById(foundPost.getId(), writer)) .isInstanceOf(BadRequestException.class) .hasMessage("게시글이 마감 시간까지 절반의 시간 이상이 지나지 않으면 조기마감을 할 수 없습니다."); } From 3f0f28a70f5e585bdd55f012a58f07bf37c06242 Mon Sep 17 00:00:00 2001 From: JunH Date: Sun, 30 Jul 2023 16:23:34 +0900 Subject: [PATCH 13/13] =?UTF-8?q?refactor:=20(#95)=20=EC=A1=B0=EA=B8=B0=20?= =?UTF-8?q?=EB=A7=88=EA=B0=90=ED=95=98=EB=8A=94=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=AA=85=EB=93=A4=EC=9D=84=20=EB=8D=94=20=EC=95=8C?= =?UTF-8?q?=EB=A7=9E=EC=9D=80=20=EB=8B=A8=EC=96=B4=EB=A1=9C=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/controller/PostController.java | 4 ++-- .../java/com/votogether/domain/post/entity/Post.java | 5 +---- .../votogether/domain/post/service/PostService.java | 4 ++-- .../com/votogether/domain/post/entity/PostTest.java | 2 +- .../domain/post/service/PostServiceTest.java | 10 ++++------ 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/com/votogether/domain/post/controller/PostController.java b/backend/src/main/java/com/votogether/domain/post/controller/PostController.java index a87cbb09a..652fae70d 100644 --- a/backend/src/main/java/com/votogether/domain/post/controller/PostController.java +++ b/backend/src/main/java/com/votogether/domain/post/controller/PostController.java @@ -99,11 +99,11 @@ public ResponseEntity getVoteOptionStatistics( @ApiResponse(responseCode = "400", description = "잘못된 입력입니다.") }) @PatchMapping("/{postId}/close") - public ResponseEntity postClosedEarly( + public ResponseEntity closePostEarly( @PathVariable final Long postId, @Auth final Member loginMember ) { - postService.postClosedEarlyById(postId, loginMember); + postService.closePostEarlyById(postId, loginMember); return ResponseEntity.ok().build(); } diff --git a/backend/src/main/java/com/votogether/domain/post/entity/Post.java b/backend/src/main/java/com/votogether/domain/post/entity/Post.java index 95635c77a..e06b498e9 100644 --- a/backend/src/main/java/com/votogether/domain/post/entity/Post.java +++ b/backend/src/main/java/com/votogether/domain/post/entity/Post.java @@ -19,10 +19,7 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import java.time.Duration; -import java.time.Instant; import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -149,7 +146,7 @@ public void validateHalfDeadLine() { } } - public void closedEarly() { + public void closeEarly() { this.deadline = LocalDateTime.now(); } diff --git a/backend/src/main/java/com/votogether/domain/post/service/PostService.java b/backend/src/main/java/com/votogether/domain/post/service/PostService.java index d7e10fa10..98ac7b421 100644 --- a/backend/src/main/java/com/votogether/domain/post/service/PostService.java +++ b/backend/src/main/java/com/votogether/domain/post/service/PostService.java @@ -136,14 +136,14 @@ private String groupAgeRange(final String ageRange) { } @Transactional - public void postClosedEarlyById(final Long id, final Member loginMember) { + public void closePostEarlyById(final Long id, final Member loginMember) { final Post post = postRepository.findById(id) .orElseThrow(() -> new IllegalArgumentException("해당 게시글은 존재하지 않습니다.")); post.validateWriter(loginMember); post.validateDeadLine(); post.validateHalfDeadLine(); - post.closedEarly(); + post.closeEarly(); } } diff --git a/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java b/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java index e4aa07ca4..93245bc74 100644 --- a/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java +++ b/backend/src/test/java/com/votogether/domain/post/entity/PostTest.java @@ -158,7 +158,7 @@ void closedEarly() { .build(); // when - post.closedEarly(); + post.closeEarly(); // then assertThat(post.getDeadline()).isBefore(deadline); diff --git a/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java b/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java index f8a6e3e5a..663832a6f 100644 --- a/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java +++ b/backend/src/test/java/com/votogether/domain/post/service/PostServiceTest.java @@ -1,6 +1,5 @@ package com.votogether.domain.post.service; -import static com.votogether.fixtures.MemberFixtures.MALE_30; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertAll; @@ -26,7 +25,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.time.Duration; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.List; @@ -346,7 +344,7 @@ void postClosedEarlyById() throws InterruptedException { Thread.sleep(50); // when - postService.postClosedEarlyById(post.getId(), writer); + postService.closePostEarlyById(post.getId(), writer); // then assertAll( @@ -372,7 +370,7 @@ void throwExceptionNotWriterPostClosedEarly() { Post foundPost = postRepository.findById(post.getId()).get(); // when, then - assertThatThrownBy(() -> postService.postClosedEarlyById(foundPost.getId(), MemberFixtures.MALE_30.get())) + assertThatThrownBy(() -> postService.closePostEarlyById(foundPost.getId(), MemberFixtures.MALE_30.get())) .isInstanceOf(BadRequestException.class) .hasMessage("해당 게시글 작성자가 아닙니다."); } @@ -394,7 +392,7 @@ void throwExceptionDeadLinePostClosedEarly() { Post foundPost = postRepository.findById(post.getId()).get(); // when, then - assertThatThrownBy(() -> postService.postClosedEarlyById(foundPost.getId(), writer)) + assertThatThrownBy(() -> postService.closePostEarlyById(foundPost.getId(), writer)) .isInstanceOf(BadRequestException.class) .hasMessage("게시글이 이미 마감되었습니다."); } @@ -416,7 +414,7 @@ void throwExceptionHalfDeadLinePostClosedEarly() { Post foundPost = postRepository.findById(post.getId()).get(); // when, then - assertThatThrownBy(() -> postService.postClosedEarlyById(foundPost.getId(), writer)) + assertThatThrownBy(() -> postService.closePostEarlyById(foundPost.getId(), writer)) .isInstanceOf(BadRequestException.class) .hasMessage("게시글이 마감 시간까지 절반의 시간 이상이 지나지 않으면 조기마감을 할 수 없습니다."); }