From 0d082109b875196bea678a453fc179fc9e2204aa Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 15:48:14 +0900 Subject: [PATCH 01/18] =?UTF-8?q?[feat]=20#5=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seminar/domain/post/domain/Category.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/org/sopt/seminar/domain/post/domain/Category.java diff --git a/src/main/java/org/sopt/seminar/domain/post/domain/Category.java b/src/main/java/org/sopt/seminar/domain/post/domain/Category.java new file mode 100644 index 0000000..87eaca5 --- /dev/null +++ b/src/main/java/org/sopt/seminar/domain/post/domain/Category.java @@ -0,0 +1,42 @@ +package org.sopt.seminar.domain.post.domain; + +import jakarta.persistence.*; +import lombok.*; +import org.sopt.seminar.global.common.BaseTimeEntity; + +import java.util.ArrayList; +import java.util.List; + +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +@Getter +@Entity +public class Category extends BaseTimeEntity { + @Id + @GeneratedValue + @Column(name = "category_id") + private Short id; + private String content; + @OneToMany + @Builder.Default + private List posts = new ArrayList<>(); + + public static Category createCategory(final String content) { + return Category.builder() + .content(content) + .build(); + } + + public void addPost(Post post) { + posts.add(post); + } + + public void removePost(Post post) { + posts.remove(post); + } + + public void updateContent(String content) { + this.content = content; + } +} From c9236da9db23d33ccdda32b16b0b5c9595d3958d Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 15:48:29 +0900 Subject: [PATCH 02/18] =?UTF-8?q?[feat]=20#5=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20repository=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seminar/domain/post/repository/CategoryRepository.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/org/sopt/seminar/domain/post/repository/CategoryRepository.java diff --git a/src/main/java/org/sopt/seminar/domain/post/repository/CategoryRepository.java b/src/main/java/org/sopt/seminar/domain/post/repository/CategoryRepository.java new file mode 100644 index 0000000..e65eaa8 --- /dev/null +++ b/src/main/java/org/sopt/seminar/domain/post/repository/CategoryRepository.java @@ -0,0 +1,7 @@ +package org.sopt.seminar.domain.post.repository; + +import org.sopt.seminar.domain.post.domain.Category; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CategoryRepository extends JpaRepository { +} From b616725f5fc905dfa76764eb6efdcbf5a6feef76 Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 15:49:12 +0900 Subject: [PATCH 03/18] =?UTF-8?q?[feat]=20#5=20=EA=B2=8C=EC=8B=9C=EB=AC=BC?= =?UTF-8?q?=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/seminar/domain/post/domain/Post.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/main/java/org/sopt/seminar/domain/post/domain/Post.java diff --git a/src/main/java/org/sopt/seminar/domain/post/domain/Post.java b/src/main/java/org/sopt/seminar/domain/post/domain/Post.java new file mode 100644 index 0000000..1b5be99 --- /dev/null +++ b/src/main/java/org/sopt/seminar/domain/post/domain/Post.java @@ -0,0 +1,65 @@ +package org.sopt.seminar.domain.post.domain; + +import jakarta.persistence.*; +import lombok.*; +import org.sopt.seminar.domain.member.domain.Member; +import org.sopt.seminar.global.common.BaseTimeEntity; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +@Getter +@Entity +public class Post extends BaseTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "post_id") + private Long id; + private String title; + private String content; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "category_id") + private Category category; + + public static Post createPost(final String title, final String content, final Category category, final Member member) { + Post post = Post.builder() + .title(title) + .content(content) + .build(); + post.changeMember(member); + post.changeCategory(category); + return post; + } + + public void changeMember(Member member) { + if (this.member != null) { + this.member.removePost(this); + } + this.member = member; + member.addPost(this); + } + + public void changeCategory(Category category) { + if (this.category != null) { + this.category.removePost(this); + } + this.category = category; + category.addPost(this); + } + + public void updateTitleAndContent(String title, String content) { + updateTitle(title); + updateContent(content); + } + + public void updateTitle(String title) { + this.title = title; + } + + public void updateContent(String content) { + this.content = content; + } +} \ No newline at end of file From 6718b84cfae4898e31523bcf5f9c5fe795242aa9 Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 15:49:37 +0900 Subject: [PATCH 04/18] =?UTF-8?q?[feat]=20#5=20=EA=B2=8C=EC=8B=9C=EB=AC=BC?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=20&=20=EC=88=98=EC=A0=95=20record=20dto?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/dto/request/PostSaveOrUpdateRequest.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/org/sopt/seminar/domain/post/dto/request/PostSaveOrUpdateRequest.java diff --git a/src/main/java/org/sopt/seminar/domain/post/dto/request/PostSaveOrUpdateRequest.java b/src/main/java/org/sopt/seminar/domain/post/dto/request/PostSaveOrUpdateRequest.java new file mode 100644 index 0000000..c88fcd2 --- /dev/null +++ b/src/main/java/org/sopt/seminar/domain/post/dto/request/PostSaveOrUpdateRequest.java @@ -0,0 +1,8 @@ +package org.sopt.seminar.domain.post.dto.request; + +public record PostSaveOrUpdateRequest( + String title, + String postContent, + String categoryContent +) { +} From 51aa4ee100fc8be7a8abadeab9419bf5dfba2484 Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 15:50:24 +0900 Subject: [PATCH 05/18] =?UTF-8?q?[feat]=20#5=20=EA=B2=8C=EC=8B=9C=EB=AC=BC?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=20=EC=9D=91=EB=8B=B5=20record=20dto=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/dto/response/PostSaveResponse.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/java/org/sopt/seminar/domain/post/dto/response/PostSaveResponse.java diff --git a/src/main/java/org/sopt/seminar/domain/post/dto/response/PostSaveResponse.java b/src/main/java/org/sopt/seminar/domain/post/dto/response/PostSaveResponse.java new file mode 100644 index 0000000..14b1771 --- /dev/null +++ b/src/main/java/org/sopt/seminar/domain/post/dto/response/PostSaveResponse.java @@ -0,0 +1,11 @@ +package org.sopt.seminar.domain.post.dto.response; + +import org.sopt.seminar.domain.post.domain.Post; + +public record PostSaveResponse( + Long postId +) { + public static PostSaveResponse of(Post post) { + return new PostSaveResponse(post.getId()); + } +} From b2b466ea74516881602f2beb15eeb1946bc5549d Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 15:50:33 +0900 Subject: [PATCH 06/18] =?UTF-8?q?[feat]=20#5=20=EA=B2=8C=EC=8B=9C=EB=AC=BC?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EC=9D=91=EB=8B=B5=20record=20dto=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/dto/response/PostGetResponse.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/org/sopt/seminar/domain/post/dto/response/PostGetResponse.java diff --git a/src/main/java/org/sopt/seminar/domain/post/dto/response/PostGetResponse.java b/src/main/java/org/sopt/seminar/domain/post/dto/response/PostGetResponse.java new file mode 100644 index 0000000..bd9a7c4 --- /dev/null +++ b/src/main/java/org/sopt/seminar/domain/post/dto/response/PostGetResponse.java @@ -0,0 +1,22 @@ +package org.sopt.seminar.domain.post.dto.response; + +import lombok.AccessLevel; +import lombok.Builder; +import org.sopt.seminar.domain.post.domain.Category; +import org.sopt.seminar.domain.post.domain.Post; + +@Builder(access = AccessLevel.PRIVATE) +public record PostGetResponse( + String title, + String postContent, + String categoryContent +) { + public static PostGetResponse of(Post post) { + Category category = post.getCategory(); + return PostGetResponse.builder() + .title(post.getTitle()) + .postContent(post.getContent()) + .categoryContent(category.getContent()) + .build(); + } +} From 2f8a23d2658e2d80880eb696c735327769a7fd5e Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 15:50:46 +0900 Subject: [PATCH 07/18] =?UTF-8?q?[feat]=20#5=20=EA=B2=8C=EC=8B=9C=EB=AC=BC?= =?UTF-8?q?=20repository=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/repository/PostRepository.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/org/sopt/seminar/domain/post/repository/PostRepository.java diff --git a/src/main/java/org/sopt/seminar/domain/post/repository/PostRepository.java b/src/main/java/org/sopt/seminar/domain/post/repository/PostRepository.java new file mode 100644 index 0000000..a17b1b1 --- /dev/null +++ b/src/main/java/org/sopt/seminar/domain/post/repository/PostRepository.java @@ -0,0 +1,17 @@ +package org.sopt.seminar.domain.post.repository; + +import org.sopt.seminar.domain.post.domain.Post; +import org.sopt.seminar.global.error.EntityNotFoundException; +import org.sopt.seminar.global.error.ErrorStatus; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PostRepository extends JpaRepository { + Page findAllByMemberId(Long memberId, Pageable pageable); + + default Post findByIdOrThrow(Long postId) { + return findById(postId) + .orElseThrow(() -> new EntityNotFoundException(ErrorStatus.POST_NOT_FOUND)); + } +} From b4cf21b3cfff2ff99dd0beea88a25c4a9837f51c Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 15:51:00 +0900 Subject: [PATCH 08/18] =?UTF-8?q?[feat]=20#5=20=EA=B2=8C=EC=8B=9C=EB=AC=BC?= =?UTF-8?q?=20not=20found=20=EC=97=90=EB=9F=AC=20=EC=BD=94=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 --- src/main/java/org/sopt/seminar/global/error/ErrorStatus.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/sopt/seminar/global/error/ErrorStatus.java b/src/main/java/org/sopt/seminar/global/error/ErrorStatus.java index 77083ab..0b47ba1 100644 --- a/src/main/java/org/sopt/seminar/global/error/ErrorStatus.java +++ b/src/main/java/org/sopt/seminar/global/error/ErrorStatus.java @@ -18,6 +18,7 @@ public enum ErrorStatus { */ ENTITY_NOT_FOUND(HttpStatus.NOT_FOUND, "대상을 찾을 수 없습니다."), MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "회원을 찾을 수 없습니다."), + POST_NOT_FOUND(HttpStatus.NOT_FOUND, "게시물을 찾을 수 없습니다."), /** * 405 Method Not Allowed From 9f37e90c6e3bfc678df8867371d72c0ce90e26e4 Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 15:51:28 +0900 Subject: [PATCH 09/18] =?UTF-8?q?[feat]=20#5=20=ED=9A=8C=EC=9B=90,=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EB=AC=BC=20=EC=97=B0=EA=B4=80=EA=B4=80?= =?UTF-8?q?=EA=B3=84=20=EB=A7=A4=ED=95=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/seminar/domain/member/domain/Member.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/org/sopt/seminar/domain/member/domain/Member.java b/src/main/java/org/sopt/seminar/domain/member/domain/Member.java index 3cbd05f..9bcbfd6 100644 --- a/src/main/java/org/sopt/seminar/domain/member/domain/Member.java +++ b/src/main/java/org/sopt/seminar/domain/member/domain/Member.java @@ -3,8 +3,12 @@ import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.DynamicUpdate; +import org.sopt.seminar.domain.post.domain.Post; import org.sopt.seminar.global.common.BaseTimeEntity; +import java.util.ArrayList; +import java.util.List; + @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @Builder(access = AccessLevel.PRIVATE) @@ -21,6 +25,9 @@ public class Member extends BaseTimeEntity { private Integer age; @Embedded private Sopt sopt; + @OneToMany(mappedBy = "member", cascade = CascadeType.REMOVE) + @Builder.Default + private List posts = new ArrayList<>(); public static Member createMember(final String name, final String nickname, final Integer age, final Sopt sopt) { return Member.builder() @@ -31,6 +38,14 @@ public static Member createMember(final String name, final String nickname, fina .build(); } + public void addPost(Post post) { + posts.add(post); + } + + public void removePost(Post post) { + posts.remove(post); + } + public void updateSopt(Sopt sopt) { this.sopt = sopt; } From 3203e61b6ade988da6e3224d9c4651a00017b1b9 Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 15:51:42 +0900 Subject: [PATCH 10/18] =?UTF-8?q?[feat]=20#5=20=EA=B2=8C=EC=8B=9C=EB=AC=BC?= =?UTF-8?q?=20=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=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 | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/main/java/org/sopt/seminar/domain/post/service/PostService.java diff --git a/src/main/java/org/sopt/seminar/domain/post/service/PostService.java b/src/main/java/org/sopt/seminar/domain/post/service/PostService.java new file mode 100644 index 0000000..6178aac --- /dev/null +++ b/src/main/java/org/sopt/seminar/domain/post/service/PostService.java @@ -0,0 +1,84 @@ +package org.sopt.seminar.domain.post.service; + +import lombok.RequiredArgsConstructor; +import org.sopt.seminar.domain.member.domain.Member; +import org.sopt.seminar.domain.member.repository.MemberRepository; +import org.sopt.seminar.domain.post.domain.Category; +import org.sopt.seminar.domain.post.domain.Post; +import org.sopt.seminar.domain.post.dto.request.PostSaveOrUpdateRequest; +import org.sopt.seminar.domain.post.dto.response.PostGetResponse; +import org.sopt.seminar.domain.post.dto.response.PostSaveResponse; +import org.sopt.seminar.domain.post.repository.CategoryRepository; +import org.sopt.seminar.domain.post.repository.PostRepository; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +import static org.sopt.seminar.domain.post.domain.Category.createCategory; +import static org.sopt.seminar.domain.post.domain.Post.createPost; + +@RequiredArgsConstructor +@Transactional(readOnly = true) +@Service +public class PostService { + private final MemberRepository memberRepository; + private final PostRepository postRepository; + private final CategoryRepository categoryRepository; + + @Transactional + public PostSaveResponse savePost(Long memberId, PostSaveOrUpdateRequest postSaveOrUpdateRequest) { + Member findMember = findMember(memberId); + Category savedCategory = createCategoryAndGetSavedCategory(postSaveOrUpdateRequest); + Post savedPost = createPostAndGetSavedPost(postSaveOrUpdateRequest, findMember, savedCategory); + return PostSaveResponse.of(savedPost); + } + + public PostGetResponse getPost(Long postId) { + Post findPost = findPost(postId); + return PostGetResponse.of(findPost); + } + + public List getPosts(Long memberId, Pageable pageable) { + return postRepository.findAllByMemberId(memberId, pageable) + .stream() + .map(PostGetResponse::of) + .toList(); + } + + @Transactional + public void updatePost(Long postId, PostSaveOrUpdateRequest postSaveOrUpdateRequest) { + Post findPost = findPost(postId); + Category category = findPost.getCategory(); + updatePostAndCategory(postSaveOrUpdateRequest, findPost, category); + } + + @Transactional + public void deletePost(Long postId) { + postRepository.deleteById(postId); + } + + private Member findMember(Long memberId) { + return memberRepository.findByIdOrThrow(memberId); + } + + private Category createCategoryAndGetSavedCategory(PostSaveOrUpdateRequest postSaveOrUpdateRequest) { + Category category = createCategory(postSaveOrUpdateRequest.categoryContent()); + return categoryRepository.save(category); + } + + private Post createPostAndGetSavedPost(PostSaveOrUpdateRequest postSaveOrUpdateRequest, Member member, Category category) { + Post post = createPost(postSaveOrUpdateRequest.title(), postSaveOrUpdateRequest.postContent(), category, member); + return postRepository.save(post); + } + + private Post findPost(Long postId) { + return postRepository.findByIdOrThrow(postId); + } + + private void updatePostAndCategory(PostSaveOrUpdateRequest postSaveOrUpdateRequest, Post post, Category category) { + post.updateTitleAndContent(postSaveOrUpdateRequest.title(), postSaveOrUpdateRequest.postContent()); + category.updateContent(postSaveOrUpdateRequest.categoryContent()); + } +} From 9e01f5f298a933803e45236084b343458b8008e5 Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 15:51:56 +0900 Subject: [PATCH 11/18] =?UTF-8?q?[feat]=20#5=20=EA=B2=8C=EC=8B=9C=EB=AC=BC?= =?UTF-8?q?=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/api/PostApiController.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/main/java/org/sopt/seminar/domain/post/api/PostApiController.java diff --git a/src/main/java/org/sopt/seminar/domain/post/api/PostApiController.java b/src/main/java/org/sopt/seminar/domain/post/api/PostApiController.java new file mode 100644 index 0000000..77b5906 --- /dev/null +++ b/src/main/java/org/sopt/seminar/domain/post/api/PostApiController.java @@ -0,0 +1,56 @@ +package org.sopt.seminar.domain.post.api; + +import lombok.RequiredArgsConstructor; +import org.sopt.seminar.domain.post.dto.request.PostSaveOrUpdateRequest; +import org.sopt.seminar.domain.post.dto.response.PostGetResponse; +import org.sopt.seminar.domain.post.dto.response.PostSaveResponse; +import org.sopt.seminar.domain.post.service.PostService; +import org.sopt.seminar.global.common.ApiResponse; +import org.sopt.seminar.global.common.SuccessStatus; +import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RequiredArgsConstructor +@RequestMapping("/api/post") +@Controller +public class PostApiController { + private static final String CUSTOM_AUTHENTICATION = "X-Auth-Id"; + private final PostService postService; + + @PostMapping + public ResponseEntity> savePost(@RequestHeader(CUSTOM_AUTHENTICATION) final Long memberId, + @RequestBody final PostSaveOrUpdateRequest postSaveOrUpdateRequest) { + final PostSaveResponse postSaveResponse = postService.savePost(memberId, postSaveOrUpdateRequest); + return ApiResponse.success(SuccessStatus.CREATED, postSaveResponse); + } + + @GetMapping("/{postId}") + public ResponseEntity> getPost(@PathVariable final Long postId) { + final PostGetResponse post = postService.getPost(postId); + return ApiResponse.success(SuccessStatus.OK, post); + } + + @GetMapping + public ResponseEntity> getPosts(@RequestHeader(CUSTOM_AUTHENTICATION) final Long memberId, + final Pageable pageable) { + final List posts = postService.getPosts(memberId, pageable); + return ApiResponse.success(SuccessStatus.OK, posts); + } + + @PatchMapping("/{postId}") + public ResponseEntity> updatePost(@PathVariable final Long postId, + @RequestBody final PostSaveOrUpdateRequest postSaveOrUpdateRequest) { + postService.updatePost(postId, postSaveOrUpdateRequest); + return ApiResponse.success(SuccessStatus.OK); + } + + @DeleteMapping("/{postId}") + public ResponseEntity> deletePost(@PathVariable final Long postId) { + postService.deletePost(postId); + return ApiResponse.success(SuccessStatus.OK); + } +} From e9eb76d9ef53958ad021ab9297b04c36d6b6fbac Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 17:42:16 +0900 Subject: [PATCH 12/18] =?UTF-8?q?[chore]=20#5=20.gitignore=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e5cbe63..0debf03 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,4 @@ out/ .DS_Store ### Yml ### -src/main/resources/application.yml \ No newline at end of file +api/src/main/resources/application.yml \ No newline at end of file From 7b4d57eab408c2b6c116858ece8bb7e7cb25ef37 Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 17:45:42 +0900 Subject: [PATCH 13/18] =?UTF-8?q?[refactor]=20#5=20=EB=8B=A8=EC=9D=BC=20?= =?UTF-8?q?=EB=AA=A8=EB=93=88=20->=20=EB=A9=80=ED=8B=B0=20=EB=AA=A8?= =?UTF-8?q?=EB=93=88=20=EB=A6=AC=ED=8C=A9=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/build.gradle | 12 +++++ .../java/org/sopt}/SeminarApplication.java | 2 +- .../java/org/sopt}/common/ApiResponse.java | 10 ++-- .../java/org/sopt}/common/SuccessStatus.java | 2 +- .../sopt}/error/GlobalExceptionHandler.java | 8 +-- .../sopt}/member/api/MemberApiController.java | 16 +++--- .../member/dto/request/MemberSaveRequest.java | 4 +- .../dto/request/MemberUpdateRequest.java | 8 +++ .../dto/response/MemberGetResponse.java | 8 +-- .../dto/response/MemberSaveResponse.java | 4 +- .../sopt}/member/service/MemberService.java | 25 +++++----- .../org/sopt}/post/api/PostApiController.java | 14 +++--- .../dto/request/PostSaveOrUpdateRequest.java | 2 +- .../post/dto/response/PostGetResponse.java | 8 +-- .../post/dto/response/PostSaveResponse.java | 4 +- .../org/sopt}/post/service/PostService.java | 27 +++++----- build.gradle | 50 +++++++++---------- common/build.gradle | 4 ++ .../org/sopt}/error/BusinessException.java | 2 +- .../org/sopt}/error/ConflictException.java | 2 +- .../sopt}/error/EntityNotFoundException.java | 2 +- .../java/org/sopt}/error/ErrorStatus.java | 2 +- .../sopt}/error/InvalidValueException.java | 2 +- domain/build.gradle | 8 +++ .../java/org/sopt}/common/BaseTimeEntity.java | 2 +- .../main/java/org/sopt}/config/JpaConfig.java | 2 +- .../java/org/sopt}/member/domain/Member.java | 6 +-- .../java/org/sopt}/member/domain/Part.java | 2 +- .../java/org/sopt}/member/domain/Sopt.java | 2 +- .../member/repository/MemberRepository.java | 9 ++-- .../java/org/sopt}/post/domain/Category.java | 4 +- .../main/java/org/sopt}/post/domain/Post.java | 6 +-- .../post/repository/CategoryRepository.java | 4 +- .../sopt}/post/repository/PostRepository.java | 8 +-- settings.gradle | 3 ++ .../dto/request/MemberUpdateRequest.java | 8 --- .../sopt/seminar/SeminarApplicationTests.java | 11 ---- 37 files changed, 151 insertions(+), 142 deletions(-) create mode 100644 api/build.gradle rename {src/main/java/org/sopt/seminar => api/src/main/java/org/sopt}/SeminarApplication.java (91%) rename {src/main/java/org/sopt/seminar/global => api/src/main/java/org/sopt}/common/ApiResponse.java (90%) rename {src/main/java/org/sopt/seminar/global => api/src/main/java/org/sopt}/common/SuccessStatus.java (91%) rename {src/main/java/org/sopt/seminar/global => api/src/main/java/org/sopt}/error/GlobalExceptionHandler.java (82%) rename {src/main/java/org/sopt/seminar/domain => api/src/main/java/org/sopt}/member/api/MemberApiController.java (79%) rename {src/main/java/org/sopt/seminar/domain => api/src/main/java/org/sopt}/member/dto/request/MemberSaveRequest.java (54%) create mode 100644 api/src/main/java/org/sopt/member/dto/request/MemberUpdateRequest.java rename {src/main/java/org/sopt/seminar/domain => api/src/main/java/org/sopt}/member/dto/response/MemberGetResponse.java (69%) rename {src/main/java/org/sopt/seminar/domain => api/src/main/java/org/sopt}/member/dto/response/MemberSaveResponse.java (63%) rename {src/main/java/org/sopt/seminar/domain => api/src/main/java/org/sopt}/member/service/MemberService.java (67%) rename {src/main/java/org/sopt/seminar/domain => api/src/main/java/org/sopt}/post/api/PostApiController.java (83%) rename {src/main/java/org/sopt/seminar/domain => api/src/main/java/org/sopt}/post/dto/request/PostSaveOrUpdateRequest.java (71%) rename {src/main/java/org/sopt/seminar/domain => api/src/main/java/org/sopt}/post/dto/response/PostGetResponse.java (71%) rename {src/main/java/org/sopt/seminar/domain => api/src/main/java/org/sopt}/post/dto/response/PostSaveResponse.java (62%) rename {src/main/java/org/sopt/seminar/domain => api/src/main/java/org/sopt}/post/service/PostService.java (72%) create mode 100644 common/build.gradle rename {src/main/java/org/sopt/seminar/global => common/src/main/java/org/sopt}/error/BusinessException.java (87%) rename {src/main/java/org/sopt/seminar/global => common/src/main/java/org/sopt}/error/ConflictException.java (85%) rename {src/main/java/org/sopt/seminar/global => common/src/main/java/org/sopt}/error/EntityNotFoundException.java (86%) rename {src/main/java/org/sopt/seminar/global => common/src/main/java/org/sopt}/error/ErrorStatus.java (96%) rename {src/main/java/org/sopt/seminar/global => common/src/main/java/org/sopt}/error/InvalidValueException.java (86%) create mode 100644 domain/build.gradle rename {src/main/java/org/sopt/seminar/global => domain/src/main/java/org/sopt}/common/BaseTimeEntity.java (94%) rename {src/main/java/org/sopt/seminar/global => domain/src/main/java/org/sopt}/config/JpaConfig.java (83%) rename {src/main/java/org/sopt/seminar/domain => domain/src/main/java/org/sopt}/member/domain/Member.java (89%) rename {src/main/java/org/sopt/seminar/domain => domain/src/main/java/org/sopt}/member/domain/Part.java (86%) rename {src/main/java/org/sopt/seminar/domain => domain/src/main/java/org/sopt}/member/domain/Sopt.java (92%) rename {src/main/java/org/sopt/seminar/domain => domain/src/main/java/org/sopt}/member/repository/MemberRepository.java (63%) rename {src/main/java/org/sopt/seminar/domain => domain/src/main/java/org/sopt}/post/domain/Category.java (90%) rename {src/main/java/org/sopt/seminar/domain => domain/src/main/java/org/sopt}/post/domain/Post.java (91%) rename {src/main/java/org/sopt/seminar/domain => domain/src/main/java/org/sopt}/post/repository/CategoryRepository.java (58%) rename {src/main/java/org/sopt/seminar/domain => domain/src/main/java/org/sopt}/post/repository/PostRepository.java (69%) delete mode 100644 src/main/java/org/sopt/seminar/domain/member/dto/request/MemberUpdateRequest.java delete mode 100644 src/test/java/org/sopt/seminar/SeminarApplicationTests.java diff --git a/api/build.gradle b/api/build.gradle new file mode 100644 index 0000000..142a570 --- /dev/null +++ b/api/build.gradle @@ -0,0 +1,12 @@ +dependencies { + // spring boot web + implementation 'org.springframework.boot:spring-boot-starter-web' + // spring data jpa + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + // h2 + runtimeOnly 'com.h2database:h2' + // domain dependency + implementation project(path: ':domain') + // common dependency + implementation project(path: ':common') +} \ No newline at end of file diff --git a/src/main/java/org/sopt/seminar/SeminarApplication.java b/api/src/main/java/org/sopt/SeminarApplication.java similarity index 91% rename from src/main/java/org/sopt/seminar/SeminarApplication.java rename to api/src/main/java/org/sopt/SeminarApplication.java index 469f33c..0b347d0 100644 --- a/src/main/java/org/sopt/seminar/SeminarApplication.java +++ b/api/src/main/java/org/sopt/SeminarApplication.java @@ -1,4 +1,4 @@ -package org.sopt.seminar; +package org.sopt; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/src/main/java/org/sopt/seminar/global/common/ApiResponse.java b/api/src/main/java/org/sopt/common/ApiResponse.java similarity index 90% rename from src/main/java/org/sopt/seminar/global/common/ApiResponse.java rename to api/src/main/java/org/sopt/common/ApiResponse.java index 125501e..6154735 100644 --- a/src/main/java/org/sopt/seminar/global/common/ApiResponse.java +++ b/api/src/main/java/org/sopt/common/ApiResponse.java @@ -1,11 +1,11 @@ -package org.sopt.seminar.global.common; +package org.sopt.common; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; -import org.sopt.seminar.global.error.ErrorStatus; +import org.sopt.error.ErrorStatus; import org.springframework.http.ResponseEntity; @Builder(access = AccessLevel.PRIVATE) @@ -18,14 +18,14 @@ public class ApiResponse { private final T data; private static ApiResponse of(SuccessStatus successStatus) { - return ApiResponse.builder() + return builder() .status(successStatus.getHttpStatus().value()) .message(successStatus.getMessage()) .build(); } private static ApiResponse of(SuccessStatus successStatus, T data) { - return ApiResponse.builder() + return builder() .status(successStatus.getHttpStatus().value()) .message(successStatus.getMessage()) .data(data) @@ -33,7 +33,7 @@ private static ApiResponse of(SuccessStatus successStatus, T data) { } private static ApiResponse of(ErrorStatus errorStatus) { - return ApiResponse.builder() + return builder() .status(errorStatus.getHttpStatus().value()) .message(errorStatus.getMessage()) .build(); diff --git a/src/main/java/org/sopt/seminar/global/common/SuccessStatus.java b/api/src/main/java/org/sopt/common/SuccessStatus.java similarity index 91% rename from src/main/java/org/sopt/seminar/global/common/SuccessStatus.java rename to api/src/main/java/org/sopt/common/SuccessStatus.java index f8b1469..15188b1 100644 --- a/src/main/java/org/sopt/seminar/global/common/SuccessStatus.java +++ b/api/src/main/java/org/sopt/common/SuccessStatus.java @@ -1,4 +1,4 @@ -package org.sopt.seminar.global.common; +package org.sopt.common; import lombok.AccessLevel; import lombok.Getter; diff --git a/src/main/java/org/sopt/seminar/global/error/GlobalExceptionHandler.java b/api/src/main/java/org/sopt/error/GlobalExceptionHandler.java similarity index 82% rename from src/main/java/org/sopt/seminar/global/error/GlobalExceptionHandler.java rename to api/src/main/java/org/sopt/error/GlobalExceptionHandler.java index 0be7bb7..854034a 100644 --- a/src/main/java/org/sopt/seminar/global/error/GlobalExceptionHandler.java +++ b/api/src/main/java/org/sopt/error/GlobalExceptionHandler.java @@ -1,7 +1,7 @@ -package org.sopt.seminar.global.error; +package org.sopt.error; import lombok.extern.slf4j.Slf4j; -import org.sopt.seminar.global.common.ApiResponse; +import org.sopt.common.ApiResponse; import org.springframework.http.ResponseEntity; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.annotation.ControllerAdvice; @@ -11,7 +11,7 @@ @ControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(HttpRequestMethodNotSupportedException.class) - protected ResponseEntity> handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) { + protected ResponseEntity> handleHttpRequestMethodNotSupportedException(final HttpRequestMethodNotSupportedException e) { log.error(">>> handle: HttpRequestMethodNotSupportedException ", e); return ApiResponse.failure(ErrorStatus.METHOD_NOT_ALLOWED); } @@ -23,7 +23,7 @@ protected ResponseEntity> handleBusinessException(final BusinessE } @ExceptionHandler(Exception.class) - protected ResponseEntity> handleException(Exception e) { + protected ResponseEntity> handleException(final Exception e) { log.error(">>> handle: Exception ", e); return ApiResponse.failure(ErrorStatus.INTERNAL_SERVER_ERROR); } diff --git a/src/main/java/org/sopt/seminar/domain/member/api/MemberApiController.java b/api/src/main/java/org/sopt/member/api/MemberApiController.java similarity index 79% rename from src/main/java/org/sopt/seminar/domain/member/api/MemberApiController.java rename to api/src/main/java/org/sopt/member/api/MemberApiController.java index f422f06..0fb8372 100644 --- a/src/main/java/org/sopt/seminar/domain/member/api/MemberApiController.java +++ b/api/src/main/java/org/sopt/member/api/MemberApiController.java @@ -1,13 +1,13 @@ -package org.sopt.seminar.domain.member.api; +package org.sopt.member.api; import lombok.RequiredArgsConstructor; -import org.sopt.seminar.domain.member.dto.request.MemberSaveRequest; -import org.sopt.seminar.domain.member.dto.request.MemberUpdateRequest; -import org.sopt.seminar.domain.member.dto.response.MemberGetResponse; -import org.sopt.seminar.domain.member.dto.response.MemberSaveResponse; -import org.sopt.seminar.domain.member.service.MemberService; -import org.sopt.seminar.global.common.ApiResponse; -import org.sopt.seminar.global.common.SuccessStatus; +import org.sopt.common.ApiResponse; +import org.sopt.common.SuccessStatus; +import org.sopt.member.dto.request.MemberSaveRequest; +import org.sopt.member.dto.request.MemberUpdateRequest; +import org.sopt.member.dto.response.MemberGetResponse; +import org.sopt.member.dto.response.MemberSaveResponse; +import org.sopt.member.service.MemberService; import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; diff --git a/src/main/java/org/sopt/seminar/domain/member/dto/request/MemberSaveRequest.java b/api/src/main/java/org/sopt/member/dto/request/MemberSaveRequest.java similarity index 54% rename from src/main/java/org/sopt/seminar/domain/member/dto/request/MemberSaveRequest.java rename to api/src/main/java/org/sopt/member/dto/request/MemberSaveRequest.java index 2ecdc83..9a4917c 100644 --- a/src/main/java/org/sopt/seminar/domain/member/dto/request/MemberSaveRequest.java +++ b/api/src/main/java/org/sopt/member/dto/request/MemberSaveRequest.java @@ -1,6 +1,6 @@ -package org.sopt.seminar.domain.member.dto.request; +package org.sopt.member.dto.request; -import org.sopt.seminar.domain.member.domain.Sopt; +import org.sopt.member.domain.Sopt; public record MemberSaveRequest( String name, diff --git a/api/src/main/java/org/sopt/member/dto/request/MemberUpdateRequest.java b/api/src/main/java/org/sopt/member/dto/request/MemberUpdateRequest.java new file mode 100644 index 0000000..a4bed65 --- /dev/null +++ b/api/src/main/java/org/sopt/member/dto/request/MemberUpdateRequest.java @@ -0,0 +1,8 @@ +package org.sopt.member.dto.request; + +import org.sopt.member.domain.Part; + +public record MemberUpdateRequest( + int generation, + Part part) { +} diff --git a/src/main/java/org/sopt/seminar/domain/member/dto/response/MemberGetResponse.java b/api/src/main/java/org/sopt/member/dto/response/MemberGetResponse.java similarity index 69% rename from src/main/java/org/sopt/seminar/domain/member/dto/response/MemberGetResponse.java rename to api/src/main/java/org/sopt/member/dto/response/MemberGetResponse.java index 032aac5..d760ab5 100644 --- a/src/main/java/org/sopt/seminar/domain/member/dto/response/MemberGetResponse.java +++ b/api/src/main/java/org/sopt/member/dto/response/MemberGetResponse.java @@ -1,9 +1,9 @@ -package org.sopt.seminar.domain.member.dto.response; +package org.sopt.member.dto.response; import lombok.AccessLevel; import lombok.Builder; -import org.sopt.seminar.domain.member.domain.Member; -import org.sopt.seminar.domain.member.domain.Sopt; +import org.sopt.member.domain.Member; +import org.sopt.member.domain.Sopt; @Builder(access = AccessLevel.PRIVATE) public record MemberGetResponse( @@ -13,7 +13,7 @@ public record MemberGetResponse( Sopt sopt ) { public static MemberGetResponse of(Member member) { - return MemberGetResponse.builder() + return builder() .name(member.getName()) .nickname(member.getNickname()) .age(member.getAge()) diff --git a/src/main/java/org/sopt/seminar/domain/member/dto/response/MemberSaveResponse.java b/api/src/main/java/org/sopt/member/dto/response/MemberSaveResponse.java similarity index 63% rename from src/main/java/org/sopt/seminar/domain/member/dto/response/MemberSaveResponse.java rename to api/src/main/java/org/sopt/member/dto/response/MemberSaveResponse.java index d24c896..0c81327 100644 --- a/src/main/java/org/sopt/seminar/domain/member/dto/response/MemberSaveResponse.java +++ b/api/src/main/java/org/sopt/member/dto/response/MemberSaveResponse.java @@ -1,6 +1,6 @@ -package org.sopt.seminar.domain.member.dto.response; +package org.sopt.member.dto.response; -import org.sopt.seminar.domain.member.domain.Member; +import org.sopt.member.domain.Member; public record MemberSaveResponse( Long memberId diff --git a/src/main/java/org/sopt/seminar/domain/member/service/MemberService.java b/api/src/main/java/org/sopt/member/service/MemberService.java similarity index 67% rename from src/main/java/org/sopt/seminar/domain/member/service/MemberService.java rename to api/src/main/java/org/sopt/member/service/MemberService.java index ad076f6..e885ffd 100644 --- a/src/main/java/org/sopt/seminar/domain/member/service/MemberService.java +++ b/api/src/main/java/org/sopt/member/service/MemberService.java @@ -1,23 +1,22 @@ -package org.sopt.seminar.domain.member.service; +package org.sopt.member.service; import lombok.RequiredArgsConstructor; -import org.sopt.seminar.domain.member.domain.Member; -import org.sopt.seminar.domain.member.domain.Sopt; -import org.sopt.seminar.domain.member.dto.request.MemberSaveRequest; -import org.sopt.seminar.domain.member.dto.request.MemberUpdateRequest; -import org.sopt.seminar.domain.member.dto.response.MemberGetResponse; -import org.sopt.seminar.domain.member.dto.response.MemberSaveResponse; -import org.sopt.seminar.domain.member.repository.MemberRepository; -import org.sopt.seminar.global.error.ConflictException; -import org.sopt.seminar.global.error.ErrorStatus; +import org.sopt.error.ConflictException; +import org.sopt.error.ErrorStatus; +import org.sopt.member.domain.Member; +import org.sopt.member.domain.Sopt; +import org.sopt.member.dto.request.MemberSaveRequest; +import org.sopt.member.dto.request.MemberUpdateRequest; +import org.sopt.member.dto.response.MemberGetResponse; +import org.sopt.member.dto.response.MemberSaveResponse; +import org.sopt.member.repository.MemberRepository; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; -import static org.sopt.seminar.domain.member.domain.Member.createMember; -import static org.sopt.seminar.domain.member.domain.Sopt.createSopt; +import static org.sopt.member.domain.Member.createMember; @RequiredArgsConstructor @Transactional(readOnly = true) @@ -49,7 +48,7 @@ public List getMembers(Pageable pageable) { @Transactional public void updateMember(Long memberId, MemberUpdateRequest memberUpdateRequest) { Member findMember = memberRepository.findByIdOrThrow(memberId); - Sopt sopt = createSopt(memberUpdateRequest.generation(), memberUpdateRequest.part()); + Sopt sopt = Sopt.createSopt(memberUpdateRequest.generation(), memberUpdateRequest.part()); findMember.updateSopt(sopt); } diff --git a/src/main/java/org/sopt/seminar/domain/post/api/PostApiController.java b/api/src/main/java/org/sopt/post/api/PostApiController.java similarity index 83% rename from src/main/java/org/sopt/seminar/domain/post/api/PostApiController.java rename to api/src/main/java/org/sopt/post/api/PostApiController.java index 77b5906..c784a45 100644 --- a/src/main/java/org/sopt/seminar/domain/post/api/PostApiController.java +++ b/api/src/main/java/org/sopt/post/api/PostApiController.java @@ -1,12 +1,12 @@ -package org.sopt.seminar.domain.post.api; +package org.sopt.post.api; import lombok.RequiredArgsConstructor; -import org.sopt.seminar.domain.post.dto.request.PostSaveOrUpdateRequest; -import org.sopt.seminar.domain.post.dto.response.PostGetResponse; -import org.sopt.seminar.domain.post.dto.response.PostSaveResponse; -import org.sopt.seminar.domain.post.service.PostService; -import org.sopt.seminar.global.common.ApiResponse; -import org.sopt.seminar.global.common.SuccessStatus; +import org.sopt.common.ApiResponse; +import org.sopt.common.SuccessStatus; +import org.sopt.post.dto.request.PostSaveOrUpdateRequest; +import org.sopt.post.dto.response.PostGetResponse; +import org.sopt.post.dto.response.PostSaveResponse; +import org.sopt.post.service.PostService; import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; diff --git a/src/main/java/org/sopt/seminar/domain/post/dto/request/PostSaveOrUpdateRequest.java b/api/src/main/java/org/sopt/post/dto/request/PostSaveOrUpdateRequest.java similarity index 71% rename from src/main/java/org/sopt/seminar/domain/post/dto/request/PostSaveOrUpdateRequest.java rename to api/src/main/java/org/sopt/post/dto/request/PostSaveOrUpdateRequest.java index c88fcd2..f35e65f 100644 --- a/src/main/java/org/sopt/seminar/domain/post/dto/request/PostSaveOrUpdateRequest.java +++ b/api/src/main/java/org/sopt/post/dto/request/PostSaveOrUpdateRequest.java @@ -1,4 +1,4 @@ -package org.sopt.seminar.domain.post.dto.request; +package org.sopt.post.dto.request; public record PostSaveOrUpdateRequest( String title, diff --git a/src/main/java/org/sopt/seminar/domain/post/dto/response/PostGetResponse.java b/api/src/main/java/org/sopt/post/dto/response/PostGetResponse.java similarity index 71% rename from src/main/java/org/sopt/seminar/domain/post/dto/response/PostGetResponse.java rename to api/src/main/java/org/sopt/post/dto/response/PostGetResponse.java index bd9a7c4..9661b7d 100644 --- a/src/main/java/org/sopt/seminar/domain/post/dto/response/PostGetResponse.java +++ b/api/src/main/java/org/sopt/post/dto/response/PostGetResponse.java @@ -1,9 +1,9 @@ -package org.sopt.seminar.domain.post.dto.response; +package org.sopt.post.dto.response; import lombok.AccessLevel; import lombok.Builder; -import org.sopt.seminar.domain.post.domain.Category; -import org.sopt.seminar.domain.post.domain.Post; +import org.sopt.post.domain.Category; +import org.sopt.post.domain.Post; @Builder(access = AccessLevel.PRIVATE) public record PostGetResponse( @@ -13,7 +13,7 @@ public record PostGetResponse( ) { public static PostGetResponse of(Post post) { Category category = post.getCategory(); - return PostGetResponse.builder() + return builder() .title(post.getTitle()) .postContent(post.getContent()) .categoryContent(category.getContent()) diff --git a/src/main/java/org/sopt/seminar/domain/post/dto/response/PostSaveResponse.java b/api/src/main/java/org/sopt/post/dto/response/PostSaveResponse.java similarity index 62% rename from src/main/java/org/sopt/seminar/domain/post/dto/response/PostSaveResponse.java rename to api/src/main/java/org/sopt/post/dto/response/PostSaveResponse.java index 14b1771..2c3a9bc 100644 --- a/src/main/java/org/sopt/seminar/domain/post/dto/response/PostSaveResponse.java +++ b/api/src/main/java/org/sopt/post/dto/response/PostSaveResponse.java @@ -1,6 +1,6 @@ -package org.sopt.seminar.domain.post.dto.response; +package org.sopt.post.dto.response; -import org.sopt.seminar.domain.post.domain.Post; +import org.sopt.post.domain.Post; public record PostSaveResponse( Long postId diff --git a/src/main/java/org/sopt/seminar/domain/post/service/PostService.java b/api/src/main/java/org/sopt/post/service/PostService.java similarity index 72% rename from src/main/java/org/sopt/seminar/domain/post/service/PostService.java rename to api/src/main/java/org/sopt/post/service/PostService.java index 6178aac..a0f1872 100644 --- a/src/main/java/org/sopt/seminar/domain/post/service/PostService.java +++ b/api/src/main/java/org/sopt/post/service/PostService.java @@ -1,24 +1,21 @@ -package org.sopt.seminar.domain.post.service; +package org.sopt.post.service; import lombok.RequiredArgsConstructor; -import org.sopt.seminar.domain.member.domain.Member; -import org.sopt.seminar.domain.member.repository.MemberRepository; -import org.sopt.seminar.domain.post.domain.Category; -import org.sopt.seminar.domain.post.domain.Post; -import org.sopt.seminar.domain.post.dto.request.PostSaveOrUpdateRequest; -import org.sopt.seminar.domain.post.dto.response.PostGetResponse; -import org.sopt.seminar.domain.post.dto.response.PostSaveResponse; -import org.sopt.seminar.domain.post.repository.CategoryRepository; -import org.sopt.seminar.domain.post.repository.PostRepository; +import org.sopt.member.domain.Member; +import org.sopt.member.repository.MemberRepository; +import org.sopt.post.domain.Category; +import org.sopt.post.domain.Post; +import org.sopt.post.dto.request.PostSaveOrUpdateRequest; +import org.sopt.post.dto.response.PostGetResponse; +import org.sopt.post.dto.response.PostSaveResponse; +import org.sopt.post.repository.CategoryRepository; +import org.sopt.post.repository.PostRepository; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; -import static org.sopt.seminar.domain.post.domain.Category.createCategory; -import static org.sopt.seminar.domain.post.domain.Post.createPost; - @RequiredArgsConstructor @Transactional(readOnly = true) @Service @@ -64,12 +61,12 @@ private Member findMember(Long memberId) { } private Category createCategoryAndGetSavedCategory(PostSaveOrUpdateRequest postSaveOrUpdateRequest) { - Category category = createCategory(postSaveOrUpdateRequest.categoryContent()); + Category category = Category.createCategory(postSaveOrUpdateRequest.categoryContent()); return categoryRepository.save(category); } private Post createPostAndGetSavedPost(PostSaveOrUpdateRequest postSaveOrUpdateRequest, Member member, Category category) { - Post post = createPost(postSaveOrUpdateRequest.title(), postSaveOrUpdateRequest.postContent(), category, member); + Post post = Post.createPost(postSaveOrUpdateRequest.title(), postSaveOrUpdateRequest.postContent(), category, member); return postRepository.save(post); } diff --git a/build.gradle b/build.gradle index 4fc9ba0..039b00d 100644 --- a/build.gradle +++ b/build.gradle @@ -4,11 +4,14 @@ plugins { id 'io.spring.dependency-management' version '1.1.3' } -group = 'org.sopt' -version = '0.0.1-SNAPSHOT' - -java { +allprojects { + group = 'org.sopt' + version = '0.0.1-SNAPSHOT' sourceCompatibility = '17' + + repositories { + mavenCentral() + } } configurations { @@ -17,30 +20,25 @@ configurations { } } -repositories { - mavenCentral() -} - -dependencies { - // spring boot - implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - - // h2 - runtimeOnly 'com.h2database:h2' +subprojects { + apply plugin: 'java' + apply plugin: 'org.springframework.boot' + apply plugin: 'io.spring.dependency-management' - // lombok - compileOnly 'org.projectlombok:lombok' - annotationProcessor 'org.projectlombok:lombok' + dependencies { + // lombok + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' - // test - testImplementation 'org.springframework.boot:spring-boot-starter-test' -} + // test + testImplementation 'org.springframework.boot:spring-boot-starter-test' + } -tasks.named('test') { - useJUnitPlatform() -} + tasks.named('test') { + useJUnitPlatform() + } -jar { - enabled = false + jar { + enabled = false + } } \ No newline at end of file diff --git a/common/build.gradle b/common/build.gradle new file mode 100644 index 0000000..a912983 --- /dev/null +++ b/common/build.gradle @@ -0,0 +1,4 @@ +dependencies { + // spring boot web + implementation 'org.springframework.boot:spring-boot-starter-web' +} \ No newline at end of file diff --git a/src/main/java/org/sopt/seminar/global/error/BusinessException.java b/common/src/main/java/org/sopt/error/BusinessException.java similarity index 87% rename from src/main/java/org/sopt/seminar/global/error/BusinessException.java rename to common/src/main/java/org/sopt/error/BusinessException.java index b985f94..770e4a8 100644 --- a/src/main/java/org/sopt/seminar/global/error/BusinessException.java +++ b/common/src/main/java/org/sopt/error/BusinessException.java @@ -1,4 +1,4 @@ -package org.sopt.seminar.global.error; +package org.sopt.error; import lombok.Getter; diff --git a/src/main/java/org/sopt/seminar/global/error/ConflictException.java b/common/src/main/java/org/sopt/error/ConflictException.java similarity index 85% rename from src/main/java/org/sopt/seminar/global/error/ConflictException.java rename to common/src/main/java/org/sopt/error/ConflictException.java index 78f5242..964e6b1 100644 --- a/src/main/java/org/sopt/seminar/global/error/ConflictException.java +++ b/common/src/main/java/org/sopt/error/ConflictException.java @@ -1,4 +1,4 @@ -package org.sopt.seminar.global.error; +package org.sopt.error; public class ConflictException extends BusinessException { public ConflictException() { diff --git a/src/main/java/org/sopt/seminar/global/error/EntityNotFoundException.java b/common/src/main/java/org/sopt/error/EntityNotFoundException.java similarity index 86% rename from src/main/java/org/sopt/seminar/global/error/EntityNotFoundException.java rename to common/src/main/java/org/sopt/error/EntityNotFoundException.java index 7793473..9793f50 100644 --- a/src/main/java/org/sopt/seminar/global/error/EntityNotFoundException.java +++ b/common/src/main/java/org/sopt/error/EntityNotFoundException.java @@ -1,4 +1,4 @@ -package org.sopt.seminar.global.error; +package org.sopt.error; public class EntityNotFoundException extends BusinessException { public EntityNotFoundException() { diff --git a/src/main/java/org/sopt/seminar/global/error/ErrorStatus.java b/common/src/main/java/org/sopt/error/ErrorStatus.java similarity index 96% rename from src/main/java/org/sopt/seminar/global/error/ErrorStatus.java rename to common/src/main/java/org/sopt/error/ErrorStatus.java index 0b47ba1..37083ff 100644 --- a/src/main/java/org/sopt/seminar/global/error/ErrorStatus.java +++ b/common/src/main/java/org/sopt/error/ErrorStatus.java @@ -1,4 +1,4 @@ -package org.sopt.seminar.global.error; +package org.sopt.error; import lombok.AccessLevel; import lombok.Getter; diff --git a/src/main/java/org/sopt/seminar/global/error/InvalidValueException.java b/common/src/main/java/org/sopt/error/InvalidValueException.java similarity index 86% rename from src/main/java/org/sopt/seminar/global/error/InvalidValueException.java rename to common/src/main/java/org/sopt/error/InvalidValueException.java index 224adb9..ecc8b88 100644 --- a/src/main/java/org/sopt/seminar/global/error/InvalidValueException.java +++ b/common/src/main/java/org/sopt/error/InvalidValueException.java @@ -1,4 +1,4 @@ -package org.sopt.seminar.global.error; +package org.sopt.error; public class InvalidValueException extends BusinessException { public InvalidValueException() { diff --git a/domain/build.gradle b/domain/build.gradle new file mode 100644 index 0000000..42eb8c6 --- /dev/null +++ b/domain/build.gradle @@ -0,0 +1,8 @@ +dependencies { + // spring data jpa + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + // h2 + runtimeOnly 'com.h2database:h2' + // common dependency + implementation project(path: ':common') +} \ No newline at end of file diff --git a/src/main/java/org/sopt/seminar/global/common/BaseTimeEntity.java b/domain/src/main/java/org/sopt/common/BaseTimeEntity.java similarity index 94% rename from src/main/java/org/sopt/seminar/global/common/BaseTimeEntity.java rename to domain/src/main/java/org/sopt/common/BaseTimeEntity.java index 002cf29..8e5797a 100644 --- a/src/main/java/org/sopt/seminar/global/common/BaseTimeEntity.java +++ b/domain/src/main/java/org/sopt/common/BaseTimeEntity.java @@ -1,4 +1,4 @@ -package org.sopt.seminar.global.common; +package org.sopt.common; import jakarta.persistence.Column; import jakarta.persistence.EntityListeners; diff --git a/src/main/java/org/sopt/seminar/global/config/JpaConfig.java b/domain/src/main/java/org/sopt/config/JpaConfig.java similarity index 83% rename from src/main/java/org/sopt/seminar/global/config/JpaConfig.java rename to domain/src/main/java/org/sopt/config/JpaConfig.java index c9a9564..e0ea3c1 100644 --- a/src/main/java/org/sopt/seminar/global/config/JpaConfig.java +++ b/domain/src/main/java/org/sopt/config/JpaConfig.java @@ -1,4 +1,4 @@ -package org.sopt.seminar.global.config; +package org.sopt.config; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; diff --git a/src/main/java/org/sopt/seminar/domain/member/domain/Member.java b/domain/src/main/java/org/sopt/member/domain/Member.java similarity index 89% rename from src/main/java/org/sopt/seminar/domain/member/domain/Member.java rename to domain/src/main/java/org/sopt/member/domain/Member.java index 9bcbfd6..a645dcd 100644 --- a/src/main/java/org/sopt/seminar/domain/member/domain/Member.java +++ b/domain/src/main/java/org/sopt/member/domain/Member.java @@ -1,10 +1,10 @@ -package org.sopt.seminar.domain.member.domain; +package org.sopt.member.domain; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.DynamicUpdate; -import org.sopt.seminar.domain.post.domain.Post; -import org.sopt.seminar.global.common.BaseTimeEntity; +import org.sopt.common.BaseTimeEntity; +import org.sopt.post.domain.Post; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/sopt/seminar/domain/member/domain/Part.java b/domain/src/main/java/org/sopt/member/domain/Part.java similarity index 86% rename from src/main/java/org/sopt/seminar/domain/member/domain/Part.java rename to domain/src/main/java/org/sopt/member/domain/Part.java index e1e82d3..fbec7c5 100644 --- a/src/main/java/org/sopt/seminar/domain/member/domain/Part.java +++ b/domain/src/main/java/org/sopt/member/domain/Part.java @@ -1,4 +1,4 @@ -package org.sopt.seminar.domain.member.domain; +package org.sopt.member.domain; import lombok.AccessLevel; import lombok.Getter; diff --git a/src/main/java/org/sopt/seminar/domain/member/domain/Sopt.java b/domain/src/main/java/org/sopt/member/domain/Sopt.java similarity index 92% rename from src/main/java/org/sopt/seminar/domain/member/domain/Sopt.java rename to domain/src/main/java/org/sopt/member/domain/Sopt.java index d53c606..c737f01 100644 --- a/src/main/java/org/sopt/seminar/domain/member/domain/Sopt.java +++ b/domain/src/main/java/org/sopt/member/domain/Sopt.java @@ -1,4 +1,4 @@ -package org.sopt.seminar.domain.member.domain; +package org.sopt.member.domain; import jakarta.persistence.Embeddable; import jakarta.persistence.EnumType; diff --git a/src/main/java/org/sopt/seminar/domain/member/repository/MemberRepository.java b/domain/src/main/java/org/sopt/member/repository/MemberRepository.java similarity index 63% rename from src/main/java/org/sopt/seminar/domain/member/repository/MemberRepository.java rename to domain/src/main/java/org/sopt/member/repository/MemberRepository.java index 0e13e34..e727293 100644 --- a/src/main/java/org/sopt/seminar/domain/member/repository/MemberRepository.java +++ b/domain/src/main/java/org/sopt/member/repository/MemberRepository.java @@ -1,9 +1,8 @@ -package org.sopt.seminar.domain.member.repository; +package org.sopt.member.repository; - -import org.sopt.seminar.domain.member.domain.Member; -import org.sopt.seminar.global.error.EntityNotFoundException; -import org.sopt.seminar.global.error.ErrorStatus; +import org.sopt.error.EntityNotFoundException; +import org.sopt.error.ErrorStatus; +import org.sopt.member.domain.Member; import org.springframework.data.jpa.repository.JpaRepository; public interface MemberRepository extends JpaRepository { diff --git a/src/main/java/org/sopt/seminar/domain/post/domain/Category.java b/domain/src/main/java/org/sopt/post/domain/Category.java similarity index 90% rename from src/main/java/org/sopt/seminar/domain/post/domain/Category.java rename to domain/src/main/java/org/sopt/post/domain/Category.java index 87eaca5..65d2668 100644 --- a/src/main/java/org/sopt/seminar/domain/post/domain/Category.java +++ b/domain/src/main/java/org/sopt/post/domain/Category.java @@ -1,8 +1,8 @@ -package org.sopt.seminar.domain.post.domain; +package org.sopt.post.domain; import jakarta.persistence.*; import lombok.*; -import org.sopt.seminar.global.common.BaseTimeEntity; +import org.sopt.common.BaseTimeEntity; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/sopt/seminar/domain/post/domain/Post.java b/domain/src/main/java/org/sopt/post/domain/Post.java similarity index 91% rename from src/main/java/org/sopt/seminar/domain/post/domain/Post.java rename to domain/src/main/java/org/sopt/post/domain/Post.java index 1b5be99..c8ffbff 100644 --- a/src/main/java/org/sopt/seminar/domain/post/domain/Post.java +++ b/domain/src/main/java/org/sopt/post/domain/Post.java @@ -1,9 +1,9 @@ -package org.sopt.seminar.domain.post.domain; +package org.sopt.post.domain; import jakarta.persistence.*; import lombok.*; -import org.sopt.seminar.domain.member.domain.Member; -import org.sopt.seminar.global.common.BaseTimeEntity; +import org.sopt.common.BaseTimeEntity; +import org.sopt.member.domain.Member; @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) diff --git a/src/main/java/org/sopt/seminar/domain/post/repository/CategoryRepository.java b/domain/src/main/java/org/sopt/post/repository/CategoryRepository.java similarity index 58% rename from src/main/java/org/sopt/seminar/domain/post/repository/CategoryRepository.java rename to domain/src/main/java/org/sopt/post/repository/CategoryRepository.java index e65eaa8..906e5c8 100644 --- a/src/main/java/org/sopt/seminar/domain/post/repository/CategoryRepository.java +++ b/domain/src/main/java/org/sopt/post/repository/CategoryRepository.java @@ -1,6 +1,6 @@ -package org.sopt.seminar.domain.post.repository; +package org.sopt.post.repository; -import org.sopt.seminar.domain.post.domain.Category; +import org.sopt.post.domain.Category; import org.springframework.data.jpa.repository.JpaRepository; public interface CategoryRepository extends JpaRepository { diff --git a/src/main/java/org/sopt/seminar/domain/post/repository/PostRepository.java b/domain/src/main/java/org/sopt/post/repository/PostRepository.java similarity index 69% rename from src/main/java/org/sopt/seminar/domain/post/repository/PostRepository.java rename to domain/src/main/java/org/sopt/post/repository/PostRepository.java index a17b1b1..c753f8b 100644 --- a/src/main/java/org/sopt/seminar/domain/post/repository/PostRepository.java +++ b/domain/src/main/java/org/sopt/post/repository/PostRepository.java @@ -1,8 +1,8 @@ -package org.sopt.seminar.domain.post.repository; +package org.sopt.post.repository; -import org.sopt.seminar.domain.post.domain.Post; -import org.sopt.seminar.global.error.EntityNotFoundException; -import org.sopt.seminar.global.error.ErrorStatus; +import org.sopt.error.EntityNotFoundException; +import org.sopt.error.ErrorStatus; +import org.sopt.post.domain.Post; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/settings.gradle b/settings.gradle index 6b30e33..39131b8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,4 @@ rootProject.name = 'seminar' +include 'api' +include 'domain' +include 'common' diff --git a/src/main/java/org/sopt/seminar/domain/member/dto/request/MemberUpdateRequest.java b/src/main/java/org/sopt/seminar/domain/member/dto/request/MemberUpdateRequest.java deleted file mode 100644 index d591d68..0000000 --- a/src/main/java/org/sopt/seminar/domain/member/dto/request/MemberUpdateRequest.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.sopt.seminar.domain.member.dto.request; - -import org.sopt.seminar.domain.member.domain.Part; - -public record MemberUpdateRequest( - int generation, - Part part) { -} diff --git a/src/test/java/org/sopt/seminar/SeminarApplicationTests.java b/src/test/java/org/sopt/seminar/SeminarApplicationTests.java deleted file mode 100644 index 63c422f..0000000 --- a/src/test/java/org/sopt/seminar/SeminarApplicationTests.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.sopt.seminar; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class SeminarApplicationTests { - @Test - void contextLoads() { - } -} From a28c96f2c80e6729866d45043c4195a36ed1ced1 Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 17:46:02 +0900 Subject: [PATCH 14/18] =?UTF-8?q?[chore]=20#5=20ci=20workflow=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 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 12bbb95..cb29113 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: - name: ✔️ application.yml 파일을 생성합니다. run: | - cd ./src/main + cd ./api/src/main mkdir resources cd ./resources echo "$APPLICATION" > ./application.yml @@ -32,4 +32,4 @@ jobs: run: chmod +x gradlew - name: ✔️ gradle build 합니다. - run: ./gradlew build \ No newline at end of file + run: ./gradlew api:build \ No newline at end of file From 37284552810976d1599690268a4450362691f56b Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 18:46:58 +0900 Subject: [PATCH 15/18] =?UTF-8?q?[chore]=20#5=20=EB=A9=80=ED=8B=B0=20?= =?UTF-8?q?=EB=AA=A8=EB=93=88=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/{ => api}/common/ApiResponse.java | 4 +- .../sopt/{ => api}/common/SuccessStatus.java | 2 +- .../error/GlobalExceptionHandler.java | 6 ++- .../member/api/MemberApiController.java | 16 ++++---- .../member/dto/request/MemberSaveRequest.java | 4 +- .../dto/request/MemberUpdateRequest.java | 4 +- .../dto/response/MemberGetResponse.java | 6 +-- .../dto/response/MemberSaveResponse.java | 4 +- .../member/service/MemberService.java | 22 +++++------ .../{ => api}/post/api/PostApiController.java | 14 +++---- .../dto/request/PostSaveOrUpdateRequest.java | 2 +- .../post/dto/response/PostGetResponse.java | 6 +-- .../post/dto/response/PostSaveResponse.java | 4 +- .../{ => api}/post/service/PostService.java | 37 +++++++++++++------ build.gradle | 6 ++- .../{ => common}/error/BusinessException.java | 2 +- .../{ => common}/error/ConflictException.java | 2 +- .../error/EntityNotFoundException.java | 2 +- .../sopt/{ => common}/error/ErrorStatus.java | 3 +- .../error/InvalidValueException.java | 2 +- .../{ => domain}/common/BaseTimeEntity.java | 2 +- .../sopt/{ => domain}/config/JpaConfig.java | 2 +- .../{ => domain}/member/domain/Member.java | 6 +-- .../sopt/{ => domain}/member/domain/Part.java | 2 +- .../sopt/{ => domain}/member/domain/Sopt.java | 2 +- .../member/repository/MemberRepository.java | 8 ++-- .../{ => domain}/post/domain/Category.java | 8 ++-- .../sopt/{ => domain}/post/domain/Post.java | 6 +-- .../post/repository/CategoryRepository.java | 5 ++- .../post/repository/PostRepository.java | 8 ++-- 30 files changed, 109 insertions(+), 88 deletions(-) rename api/src/main/java/org/sopt/{ => api}/common/ApiResponse.java (96%) rename api/src/main/java/org/sopt/{ => api}/common/SuccessStatus.java (93%) rename api/src/main/java/org/sopt/{ => api}/error/GlobalExceptionHandler.java (88%) rename api/src/main/java/org/sopt/{ => api}/member/api/MemberApiController.java (82%) rename api/src/main/java/org/sopt/{ => api}/member/dto/request/MemberSaveRequest.java (59%) rename api/src/main/java/org/sopt/{ => api}/member/dto/request/MemberUpdateRequest.java (50%) rename api/src/main/java/org/sopt/{ => api}/member/dto/response/MemberGetResponse.java (79%) rename api/src/main/java/org/sopt/{ => api}/member/dto/response/MemberSaveResponse.java (67%) rename api/src/main/java/org/sopt/{ => api}/member/service/MemberService.java (76%) rename api/src/main/java/org/sopt/{ => api}/post/api/PostApiController.java (86%) rename api/src/main/java/org/sopt/{ => api}/post/dto/request/PostSaveOrUpdateRequest.java (76%) rename api/src/main/java/org/sopt/{ => api}/post/dto/response/PostGetResponse.java (80%) rename api/src/main/java/org/sopt/{ => api}/post/dto/response/PostSaveResponse.java (67%) rename api/src/main/java/org/sopt/{ => api}/post/service/PostService.java (67%) rename common/src/main/java/org/sopt/{ => common}/error/BusinessException.java (90%) rename common/src/main/java/org/sopt/{ => common}/error/ConflictException.java (88%) rename common/src/main/java/org/sopt/{ => common}/error/EntityNotFoundException.java (89%) rename common/src/main/java/org/sopt/{ => common}/error/ErrorStatus.java (90%) rename common/src/main/java/org/sopt/{ => common}/error/InvalidValueException.java (88%) rename domain/src/main/java/org/sopt/{ => domain}/common/BaseTimeEntity.java (95%) rename domain/src/main/java/org/sopt/{ => domain}/config/JpaConfig.java (86%) rename domain/src/main/java/org/sopt/{ => domain}/member/domain/Member.java (90%) rename domain/src/main/java/org/sopt/{ => domain}/member/domain/Part.java (88%) rename domain/src/main/java/org/sopt/{ => domain}/member/domain/Sopt.java (93%) rename domain/src/main/java/org/sopt/{ => domain}/member/repository/MemberRepository.java (66%) rename domain/src/main/java/org/sopt/{ => domain}/post/domain/Category.java (83%) rename domain/src/main/java/org/sopt/{ => domain}/post/domain/Post.java (92%) rename domain/src/main/java/org/sopt/{ => domain}/post/repository/CategoryRepository.java (52%) rename domain/src/main/java/org/sopt/{ => domain}/post/repository/PostRepository.java (72%) diff --git a/api/src/main/java/org/sopt/common/ApiResponse.java b/api/src/main/java/org/sopt/api/common/ApiResponse.java similarity index 96% rename from api/src/main/java/org/sopt/common/ApiResponse.java rename to api/src/main/java/org/sopt/api/common/ApiResponse.java index 6154735..c785d3c 100644 --- a/api/src/main/java/org/sopt/common/ApiResponse.java +++ b/api/src/main/java/org/sopt/api/common/ApiResponse.java @@ -1,11 +1,11 @@ -package org.sopt.common; +package org.sopt.api.common; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; -import org.sopt.error.ErrorStatus; +import org.sopt.common.error.ErrorStatus; import org.springframework.http.ResponseEntity; @Builder(access = AccessLevel.PRIVATE) diff --git a/api/src/main/java/org/sopt/common/SuccessStatus.java b/api/src/main/java/org/sopt/api/common/SuccessStatus.java similarity index 93% rename from api/src/main/java/org/sopt/common/SuccessStatus.java rename to api/src/main/java/org/sopt/api/common/SuccessStatus.java index 15188b1..d5480f4 100644 --- a/api/src/main/java/org/sopt/common/SuccessStatus.java +++ b/api/src/main/java/org/sopt/api/common/SuccessStatus.java @@ -1,4 +1,4 @@ -package org.sopt.common; +package org.sopt.api.common; import lombok.AccessLevel; import lombok.Getter; diff --git a/api/src/main/java/org/sopt/error/GlobalExceptionHandler.java b/api/src/main/java/org/sopt/api/error/GlobalExceptionHandler.java similarity index 88% rename from api/src/main/java/org/sopt/error/GlobalExceptionHandler.java rename to api/src/main/java/org/sopt/api/error/GlobalExceptionHandler.java index 854034a..931b85c 100644 --- a/api/src/main/java/org/sopt/error/GlobalExceptionHandler.java +++ b/api/src/main/java/org/sopt/api/error/GlobalExceptionHandler.java @@ -1,7 +1,9 @@ -package org.sopt.error; +package org.sopt.api.error; import lombok.extern.slf4j.Slf4j; -import org.sopt.common.ApiResponse; +import org.sopt.api.common.ApiResponse; +import org.sopt.common.error.BusinessException; +import org.sopt.common.error.ErrorStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.annotation.ControllerAdvice; diff --git a/api/src/main/java/org/sopt/member/api/MemberApiController.java b/api/src/main/java/org/sopt/api/member/api/MemberApiController.java similarity index 82% rename from api/src/main/java/org/sopt/member/api/MemberApiController.java rename to api/src/main/java/org/sopt/api/member/api/MemberApiController.java index 0fb8372..cf6ec07 100644 --- a/api/src/main/java/org/sopt/member/api/MemberApiController.java +++ b/api/src/main/java/org/sopt/api/member/api/MemberApiController.java @@ -1,13 +1,13 @@ -package org.sopt.member.api; +package org.sopt.api.member.api; import lombok.RequiredArgsConstructor; -import org.sopt.common.ApiResponse; -import org.sopt.common.SuccessStatus; -import org.sopt.member.dto.request.MemberSaveRequest; -import org.sopt.member.dto.request.MemberUpdateRequest; -import org.sopt.member.dto.response.MemberGetResponse; -import org.sopt.member.dto.response.MemberSaveResponse; -import org.sopt.member.service.MemberService; +import org.sopt.api.common.ApiResponse; +import org.sopt.api.common.SuccessStatus; +import org.sopt.api.member.dto.request.MemberSaveRequest; +import org.sopt.api.member.dto.request.MemberUpdateRequest; +import org.sopt.api.member.dto.response.MemberGetResponse; +import org.sopt.api.member.dto.response.MemberSaveResponse; +import org.sopt.api.member.service.MemberService; import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; diff --git a/api/src/main/java/org/sopt/member/dto/request/MemberSaveRequest.java b/api/src/main/java/org/sopt/api/member/dto/request/MemberSaveRequest.java similarity index 59% rename from api/src/main/java/org/sopt/member/dto/request/MemberSaveRequest.java rename to api/src/main/java/org/sopt/api/member/dto/request/MemberSaveRequest.java index 9a4917c..b891b19 100644 --- a/api/src/main/java/org/sopt/member/dto/request/MemberSaveRequest.java +++ b/api/src/main/java/org/sopt/api/member/dto/request/MemberSaveRequest.java @@ -1,6 +1,6 @@ -package org.sopt.member.dto.request; +package org.sopt.api.member.dto.request; -import org.sopt.member.domain.Sopt; +import org.sopt.domain.member.domain.Sopt; public record MemberSaveRequest( String name, diff --git a/api/src/main/java/org/sopt/member/dto/request/MemberUpdateRequest.java b/api/src/main/java/org/sopt/api/member/dto/request/MemberUpdateRequest.java similarity index 50% rename from api/src/main/java/org/sopt/member/dto/request/MemberUpdateRequest.java rename to api/src/main/java/org/sopt/api/member/dto/request/MemberUpdateRequest.java index a4bed65..34123fd 100644 --- a/api/src/main/java/org/sopt/member/dto/request/MemberUpdateRequest.java +++ b/api/src/main/java/org/sopt/api/member/dto/request/MemberUpdateRequest.java @@ -1,6 +1,6 @@ -package org.sopt.member.dto.request; +package org.sopt.api.member.dto.request; -import org.sopt.member.domain.Part; +import org.sopt.domain.member.domain.Part; public record MemberUpdateRequest( int generation, diff --git a/api/src/main/java/org/sopt/member/dto/response/MemberGetResponse.java b/api/src/main/java/org/sopt/api/member/dto/response/MemberGetResponse.java similarity index 79% rename from api/src/main/java/org/sopt/member/dto/response/MemberGetResponse.java rename to api/src/main/java/org/sopt/api/member/dto/response/MemberGetResponse.java index d760ab5..93578fe 100644 --- a/api/src/main/java/org/sopt/member/dto/response/MemberGetResponse.java +++ b/api/src/main/java/org/sopt/api/member/dto/response/MemberGetResponse.java @@ -1,9 +1,9 @@ -package org.sopt.member.dto.response; +package org.sopt.api.member.dto.response; import lombok.AccessLevel; import lombok.Builder; -import org.sopt.member.domain.Member; -import org.sopt.member.domain.Sopt; +import org.sopt.domain.member.domain.Member; +import org.sopt.domain.member.domain.Sopt; @Builder(access = AccessLevel.PRIVATE) public record MemberGetResponse( diff --git a/api/src/main/java/org/sopt/member/dto/response/MemberSaveResponse.java b/api/src/main/java/org/sopt/api/member/dto/response/MemberSaveResponse.java similarity index 67% rename from api/src/main/java/org/sopt/member/dto/response/MemberSaveResponse.java rename to api/src/main/java/org/sopt/api/member/dto/response/MemberSaveResponse.java index 0c81327..7137d00 100644 --- a/api/src/main/java/org/sopt/member/dto/response/MemberSaveResponse.java +++ b/api/src/main/java/org/sopt/api/member/dto/response/MemberSaveResponse.java @@ -1,6 +1,6 @@ -package org.sopt.member.dto.response; +package org.sopt.api.member.dto.response; -import org.sopt.member.domain.Member; +import org.sopt.domain.member.domain.Member; public record MemberSaveResponse( Long memberId diff --git a/api/src/main/java/org/sopt/member/service/MemberService.java b/api/src/main/java/org/sopt/api/member/service/MemberService.java similarity index 76% rename from api/src/main/java/org/sopt/member/service/MemberService.java rename to api/src/main/java/org/sopt/api/member/service/MemberService.java index e885ffd..9819cb8 100644 --- a/api/src/main/java/org/sopt/member/service/MemberService.java +++ b/api/src/main/java/org/sopt/api/member/service/MemberService.java @@ -1,22 +1,22 @@ -package org.sopt.member.service; +package org.sopt.api.member.service; import lombok.RequiredArgsConstructor; -import org.sopt.error.ConflictException; -import org.sopt.error.ErrorStatus; -import org.sopt.member.domain.Member; -import org.sopt.member.domain.Sopt; -import org.sopt.member.dto.request.MemberSaveRequest; -import org.sopt.member.dto.request.MemberUpdateRequest; -import org.sopt.member.dto.response.MemberGetResponse; -import org.sopt.member.dto.response.MemberSaveResponse; -import org.sopt.member.repository.MemberRepository; +import org.sopt.common.error.ConflictException; +import org.sopt.common.error.ErrorStatus; +import org.sopt.domain.member.domain.Member; +import org.sopt.domain.member.domain.Sopt; +import org.sopt.api.member.dto.request.MemberSaveRequest; +import org.sopt.api.member.dto.request.MemberUpdateRequest; +import org.sopt.api.member.dto.response.MemberGetResponse; +import org.sopt.api.member.dto.response.MemberSaveResponse; +import org.sopt.domain.member.repository.MemberRepository; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; -import static org.sopt.member.domain.Member.createMember; +import static org.sopt.domain.member.domain.Member.createMember; @RequiredArgsConstructor @Transactional(readOnly = true) diff --git a/api/src/main/java/org/sopt/post/api/PostApiController.java b/api/src/main/java/org/sopt/api/post/api/PostApiController.java similarity index 86% rename from api/src/main/java/org/sopt/post/api/PostApiController.java rename to api/src/main/java/org/sopt/api/post/api/PostApiController.java index c784a45..c822e41 100644 --- a/api/src/main/java/org/sopt/post/api/PostApiController.java +++ b/api/src/main/java/org/sopt/api/post/api/PostApiController.java @@ -1,12 +1,12 @@ -package org.sopt.post.api; +package org.sopt.api.post.api; import lombok.RequiredArgsConstructor; -import org.sopt.common.ApiResponse; -import org.sopt.common.SuccessStatus; -import org.sopt.post.dto.request.PostSaveOrUpdateRequest; -import org.sopt.post.dto.response.PostGetResponse; -import org.sopt.post.dto.response.PostSaveResponse; -import org.sopt.post.service.PostService; +import org.sopt.api.common.ApiResponse; +import org.sopt.api.common.SuccessStatus; +import org.sopt.api.post.dto.request.PostSaveOrUpdateRequest; +import org.sopt.api.post.dto.response.PostGetResponse; +import org.sopt.api.post.dto.response.PostSaveResponse; +import org.sopt.api.post.service.PostService; import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; diff --git a/api/src/main/java/org/sopt/post/dto/request/PostSaveOrUpdateRequest.java b/api/src/main/java/org/sopt/api/post/dto/request/PostSaveOrUpdateRequest.java similarity index 76% rename from api/src/main/java/org/sopt/post/dto/request/PostSaveOrUpdateRequest.java rename to api/src/main/java/org/sopt/api/post/dto/request/PostSaveOrUpdateRequest.java index f35e65f..e0c8474 100644 --- a/api/src/main/java/org/sopt/post/dto/request/PostSaveOrUpdateRequest.java +++ b/api/src/main/java/org/sopt/api/post/dto/request/PostSaveOrUpdateRequest.java @@ -1,4 +1,4 @@ -package org.sopt.post.dto.request; +package org.sopt.api.post.dto.request; public record PostSaveOrUpdateRequest( String title, diff --git a/api/src/main/java/org/sopt/post/dto/response/PostGetResponse.java b/api/src/main/java/org/sopt/api/post/dto/response/PostGetResponse.java similarity index 80% rename from api/src/main/java/org/sopt/post/dto/response/PostGetResponse.java rename to api/src/main/java/org/sopt/api/post/dto/response/PostGetResponse.java index 9661b7d..4263163 100644 --- a/api/src/main/java/org/sopt/post/dto/response/PostGetResponse.java +++ b/api/src/main/java/org/sopt/api/post/dto/response/PostGetResponse.java @@ -1,9 +1,9 @@ -package org.sopt.post.dto.response; +package org.sopt.api.post.dto.response; import lombok.AccessLevel; import lombok.Builder; -import org.sopt.post.domain.Category; -import org.sopt.post.domain.Post; +import org.sopt.domain.post.domain.Category; +import org.sopt.domain.post.domain.Post; @Builder(access = AccessLevel.PRIVATE) public record PostGetResponse( diff --git a/api/src/main/java/org/sopt/post/dto/response/PostSaveResponse.java b/api/src/main/java/org/sopt/api/post/dto/response/PostSaveResponse.java similarity index 67% rename from api/src/main/java/org/sopt/post/dto/response/PostSaveResponse.java rename to api/src/main/java/org/sopt/api/post/dto/response/PostSaveResponse.java index 2c3a9bc..b389831 100644 --- a/api/src/main/java/org/sopt/post/dto/response/PostSaveResponse.java +++ b/api/src/main/java/org/sopt/api/post/dto/response/PostSaveResponse.java @@ -1,6 +1,6 @@ -package org.sopt.post.dto.response; +package org.sopt.api.post.dto.response; -import org.sopt.post.domain.Post; +import org.sopt.domain.post.domain.Post; public record PostSaveResponse( Long postId diff --git a/api/src/main/java/org/sopt/post/service/PostService.java b/api/src/main/java/org/sopt/api/post/service/PostService.java similarity index 67% rename from api/src/main/java/org/sopt/post/service/PostService.java rename to api/src/main/java/org/sopt/api/post/service/PostService.java index a0f1872..a44940f 100644 --- a/api/src/main/java/org/sopt/post/service/PostService.java +++ b/api/src/main/java/org/sopt/api/post/service/PostService.java @@ -1,21 +1,27 @@ -package org.sopt.post.service; +package org.sopt.api.post.service; import lombok.RequiredArgsConstructor; -import org.sopt.member.domain.Member; -import org.sopt.member.repository.MemberRepository; -import org.sopt.post.domain.Category; -import org.sopt.post.domain.Post; -import org.sopt.post.dto.request.PostSaveOrUpdateRequest; -import org.sopt.post.dto.response.PostGetResponse; -import org.sopt.post.dto.response.PostSaveResponse; -import org.sopt.post.repository.CategoryRepository; -import org.sopt.post.repository.PostRepository; +import org.sopt.common.error.ConflictException; +import org.sopt.common.error.ErrorStatus; +import org.sopt.domain.member.domain.Member; +import org.sopt.domain.member.repository.MemberRepository; +import org.sopt.domain.post.domain.Category; +import org.sopt.domain.post.domain.Post; +import org.sopt.api.post.dto.request.PostSaveOrUpdateRequest; +import org.sopt.api.post.dto.response.PostGetResponse; +import org.sopt.api.post.dto.response.PostSaveResponse; + +import org.sopt.domain.post.repository.CategoryRepository; +import org.sopt.domain.post.repository.PostRepository; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; +import static org.sopt.domain.post.domain.Category.createCategory; +import static org.sopt.domain.post.domain.Post.createPost; + @RequiredArgsConstructor @Transactional(readOnly = true) @Service @@ -27,6 +33,7 @@ public class PostService { @Transactional public PostSaveResponse savePost(Long memberId, PostSaveOrUpdateRequest postSaveOrUpdateRequest) { Member findMember = findMember(memberId); + validateDuplicateCategory(postSaveOrUpdateRequest.categoryContent()); Category savedCategory = createCategoryAndGetSavedCategory(postSaveOrUpdateRequest); Post savedPost = createPostAndGetSavedPost(postSaveOrUpdateRequest, findMember, savedCategory); return PostSaveResponse.of(savedPost); @@ -60,13 +67,19 @@ private Member findMember(Long memberId) { return memberRepository.findByIdOrThrow(memberId); } + private void validateDuplicateCategory(String content) { + if (categoryRepository.existsByContent(content)) { + throw new ConflictException(ErrorStatus.DUPLICATE_CATEGORY); + } + } + private Category createCategoryAndGetSavedCategory(PostSaveOrUpdateRequest postSaveOrUpdateRequest) { - Category category = Category.createCategory(postSaveOrUpdateRequest.categoryContent()); + Category category = createCategory(postSaveOrUpdateRequest.categoryContent()); return categoryRepository.save(category); } private Post createPostAndGetSavedPost(PostSaveOrUpdateRequest postSaveOrUpdateRequest, Member member, Category category) { - Post post = Post.createPost(postSaveOrUpdateRequest.title(), postSaveOrUpdateRequest.postContent(), category, member); + Post post = createPost(postSaveOrUpdateRequest.title(), postSaveOrUpdateRequest.postContent(), category, member); return postRepository.save(post); } diff --git a/build.gradle b/build.gradle index 039b00d..6803218 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,11 @@ subprojects { useJUnitPlatform() } - jar { + bootJar { enabled = false } + + jar { + enabled = true + } } \ No newline at end of file diff --git a/common/src/main/java/org/sopt/error/BusinessException.java b/common/src/main/java/org/sopt/common/error/BusinessException.java similarity index 90% rename from common/src/main/java/org/sopt/error/BusinessException.java rename to common/src/main/java/org/sopt/common/error/BusinessException.java index 770e4a8..0f2da61 100644 --- a/common/src/main/java/org/sopt/error/BusinessException.java +++ b/common/src/main/java/org/sopt/common/error/BusinessException.java @@ -1,4 +1,4 @@ -package org.sopt.error; +package org.sopt.common.error; import lombok.Getter; diff --git a/common/src/main/java/org/sopt/error/ConflictException.java b/common/src/main/java/org/sopt/common/error/ConflictException.java similarity index 88% rename from common/src/main/java/org/sopt/error/ConflictException.java rename to common/src/main/java/org/sopt/common/error/ConflictException.java index 964e6b1..274160c 100644 --- a/common/src/main/java/org/sopt/error/ConflictException.java +++ b/common/src/main/java/org/sopt/common/error/ConflictException.java @@ -1,4 +1,4 @@ -package org.sopt.error; +package org.sopt.common.error; public class ConflictException extends BusinessException { public ConflictException() { diff --git a/common/src/main/java/org/sopt/error/EntityNotFoundException.java b/common/src/main/java/org/sopt/common/error/EntityNotFoundException.java similarity index 89% rename from common/src/main/java/org/sopt/error/EntityNotFoundException.java rename to common/src/main/java/org/sopt/common/error/EntityNotFoundException.java index 9793f50..5f11799 100644 --- a/common/src/main/java/org/sopt/error/EntityNotFoundException.java +++ b/common/src/main/java/org/sopt/common/error/EntityNotFoundException.java @@ -1,4 +1,4 @@ -package org.sopt.error; +package org.sopt.common.error; public class EntityNotFoundException extends BusinessException { public EntityNotFoundException() { diff --git a/common/src/main/java/org/sopt/error/ErrorStatus.java b/common/src/main/java/org/sopt/common/error/ErrorStatus.java similarity index 90% rename from common/src/main/java/org/sopt/error/ErrorStatus.java rename to common/src/main/java/org/sopt/common/error/ErrorStatus.java index 37083ff..56fa0ac 100644 --- a/common/src/main/java/org/sopt/error/ErrorStatus.java +++ b/common/src/main/java/org/sopt/common/error/ErrorStatus.java @@ -1,4 +1,4 @@ -package org.sopt.error; +package org.sopt.common.error; import lombok.AccessLevel; import lombok.Getter; @@ -30,6 +30,7 @@ public enum ErrorStatus { */ CONFLICT(HttpStatus.CONFLICT, "이미 존재하는 리소스입니다."), DUPLICATE_MEMBER(HttpStatus.CONFLICT, "이미 존재하는 회원입니다."), + DUPLICATE_CATEGORY(HttpStatus.CONFLICT, "이미 존재하는 카테고리입니다."), /** * 500 Internal Server Error diff --git a/common/src/main/java/org/sopt/error/InvalidValueException.java b/common/src/main/java/org/sopt/common/error/InvalidValueException.java similarity index 88% rename from common/src/main/java/org/sopt/error/InvalidValueException.java rename to common/src/main/java/org/sopt/common/error/InvalidValueException.java index ecc8b88..ec7a515 100644 --- a/common/src/main/java/org/sopt/error/InvalidValueException.java +++ b/common/src/main/java/org/sopt/common/error/InvalidValueException.java @@ -1,4 +1,4 @@ -package org.sopt.error; +package org.sopt.common.error; public class InvalidValueException extends BusinessException { public InvalidValueException() { diff --git a/domain/src/main/java/org/sopt/common/BaseTimeEntity.java b/domain/src/main/java/org/sopt/domain/common/BaseTimeEntity.java similarity index 95% rename from domain/src/main/java/org/sopt/common/BaseTimeEntity.java rename to domain/src/main/java/org/sopt/domain/common/BaseTimeEntity.java index 8e5797a..1a8475f 100644 --- a/domain/src/main/java/org/sopt/common/BaseTimeEntity.java +++ b/domain/src/main/java/org/sopt/domain/common/BaseTimeEntity.java @@ -1,4 +1,4 @@ -package org.sopt.common; +package org.sopt.domain.common; import jakarta.persistence.Column; import jakarta.persistence.EntityListeners; diff --git a/domain/src/main/java/org/sopt/config/JpaConfig.java b/domain/src/main/java/org/sopt/domain/config/JpaConfig.java similarity index 86% rename from domain/src/main/java/org/sopt/config/JpaConfig.java rename to domain/src/main/java/org/sopt/domain/config/JpaConfig.java index e0ea3c1..69facbd 100644 --- a/domain/src/main/java/org/sopt/config/JpaConfig.java +++ b/domain/src/main/java/org/sopt/domain/config/JpaConfig.java @@ -1,4 +1,4 @@ -package org.sopt.config; +package org.sopt.domain.config; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; diff --git a/domain/src/main/java/org/sopt/member/domain/Member.java b/domain/src/main/java/org/sopt/domain/member/domain/Member.java similarity index 90% rename from domain/src/main/java/org/sopt/member/domain/Member.java rename to domain/src/main/java/org/sopt/domain/member/domain/Member.java index a645dcd..e2d767c 100644 --- a/domain/src/main/java/org/sopt/member/domain/Member.java +++ b/domain/src/main/java/org/sopt/domain/member/domain/Member.java @@ -1,10 +1,10 @@ -package org.sopt.member.domain; +package org.sopt.domain.member.domain; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.DynamicUpdate; -import org.sopt.common.BaseTimeEntity; -import org.sopt.post.domain.Post; +import org.sopt.domain.common.BaseTimeEntity; +import org.sopt.domain.post.domain.Post; import java.util.ArrayList; import java.util.List; diff --git a/domain/src/main/java/org/sopt/member/domain/Part.java b/domain/src/main/java/org/sopt/domain/member/domain/Part.java similarity index 88% rename from domain/src/main/java/org/sopt/member/domain/Part.java rename to domain/src/main/java/org/sopt/domain/member/domain/Part.java index fbec7c5..9ad1a88 100644 --- a/domain/src/main/java/org/sopt/member/domain/Part.java +++ b/domain/src/main/java/org/sopt/domain/member/domain/Part.java @@ -1,4 +1,4 @@ -package org.sopt.member.domain; +package org.sopt.domain.member.domain; import lombok.AccessLevel; import lombok.Getter; diff --git a/domain/src/main/java/org/sopt/member/domain/Sopt.java b/domain/src/main/java/org/sopt/domain/member/domain/Sopt.java similarity index 93% rename from domain/src/main/java/org/sopt/member/domain/Sopt.java rename to domain/src/main/java/org/sopt/domain/member/domain/Sopt.java index c737f01..385afc1 100644 --- a/domain/src/main/java/org/sopt/member/domain/Sopt.java +++ b/domain/src/main/java/org/sopt/domain/member/domain/Sopt.java @@ -1,4 +1,4 @@ -package org.sopt.member.domain; +package org.sopt.domain.member.domain; import jakarta.persistence.Embeddable; import jakarta.persistence.EnumType; diff --git a/domain/src/main/java/org/sopt/member/repository/MemberRepository.java b/domain/src/main/java/org/sopt/domain/member/repository/MemberRepository.java similarity index 66% rename from domain/src/main/java/org/sopt/member/repository/MemberRepository.java rename to domain/src/main/java/org/sopt/domain/member/repository/MemberRepository.java index e727293..551173c 100644 --- a/domain/src/main/java/org/sopt/member/repository/MemberRepository.java +++ b/domain/src/main/java/org/sopt/domain/member/repository/MemberRepository.java @@ -1,8 +1,8 @@ -package org.sopt.member.repository; +package org.sopt.domain.member.repository; -import org.sopt.error.EntityNotFoundException; -import org.sopt.error.ErrorStatus; -import org.sopt.member.domain.Member; +import org.sopt.common.error.EntityNotFoundException; +import org.sopt.common.error.ErrorStatus; +import org.sopt.domain.member.domain.Member; import org.springframework.data.jpa.repository.JpaRepository; public interface MemberRepository extends JpaRepository { diff --git a/domain/src/main/java/org/sopt/post/domain/Category.java b/domain/src/main/java/org/sopt/domain/post/domain/Category.java similarity index 83% rename from domain/src/main/java/org/sopt/post/domain/Category.java rename to domain/src/main/java/org/sopt/domain/post/domain/Category.java index 65d2668..a0c537e 100644 --- a/domain/src/main/java/org/sopt/post/domain/Category.java +++ b/domain/src/main/java/org/sopt/domain/post/domain/Category.java @@ -1,8 +1,8 @@ -package org.sopt.post.domain; +package org.sopt.domain.post.domain; import jakarta.persistence.*; import lombok.*; -import org.sopt.common.BaseTimeEntity; +import org.sopt.domain.common.BaseTimeEntity; import java.util.ArrayList; import java.util.List; @@ -14,11 +14,11 @@ @Entity public class Category extends BaseTimeEntity { @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "category_id") private Short id; private String content; - @OneToMany + @OneToMany(mappedBy = "category") @Builder.Default private List posts = new ArrayList<>(); diff --git a/domain/src/main/java/org/sopt/post/domain/Post.java b/domain/src/main/java/org/sopt/domain/post/domain/Post.java similarity index 92% rename from domain/src/main/java/org/sopt/post/domain/Post.java rename to domain/src/main/java/org/sopt/domain/post/domain/Post.java index c8ffbff..169c184 100644 --- a/domain/src/main/java/org/sopt/post/domain/Post.java +++ b/domain/src/main/java/org/sopt/domain/post/domain/Post.java @@ -1,9 +1,9 @@ -package org.sopt.post.domain; +package org.sopt.domain.post.domain; import jakarta.persistence.*; import lombok.*; -import org.sopt.common.BaseTimeEntity; -import org.sopt.member.domain.Member; +import org.sopt.domain.common.BaseTimeEntity; +import org.sopt.domain.member.domain.Member; @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) diff --git a/domain/src/main/java/org/sopt/post/repository/CategoryRepository.java b/domain/src/main/java/org/sopt/domain/post/repository/CategoryRepository.java similarity index 52% rename from domain/src/main/java/org/sopt/post/repository/CategoryRepository.java rename to domain/src/main/java/org/sopt/domain/post/repository/CategoryRepository.java index 906e5c8..0909379 100644 --- a/domain/src/main/java/org/sopt/post/repository/CategoryRepository.java +++ b/domain/src/main/java/org/sopt/domain/post/repository/CategoryRepository.java @@ -1,7 +1,8 @@ -package org.sopt.post.repository; +package org.sopt.domain.post.repository; -import org.sopt.post.domain.Category; +import org.sopt.domain.post.domain.Category; import org.springframework.data.jpa.repository.JpaRepository; public interface CategoryRepository extends JpaRepository { + boolean existsByContent(String content); } diff --git a/domain/src/main/java/org/sopt/post/repository/PostRepository.java b/domain/src/main/java/org/sopt/domain/post/repository/PostRepository.java similarity index 72% rename from domain/src/main/java/org/sopt/post/repository/PostRepository.java rename to domain/src/main/java/org/sopt/domain/post/repository/PostRepository.java index c753f8b..5e442db 100644 --- a/domain/src/main/java/org/sopt/post/repository/PostRepository.java +++ b/domain/src/main/java/org/sopt/domain/post/repository/PostRepository.java @@ -1,8 +1,8 @@ -package org.sopt.post.repository; +package org.sopt.domain.post.repository; -import org.sopt.error.EntityNotFoundException; -import org.sopt.error.ErrorStatus; -import org.sopt.post.domain.Post; +import org.sopt.common.error.EntityNotFoundException; +import org.sopt.common.error.ErrorStatus; +import org.sopt.domain.post.domain.Post; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; From 0e069b5891e6bd77cd0991dd59f974d7477085d4 Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 19:00:47 +0900 Subject: [PATCH 16/18] =?UTF-8?q?[chore]=20#5=20bootJar=20&=20jar=20?= =?UTF-8?q?=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/build.gradle | 4 ++++ build.gradle | 8 -------- common/build.gradle | 8 ++++++++ domain/build.gradle | 8 ++++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index 142a570..3bd0525 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -9,4 +9,8 @@ dependencies { implementation project(path: ':domain') // common dependency implementation project(path: ':common') +} + +jar { + enabled = false } \ No newline at end of file diff --git a/build.gradle b/build.gradle index 6803218..514a72f 100644 --- a/build.gradle +++ b/build.gradle @@ -37,12 +37,4 @@ subprojects { tasks.named('test') { useJUnitPlatform() } - - bootJar { - enabled = false - } - - jar { - enabled = true - } } \ No newline at end of file diff --git a/common/build.gradle b/common/build.gradle index a912983..7d81676 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,4 +1,12 @@ dependencies { // spring boot web implementation 'org.springframework.boot:spring-boot-starter-web' +} + +bootJar { + enabled = false +} + +jar { + enabled = true } \ No newline at end of file diff --git a/domain/build.gradle b/domain/build.gradle index 42eb8c6..4b3bd02 100644 --- a/domain/build.gradle +++ b/domain/build.gradle @@ -5,4 +5,12 @@ dependencies { runtimeOnly 'com.h2database:h2' // common dependency implementation project(path: ':common') +} + +bootJar { + enabled = false +} + +jar { + enabled = true } \ No newline at end of file From f914b0559bc92b1ac1e5c102b5d3a5cf3b34bfbd Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 19:22:41 +0900 Subject: [PATCH 17/18] =?UTF-8?q?[feat]=20#5=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=A4=91=EB=B3=B5=20=EC=A0=80=EC=9E=A5=20=EB=B0=A9?= =?UTF-8?q?=EC=A7=80=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/api/post/service/PostService.java | 31 +++++++++---------- .../org/sopt/common/error/ErrorStatus.java | 2 +- .../post/repository/CategoryRepository.java | 11 ++++++- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/api/src/main/java/org/sopt/api/post/service/PostService.java b/api/src/main/java/org/sopt/api/post/service/PostService.java index a44940f..0b4ba2d 100644 --- a/api/src/main/java/org/sopt/api/post/service/PostService.java +++ b/api/src/main/java/org/sopt/api/post/service/PostService.java @@ -1,16 +1,14 @@ package org.sopt.api.post.service; import lombok.RequiredArgsConstructor; -import org.sopt.common.error.ConflictException; -import org.sopt.common.error.ErrorStatus; +import org.sopt.api.post.dto.request.PostSaveOrUpdateRequest; +import org.sopt.api.post.dto.response.PostGetResponse; +import org.sopt.api.post.dto.response.PostSaveResponse; +import org.sopt.common.error.EntityNotFoundException; import org.sopt.domain.member.domain.Member; import org.sopt.domain.member.repository.MemberRepository; import org.sopt.domain.post.domain.Category; import org.sopt.domain.post.domain.Post; -import org.sopt.api.post.dto.request.PostSaveOrUpdateRequest; -import org.sopt.api.post.dto.response.PostGetResponse; -import org.sopt.api.post.dto.response.PostSaveResponse; - import org.sopt.domain.post.repository.CategoryRepository; import org.sopt.domain.post.repository.PostRepository; import org.springframework.data.domain.Pageable; @@ -33,8 +31,7 @@ public class PostService { @Transactional public PostSaveResponse savePost(Long memberId, PostSaveOrUpdateRequest postSaveOrUpdateRequest) { Member findMember = findMember(memberId); - validateDuplicateCategory(postSaveOrUpdateRequest.categoryContent()); - Category savedCategory = createCategoryAndGetSavedCategory(postSaveOrUpdateRequest); + Category savedCategory = createCategoryAndGetSavedCategoryOrGetCategory(postSaveOrUpdateRequest); Post savedPost = createPostAndGetSavedPost(postSaveOrUpdateRequest, findMember, savedCategory); return PostSaveResponse.of(savedPost); } @@ -67,17 +64,15 @@ private Member findMember(Long memberId) { return memberRepository.findByIdOrThrow(memberId); } - private void validateDuplicateCategory(String content) { - if (categoryRepository.existsByContent(content)) { - throw new ConflictException(ErrorStatus.DUPLICATE_CATEGORY); + private Category createCategoryAndGetSavedCategoryOrGetCategory(PostSaveOrUpdateRequest postSaveOrUpdateRequest) { + try { + return findCategory(postSaveOrUpdateRequest.categoryContent()); + } catch (EntityNotFoundException e) { + Category category = createCategory(postSaveOrUpdateRequest.categoryContent()); + return categoryRepository.save(category); } } - private Category createCategoryAndGetSavedCategory(PostSaveOrUpdateRequest postSaveOrUpdateRequest) { - Category category = createCategory(postSaveOrUpdateRequest.categoryContent()); - return categoryRepository.save(category); - } - private Post createPostAndGetSavedPost(PostSaveOrUpdateRequest postSaveOrUpdateRequest, Member member, Category category) { Post post = createPost(postSaveOrUpdateRequest.title(), postSaveOrUpdateRequest.postContent(), category, member); return postRepository.save(post); @@ -91,4 +86,8 @@ private void updatePostAndCategory(PostSaveOrUpdateRequest postSaveOrUpdateReque post.updateTitleAndContent(postSaveOrUpdateRequest.title(), postSaveOrUpdateRequest.postContent()); category.updateContent(postSaveOrUpdateRequest.categoryContent()); } + + private Category findCategory(String content) { + return categoryRepository.findByContentOrThrow(content); + } } diff --git a/common/src/main/java/org/sopt/common/error/ErrorStatus.java b/common/src/main/java/org/sopt/common/error/ErrorStatus.java index 56fa0ac..b99f12f 100644 --- a/common/src/main/java/org/sopt/common/error/ErrorStatus.java +++ b/common/src/main/java/org/sopt/common/error/ErrorStatus.java @@ -19,6 +19,7 @@ public enum ErrorStatus { ENTITY_NOT_FOUND(HttpStatus.NOT_FOUND, "대상을 찾을 수 없습니다."), MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "회원을 찾을 수 없습니다."), POST_NOT_FOUND(HttpStatus.NOT_FOUND, "게시물을 찾을 수 없습니다."), + CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, "카테고리를 찾을 수 없습니다."), /** * 405 Method Not Allowed @@ -30,7 +31,6 @@ public enum ErrorStatus { */ CONFLICT(HttpStatus.CONFLICT, "이미 존재하는 리소스입니다."), DUPLICATE_MEMBER(HttpStatus.CONFLICT, "이미 존재하는 회원입니다."), - DUPLICATE_CATEGORY(HttpStatus.CONFLICT, "이미 존재하는 카테고리입니다."), /** * 500 Internal Server Error diff --git a/domain/src/main/java/org/sopt/domain/post/repository/CategoryRepository.java b/domain/src/main/java/org/sopt/domain/post/repository/CategoryRepository.java index 0909379..7c53e57 100644 --- a/domain/src/main/java/org/sopt/domain/post/repository/CategoryRepository.java +++ b/domain/src/main/java/org/sopt/domain/post/repository/CategoryRepository.java @@ -1,8 +1,17 @@ package org.sopt.domain.post.repository; +import org.sopt.common.error.EntityNotFoundException; +import org.sopt.common.error.ErrorStatus; import org.sopt.domain.post.domain.Category; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface CategoryRepository extends JpaRepository { - boolean existsByContent(String content); + Optional findByContent(String content); + + default Category findByContentOrThrow(String content) { + return findByContent(content) + .orElseThrow(() -> new EntityNotFoundException(ErrorStatus.CATEGORY_NOT_FOUND)); + } } From b4b817c6f548f04b7c069f2667213f128c93ae20 Mon Sep 17 00:00:00 2001 From: sunwoong Date: Thu, 9 Nov 2023 19:40:02 +0900 Subject: [PATCH 18/18] =?UTF-8?q?[refactor]=20#5=20static=20import=20?= =?UTF-8?q?=ED=99=9C=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/sopt/api/member/service/MemberService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/org/sopt/api/member/service/MemberService.java b/api/src/main/java/org/sopt/api/member/service/MemberService.java index 9819cb8..e8531b3 100644 --- a/api/src/main/java/org/sopt/api/member/service/MemberService.java +++ b/api/src/main/java/org/sopt/api/member/service/MemberService.java @@ -17,6 +17,7 @@ import java.util.List; import static org.sopt.domain.member.domain.Member.createMember; +import static org.sopt.domain.member.domain.Sopt.createSopt; @RequiredArgsConstructor @Transactional(readOnly = true) @@ -48,7 +49,7 @@ public List getMembers(Pageable pageable) { @Transactional public void updateMember(Long memberId, MemberUpdateRequest memberUpdateRequest) { Member findMember = memberRepository.findByIdOrThrow(memberId); - Sopt sopt = Sopt.createSopt(memberUpdateRequest.generation(), memberUpdateRequest.part()); + Sopt sopt = createSopt(memberUpdateRequest.generation(), memberUpdateRequest.part()); findMember.updateSopt(sopt); }