From 5ae0b512abd1b8494cdf3de7d211c72af9b9238a Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 00:44:00 +0900 Subject: [PATCH 01/28] =?UTF-8?q?feat:=20=EA=B1=B4=EC=9D=98/=EA=B0=90?= =?UTF-8?q?=EC=82=AC=20=EA=B8=80=20request=20dto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/dto/PostRequestDto.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/EBus/EBusback/domain/post/dto/PostRequestDto.java diff --git a/src/main/java/EBus/EBusback/domain/post/dto/PostRequestDto.java b/src/main/java/EBus/EBusback/domain/post/dto/PostRequestDto.java new file mode 100644 index 0000000..938cf7e --- /dev/null +++ b/src/main/java/EBus/EBusback/domain/post/dto/PostRequestDto.java @@ -0,0 +1,17 @@ +package EBus.EBusback.domain.post.dto; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; +import lombok.Getter; + +@Getter +public class PostRequestDto { + + @NotBlank + @Size(min = 1, max = 30) + private String title; + + @NotBlank + @Size(min = 1, max = 100) + private String content; +} From 1891db4e4c67c43a7ecbe704d6b6dcb9601608b3 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 00:52:12 +0900 Subject: [PATCH 02/28] =?UTF-8?q?feat:=20=EA=B1=B4=EC=9D=98/=EA=B0=90?= =?UTF-8?q?=EC=82=AC=20=EA=B8=80=20response=20dto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/dto/PostResponseDto.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/EBus/EBusback/domain/post/dto/PostResponseDto.java diff --git a/src/main/java/EBus/EBusback/domain/post/dto/PostResponseDto.java b/src/main/java/EBus/EBusback/domain/post/dto/PostResponseDto.java new file mode 100644 index 0000000..993eb8b --- /dev/null +++ b/src/main/java/EBus/EBusback/domain/post/dto/PostResponseDto.java @@ -0,0 +1,17 @@ +package EBus.EBusback.domain.post.dto; + +import java.time.LocalDateTime; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class PostResponseDto { + + private Long postId; + private String title; + private String content; + private Boolean isSuggestion; + private LocalDateTime createdDate; +} From 49c322272ff0801bcac1feb638633af80fe7b373 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 00:55:00 +0900 Subject: [PATCH 03/28] =?UTF-8?q?fix:=20Post=EC=97=90=20createDate=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EBusback/domain/post/entity/Post.java | 61 +++++++++++-------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/src/main/java/EBus/EBusback/domain/post/entity/Post.java b/src/main/java/EBus/EBusback/domain/post/entity/Post.java index 7a360c8..c5bac45 100644 --- a/src/main/java/EBus/EBusback/domain/post/entity/Post.java +++ b/src/main/java/EBus/EBusback/domain/post/entity/Post.java @@ -1,36 +1,49 @@ package EBus.EBusback.domain.post.entity; import EBus.EBusback.domain.member.entity.Member; -import jakarta.persistence.*; -import lombok.*; +import EBus.EBusback.global.entity.BaseTimeEntity; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; @Entity -@Getter @Setter +@Getter +@Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Post { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(nullable = false, updatable = false) - private Long postId; +public class Post extends BaseTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false, updatable = false) + private Long postId; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "writer_id", nullable = false) - private Member writer; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "writer_id", nullable = false) + private Member writer; - @Column(nullable = false, length = 30) - private String title; + @Column(nullable = false, length = 30) + private String title; - @Column(nullable = false, length = 100) - private String content; + @Column(nullable = false, length = 100) + private String content; - @Column(nullable = false) - private Boolean isSuggestion; + @Column(nullable = false) + private Boolean isSuggestion; - @Builder - public Post(Member writer, String title, String content, Boolean isSuggestion){ - this.writer = writer; - this.title = title; - this.content = content; - this.isSuggestion = isSuggestion; - } + @Builder + public Post(Member writer, String title, String content, Boolean isSuggestion) { + this.writer = writer; + this.title = title; + this.content = content; + this.isSuggestion = isSuggestion; + } } From c1d4535cf91a1c7905164db6f88014591bdb4cb2 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 01:01:21 +0900 Subject: [PATCH 04/28] =?UTF-8?q?feat:=20PostRepository=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EBusback/domain/post/repository/PostRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/EBus/EBusback/domain/post/repository/PostRepository.java diff --git a/src/main/java/EBus/EBusback/domain/post/repository/PostRepository.java b/src/main/java/EBus/EBusback/domain/post/repository/PostRepository.java new file mode 100644 index 0000000..10540cf --- /dev/null +++ b/src/main/java/EBus/EBusback/domain/post/repository/PostRepository.java @@ -0,0 +1,8 @@ +package EBus.EBusback.domain.post.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import EBus.EBusback.domain.post.entity.Post; + +public interface PostRepository extends JpaRepository { +} From 0ce511c661ecb0bd2fb0217912b5491071a0844c Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 01:03:38 +0900 Subject: [PATCH 05/28] =?UTF-8?q?feat:=20=EA=B1=B4=EC=9D=98/=EA=B0=90?= =?UTF-8?q?=EC=82=AC=20=EA=B8=80=20=EC=A0=80=EC=9E=A5=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A9=94=EC=86=8C?= =?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/service/PostService.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/EBus/EBusback/domain/post/service/PostService.java diff --git a/src/main/java/EBus/EBusback/domain/post/service/PostService.java b/src/main/java/EBus/EBusback/domain/post/service/PostService.java new file mode 100644 index 0000000..3565115 --- /dev/null +++ b/src/main/java/EBus/EBusback/domain/post/service/PostService.java @@ -0,0 +1,34 @@ +package EBus.EBusback.domain.post.service; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import EBus.EBusback.domain.member.entity.Member; +import EBus.EBusback.domain.post.dto.PostRequestDto; +import EBus.EBusback.domain.post.dto.PostResponseDto; +import EBus.EBusback.domain.post.entity.Post; +import EBus.EBusback.domain.post.repository.PostRepository; +import EBus.EBusback.global.SecurityUtil; +import lombok.RequiredArgsConstructor; + +@Service +@Transactional +@RequiredArgsConstructor +public class PostService { + + private final PostRepository postRepository; + + public PostResponseDto createPost(PostRequestDto requestDto, Boolean isSuggestion) { + Member writer = SecurityUtil.getCurrentUser(); + Post post = postRepository.save( + Post.builder() + .title(requestDto.getTitle()) + .content(requestDto.getContent()) + .isSuggestion(isSuggestion) + .writer(writer) + .build() + ); + return new PostResponseDto(post.getPostId(), post.getTitle(), post.getContent(), post.getIsSuggestion(), + post.getCreatedDate()); + } +} From 8f8478141e71e4f837bf3cb0a3d4b8aca765751c Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 01:06:31 +0900 Subject: [PATCH 06/28] =?UTF-8?q?feat:=20=EA=B1=B4=EC=9D=98=20=EA=B8=80=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/controller/PostController.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/EBus/EBusback/domain/post/controller/PostController.java diff --git a/src/main/java/EBus/EBusback/domain/post/controller/PostController.java b/src/main/java/EBus/EBusback/domain/post/controller/PostController.java new file mode 100644 index 0000000..3d6a545 --- /dev/null +++ b/src/main/java/EBus/EBusback/domain/post/controller/PostController.java @@ -0,0 +1,27 @@ +package EBus.EBusback.domain.post.controller; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import EBus.EBusback.domain.post.dto.PostRequestDto; +import EBus.EBusback.domain.post.dto.PostResponseDto; +import EBus.EBusback.domain.post.service.PostService; +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/posts") +public class PostController { + + private final PostService postService; + + @PostMapping("/suggestion") + @ResponseStatus(HttpStatus.CREATED) + public PostResponseDto createSuggestion(@RequestBody PostRequestDto requestDto) { + return postService.createPost(requestDto, true); + } +} From 29c84ef459fc69af34099d63632cc3e2a20d9117 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 01:08:52 +0900 Subject: [PATCH 07/28] =?UTF-8?q?feat:=20=EA=B0=90=EC=82=AC=20=EA=B8=80=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EBusback/domain/post/controller/PostController.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/EBus/EBusback/domain/post/controller/PostController.java b/src/main/java/EBus/EBusback/domain/post/controller/PostController.java index 3d6a545..dfe401a 100644 --- a/src/main/java/EBus/EBusback/domain/post/controller/PostController.java +++ b/src/main/java/EBus/EBusback/domain/post/controller/PostController.java @@ -24,4 +24,10 @@ public class PostController { public PostResponseDto createSuggestion(@RequestBody PostRequestDto requestDto) { return postService.createPost(requestDto, true); } + + @PostMapping("/appreciation") + @ResponseStatus(HttpStatus.CREATED) + public PostResponseDto createAppreciation(@RequestBody PostRequestDto requestDto) { + return postService.createPost(requestDto, false); + } } From df78652bf846e51153c37918f6ec2e1dd286d69f Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 01:14:28 +0900 Subject: [PATCH 08/28] =?UTF-8?q?fix:=20=EA=B1=B4=EC=9D=98/=EA=B0=90?= =?UTF-8?q?=EC=82=AC=20=EA=B8=80=20=EB=93=B1=EB=A1=9D=20=EC=8B=9C=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=EB=90=98=EB=8A=94=20=EC=9D=91=EB=8B=B5=20Dto?= =?UTF-8?q?=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EBusback/domain/post/controller/PostController.java | 6 +++--- .../{PostResponseDto.java => PostCreateResponseDto.java} | 2 +- .../java/EBus/EBusback/domain/post/service/PostService.java | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) rename src/main/java/EBus/EBusback/domain/post/dto/{PostResponseDto.java => PostCreateResponseDto.java} (88%) diff --git a/src/main/java/EBus/EBusback/domain/post/controller/PostController.java b/src/main/java/EBus/EBusback/domain/post/controller/PostController.java index dfe401a..d51b4a4 100644 --- a/src/main/java/EBus/EBusback/domain/post/controller/PostController.java +++ b/src/main/java/EBus/EBusback/domain/post/controller/PostController.java @@ -7,8 +7,8 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import EBus.EBusback.domain.post.dto.PostCreateResponseDto; import EBus.EBusback.domain.post.dto.PostRequestDto; -import EBus.EBusback.domain.post.dto.PostResponseDto; import EBus.EBusback.domain.post.service.PostService; import lombok.RequiredArgsConstructor; @@ -21,13 +21,13 @@ public class PostController { @PostMapping("/suggestion") @ResponseStatus(HttpStatus.CREATED) - public PostResponseDto createSuggestion(@RequestBody PostRequestDto requestDto) { + public PostCreateResponseDto createSuggestion(@RequestBody PostRequestDto requestDto) { return postService.createPost(requestDto, true); } @PostMapping("/appreciation") @ResponseStatus(HttpStatus.CREATED) - public PostResponseDto createAppreciation(@RequestBody PostRequestDto requestDto) { + public PostCreateResponseDto createAppreciation(@RequestBody PostRequestDto requestDto) { return postService.createPost(requestDto, false); } } diff --git a/src/main/java/EBus/EBusback/domain/post/dto/PostResponseDto.java b/src/main/java/EBus/EBusback/domain/post/dto/PostCreateResponseDto.java similarity index 88% rename from src/main/java/EBus/EBusback/domain/post/dto/PostResponseDto.java rename to src/main/java/EBus/EBusback/domain/post/dto/PostCreateResponseDto.java index 993eb8b..f41577e 100644 --- a/src/main/java/EBus/EBusback/domain/post/dto/PostResponseDto.java +++ b/src/main/java/EBus/EBusback/domain/post/dto/PostCreateResponseDto.java @@ -7,7 +7,7 @@ @Getter @AllArgsConstructor -public class PostResponseDto { +public class PostCreateResponseDto { private Long postId; private String title; diff --git a/src/main/java/EBus/EBusback/domain/post/service/PostService.java b/src/main/java/EBus/EBusback/domain/post/service/PostService.java index 3565115..b2ac85c 100644 --- a/src/main/java/EBus/EBusback/domain/post/service/PostService.java +++ b/src/main/java/EBus/EBusback/domain/post/service/PostService.java @@ -4,8 +4,8 @@ import org.springframework.transaction.annotation.Transactional; import EBus.EBusback.domain.member.entity.Member; +import EBus.EBusback.domain.post.dto.PostCreateResponseDto; import EBus.EBusback.domain.post.dto.PostRequestDto; -import EBus.EBusback.domain.post.dto.PostResponseDto; import EBus.EBusback.domain.post.entity.Post; import EBus.EBusback.domain.post.repository.PostRepository; import EBus.EBusback.global.SecurityUtil; @@ -18,7 +18,7 @@ public class PostService { private final PostRepository postRepository; - public PostResponseDto createPost(PostRequestDto requestDto, Boolean isSuggestion) { + public PostCreateResponseDto createPost(PostRequestDto requestDto, Boolean isSuggestion) { Member writer = SecurityUtil.getCurrentUser(); Post post = postRepository.save( Post.builder() @@ -28,7 +28,7 @@ public PostResponseDto createPost(PostRequestDto requestDto, Boolean isSuggestio .writer(writer) .build() ); - return new PostResponseDto(post.getPostId(), post.getTitle(), post.getContent(), post.getIsSuggestion(), + return new PostCreateResponseDto(post.getPostId(), post.getTitle(), post.getContent(), post.getIsSuggestion(), post.getCreatedDate()); } } From 72c7753b1dfa9097e7ba9812029a8874f1638be3 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 01:56:21 +0900 Subject: [PATCH 09/28] =?UTF-8?q?fix:=20=EA=B1=B4=EC=9D=98/=EA=B0=90?= =?UTF-8?q?=EC=82=AC=20=EA=B8=80=20=EB=93=B1=EB=A1=9D=20=EC=8B=9C=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=EB=90=98=EB=8A=94=20=EC=9D=91=EB=8B=B5=20Dto?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=EC=9E=90=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/dto/PostCreateResponseDto.java | 11 +++++++++-- .../EBusback/domain/post/service/PostService.java | 3 +-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/EBus/EBusback/domain/post/dto/PostCreateResponseDto.java b/src/main/java/EBus/EBusback/domain/post/dto/PostCreateResponseDto.java index f41577e..fd6f390 100644 --- a/src/main/java/EBus/EBusback/domain/post/dto/PostCreateResponseDto.java +++ b/src/main/java/EBus/EBusback/domain/post/dto/PostCreateResponseDto.java @@ -2,11 +2,10 @@ import java.time.LocalDateTime; -import lombok.AllArgsConstructor; +import EBus.EBusback.domain.post.entity.Post; import lombok.Getter; @Getter -@AllArgsConstructor public class PostCreateResponseDto { private Long postId; @@ -14,4 +13,12 @@ public class PostCreateResponseDto { private String content; private Boolean isSuggestion; private LocalDateTime createdDate; + + public PostCreateResponseDto(Post post) { + this.postId = post.getPostId(); + this.title = post.getTitle(); + this.content = post.getContent(); + this.isSuggestion = post.getIsSuggestion(); + this.createdDate = post.getCreatedDate(); + } } diff --git a/src/main/java/EBus/EBusback/domain/post/service/PostService.java b/src/main/java/EBus/EBusback/domain/post/service/PostService.java index b2ac85c..2c718a2 100644 --- a/src/main/java/EBus/EBusback/domain/post/service/PostService.java +++ b/src/main/java/EBus/EBusback/domain/post/service/PostService.java @@ -28,7 +28,6 @@ public PostCreateResponseDto createPost(PostRequestDto requestDto, Boolean isSug .writer(writer) .build() ); - return new PostCreateResponseDto(post.getPostId(), post.getTitle(), post.getContent(), post.getIsSuggestion(), - post.getCreatedDate()); + return new PostCreateResponseDto(post); } } From 55920983731b6a045d9de7fbe8a30aabc310d264 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 02:02:29 +0900 Subject: [PATCH 10/28] =?UTF-8?q?feat:=20=EA=B1=B4=EC=9D=98/=EA=B0=90?= =?UTF-8?q?=EC=82=AC=20=EA=B8=80=EC=97=90=EC=84=9C=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=EC=99=80=20=EC=97=B0=EA=B4=80=EB=90=9C=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=A5=BC=20=EB=8B=B4=EB=8A=94=20Dto=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EBus/EBusback/domain/post/dto/PostMemberDto.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/EBus/EBusback/domain/post/dto/PostMemberDto.java diff --git a/src/main/java/EBus/EBusback/domain/post/dto/PostMemberDto.java b/src/main/java/EBus/EBusback/domain/post/dto/PostMemberDto.java new file mode 100644 index 0000000..20a37aa --- /dev/null +++ b/src/main/java/EBus/EBusback/domain/post/dto/PostMemberDto.java @@ -0,0 +1,12 @@ +package EBus.EBusback.domain.post.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class PostMemberDto { + + private Boolean hasHeart; + private Boolean isWriter; +} From a6085fd3b3eae15c24bb38dc8831f8a32dc87c17 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 02:02:48 +0900 Subject: [PATCH 11/28] =?UTF-8?q?feat:=20=EA=B1=B4=EC=9D=98/=EA=B0=90?= =?UTF-8?q?=EC=82=AC=20=EA=B8=80=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EC=9D=91=EB=8B=B5=20Dto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/dto/PostDetailResponseDto.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/main/java/EBus/EBusback/domain/post/dto/PostDetailResponseDto.java diff --git a/src/main/java/EBus/EBusback/domain/post/dto/PostDetailResponseDto.java b/src/main/java/EBus/EBusback/domain/post/dto/PostDetailResponseDto.java new file mode 100644 index 0000000..ff585c0 --- /dev/null +++ b/src/main/java/EBus/EBusback/domain/post/dto/PostDetailResponseDto.java @@ -0,0 +1,13 @@ +package EBus.EBusback.domain.post.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class PostDetailResponseDto { + + private PostCreateResponseDto post; + private Long heartCount; + private PostMemberDto member; +} From 7cab20dc42c5bef8f3f011ed12d9efd805460c02 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 02:03:53 +0900 Subject: [PATCH 12/28] =?UTF-8?q?fix:=20=EC=9D=B8=EC=A6=9D=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=97=86=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20=ED=98=84?= =?UTF-8?q?=EC=9E=AC=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EA=B0=9D=EC=B2=B4=20?= =?UTF-8?q?=EB=8C=80=EC=8B=A0=20null=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/EBus/EBusback/global/SecurityUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/EBus/EBusback/global/SecurityUtil.java b/src/main/java/EBus/EBusback/global/SecurityUtil.java index 69dc318..cf9622d 100644 --- a/src/main/java/EBus/EBusback/global/SecurityUtil.java +++ b/src/main/java/EBus/EBusback/global/SecurityUtil.java @@ -10,7 +10,7 @@ public class SecurityUtil { public static Member getCurrentUser() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || authentication.getPrincipal() == null) { - throw new RuntimeException("No authentication information"); + return null; } return (Member)authentication.getPrincipal(); } From 76ed078a6f6c1e96c428be5400128df2b74947d6 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 02:05:21 +0900 Subject: [PATCH 13/28] =?UTF-8?q?feat:=20=EA=B1=B4=EC=9D=98/=EA=B0=90?= =?UTF-8?q?=EC=82=AC=20=EA=B8=80=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EC=8B=9C=20=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=88=98=20?= =?UTF-8?q?=EA=B3=84=EC=82=B0=20=EB=A1=9C=EC=A7=81=EC=9D=84=20=EC=A0=9C?= =?UTF-8?q?=EC=99=B8=ED=95=9C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/service/PostService.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/EBus/EBusback/domain/post/service/PostService.java b/src/main/java/EBus/EBusback/domain/post/service/PostService.java index 2c718a2..b2894e1 100644 --- a/src/main/java/EBus/EBusback/domain/post/service/PostService.java +++ b/src/main/java/EBus/EBusback/domain/post/service/PostService.java @@ -5,6 +5,8 @@ import EBus.EBusback.domain.member.entity.Member; import EBus.EBusback.domain.post.dto.PostCreateResponseDto; +import EBus.EBusback.domain.post.dto.PostDetailResponseDto; +import EBus.EBusback.domain.post.dto.PostMemberDto; import EBus.EBusback.domain.post.dto.PostRequestDto; import EBus.EBusback.domain.post.entity.Post; import EBus.EBusback.domain.post.repository.PostRepository; @@ -30,4 +32,27 @@ public PostCreateResponseDto createPost(PostRequestDto requestDto, Boolean isSug ); return new PostCreateResponseDto(post); } + + public PostDetailResponseDto findPost(Long postId) { + Post post = postRepository.findById(postId) + .orElseThrow(() -> new IllegalArgumentException("글을 찾을 수 없습니다.")); + // Heartcount + Long heartCount = 0L; + // member + Member member = SecurityUtil.getCurrentUser(); + return new PostDetailResponseDto(new PostCreateResponseDto(post), heartCount, findPostMemberInfo(post, member)); + } + + public PostMemberDto findPostMemberInfo(Post post, Member member) { + Boolean hasHeart = false; + Boolean isWriter = false; + + if (member != null) { + // hasHeart + + // isWriter + isWriter = post.getWriter().equals(member); + } + return new PostMemberDto(hasHeart, isWriter); + } } From 55cd53eee1423a2a2ed28760d8743d1f78bcb4c2 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 02:05:50 +0900 Subject: [PATCH 14/28] =?UTF-8?q?feat:=20=EA=B1=B4=EC=9D=98/=EA=B0=90?= =?UTF-8?q?=EC=82=AC=20=EA=B8=80=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EB=A9=94=EC=84=9C?= =?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 --- .../EBusback/domain/post/controller/PostController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/EBus/EBusback/domain/post/controller/PostController.java b/src/main/java/EBus/EBusback/domain/post/controller/PostController.java index d51b4a4..946b553 100644 --- a/src/main/java/EBus/EBusback/domain/post/controller/PostController.java +++ b/src/main/java/EBus/EBusback/domain/post/controller/PostController.java @@ -1,6 +1,8 @@ package EBus.EBusback.domain.post.controller; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -8,6 +10,7 @@ import org.springframework.web.bind.annotation.RestController; import EBus.EBusback.domain.post.dto.PostCreateResponseDto; +import EBus.EBusback.domain.post.dto.PostDetailResponseDto; import EBus.EBusback.domain.post.dto.PostRequestDto; import EBus.EBusback.domain.post.service.PostService; import lombok.RequiredArgsConstructor; @@ -30,4 +33,10 @@ public PostCreateResponseDto createSuggestion(@RequestBody PostRequestDto reques public PostCreateResponseDto createAppreciation(@RequestBody PostRequestDto requestDto) { return postService.createPost(requestDto, false); } + + @GetMapping("/{postId}") + @ResponseStatus(HttpStatus.OK) + public PostDetailResponseDto findPost(@PathVariable Long postId) { + return postService.findPost(postId); + } } From 0ef3cb381bbad51f1babbeabe698f77b763cb3b6 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 02:31:24 +0900 Subject: [PATCH 15/28] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=9C=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B8=80=EC=9D=98=20id=EB=A5=BC=20=EB=8B=B4?= =?UTF-8?q?=EB=8A=94=20dto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EBus/EBusback/domain/heart/dto/HeartRequestDto.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/EBus/EBusback/domain/heart/dto/HeartRequestDto.java diff --git a/src/main/java/EBus/EBusback/domain/heart/dto/HeartRequestDto.java b/src/main/java/EBus/EBusback/domain/heart/dto/HeartRequestDto.java new file mode 100644 index 0000000..812cf00 --- /dev/null +++ b/src/main/java/EBus/EBusback/domain/heart/dto/HeartRequestDto.java @@ -0,0 +1,9 @@ +package EBus.EBusback.domain.heart.dto; + +import lombok.Getter; + +@Getter +public class HeartRequestDto { + + private Long postId; +} From 63c8a83db776d56bdf5d024ca85d83f1ca5cd92d Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 02:32:46 +0900 Subject: [PATCH 16/28] =?UTF-8?q?feat:=20=EC=A2=8B=EC=95=84=EC=9A=94=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D/=EC=B7=A8=EC=86=8C=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=A9=94=EC=84=9C=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 --- .../EBusback/domain/heart/entity/Heart.java | 49 ++++++++++++------- .../heart/repository/HeartRepository.java | 14 ++++++ .../domain/heart/service/HeartService.java | 40 +++++++++++++++ 3 files changed, 84 insertions(+), 19 deletions(-) create mode 100644 src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java create mode 100644 src/main/java/EBus/EBusback/domain/heart/service/HeartService.java diff --git a/src/main/java/EBus/EBusback/domain/heart/entity/Heart.java b/src/main/java/EBus/EBusback/domain/heart/entity/Heart.java index 2611b96..61f7706 100644 --- a/src/main/java/EBus/EBusback/domain/heart/entity/Heart.java +++ b/src/main/java/EBus/EBusback/domain/heart/entity/Heart.java @@ -1,9 +1,15 @@ package EBus.EBusback.domain.heart.entity; import EBus.EBusback.domain.member.entity.Member; - import EBus.EBusback.domain.post.entity.Post; -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -13,25 +19,30 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Heart { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(nullable = false, updatable = false) - private Long heartId; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false, updatable = false) + private Long heartId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id", nullable = false) + private Member member; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "member_id", nullable = false) - private Member member; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "post_id", nullable = false) + private Post post; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "post_id", nullable = false) - private Post post; + @Column(nullable = false) + private Boolean isValid; - @Column(nullable = false) - private Boolean isValid; + @Builder + public Heart(Member member, Post post) { + this.member = member; + this.post = post; + this.isValid = false; + } - @Builder - public Heart(Member member, Post post){ - this.member = member; - this.post = post; - } + public void updateHeart() { + this.isValid = !isValid; + } } diff --git a/src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java b/src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java new file mode 100644 index 0000000..ae677cf --- /dev/null +++ b/src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java @@ -0,0 +1,14 @@ +package EBus.EBusback.domain.heart.repository; + +import java.util.Optional; + +import org.springframework.data.jpa.repository.JpaRepository; + +import EBus.EBusback.domain.heart.entity.Heart; +import EBus.EBusback.domain.member.entity.Member; +import EBus.EBusback.domain.post.entity.Post; + +public interface HeartRepository extends JpaRepository { + + Optional findByMemberAndPost(Member member, Post post); +} diff --git a/src/main/java/EBus/EBusback/domain/heart/service/HeartService.java b/src/main/java/EBus/EBusback/domain/heart/service/HeartService.java new file mode 100644 index 0000000..3cb6884 --- /dev/null +++ b/src/main/java/EBus/EBusback/domain/heart/service/HeartService.java @@ -0,0 +1,40 @@ +package EBus.EBusback.domain.heart.service; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import EBus.EBusback.domain.heart.entity.Heart; +import EBus.EBusback.domain.heart.repository.HeartRepository; +import EBus.EBusback.domain.member.entity.Member; +import EBus.EBusback.domain.post.entity.Post; +import EBus.EBusback.domain.post.repository.PostRepository; +import EBus.EBusback.global.SecurityUtil; +import lombok.RequiredArgsConstructor; + +@Service +@Transactional +@RequiredArgsConstructor +public class HeartService { + + private final HeartRepository heartRepository; + private final PostRepository postRepository; + + public String createOrRemoveHeart(Long postId) { + Member member = SecurityUtil.getCurrentUser(); + if (member == null) + throw new RuntimeException("사용자를 찾을 수 없습니다."); + + Post post = postRepository.findById(postId) + .orElseThrow(() -> new IllegalArgumentException("글을 찾을 수 없습니다.")); + + Heart heart = heartRepository.findByMemberAndPost(member, post) + .orElseGet(() -> heartRepository.save(Heart.builder().member(member).post(post).build())); + + heart.updateHeart(); + + if (heart.getIsValid()) + return "좋아요가 등록되었습니다."; + else + return "좋아요가 취소되었습니다."; + } +} From 91c5147f9c03cf8f89657f60b1e8335d00179ebe Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 02:33:00 +0900 Subject: [PATCH 17/28] =?UTF-8?q?feat:=20=EC=A2=8B=EC=95=84=EC=9A=94=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D/=EC=B7=A8=EC=86=8C=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../heart/controller/HeartController.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/EBus/EBusback/domain/heart/controller/HeartController.java diff --git a/src/main/java/EBus/EBusback/domain/heart/controller/HeartController.java b/src/main/java/EBus/EBusback/domain/heart/controller/HeartController.java new file mode 100644 index 0000000..23d2cca --- /dev/null +++ b/src/main/java/EBus/EBusback/domain/heart/controller/HeartController.java @@ -0,0 +1,23 @@ +package EBus.EBusback.domain.heart.controller; + +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import EBus.EBusback.domain.heart.dto.HeartRequestDto; +import EBus.EBusback.domain.heart.service.HeartService; +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/hearts") +public class HeartController { + + private final HeartService heartService; + + @PostMapping + public String clickHeart(@RequestBody HeartRequestDto requestDto) { + return heartService.createOrRemoveHeart(requestDto.getPostId()); + } +} From 8a7600875d7acfbb16b60a59e518dd9e689d231f Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 02:38:50 +0900 Subject: [PATCH 18/28] =?UTF-8?q?feat:=20=EA=B1=B4=EC=9D=98/=EA=B0=90?= =?UTF-8?q?=EC=82=AC=20=EA=B8=80=EC=9D=98=20=EC=A2=8B=EC=95=84=EC=9A=94=20?= =?UTF-8?q?=EC=88=98=20=EA=B3=84=EC=82=B0=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EBusback/domain/heart/repository/HeartRepository.java | 3 +++ .../EBus/EBusback/domain/heart/service/HeartService.java | 4 ++++ .../EBusback/domain/post/dto/PostDetailResponseDto.java | 2 +- .../EBus/EBusback/domain/post/service/PostService.java | 8 ++++---- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java b/src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java index ae677cf..be667f8 100644 --- a/src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java +++ b/src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java @@ -1,5 +1,6 @@ package EBus.EBusback.domain.heart.repository; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -11,4 +12,6 @@ public interface HeartRepository extends JpaRepository { Optional findByMemberAndPost(Member member, Post post); + + List findByPost(Post post); } diff --git a/src/main/java/EBus/EBusback/domain/heart/service/HeartService.java b/src/main/java/EBus/EBusback/domain/heart/service/HeartService.java index 3cb6884..51a44e6 100644 --- a/src/main/java/EBus/EBusback/domain/heart/service/HeartService.java +++ b/src/main/java/EBus/EBusback/domain/heart/service/HeartService.java @@ -37,4 +37,8 @@ public String createOrRemoveHeart(Long postId) { else return "좋아요가 취소되었습니다."; } + + public Integer findHeartCount(Post post) { + return heartRepository.findByPost(post).size(); + } } diff --git a/src/main/java/EBus/EBusback/domain/post/dto/PostDetailResponseDto.java b/src/main/java/EBus/EBusback/domain/post/dto/PostDetailResponseDto.java index ff585c0..9aa6482 100644 --- a/src/main/java/EBus/EBusback/domain/post/dto/PostDetailResponseDto.java +++ b/src/main/java/EBus/EBusback/domain/post/dto/PostDetailResponseDto.java @@ -8,6 +8,6 @@ public class PostDetailResponseDto { private PostCreateResponseDto post; - private Long heartCount; + private Integer heartCount; private PostMemberDto member; } diff --git a/src/main/java/EBus/EBusback/domain/post/service/PostService.java b/src/main/java/EBus/EBusback/domain/post/service/PostService.java index b2894e1..934c63e 100644 --- a/src/main/java/EBus/EBusback/domain/post/service/PostService.java +++ b/src/main/java/EBus/EBusback/domain/post/service/PostService.java @@ -3,6 +3,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import EBus.EBusback.domain.heart.service.HeartService; import EBus.EBusback.domain.member.entity.Member; import EBus.EBusback.domain.post.dto.PostCreateResponseDto; import EBus.EBusback.domain.post.dto.PostDetailResponseDto; @@ -19,6 +20,7 @@ public class PostService { private final PostRepository postRepository; + private final HeartService heartService; public PostCreateResponseDto createPost(PostRequestDto requestDto, Boolean isSuggestion) { Member writer = SecurityUtil.getCurrentUser(); @@ -36,11 +38,9 @@ public PostCreateResponseDto createPost(PostRequestDto requestDto, Boolean isSug public PostDetailResponseDto findPost(Long postId) { Post post = postRepository.findById(postId) .orElseThrow(() -> new IllegalArgumentException("글을 찾을 수 없습니다.")); - // Heartcount - Long heartCount = 0L; - // member Member member = SecurityUtil.getCurrentUser(); - return new PostDetailResponseDto(new PostCreateResponseDto(post), heartCount, findPostMemberInfo(post, member)); + return new PostDetailResponseDto(new PostCreateResponseDto(post), heartService.findHeartCount(post), + findPostMemberInfo(post, member)); } public PostMemberDto findPostMemberInfo(Post post, Member member) { From 2e7b1f72bcf8cd1958606a93fe18f1b3dbc10536 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 02:54:15 +0900 Subject: [PATCH 19/28] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EC=9D=98=20=EA=B1=B4=EC=9D=98/=EA=B0=90=EC=82=AC=20=EA=B8=80?= =?UTF-8?q?=20=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=97=AC=EB=B6=80=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EBusback/domain/heart/repository/HeartRepository.java | 2 ++ .../EBus/EBusback/domain/heart/service/HeartService.java | 4 ++++ .../java/EBus/EBusback/domain/post/service/PostService.java | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java b/src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java index be667f8..80fe23c 100644 --- a/src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java +++ b/src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java @@ -14,4 +14,6 @@ public interface HeartRepository extends JpaRepository { Optional findByMemberAndPost(Member member, Post post); List findByPost(Post post); + + Boolean existsByMemberAndPostAndIsValid(Member member, Post post, Boolean isValid); } diff --git a/src/main/java/EBus/EBusback/domain/heart/service/HeartService.java b/src/main/java/EBus/EBusback/domain/heart/service/HeartService.java index 51a44e6..68f7a9a 100644 --- a/src/main/java/EBus/EBusback/domain/heart/service/HeartService.java +++ b/src/main/java/EBus/EBusback/domain/heart/service/HeartService.java @@ -41,4 +41,8 @@ public String createOrRemoveHeart(Long postId) { public Integer findHeartCount(Post post) { return heartRepository.findByPost(post).size(); } + + public Boolean existsHeart(Member member, Post post) { + return heartRepository.existsByMemberAndPostAndIsValid(member, post, true); + } } diff --git a/src/main/java/EBus/EBusback/domain/post/service/PostService.java b/src/main/java/EBus/EBusback/domain/post/service/PostService.java index 934c63e..1635d2b 100644 --- a/src/main/java/EBus/EBusback/domain/post/service/PostService.java +++ b/src/main/java/EBus/EBusback/domain/post/service/PostService.java @@ -13,7 +13,9 @@ import EBus.EBusback.domain.post.repository.PostRepository; import EBus.EBusback.global.SecurityUtil; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Service @Transactional @RequiredArgsConstructor @@ -48,8 +50,7 @@ public PostMemberDto findPostMemberInfo(Post post, Member member) { Boolean isWriter = false; if (member != null) { - // hasHeart - + hasHeart = heartService.existsHeart(member, post); // isWriter isWriter = post.getWriter().equals(member); } From f00ed876b11f8821de09a58c34a0c5fb761dbf00 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 02:55:06 +0900 Subject: [PATCH 20/28] =?UTF-8?q?fix:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EA=B0=80=20=EA=B1=B4=EC=9D=98/=EA=B0=90=EC=82=AC=20=EA=B8=80?= =?UTF-8?q?=EC=9D=98=20=EC=9E=91=EC=84=B1=EC=9E=90=EC=9D=B8=EC=A7=80=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/EBus/EBusback/domain/post/service/PostService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/EBus/EBusback/domain/post/service/PostService.java b/src/main/java/EBus/EBusback/domain/post/service/PostService.java index 1635d2b..a690318 100644 --- a/src/main/java/EBus/EBusback/domain/post/service/PostService.java +++ b/src/main/java/EBus/EBusback/domain/post/service/PostService.java @@ -51,8 +51,7 @@ public PostMemberDto findPostMemberInfo(Post post, Member member) { if (member != null) { hasHeart = heartService.existsHeart(member, post); - // isWriter - isWriter = post.getWriter().equals(member); + isWriter = post.getWriter().getMemberId().equals(member.getMemberId()); } return new PostMemberDto(hasHeart, isWriter); } From a6fcdbe6c4d8c0667b26b20a2161fcb7d5309f95 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 03:42:31 +0900 Subject: [PATCH 21/28] =?UTF-8?q?feat:=20=EA=B1=B4=EC=9D=98/=EA=B0=90?= =?UTF-8?q?=EC=82=AC=20=EA=B8=80=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20Dto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/dto/PostOutlineResponseDto.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/EBus/EBusback/domain/post/dto/PostOutlineResponseDto.java diff --git a/src/main/java/EBus/EBusback/domain/post/dto/PostOutlineResponseDto.java b/src/main/java/EBus/EBusback/domain/post/dto/PostOutlineResponseDto.java new file mode 100644 index 0000000..cbdbb47 --- /dev/null +++ b/src/main/java/EBus/EBusback/domain/post/dto/PostOutlineResponseDto.java @@ -0,0 +1,22 @@ +package EBus.EBusback.domain.post.dto; + +import java.time.LocalDateTime; + +import EBus.EBusback.domain.post.entity.Post; +import lombok.Getter; + +@Getter +public class PostOutlineResponseDto { + + private Long postId; + private String title; + private LocalDateTime createdDate; + private Integer heartCount; + + public PostOutlineResponseDto(Post post, Integer heartCount) { + this.postId = post.getPostId(); + this.title = post.getTitle(); + this.createdDate = post.getCreatedDate(); + this.heartCount = heartCount; + } +} From 053394dc39c2e39fd4d39531fc697a56f5a57bea Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 03:43:36 +0900 Subject: [PATCH 22/28] =?UTF-8?q?feat:=20=EA=B1=B4=EC=9D=98/=EA=B0=90?= =?UTF-8?q?=EC=82=AC=20=EA=B8=80=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=A9=94=EC=84=9C=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/repository/PostRepository.java | 4 ++++ .../EBusback/domain/post/service/PostService.java | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/EBus/EBusback/domain/post/repository/PostRepository.java b/src/main/java/EBus/EBusback/domain/post/repository/PostRepository.java index 10540cf..d631914 100644 --- a/src/main/java/EBus/EBusback/domain/post/repository/PostRepository.java +++ b/src/main/java/EBus/EBusback/domain/post/repository/PostRepository.java @@ -1,8 +1,12 @@ package EBus.EBusback.domain.post.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; import EBus.EBusback.domain.post.entity.Post; public interface PostRepository extends JpaRepository { + + List findAllByIsSuggestion(Boolean isSuggestion); } diff --git a/src/main/java/EBus/EBusback/domain/post/service/PostService.java b/src/main/java/EBus/EBusback/domain/post/service/PostService.java index a690318..1b2c136 100644 --- a/src/main/java/EBus/EBusback/domain/post/service/PostService.java +++ b/src/main/java/EBus/EBusback/domain/post/service/PostService.java @@ -1,5 +1,8 @@ package EBus.EBusback.domain.post.service; +import java.util.List; +import java.util.stream.Collectors; + import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -8,6 +11,7 @@ import EBus.EBusback.domain.post.dto.PostCreateResponseDto; import EBus.EBusback.domain.post.dto.PostDetailResponseDto; import EBus.EBusback.domain.post.dto.PostMemberDto; +import EBus.EBusback.domain.post.dto.PostOutlineResponseDto; import EBus.EBusback.domain.post.dto.PostRequestDto; import EBus.EBusback.domain.post.entity.Post; import EBus.EBusback.domain.post.repository.PostRepository; @@ -55,4 +59,11 @@ public PostMemberDto findPostMemberInfo(Post post, Member member) { } return new PostMemberDto(hasHeart, isWriter); } + + public List findPostList(Boolean isSuggestion) { + List postList = postRepository.findAllByIsSuggestion(isSuggestion); + return postList.stream() + .map(post -> new PostOutlineResponseDto(post, heartService.findHeartCount(post))) + .collect(Collectors.toList()); + } } From ceaf1b01a34f70fdf6d6707c19c348f062080dc8 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 03:43:47 +0900 Subject: [PATCH 23/28] =?UTF-8?q?feat:=20=EA=B1=B4=EC=9D=98=20=EA=B8=80=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=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 --- .../EBusback/domain/post/controller/PostController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/EBus/EBusback/domain/post/controller/PostController.java b/src/main/java/EBus/EBusback/domain/post/controller/PostController.java index 946b553..daf64fc 100644 --- a/src/main/java/EBus/EBusback/domain/post/controller/PostController.java +++ b/src/main/java/EBus/EBusback/domain/post/controller/PostController.java @@ -1,5 +1,7 @@ package EBus.EBusback.domain.post.controller; +import java.util.List; + import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -11,6 +13,7 @@ import EBus.EBusback.domain.post.dto.PostCreateResponseDto; import EBus.EBusback.domain.post.dto.PostDetailResponseDto; +import EBus.EBusback.domain.post.dto.PostOutlineResponseDto; import EBus.EBusback.domain.post.dto.PostRequestDto; import EBus.EBusback.domain.post.service.PostService; import lombok.RequiredArgsConstructor; @@ -39,4 +42,10 @@ public PostCreateResponseDto createAppreciation(@RequestBody PostRequestDto requ public PostDetailResponseDto findPost(@PathVariable Long postId) { return postService.findPost(postId); } + + @GetMapping("/suggestion") + @ResponseStatus(HttpStatus.OK) + public List findSuggestionList() { + return postService.findPostList(true); + } } From d62760bf095e5dc36b566e8f4845297ec405bdf1 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 03:45:13 +0900 Subject: [PATCH 24/28] =?UTF-8?q?feat:=20=EA=B0=90=EC=82=AC=20=EA=B8=80=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=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 --- .../EBusback/domain/post/controller/PostController.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/EBus/EBusback/domain/post/controller/PostController.java b/src/main/java/EBus/EBusback/domain/post/controller/PostController.java index daf64fc..976f9a0 100644 --- a/src/main/java/EBus/EBusback/domain/post/controller/PostController.java +++ b/src/main/java/EBus/EBusback/domain/post/controller/PostController.java @@ -48,4 +48,10 @@ public PostDetailResponseDto findPost(@PathVariable Long postId) { public List findSuggestionList() { return postService.findPostList(true); } + + @GetMapping("/appreciation") + @ResponseStatus(HttpStatus.OK) + public List findAppreciationList() { + return postService.findPostList(false); + } } From d6132a29606a13b924aab6db61dcfd6020140869 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 04:19:27 +0900 Subject: [PATCH 25/28] =?UTF-8?q?fix:=20=EA=B1=B4=EC=9D=98/=EA=B0=90?= =?UTF-8?q?=EC=82=AC=20=EA=B8=80=EC=9D=B4=20=EC=82=AD=EC=A0=9C=EB=90=A0=20?= =?UTF-8?q?=EB=95=8C=20=ED=95=B4=EB=8B=B9=20=EA=B8=80=EC=9D=98=20=EC=A2=8B?= =?UTF-8?q?=EC=95=84=EC=9A=94=EB=8F=84=20=ED=95=A8=EA=BB=98=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=EB=90=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/EBus/EBusback/domain/post/entity/Post.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/EBus/EBusback/domain/post/entity/Post.java b/src/main/java/EBus/EBusback/domain/post/entity/Post.java index c5bac45..2afa849 100644 --- a/src/main/java/EBus/EBusback/domain/post/entity/Post.java +++ b/src/main/java/EBus/EBusback/domain/post/entity/Post.java @@ -1,5 +1,9 @@ package EBus.EBusback.domain.post.entity; +import java.util.ArrayList; +import java.util.List; + +import EBus.EBusback.domain.heart.entity.Heart; import EBus.EBusback.domain.member.entity.Member; import EBus.EBusback.global.entity.BaseTimeEntity; import jakarta.persistence.Column; @@ -10,6 +14,7 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -39,6 +44,9 @@ public class Post extends BaseTimeEntity { @Column(nullable = false) private Boolean isSuggestion; + @OneToMany(mappedBy = "post", orphanRemoval = true) + private List heartList = new ArrayList<>(); + @Builder public Post(Member writer, String title, String content, Boolean isSuggestion) { this.writer = writer; From e8b921f638b8bebcfe2b40ec2939e6414f1fa93f Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 04:20:09 +0900 Subject: [PATCH 26/28] =?UTF-8?q?feat:=20=EA=B1=B4=EC=9D=98/=EA=B0=90?= =?UTF-8?q?=EC=82=AC=20=EA=B8=80=20=EC=82=AD=EC=A0=9C=EB=A5=BC=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A9=94=EC=84=9C?= =?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 --- .../EBus/EBusback/domain/post/service/PostService.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/EBus/EBusback/domain/post/service/PostService.java b/src/main/java/EBus/EBusback/domain/post/service/PostService.java index 1b2c136..76910d3 100644 --- a/src/main/java/EBus/EBusback/domain/post/service/PostService.java +++ b/src/main/java/EBus/EBusback/domain/post/service/PostService.java @@ -66,4 +66,13 @@ public List findPostList(Boolean isSuggestion) { .map(post -> new PostOutlineResponseDto(post, heartService.findHeartCount(post))) .collect(Collectors.toList()); } + + public void removePost(Long postId) { + Member member = SecurityUtil.getCurrentUser(); + Post post = postRepository.findById(postId) + .orElseThrow(() -> new IllegalArgumentException("글을 찾을 수 없습니다.")); + if (!post.getWriter().getMemberId().equals(member.getMemberId())) + throw new RuntimeException("작성자만 삭제할 수 있습니다."); + postRepository.delete(post); + } } From cbee9fc6b5bca6bc3d4f4e8eb43e29cef5a52256 Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 04:20:18 +0900 Subject: [PATCH 27/28] =?UTF-8?q?feat:=20=EA=B1=B4=EC=9D=98/=EA=B0=90?= =?UTF-8?q?=EC=82=AC=20=EA=B8=80=20=EC=82=AD=EC=A0=9C=EB=A5=BC=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=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 --- .../EBusback/domain/post/controller/PostController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/EBus/EBusback/domain/post/controller/PostController.java b/src/main/java/EBus/EBusback/domain/post/controller/PostController.java index 976f9a0..700b8c0 100644 --- a/src/main/java/EBus/EBusback/domain/post/controller/PostController.java +++ b/src/main/java/EBus/EBusback/domain/post/controller/PostController.java @@ -3,6 +3,7 @@ import java.util.List; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -54,4 +55,12 @@ public List findSuggestionList() { public List findAppreciationList() { return postService.findPostList(false); } + + @DeleteMapping("/{postId}") + @ResponseStatus(HttpStatus.OK) + public String removePost(@PathVariable Long postId) { + postService.removePost(postId); + return "글이 삭제되었습니다."; + } + } From fd83efc18a496a217a8a7fedfc45e8d10a31b9ec Mon Sep 17 00:00:00 2001 From: yeji Date: Sat, 16 Mar 2024 04:22:18 +0900 Subject: [PATCH 28/28] =?UTF-8?q?refactor:=20=EC=97=B0=EA=B4=80=EA=B4=80?= =?UTF-8?q?=EA=B3=84=20=EC=84=A4=EC=A0=95=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=88=98=20=EA=B3=84=EC=82=B0=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EBusback/domain/heart/repository/HeartRepository.java | 3 --- .../java/EBus/EBusback/domain/heart/service/HeartService.java | 4 ---- .../java/EBus/EBusback/domain/post/service/PostService.java | 4 ++-- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java b/src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java index 80fe23c..c50ea39 100644 --- a/src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java +++ b/src/main/java/EBus/EBusback/domain/heart/repository/HeartRepository.java @@ -1,6 +1,5 @@ package EBus.EBusback.domain.heart.repository; -import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -13,7 +12,5 @@ public interface HeartRepository extends JpaRepository { Optional findByMemberAndPost(Member member, Post post); - List findByPost(Post post); - Boolean existsByMemberAndPostAndIsValid(Member member, Post post, Boolean isValid); } diff --git a/src/main/java/EBus/EBusback/domain/heart/service/HeartService.java b/src/main/java/EBus/EBusback/domain/heart/service/HeartService.java index 68f7a9a..b138d90 100644 --- a/src/main/java/EBus/EBusback/domain/heart/service/HeartService.java +++ b/src/main/java/EBus/EBusback/domain/heart/service/HeartService.java @@ -38,10 +38,6 @@ public String createOrRemoveHeart(Long postId) { return "좋아요가 취소되었습니다."; } - public Integer findHeartCount(Post post) { - return heartRepository.findByPost(post).size(); - } - public Boolean existsHeart(Member member, Post post) { return heartRepository.existsByMemberAndPostAndIsValid(member, post, true); } diff --git a/src/main/java/EBus/EBusback/domain/post/service/PostService.java b/src/main/java/EBus/EBusback/domain/post/service/PostService.java index 76910d3..1b742ad 100644 --- a/src/main/java/EBus/EBusback/domain/post/service/PostService.java +++ b/src/main/java/EBus/EBusback/domain/post/service/PostService.java @@ -45,7 +45,7 @@ public PostDetailResponseDto findPost(Long postId) { Post post = postRepository.findById(postId) .orElseThrow(() -> new IllegalArgumentException("글을 찾을 수 없습니다.")); Member member = SecurityUtil.getCurrentUser(); - return new PostDetailResponseDto(new PostCreateResponseDto(post), heartService.findHeartCount(post), + return new PostDetailResponseDto(new PostCreateResponseDto(post), post.getHeartList().size(), findPostMemberInfo(post, member)); } @@ -63,7 +63,7 @@ public PostMemberDto findPostMemberInfo(Post post, Member member) { public List findPostList(Boolean isSuggestion) { List postList = postRepository.findAllByIsSuggestion(isSuggestion); return postList.stream() - .map(post -> new PostOutlineResponseDto(post, heartService.findHeartCount(post))) + .map(post -> new PostOutlineResponseDto(post, post.getHeartList().size())) .collect(Collectors.toList()); }