From c3acd0285e274f42fcea72e7296f5fea0e3087df Mon Sep 17 00:00:00 2001 From: yumzen Date: Tue, 30 Jan 2024 14:36:55 +0900 Subject: [PATCH 01/15] =?UTF-8?q?feat:=20PostController=20delete=20?= =?UTF-8?q?=EC=BD=94=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 --- .../server/domain/post/controller/PostController.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/gongjakso/server/domain/post/controller/PostController.java b/src/main/java/com/gongjakso/server/domain/post/controller/PostController.java index 8b475160..72e8b1af 100644 --- a/src/main/java/com/gongjakso/server/domain/post/controller/PostController.java +++ b/src/main/java/com/gongjakso/server/domain/post/controller/PostController.java @@ -1,5 +1,6 @@ package com.gongjakso.server.domain.post.controller; +import com.gongjakso.server.domain.post.dto.PostDeleteRes; import com.gongjakso.server.domain.post.dto.PostReq; import com.gongjakso.server.domain.post.dto.PostRes; import com.gongjakso.server.domain.post.service.PostService; @@ -44,4 +45,9 @@ public class PostController { public ResponseEntity modify(@PathVariable("id") Long id, @RequestBody PostReq req) { return ResponseEntity.ok(postService.modify(id, req)); } + + @PatchMapping("/?{id}") + public ResponseEntity modify(@PathVariable("id") Long id){ + return ResponseEntity.ok(postService.delete(id)); + } } \ No newline at end of file From 3ab4b5abfa5e6a44c433aca65d21e07d5110758b Mon Sep 17 00:00:00 2001 From: yumzen Date: Tue, 30 Jan 2024 14:37:24 +0900 Subject: [PATCH 02/15] =?UTF-8?q?feat:=20PostDeleteRes=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 --- .../server/domain/post/dto/PostDeleteRes.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/PostDeleteRes.java diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/PostDeleteRes.java b/src/main/java/com/gongjakso/server/domain/post/dto/PostDeleteRes.java new file mode 100644 index 00000000..7e283a14 --- /dev/null +++ b/src/main/java/com/gongjakso/server/domain/post/dto/PostDeleteRes.java @@ -0,0 +1,20 @@ +package com.gongjakso.server.domain.post.dto; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +public class PostDeleteRes { + private Long postId; + private Long memberId; + private LocalDateTime deletedAt; + + @Builder + public PostDeleteRes(Long postId, Long memberId, LocalDateTime deletedAt){ + this.postId = postId; + this.memberId = memberId; + this.deletedAt = deletedAt; + } +} From 752c4e8d9cdb0dd6cc1426595c672e9e41aad7f7 Mon Sep 17 00:00:00 2001 From: yumzen Date: Tue, 30 Jan 2024 14:38:11 +0900 Subject: [PATCH 03/15] =?UTF-8?q?feat:Post=20Entity=20delete=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 --- .../java/com/gongjakso/server/domain/post/entity/Post.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/gongjakso/server/domain/post/entity/Post.java b/src/main/java/com/gongjakso/server/domain/post/entity/Post.java index 1f8c9387..7168d979 100644 --- a/src/main/java/com/gongjakso/server/domain/post/entity/Post.java +++ b/src/main/java/com/gongjakso/server/domain/post/entity/Post.java @@ -92,4 +92,8 @@ public void modify(PostReq req) { this.questionMethod = req.isQuestionMethod(); this.questionLink = req.getQuestionLink(); } + + public void delete(){ + super.deletedAt = LocalDateTime.now(); + } } \ No newline at end of file From 793e9f17b54dd97b33b490095b912c967f14c0e6 Mon Sep 17 00:00:00 2001 From: yumzen Date: Tue, 30 Jan 2024 14:38:49 +0900 Subject: [PATCH 04/15] =?UTF-8?q?feat:=20Post=20Service=20delete=20?= =?UTF-8?q?=EC=BD=94=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 --- .../server/domain/post/service/PostService.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gongjakso/server/domain/post/service/PostService.java b/src/main/java/com/gongjakso/server/domain/post/service/PostService.java index 81cecc26..19778f25 100644 --- a/src/main/java/com/gongjakso/server/domain/post/service/PostService.java +++ b/src/main/java/com/gongjakso/server/domain/post/service/PostService.java @@ -1,5 +1,6 @@ package com.gongjakso.server.domain.post.service; +import com.gongjakso.server.domain.post.dto.PostDeleteRes; import com.gongjakso.server.domain.post.dto.PostReq; import com.gongjakso.server.domain.post.dto.PostRes; import com.gongjakso.server.domain.post.entity.Post; @@ -8,7 +9,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.time.LocalDateTime; @Service @Transactional(readOnly = true) @@ -42,4 +42,18 @@ public PostRes modify(Long id, PostReq req) { .build(); } + + + @Transactional + public PostDeleteRes delete(Long id) { + Post entity = postRepository.findById(id) + .orElseThrow(() -> new IllegalArgumentException()); + entity.delete(); + + return PostDeleteRes.builder() + .postId(entity.getPostId()) + .memberId(entity.getMember().getMemberId()) + .deletedAt(entity.getDeletedAt()) + .build(); + } } \ No newline at end of file From d783007c0423ff67e524f5fec0cc50f7fc4bcf66 Mon Sep 17 00:00:00 2001 From: yumzen Date: Tue, 30 Jan 2024 14:39:16 +0900 Subject: [PATCH 05/15] =?UTF-8?q?feat:=20BaseTimeEntity=20DeletedAt=20prot?= =?UTF-8?q?ected=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/gongjakso/server/global/common/BaseTimeEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gongjakso/server/global/common/BaseTimeEntity.java b/src/main/java/com/gongjakso/server/global/common/BaseTimeEntity.java index a22f9c5c..843654e1 100644 --- a/src/main/java/com/gongjakso/server/global/common/BaseTimeEntity.java +++ b/src/main/java/com/gongjakso/server/global/common/BaseTimeEntity.java @@ -25,5 +25,5 @@ public abstract class BaseTimeEntity { private LocalDateTime modifiedAt; @Column(name = "deleted_at", columnDefinition = "TIMESTAMP") - private LocalDateTime deletedAt; + protected LocalDateTime deletedAt; } \ No newline at end of file From 43d46eef12ac91284bdcf09c7f81387431491164 Mon Sep 17 00:00:00 2001 From: yumzen Date: Tue, 30 Jan 2024 14:59:36 +0900 Subject: [PATCH 06/15] =?UTF-8?q?feat:=20controller=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/domain/post/controller/PostController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gongjakso/server/domain/post/controller/PostController.java b/src/main/java/com/gongjakso/server/domain/post/controller/PostController.java index 72e8b1af..70a71c7b 100644 --- a/src/main/java/com/gongjakso/server/domain/post/controller/PostController.java +++ b/src/main/java/com/gongjakso/server/domain/post/controller/PostController.java @@ -47,7 +47,8 @@ public ResponseEntity modify(@PathVariable("id") Long id, @RequestBody } @PatchMapping("/?{id}") - public ResponseEntity modify(@PathVariable("id") Long id){ + public ResponseEntity delete(@PathVariable("id") Long id){ return ResponseEntity.ok(postService.delete(id)); } + } \ No newline at end of file From 112871d896b187bcd2d136b7beef3cd7e6fda441 Mon Sep 17 00:00:00 2001 From: yumzen Date: Tue, 30 Jan 2024 17:45:44 +0900 Subject: [PATCH 07/15] =?UTF-8?q?feat:=20isProject=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gongjakso/server/domain/post/dto/GetProjectRes.java | 2 ++ src/main/java/com/gongjakso/server/domain/post/entity/Post.java | 1 + 2 files changed, 3 insertions(+) create mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/GetProjectRes.java diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/GetProjectRes.java b/src/main/java/com/gongjakso/server/domain/post/dto/GetProjectRes.java new file mode 100644 index 00000000..65cb44e3 --- /dev/null +++ b/src/main/java/com/gongjakso/server/domain/post/dto/GetProjectRes.java @@ -0,0 +1,2 @@ +package com.gongjakso.server.domain.post.dto;public class GetProjectRes { +} diff --git a/src/main/java/com/gongjakso/server/domain/post/entity/Post.java b/src/main/java/com/gongjakso/server/domain/post/entity/Post.java index 7168d979..28e1e0ee 100644 --- a/src/main/java/com/gongjakso/server/domain/post/entity/Post.java +++ b/src/main/java/com/gongjakso/server/domain/post/entity/Post.java @@ -91,6 +91,7 @@ public void modify(PostReq req) { this.meetingArea = req.getMeetingArea(); this.questionMethod = req.isQuestionMethod(); this.questionLink = req.getQuestionLink(); + this.isProject = req.isProject(); } public void delete(){ From 6367629f8efea6c11dce01384cd6c2d760d18c15 Mon Sep 17 00:00:00 2001 From: yumzen Date: Wed, 31 Jan 2024 20:38:28 +0900 Subject: [PATCH 08/15] =?UTF-8?q?feat:=20BaseTimeEntity=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 --- .../java/com/gongjakso/server/global/common/BaseTimeEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gongjakso/server/global/common/BaseTimeEntity.java b/src/main/java/com/gongjakso/server/global/common/BaseTimeEntity.java index 843654e1..a22f9c5c 100644 --- a/src/main/java/com/gongjakso/server/global/common/BaseTimeEntity.java +++ b/src/main/java/com/gongjakso/server/global/common/BaseTimeEntity.java @@ -25,5 +25,5 @@ public abstract class BaseTimeEntity { private LocalDateTime modifiedAt; @Column(name = "deleted_at", columnDefinition = "TIMESTAMP") - protected LocalDateTime deletedAt; + private LocalDateTime deletedAt; } \ No newline at end of file From 618110b903a643c69a7f86768450c6b55fb73d5f Mon Sep 17 00:00:00 2001 From: yumzen Date: Wed, 31 Jan 2024 21:11:15 +0900 Subject: [PATCH 09/15] =?UTF-8?q?feat:=20post=20entity=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 --- .../server/domain/post/entity/Post.java | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/gongjakso/server/domain/post/entity/Post.java b/src/main/java/com/gongjakso/server/domain/post/entity/Post.java index 28e1e0ee..05e74c55 100644 --- a/src/main/java/com/gongjakso/server/domain/post/entity/Post.java +++ b/src/main/java/com/gongjakso/server/domain/post/entity/Post.java @@ -6,14 +6,18 @@ import com.gongjakso.server.domain.post.enumerate.PostStatus; import com.gongjakso.server.global.common.BaseTimeEntity; import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; import java.time.LocalDateTime; -import lombok.*; - @Getter @Entity @Table(name = "post") +@SQLDelete(sql="UPDATE post SET deleted_at = NOW() where post_id=?") @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Post extends BaseTimeEntity { @@ -42,6 +46,9 @@ public class Post extends BaseTimeEntity { @Column(name = "end_date", nullable = false, columnDefinition = "timestamp") private LocalDateTime endDate; + @Column(name = "finish_date", nullable = false, columnDefinition = "timestamp") + private LocalDateTime finishDate; + @Column(name = "max_person", nullable = false, columnDefinition = "bigint") private Long maxPerson; @@ -58,26 +65,28 @@ public class Post extends BaseTimeEntity { @Column(name = "question_link", nullable = false, columnDefinition = "text") private String questionLink; - @Column(name = "is_project", nullable = false, columnDefinition = "tinyint") - private boolean isProject; + @Column(name = "post_type", nullable = false, columnDefinition = "tinyint") + private boolean postType; + + @Builder - public Post(Long postId, Member member, String title, String contents, PostStatus status, LocalDateTime startDate, - LocalDateTime endDate, Long maxPerson, MeetingMethod meetingMethod, String meetingArea, boolean questionMethod, - String questionLink, boolean isProject) { - this.postId = postId; - this.member = member; + public Post(String title, Member member, String contents, PostStatus status, LocalDateTime startDate, + LocalDateTime endDate, LocalDateTime finishDate, Long maxPerson, MeetingMethod meetingMethod, + String meetingArea, boolean questionMethod, String questionLink, boolean postType) { this.title = title; + this.member = member; this.contents = contents; this.status = status; this.startDate = startDate; + this.finishDate = finishDate; this.endDate = endDate; this.maxPerson = maxPerson; this.meetingMethod = meetingMethod; this.meetingArea = meetingArea; this.questionMethod = questionMethod; this.questionLink = questionLink; - this.isProject = isProject; + this.postType = postType; } public void modify(PostReq req) { @@ -86,15 +95,13 @@ public void modify(PostReq req) { this.status = req.getStatus(); this.startDate = req.getStartDate(); this.endDate = req.getEndDate(); + this.finishDate = req.getFinishDate(); this.maxPerson = req.getMaxPerson(); this.meetingMethod = req.getMeetingMethod(); this.meetingArea = req.getMeetingArea(); this.questionMethod = req.isQuestionMethod(); this.questionLink = req.getQuestionLink(); - this.isProject = req.isProject(); + this.postType = req.isPostType(); } - public void delete(){ - super.deletedAt = LocalDateTime.now(); - } } \ No newline at end of file From 95a8144eb47400402e2b97610123fac730be174c Mon Sep 17 00:00:00 2001 From: yumzen Date: Wed, 31 Jan 2024 21:11:42 +0900 Subject: [PATCH 10/15] =?UTF-8?q?feat:=20post=20controller=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 --- .../post/controller/PostController.java | 47 +++++-------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/gongjakso/server/domain/post/controller/PostController.java b/src/main/java/com/gongjakso/server/domain/post/controller/PostController.java index 70a71c7b..47d52696 100644 --- a/src/main/java/com/gongjakso/server/domain/post/controller/PostController.java +++ b/src/main/java/com/gongjakso/server/domain/post/controller/PostController.java @@ -4,9 +4,11 @@ import com.gongjakso.server.domain.post.dto.PostReq; import com.gongjakso.server.domain.post.dto.PostRes; import com.gongjakso.server.domain.post.service.PostService; +import com.gongjakso.server.global.common.ApplicationResponse; +import com.gongjakso.server.global.security.PrincipalDetails; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; @RestController @@ -15,40 +17,17 @@ @Tag(name = "Post", description = "공고 관련 API") public class PostController { private final PostService postService; - - // @PostMapping - // public ResponseEntity<> createPost() { - // - // } - - /** - * 모집글 게시(CREATE) - */ - // @PostMapping("/posts") - // public ResponseEntity createPost( - // @RequestBody @Validated PostCreationRequest request, - // @AuthenticationPrincipal OAuth2User user) { - // - // String email = user.getName(); - // Post post = postService.createPost(request, email); - // keywordService.addKeywords(post, request); - // - // return ResponseEntity.ok( - // PostCreationResponse.builder() - // .id(post.getId()) - // .title(post.getThumbnail().getTitle()) - // .createdDate(post.getCreatedDate()) - // .build()); - // } - - @PutMapping("/?{id}") - public ResponseEntity modify(@PathVariable("id") Long id, @RequestBody PostReq req) { - return ResponseEntity.ok(postService.modify(id, req)); + @PostMapping("") + public ApplicationResponse create(@AuthenticationPrincipal PrincipalDetails principalDetails, @RequestBody PostReq req) { + return ApplicationResponse.ok(postService.create(principalDetails.getMember(), req)); + } + @PutMapping("/{id}") + public ApplicationResponse modify(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("id") Long id, @RequestBody PostReq req) { + return ApplicationResponse.ok(postService.modify(principalDetails.getMember(), id, req)); } - @PatchMapping("/?{id}") - public ResponseEntity delete(@PathVariable("id") Long id){ - return ResponseEntity.ok(postService.delete(id)); + @PatchMapping("/{id}") + public ApplicationResponse delete(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("id") Long id){ + return ApplicationResponse.ok(postService.delete(principalDetails.getMember(), id)); } - } \ No newline at end of file From dd0149b80151557d842c66052d8e3f83c6b70896 Mon Sep 17 00:00:00 2001 From: yumzen Date: Wed, 31 Jan 2024 21:12:28 +0900 Subject: [PATCH 11/15] =?UTF-8?q?feat:=20post=20delete=20response=20DTO=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gongjakso/server/domain/post/dto/PostDeleteRes.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/PostDeleteRes.java b/src/main/java/com/gongjakso/server/domain/post/dto/PostDeleteRes.java index 7e283a14..d9b2e6cb 100644 --- a/src/main/java/com/gongjakso/server/domain/post/dto/PostDeleteRes.java +++ b/src/main/java/com/gongjakso/server/domain/post/dto/PostDeleteRes.java @@ -3,18 +3,14 @@ import lombok.Builder; import lombok.Getter; -import java.time.LocalDateTime; - @Getter public class PostDeleteRes { private Long postId; private Long memberId; - private LocalDateTime deletedAt; @Builder - public PostDeleteRes(Long postId, Long memberId, LocalDateTime deletedAt){ + public PostDeleteRes(Long postId, Long memberId){ this.postId = postId; this.memberId = memberId; - this.deletedAt = deletedAt; } } From 80116e8a5dd1c7807bc313799d891a977f9fa86e Mon Sep 17 00:00:00 2001 From: yumzen Date: Wed, 31 Jan 2024 21:12:49 +0900 Subject: [PATCH 12/15] =?UTF-8?q?feat:=20post=20repository=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 --- .../server/domain/post/repository/PostRepository.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gongjakso/server/domain/post/repository/PostRepository.java b/src/main/java/com/gongjakso/server/domain/post/repository/PostRepository.java index d7a6506e..2d6f0901 100644 --- a/src/main/java/com/gongjakso/server/domain/post/repository/PostRepository.java +++ b/src/main/java/com/gongjakso/server/domain/post/repository/PostRepository.java @@ -3,6 +3,12 @@ import com.gongjakso.server.domain.post.entity.Post; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface PostRepository extends JpaRepository { + //Page findAll(Pageable pageable); //전체 조회(페이징) + + //Page findByCategory(StackName stackname, Pageable pageable); -} + Optional findByPostIdAndDeletedAtIsNull(Long postId); +} \ No newline at end of file From 83753b67dd3b0892c67936f13ee34514813c14ad Mon Sep 17 00:00:00 2001 From: yumzen Date: Wed, 31 Jan 2024 21:13:10 +0900 Subject: [PATCH 13/15] =?UTF-8?q?feat:=20post=20request=20DTO=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 --- .../java/com/gongjakso/server/domain/post/dto/PostReq.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/PostReq.java b/src/main/java/com/gongjakso/server/domain/post/dto/PostReq.java index e3666dbb..38dd6ff6 100644 --- a/src/main/java/com/gongjakso/server/domain/post/dto/PostReq.java +++ b/src/main/java/com/gongjakso/server/domain/post/dto/PostReq.java @@ -17,12 +17,13 @@ public class PostReq { private PostStatus status; private LocalDateTime startDate; private LocalDateTime endDate; + private LocalDateTime finishDate; private Long maxPerson; private MeetingMethod meetingMethod; private String meetingArea; private boolean questionMethod; private String questionLink; - private boolean isProject; + private boolean postType; /* * @Builder From c777914cbdda98eaeb1e50579cdae5c24a78f1be Mon Sep 17 00:00:00 2001 From: yumzen Date: Wed, 31 Jan 2024 21:13:34 +0900 Subject: [PATCH 14/15] =?UTF-8?q?feat:=20post=20response=20DTO=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/gongjakso/server/domain/post/dto/PostRes.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/PostRes.java b/src/main/java/com/gongjakso/server/domain/post/dto/PostRes.java index d02bd06d..ea9dc39e 100644 --- a/src/main/java/com/gongjakso/server/domain/post/dto/PostRes.java +++ b/src/main/java/com/gongjakso/server/domain/post/dto/PostRes.java @@ -1,6 +1,5 @@ package com.gongjakso.server.domain.post.dto; -import com.gongjakso.server.domain.member.entity.Member; import com.gongjakso.server.domain.post.enumerate.MeetingMethod; import com.gongjakso.server.domain.post.enumerate.PostStatus; import lombok.Builder; @@ -17,12 +16,13 @@ public class PostRes { private PostStatus status; private LocalDateTime startDate; private LocalDateTime endDate; + private LocalDateTime finishDate; private Long maxPerson; private MeetingMethod meetingMethod; private String meetingArea; private boolean questionMethod; private String questionLink; - private boolean isProject; + private boolean postType; private LocalDateTime createdAt; private LocalDateTime modifiedAt; @@ -30,8 +30,8 @@ public class PostRes { @Builder public PostRes(Long postId, Long memberId, String title, String contents, PostStatus status, LocalDateTime startDate, LocalDateTime endDate, - Long maxPerson, MeetingMethod meetingMethod, String meetingArea, boolean questionMethod, String questionLink, - boolean isProject, LocalDateTime createdAt, LocalDateTime modifiedAt, LocalDateTime deletedAt) { + LocalDateTime finishDate, Long maxPerson, MeetingMethod meetingMethod, String meetingArea, boolean questionMethod, String questionLink, + boolean postType, LocalDateTime createdAt, LocalDateTime modifiedAt, LocalDateTime deletedAt) { this.postId = postId; this.memberId = memberId; this.title = title; @@ -39,12 +39,13 @@ public PostRes(Long postId, Long memberId, String title, String contents, PostSt this.status = status; this.startDate = startDate; this.endDate = endDate; + this.finishDate = finishDate; this.maxPerson = maxPerson; this.meetingArea = meetingArea; this.meetingMethod = meetingMethod; this.questionMethod = questionMethod; this.questionLink = questionLink; - this.isProject = isProject; + this.postType = postType; this.createdAt = createdAt; this.modifiedAt = modifiedAt; this.deletedAt = deletedAt; From 442e3959226a382a80feae6813d030251f59fe1c Mon Sep 17 00:00:00 2001 From: yumzen Date: Wed, 31 Jan 2024 21:14:21 +0900 Subject: [PATCH 15/15] =?UTF-8?q?feat:=20post=20service=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 --- .../domain/post/service/PostService.java | 71 ++++++++++++++++--- 1 file changed, 62 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/gongjakso/server/domain/post/service/PostService.java b/src/main/java/com/gongjakso/server/domain/post/service/PostService.java index 19778f25..9f06753f 100644 --- a/src/main/java/com/gongjakso/server/domain/post/service/PostService.java +++ b/src/main/java/com/gongjakso/server/domain/post/service/PostService.java @@ -1,14 +1,19 @@ package com.gongjakso.server.domain.post.service; +import com.gongjakso.server.domain.member.entity.Member; import com.gongjakso.server.domain.post.dto.PostDeleteRes; import com.gongjakso.server.domain.post.dto.PostReq; import com.gongjakso.server.domain.post.dto.PostRes; import com.gongjakso.server.domain.post.entity.Post; import com.gongjakso.server.domain.post.repository.PostRepository; +import com.gongjakso.server.global.exception.ApplicationException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import static com.gongjakso.server.global.exception.ErrorCode.NOT_FOUND_EXCEPTION; +import static com.gongjakso.server.global.exception.ErrorCode.UNAUTHORIZED_EXCEPTION; + @Service @Transactional(readOnly = true) @@ -16,10 +21,44 @@ public class PostService { private final PostRepository postRepository; + @Transactional - public PostRes modify(Long id, PostReq req) { - Post entity = postRepository.findById(id) - .orElseThrow(() -> new IllegalArgumentException()); + public PostRes create(Member member, PostReq req) { + Post entity = new Post(req.getTitle(), member, req.getContents(), req.getStatus(), req.getStartDate(), req.getEndDate(), + req.getFinishDate(), req.getMaxPerson(), req.getMeetingMethod(), req.getMeetingArea(), req.isQuestionMethod(), + req.getQuestionLink(), req.isPostType()); + + postRepository.save(entity); + + return PostRes.builder() + .postId(entity.getPostId()) + .memberId(entity.getMember().getMemberId()) + .title(entity.getTitle()) + .contents(entity.getContents()) + .status(entity.getStatus()) + .startDate(entity.getStartDate()) + .endDate(entity.getEndDate()) + .finishDate(entity.getFinishDate()) + .maxPerson(entity.getMaxPerson()) + .meetingMethod(entity.getMeetingMethod()) + .meetingArea(entity.getMeetingArea()) + .questionMethod(entity.isQuestionMethod()) + .questionLink(entity.getQuestionLink()) + .postType(entity.isPostType()) + .createdAt(entity.getCreatedAt()) + .modifiedAt(entity.getModifiedAt()) + .deletedAt(entity.getDeletedAt()) + .build(); + + } + @Transactional + public PostRes modify(Member member, Long id, PostReq req) { + Post entity = postRepository.findByPostIdAndDeletedAtIsNull(id) + .orElseThrow(() -> new ApplicationException(NOT_FOUND_EXCEPTION)); + if(!member.getMemberId().equals(entity.getMember().getMemberId())){ + throw new ApplicationException(UNAUTHORIZED_EXCEPTION); + } + entity.modify(req); return PostRes.builder() @@ -30,12 +69,13 @@ public PostRes modify(Long id, PostReq req) { .status(entity.getStatus()) .startDate(entity.getStartDate()) .endDate(entity.getEndDate()) + .finishDate(entity.getFinishDate()) .maxPerson(entity.getMaxPerson()) .meetingMethod(entity.getMeetingMethod()) .meetingArea(entity.getMeetingArea()) .questionMethod(entity.isQuestionMethod()) .questionLink(entity.getQuestionLink()) - .isProject(entity.isProject()) + .postType(entity.isPostType()) .createdAt(entity.getCreatedAt()) .modifiedAt(entity.getModifiedAt()) .deletedAt(entity.getDeletedAt()) @@ -45,15 +85,28 @@ public PostRes modify(Long id, PostReq req) { @Transactional - public PostDeleteRes delete(Long id) { - Post entity = postRepository.findById(id) - .orElseThrow(() -> new IllegalArgumentException()); - entity.delete(); + public PostDeleteRes delete(Member member, Long id) { + Post entity = postRepository.findByPostIdAndDeletedAtIsNull(id) + .orElseThrow(() -> new ApplicationException(NOT_FOUND_EXCEPTION)); + postRepository.delete(entity); return PostDeleteRes.builder() .postId(entity.getPostId()) .memberId(entity.getMember().getMemberId()) - .deletedAt(entity.getDeletedAt()) .build(); } + + /* + public Page getProjects(Pageable page) throws ApplicationException { + try { + return postRepository.findAll(page).map(projects -> new GetProjectRes( + projects.getPostId(), + projects.getTitle(), + projects.getMeetingArea()); + } catch (Exception e) { + throw new ApplicationException(INVALID_VALUE_EXCEPTION); + } + } + +*/ } \ No newline at end of file