From b2dd6b1a9467361c81f55c84850c48a4e3984604 Mon Sep 17 00:00:00 2001 From: JaeWon Lee Date: Thu, 11 Apr 2024 21:41:43 +0900 Subject: [PATCH 01/10] =?UTF-8?q?[feat]=20develop=EC=97=90=201=EC=B0=A8=20?= =?UTF-8?q?=EB=B3=91=ED=95=A9=20=ED=9B=84=20=EB=8B=A4=EC=8B=9C=20=EC=83=88?= =?UTF-8?q?=EB=A1=9C=EC=9A=B4=20post=20=EB=B8=8C=EB=9E=9C=EC=B9=98=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=ED=9B=84=20=EC=8B=9C=EC=9E=91=20=EC=A7=80?= =?UTF-8?q?=EC=A0=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/command/aggregate/Post.java | 12 +- .../command/controller/PostController.java | 2 +- .../post/command/dto/MyPostListDTO.java | 9 +- .../command/dto/PostListByCategoryDTO.java | 18 +++ .../command/repository/PostRepository.java | 4 + .../post/command/service/PostServiceImpl.java | 2 +- .../command/service/PostServiceImpl_old.java | 109 ------------------ .../vo/ResponsePostListByCategory.java | 4 + 8 files changed, 33 insertions(+), 127 deletions(-) create mode 100644 OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/PostListByCategoryDTO.java delete mode 100644 OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/service/PostServiceImpl_old.java create mode 100644 OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/ResponsePostListByCategory.java diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Post.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Post.java index e6679f1..3215f66 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Post.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Post.java @@ -3,20 +3,18 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.*; import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.UpdateTimestamp; import java.time.LocalDateTime; -@Entity +@NoArgsConstructor @AllArgsConstructor @Getter @Setter @ToString +@Entity @Table(name = "post") public class Post { @@ -70,8 +68,4 @@ public void increaseHits() { public void markAsDeleted() { this.isDeleted = true; } - - public Post() { - } - } diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/controller/PostController.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/controller/PostController.java index 805602f..b850937 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/controller/PostController.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/controller/PostController.java @@ -89,7 +89,7 @@ public ResponseEntity removePost(@PathVariable Integer postId) { public ResponseEntity viewMyPosts(@PathVariable String memberId) { logger.info("나의 게시글 리스트 요청: 맴버 ID {}", memberId); List myPosts = postService.viewMyPosts(memberId); - logger.info("나의 게시물 리스트 조회 완료 {}", memberId); + logger.info("나의 게시물 리스트 조회 완료 {}", myPosts); ResponseMyPostList myPostList = new ResponseMyPostList(myPosts); return ResponseEntity.ok(myPostList); diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/MyPostListDTO.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/MyPostListDTO.java index ccd670a..1211183 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/MyPostListDTO.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/MyPostListDTO.java @@ -1,13 +1,11 @@ package org.omoknoone.onionhotsayyo.post.command.dto; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.*; import java.io.Serializable; import java.time.LocalDateTime; +@NoArgsConstructor @AllArgsConstructor @Getter @Setter @@ -20,7 +18,4 @@ public class MyPostListDTO implements Serializable { private int hits; private String categoryId; private String location; - - public MyPostListDTO() { - } } \ No newline at end of file diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/PostListByCategoryDTO.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/PostListByCategoryDTO.java new file mode 100644 index 0000000..a57a7ae --- /dev/null +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/PostListByCategoryDTO.java @@ -0,0 +1,18 @@ +package org.omoknoone.onionhotsayyo.post.command.dto; + +import lombok.*; + +import java.time.LocalDateTime; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class PostListByCategoryDTO { + + private String categoryName; + private String title; + private LocalDateTime postedDate; + private int hits; +} diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/repository/PostRepository.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/repository/PostRepository.java index e8d4858..53ae858 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/repository/PostRepository.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/repository/PostRepository.java @@ -13,6 +13,10 @@ public interface PostRepository extends JpaRepository { List findByCategoryId(String categoryId); // JPQL + @Query("SELECT new org.omoknoone.onionhotsayyo.post.command.dto.PostWithCategoryNameDTO(p.postId, p.title, p.content, c.categoryName) " + + "FROM Post p JOIN p.category c " + + "WHERE p.memberId = :memberId") + // @Query("SELECT p FROM Post p WHERE p.categoryId = :categoryId AND p.isDeleted = false") // List findActivePostsByCategoryId(@Param("categoryId") String categoryId); diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/service/PostServiceImpl.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/service/PostServiceImpl.java index e5d83f9..fa15872 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/service/PostServiceImpl.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/service/PostServiceImpl.java @@ -24,8 +24,8 @@ public class PostServiceImpl implements PostService { private static final Logger log = LoggerFactory.getLogger(PostServiceImpl.class); - private final PostRepository postRepository; private final ModelMapper modelMapper; + private final PostRepository postRepository; private final MemberService memberService; @Autowired diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/service/PostServiceImpl_old.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/service/PostServiceImpl_old.java deleted file mode 100644 index 1d43467..0000000 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/service/PostServiceImpl_old.java +++ /dev/null @@ -1,109 +0,0 @@ -//package org.omoknoone.onionhotsayyo.post.command.service; -// -//import org.modelmapper.ModelMapper; -//import org.omoknoone.onionhotsayyo.exceptions.BusinessRuleViolationException; -//import org.omoknoone.onionhotsayyo.post.command.aggregate.Location; -//import org.omoknoone.onionhotsayyo.post.command.aggregate.Post; -//import org.omoknoone.onionhotsayyo.post.command.dto.PostFormDTO; -//import org.omoknoone.onionhotsayyo.post.command.repository.LocationRepository; -//import org.omoknoone.onionhotsayyo.post.command.vo.PostDetailVO; -//import org.omoknoone.onionhotsayyo.post.command.vo.PostSummaryVO; -//import org.omoknoone.onionhotsayyo.post.command.repository.PostRepository; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.stereotype.Service; -//import org.springframework.transaction.annotation.Transactional; -// -//import java.util.List; -//import java.util.stream.Collectors; -// -//@Service -//public class PostServiceImpl implements PostService { -// -// private final PostRepository postRepository; -// private final LocationRepository locationRepository; -// private final ModelMapper modelMapper; -// -// @Autowired -// public PostServiceImpl(PostRepository postRepository, LocationRepository locationRepository, ModelMapper modelMapper) { -// this.postRepository = postRepository; -// this.locationRepository = locationRepository; -// this.modelMapper = modelMapper; -// } -// -// @Transactional(readOnly = true) -// @Override -// public List viewPostsByCategory(String categoryId) { -// -// // PostRepository 를 사용하여 특정 카테고리에 속하는 게시물 조회. -// List posts = postRepository.findByCategoryId(categoryId); -// -// // 조회된 Post 엔티티 목록을 PostSummaryVO(게시물 목록)로 반환 -// return posts.stream() -// .map(post -> modelMapper.map(post, PostSummaryVO.class)) -// .collect(Collectors.toList()); -// } -// -// @Transactional(readOnly = true) -// @Override -// public PostDetailVO viewPostById(Integer postId) { -// Post post = postRepository.findById(postId) -// .orElseThrow(() -> -// new BusinessRuleViolationException("게시글 ID " + postId + " 는 존재하지 않습니다!(ㅠ.ㅠ).")); -// -// return modelMapper.map(post, PostDetailVO.class); -// } -// -// @Transactional -// @Override -// public PostFormDTO createPost(PostFormDTO postFormDTO) { -// -// // PostFormDTO에서 Post 엔티티로 변환. Location은 별도로 처리. -// Post post = modelMapper.map(postFormDTO, Post.class); -// -// // 지역 이름으로 Location 엔티티 조회 -// Location location = locationRepository.findByLocation(postFormDTO.getLocation()); -// post.setLocation(location); // Post 엔티티에 Location 설정 -// -// // 작성된 게시글 저장 -// Post savedPost = postRepository.save(post); -// -// // 저장된 Post 엔티티를 PostFormDTO로 변환하여 반환 -// return modelMapper.map(savedPost, PostFormDTO.class); -// } -// -// @Transactional -// @Override -// public PostFormDTO modifyPost(Integer postId, PostFormDTO postFormDTO) { -// Post existingPost = postRepository.findById(postId) -// .orElseThrow(() -> -// new BusinessRuleViolationException("게시글 ID " + postId + "에 해당하는 게시글이 아니군요!.")); -// -// // PostFormDTO에서 제공하는 정보를 기반으로 기존 Post 엔티티 수정 -// existingPost.setTitle(postFormDTO.getTitle()); -// existingPost.setContent(postFormDTO.getContent()); -// existingPost.setCategoryId(postFormDTO.getCategoryId()); -// existingPost.setImage(postFormDTO.getImage()); -// -// // 지역명으로 Location 정보 업데이트 처리 -// Location location = locationRepository.findByLocation(postFormDTO.getLocation()); -// existingPost.setLocation(location); -// -// // 수정된 게시물 저장 -// Post modifiedPost = postRepository.save(existingPost); -// -// // 저장된 Post 엔티티를 PostFormDTO로 변환하여 반환 -// return modelMapper.map(modifiedPost, PostFormDTO.class); -// } -// -// @Transactional -// @Override -// public void removePost(Integer postId) { -// Post post = postRepository.findById(postId) -// .orElseThrow(() -> -// new BusinessRuleViolationException("게시글 ID " + postId + "은 이미 삭제된 게시글입니다.")); -// -// // 게시물을 소프트 삭제 처리 -// post.setDeleted(true); -// postRepository.save(post); -// } -//} diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/ResponsePostListByCategory.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/ResponsePostListByCategory.java new file mode 100644 index 0000000..671a6d3 --- /dev/null +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/ResponsePostListByCategory.java @@ -0,0 +1,4 @@ +package org.omoknoone.onionhotsayyo.post.command.vo; + +public class ResponsePostListByCategory { +} From db8c99f2d2346cc495d57b906ebc04ed2973d38e Mon Sep 17 00:00:00 2001 From: JaewonLee Date: Thu, 11 Apr 2024 23:19:58 +0900 Subject: [PATCH 02/10] =?UTF-8?q?#44=20[refactor]=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=20aggregate=20dto.=20vo=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 수정으로 인해 해당 파일들의 이름이 변경과 삭제가 있었습니다. --- .../{command => }/aggregate/Category.java | 2 +- .../{command => }/aggregate/Language.java | 2 +- .../{command => }/aggregate/Location.java | 2 +- .../post/{command => }/aggregate/Post.java | 4 +- .../post/command/dto/PostFormDTO.java | 65 ------------------- .../post/command/vo/PostSummaryVO.java | 26 -------- .../post/command/vo/RequestMyPostList.java | 21 ------ .../post/command/vo/ResponseMyPostList.java | 25 ------- .../vo/ResponsePostListByCategory.java | 4 -- .../post/{command => }/dto/MyPostListDTO.java | 6 +- .../dto/PostListByCategoryDTO.java | 4 +- .../post/dto/WritePostDetailDTO.java | 18 +++++ .../post/vo/ResponseMyPostList.java | 20 ++++++ .../ResponsePostDetail.java} | 7 +- .../post/vo/ResponsePostListByCategory.java | 20 ++++++ 15 files changed, 71 insertions(+), 155 deletions(-) rename OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/{command => }/aggregate/Category.java (85%) rename OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/{command => }/aggregate/Language.java (79%) rename OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/{command => }/aggregate/Location.java (88%) rename OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/{command => }/aggregate/Post.java (94%) delete mode 100644 OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/PostFormDTO.java delete mode 100644 OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/PostSummaryVO.java delete mode 100644 OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/RequestMyPostList.java delete mode 100644 OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/ResponseMyPostList.java delete mode 100644 OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/ResponsePostListByCategory.java rename OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/{command => }/dto/MyPostListDTO.java (61%) rename OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/{command => }/dto/PostListByCategoryDTO.java (73%) create mode 100644 OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/WritePostDetailDTO.java create mode 100644 OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponseMyPostList.java rename OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/{command/vo/PostDetailVO.java => vo/ResponsePostDetail.java} (81%) create mode 100644 OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponsePostListByCategory.java diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Category.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Category.java similarity index 85% rename from OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Category.java rename to OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Category.java index 0a7db05..5603017 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Category.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Category.java @@ -1,4 +1,4 @@ -package org.omoknoone.onionhotsayyo.post.command.aggregate; +package org.omoknoone.onionhotsayyo.post.aggregate; import jakarta.persistence.*; import lombok.*; diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Language.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Language.java similarity index 79% rename from OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Language.java rename to OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Language.java index 822d4c0..80a10aa 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Language.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Language.java @@ -1,4 +1,4 @@ -package org.omoknoone.onionhotsayyo.post.command.aggregate; +package org.omoknoone.onionhotsayyo.post.aggregate; import jakarta.persistence.*; import lombok.*; diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Location.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Location.java similarity index 88% rename from OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Location.java rename to OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Location.java index 114201f..325f234 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Location.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Location.java @@ -1,4 +1,4 @@ -package org.omoknoone.onionhotsayyo.post.command.aggregate; +package org.omoknoone.onionhotsayyo.post.aggregate; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Post.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Post.java similarity index 94% rename from OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Post.java rename to OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Post.java index 3215f66..7b085cb 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/aggregate/Post.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Post.java @@ -1,4 +1,4 @@ -package org.omoknoone.onionhotsayyo.post.command.aggregate; +package org.omoknoone.onionhotsayyo.post.aggregate; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; @@ -56,7 +56,7 @@ public class Post { @Column(name = "image") private String image; - @JoinColumn(name = "location_id") + @JoinColumn(name = "location") private String location; // 조회수 증가 diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/PostFormDTO.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/PostFormDTO.java deleted file mode 100644 index df3b7f8..0000000 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/PostFormDTO.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.omoknoone.onionhotsayyo.post.command.dto; - -import lombok.*; - - -// 게시글 작성시에 작성자가 직접 입력해야 하는 데이터 -@ToString -public class PostFormDTO { - private String title; - private String content; - private String categoryId; - private String image; - private String location; // Location 엔티티로부터 location을 사용하기 위한 설정 - - public PostFormDTO() { - } - - public PostFormDTO(String title, String content, String categoryId, String image, String location) { - this.title = title; - this.content = content; - this.categoryId = categoryId; - this.image = image; - this.location = location; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public String getCategoryId() { - return categoryId; - } - - public void setCategoryId(String categoryId) { - this.categoryId = categoryId; - } - - public String getImage() { - return image; - } - - public void setImage(String image) { - this.image = image; - } - - public String getLocation() { - return location; - } - - public void setLocation(String location) { - this.location = location; - } -} diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/PostSummaryVO.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/PostSummaryVO.java deleted file mode 100644 index aa70a13..0000000 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/PostSummaryVO.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.omoknoone.onionhotsayyo.post.command.vo; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; -import org.omoknoone.onionhotsayyo.post.command.aggregate.Location; - -import java.time.LocalDateTime; - - -// 게시물의 목록에 포함되어야 하는 데이터 -@NoArgsConstructor -@AllArgsConstructor -@Getter -@ToString -public class PostSummaryVO { - - private int postingId; - private String title; - private LocalDateTime postedDate; - private int hits; - private String categoryId; - private String location; - -} diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/RequestMyPostList.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/RequestMyPostList.java deleted file mode 100644 index 70470e5..0000000 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/RequestMyPostList.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.omoknoone.onionhotsayyo.post.command.vo; - -public class RequestMyPostList { - - private final String memberId; - - public RequestMyPostList(String memberId) { - this.memberId = memberId; - } - - public String getMemberId() { - return memberId; - } - - @Override - public String toString() { - return "RequestMyPosts{" + - "memberId='" + memberId + '\'' + - '}'; - } -} diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/ResponseMyPostList.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/ResponseMyPostList.java deleted file mode 100644 index cdbc573..0000000 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/ResponseMyPostList.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.omoknoone.onionhotsayyo.post.command.vo; - -import org.omoknoone.onionhotsayyo.post.command.dto.MyPostListDTO; - -import java.util.List; - -public class ResponseMyPostList { - private final List myPosts; - - public ResponseMyPostList(List myPosts) { - this.myPosts = myPosts; - } - - public List getMyPosts() { - return myPosts; - } - - @Override - public String toString() { - return "ResponseMyPosts{" + - "myPosts=" + myPosts + - '}'; - } -} - diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/ResponsePostListByCategory.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/ResponsePostListByCategory.java deleted file mode 100644 index 671a6d3..0000000 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/ResponsePostListByCategory.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.omoknoone.onionhotsayyo.post.command.vo; - -public class ResponsePostListByCategory { -} diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/MyPostListDTO.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/MyPostListDTO.java similarity index 61% rename from OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/MyPostListDTO.java rename to OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/MyPostListDTO.java index 1211183..f3f4dcb 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/MyPostListDTO.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/MyPostListDTO.java @@ -1,4 +1,4 @@ -package org.omoknoone.onionhotsayyo.post.command.dto; +package org.omoknoone.onionhotsayyo.post.dto; import lombok.*; @@ -10,12 +10,10 @@ @Getter @Setter @ToString -public class MyPostListDTO implements Serializable { +public class MyPostListDTO { private Integer postId; private String title; private LocalDateTime postedDate; private int hits; - private String categoryId; - private String location; } \ No newline at end of file diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/PostListByCategoryDTO.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/PostListByCategoryDTO.java similarity index 73% rename from OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/PostListByCategoryDTO.java rename to OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/PostListByCategoryDTO.java index a57a7ae..22cde61 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/dto/PostListByCategoryDTO.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/PostListByCategoryDTO.java @@ -1,4 +1,4 @@ -package org.omoknoone.onionhotsayyo.post.command.dto; +package org.omoknoone.onionhotsayyo.post.dto; import lombok.*; @@ -11,7 +11,7 @@ @ToString public class PostListByCategoryDTO { - private String categoryName; + private String categoryId; private String title; private LocalDateTime postedDate; private int hits; diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/WritePostDetailDTO.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/WritePostDetailDTO.java new file mode 100644 index 0000000..0e10875 --- /dev/null +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/WritePostDetailDTO.java @@ -0,0 +1,18 @@ +package org.omoknoone.onionhotsayyo.post.dto; + +import lombok.*; + + +// 게시글 작성시에 작성자가 직접 입력해야 하는 데이터 +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class WritePostDetailDTO { + private String title; + private String content; + private String categoryId; + private String image; + private String location; // Location 엔티티로부터 location을 사용하기 위한 설정 +} diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponseMyPostList.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponseMyPostList.java new file mode 100644 index 0000000..39f5041 --- /dev/null +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponseMyPostList.java @@ -0,0 +1,20 @@ +package org.omoknoone.onionhotsayyo.post.vo; + +import lombok.Getter; +import lombok.ToString; +import org.omoknoone.onionhotsayyo.post.dto.MyPostListDTO; + +import java.util.List; + +@Getter +@ToString +// 본인이 작성한 게시물 리스트 응답 +public class ResponseMyPostList { + private final List myPosts; + + public ResponseMyPostList(List myPosts) { + this.myPosts = myPosts; + } + +} + diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/PostDetailVO.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponsePostDetail.java similarity index 81% rename from OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/PostDetailVO.java rename to OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponsePostDetail.java index 2381bc8..2892862 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/vo/PostDetailVO.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponsePostDetail.java @@ -1,4 +1,4 @@ -package org.omoknoone.onionhotsayyo.post.command.vo; +package org.omoknoone.onionhotsayyo.post.vo; import lombok.AllArgsConstructor; import lombok.Getter; @@ -7,13 +7,14 @@ import java.time.LocalDateTime; +// 게시물 작성, 수정 시 응답 @NoArgsConstructor @AllArgsConstructor @Getter @ToString -public class PostDetailVO { +public class ResponsePostDetail { - private Integer postingId; + private Integer postId; private String title; private String content; private LocalDateTime postedDate; diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponsePostListByCategory.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponsePostListByCategory.java new file mode 100644 index 0000000..2ba12c9 --- /dev/null +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponsePostListByCategory.java @@ -0,0 +1,20 @@ +package org.omoknoone.onionhotsayyo.post.vo; + +import lombok.*; +import org.omoknoone.onionhotsayyo.post.dto.PostListByCategoryDTO; + +import java.time.LocalDateTime; +import java.util.List; + + +@Getter +@ToString +// 카테고리 별 게시물 리스트 응답 +public class ResponsePostListByCategory { + + private final List categoryPosts; + + public ResponsePostListByCategory(List categoryPosts) { + this.categoryPosts = categoryPosts; + } +} From e090d3e022d17e7c94fc88b1c138508bba8edc75 Mon Sep 17 00:00:00 2001 From: JaewonLee Date: Thu, 11 Apr 2024 23:22:20 +0900 Subject: [PATCH 03/10] =?UTF-8?q?#44=20[refactor]=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=20=EA=B8=B0=EB=8A=A5=EC=97=90=20=ED=8F=AC=ED=95=A8?= =?UTF-8?q?=EB=90=9C=20dto.=20vo=20=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dto, vo의 이름의 수정을 기능에도 반영했습니다 (PostController, PostService, PostServiceImpl, PostRepository). --- .../controller/PostController.java | 48 +++++++------- .../repository/PostRepository.java | 11 ++-- .../{command => }/service/PostService.java | 18 +++--- .../service/PostServiceImpl.java | 62 +++++++++++-------- 4 files changed, 78 insertions(+), 61 deletions(-) rename OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/{command => }/controller/PostController.java (63%) rename OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/{command => }/repository/PostRepository.java (58%) rename OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/{command => }/service/PostService.java (63%) rename OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/{command => }/service/PostServiceImpl.java (67%) diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/controller/PostController.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/controller/PostController.java similarity index 63% rename from OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/controller/PostController.java rename to OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/controller/PostController.java index b850937..727bacb 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/controller/PostController.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/controller/PostController.java @@ -1,11 +1,11 @@ -package org.omoknoone.onionhotsayyo.post.command.controller; - -import org.omoknoone.onionhotsayyo.post.command.dto.MyPostListDTO; -import org.omoknoone.onionhotsayyo.post.command.dto.PostFormDTO; -import org.omoknoone.onionhotsayyo.post.command.service.PostService; -import org.omoknoone.onionhotsayyo.post.command.vo.PostDetailVO; -import org.omoknoone.onionhotsayyo.post.command.vo.PostSummaryVO; -import org.omoknoone.onionhotsayyo.post.command.vo.ResponseMyPostList; +package org.omoknoone.onionhotsayyo.post.controller; + +import org.omoknoone.onionhotsayyo.post.dto.MyPostListDTO; +import org.omoknoone.onionhotsayyo.post.dto.WritePostDetailDTO; +import org.omoknoone.onionhotsayyo.post.service.PostService; +import org.omoknoone.onionhotsayyo.post.vo.ResponsePostDetail; +import org.omoknoone.onionhotsayyo.post.vo.ResponseMyPostList; +import org.omoknoone.onionhotsayyo.post.vo.ResponsePostListByCategory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -30,19 +30,19 @@ public PostController(PostService postService) { // 카테고리별 게시글 목록 조회 @GetMapping("/list/{categoryId}") - public ResponseEntity> viewPostListByCategory(@PathVariable String categoryId) { + public ResponseEntity> viewPostListByCategory(@PathVariable String categoryId) { logger.info("카테고리별 게시글 목록 조회 요청: 카테고리 ID {}", categoryId); - List posts = postService.viewPostsByCategory(categoryId); - logger.info("카테고리 ID {}에 대한 게시글 {}개 발견", categoryId, posts.size()); + List categoryPosts = postService.viewPostsByCategory(categoryId); + logger.info("카테고리 ID {}에 대한 게시글 {}개 발견", categoryId, categoryPosts.size()); - return ResponseEntity.ok(posts); + return ResponseEntity.ok(categoryPosts); } // 게시글 상세 조회 @GetMapping("/view/{postId}") - public ResponseEntity viewPostById(@PathVariable Integer postId) { + public ResponseEntity viewPostById(@PathVariable Integer postId) { logger.info("게시글 상세 조회 요청: 게시글 ID {}", postId); - PostDetailVO postDetail = postService.viewPostById(postId); + ResponsePostDetail postDetail = postService.viewPostById(postId); if (postDetail == null) { logger.error("게시글 ID {}에 해당하는 게시글을 찾을 수 없음", postId); return ResponseEntity.notFound().build(); @@ -54,24 +54,28 @@ public ResponseEntity viewPostById(@PathVariable Integer postId) { // 게시글 작성 @PostMapping("/create") - public ResponseEntity createPost(@RequestBody PostFormDTO postFormDTO) { - logger.info("새 게시글 작성 요청: 제목 {}", postFormDTO.getTitle()); - PostFormDTO createdPost = postService.createPost(postFormDTO); - logger.info("게시글 생성 완료: 게시글 ID {}", createdPost.getTitle()); + public ResponseEntity createPost(@RequestBody WritePostDetailDTO writePostDetailDTO) { + logger.info("새 게시글 작성 요청: 제목 {}", writePostDetailDTO.getTitle()); - return new ResponseEntity<>(createdPost, HttpStatus.CREATED); + ResponsePostDetail response = postService.createPost(writePostDetailDTO); + logger.info("게시글 생성 완료: 게시글 ID {}", response.getPostId()); + + return new ResponseEntity<>(response, HttpStatus.CREATED); } // 게시글 수정 @PutMapping("/modify/{postId}") - public ResponseEntity modifyPost(@PathVariable Integer postId, @RequestBody PostFormDTO postFormDTO) { + public ResponseEntity modifyPost(@PathVariable Integer postId, + @RequestBody WritePostDetailDTO writePostDetailDTO) { logger.info("게시글 수정 요청: 게시글 ID {}", postId); - PostFormDTO updatedPost = postService.modifyPost(postId, postFormDTO); + + ResponsePostDetail updatedPost = postService.modifyPost(postId, writePostDetailDTO); if (updatedPost == null) { logger.error("게시글 ID {}를 찾을 수 없어 수정 불가", postId); return ResponseEntity.notFound().build(); } logger.info("게시글 ID {} 수정 완료", postId); + return ResponseEntity.ok(updatedPost); } @@ -79,8 +83,10 @@ public ResponseEntity modifyPost(@PathVariable Integer postId, @Req @DeleteMapping("/remove/{postId}") public ResponseEntity removePost(@PathVariable Integer postId) { logger.info("게시글 삭제 요청: 게시글 ID {}", postId); + postService.removePost(postId); logger.info("게시글 ID {} 삭제 완료", postId); + return ResponseEntity.noContent().build(); } diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/repository/PostRepository.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/repository/PostRepository.java similarity index 58% rename from OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/repository/PostRepository.java rename to OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/repository/PostRepository.java index 53ae858..52654e4 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/repository/PostRepository.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/repository/PostRepository.java @@ -1,9 +1,8 @@ -package org.omoknoone.onionhotsayyo.post.command.repository; +package org.omoknoone.onionhotsayyo.post.repository; -import org.omoknoone.onionhotsayyo.post.command.aggregate.Post; +import org.omoknoone.onionhotsayyo.post.aggregate.Post; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; import java.util.List; @@ -13,9 +12,9 @@ public interface PostRepository extends JpaRepository { List findByCategoryId(String categoryId); // JPQL - @Query("SELECT new org.omoknoone.onionhotsayyo.post.command.dto.PostWithCategoryNameDTO(p.postId, p.title, p.content, c.categoryName) " + - "FROM Post p JOIN p.category c " + - "WHERE p.memberId = :memberId") +// @Query("SELECT new org.omoknoone.onionhotsayyo.post.command.dto.PostWithCategoryNameDTO(p.postId, p.title, p.content, c.categoryName) " + +// "FROM Post p JOIN p.category c " + +// "WHERE p.memberId = :memberId") // @Query("SELECT p FROM Post p WHERE p.categoryId = :categoryId AND p.isDeleted = false") // List findActivePostsByCategoryId(@Param("categoryId") String categoryId); diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/service/PostService.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/service/PostService.java similarity index 63% rename from OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/service/PostService.java rename to OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/service/PostService.java index b1014b4..6500801 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/service/PostService.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/service/PostService.java @@ -1,25 +1,25 @@ -package org.omoknoone.onionhotsayyo.post.command.service; +package org.omoknoone.onionhotsayyo.post.service; -import org.omoknoone.onionhotsayyo.post.command.dto.MyPostListDTO; -import org.omoknoone.onionhotsayyo.post.command.dto.PostFormDTO; -import org.omoknoone.onionhotsayyo.post.command.vo.PostDetailVO; -import org.omoknoone.onionhotsayyo.post.command.vo.PostSummaryVO; +import org.omoknoone.onionhotsayyo.post.dto.MyPostListDTO; +import org.omoknoone.onionhotsayyo.post.dto.WritePostDetailDTO; +import org.omoknoone.onionhotsayyo.post.vo.ResponsePostDetail; +import org.omoknoone.onionhotsayyo.post.vo.ResponsePostListByCategory; import java.util.List; public interface PostService { // 카테고리별 게시글 목록 조회 - List viewPostsByCategory(String categoryId); + List viewPostsByCategory(String categoryId); // 게시글 상세 조회 - PostDetailVO viewPostById(Integer postId); + ResponsePostDetail viewPostById(Integer postId); // 게시글 작성 - PostFormDTO createPost(PostFormDTO postFormDTO); + ResponsePostDetail createPost(WritePostDetailDTO writePostDetailDTO); // 게시글 수정 - PostFormDTO modifyPost(Integer postId, PostFormDTO postFormDTO); + ResponsePostDetail modifyPost(Integer postId, WritePostDetailDTO writePostDetailDTO); // 게시글 삭제 void removePost(Integer postId); diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/service/PostServiceImpl.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/service/PostServiceImpl.java similarity index 67% rename from OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/service/PostServiceImpl.java rename to OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/service/PostServiceImpl.java index fa15872..adb5b07 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/command/service/PostServiceImpl.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/service/PostServiceImpl.java @@ -1,15 +1,15 @@ -package org.omoknoone.onionhotsayyo.post.command.service; +package org.omoknoone.onionhotsayyo.post.service; import org.modelmapper.ModelMapper; import org.omoknoone.onionhotsayyo.exceptions.PostNotFoundException; import org.omoknoone.onionhotsayyo.member.dto.MemberDTO; import org.omoknoone.onionhotsayyo.member.service.MemberService; -import org.omoknoone.onionhotsayyo.post.command.aggregate.Post; -import org.omoknoone.onionhotsayyo.post.command.dto.MyPostListDTO; -import org.omoknoone.onionhotsayyo.post.command.dto.PostFormDTO; -import org.omoknoone.onionhotsayyo.post.command.repository.PostRepository; -import org.omoknoone.onionhotsayyo.post.command.vo.PostDetailVO; -import org.omoknoone.onionhotsayyo.post.command.vo.PostSummaryVO; +import org.omoknoone.onionhotsayyo.post.aggregate.Post; +import org.omoknoone.onionhotsayyo.post.dto.MyPostListDTO; +import org.omoknoone.onionhotsayyo.post.dto.WritePostDetailDTO; +import org.omoknoone.onionhotsayyo.post.repository.PostRepository; +import org.omoknoone.onionhotsayyo.post.vo.ResponsePostDetail; +import org.omoknoone.onionhotsayyo.post.vo.ResponsePostListByCategory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -37,55 +37,66 @@ public PostServiceImpl(PostRepository postRepository, ModelMapper modelMapper, M @Transactional(readOnly = true) @Override - public List viewPostsByCategory(String categoryId) { + public List viewPostsByCategory(String categoryId) { log.info("카테고리 ID {}에 해당하는 게시물 목록 조회를 시작합니다.", categoryId); + List posts = postRepository.findByCategoryId(categoryId); - List postSummaryVOList = posts.stream() - .map(post -> modelMapper.map(post, PostSummaryVO.class)) + + List CategoryPostList = posts.stream() + .map(post -> modelMapper.map(post, ResponsePostListByCategory.class)) .collect(Collectors.toList()); - log.info("카테고리 ID {}에 해당하는 게시물 목록 조회를 완료했습니다. 조회된 게시물 수: {}", categoryId, postSummaryVOList.size()); - return postSummaryVOList; + log.info("카테고리 ID {}에 해당하는 게시물 목록 조회를 완료했습니다." + + " 조회된 게시물 수: {}", categoryId, CategoryPostList.size()); + + return CategoryPostList; } @Transactional(readOnly = true) @Override - public PostDetailVO viewPostById(Integer postId) { + public ResponsePostDetail viewPostById(Integer postId) { log.info("게시물 ID {}에 해당하는 게시물 상세 조회를 시작합니다.", postId); - Post post = postRepository.findById(postId).orElseThrow(() -> new PostNotFoundException("게시물 ID를 찾을 수 없습니다: " + postId)); - PostDetailVO postDetailVO = modelMapper.map(post, PostDetailVO.class); + + Post post = postRepository.findById(postId).orElseThrow(() + -> new PostNotFoundException("게시물 ID를 찾을 수 없습니다: " + postId)); + + ResponsePostDetail responsePostDetail = modelMapper.map(post, ResponsePostDetail.class); log.info("게시물 ID {}에 해당하는 게시물 상세 조회를 완료했습니다.", postId); - return postDetailVO; + return responsePostDetail; } @Transactional @Override - public PostFormDTO createPost(PostFormDTO postFormDTO) { - log.info("새 게시물 생성을 시작합니다. 제목: {}", postFormDTO.getTitle()); - Post post = modelMapper.map(postFormDTO, Post.class); - Post savedPost = postRepository.save(post); - log.info("새 게시물이 성공적으로 생성되었습니다. 게시물 ID: {}", savedPost.getPostId()); - return modelMapper.map(savedPost, PostFormDTO.class); + public ResponsePostDetail createPost(WritePostDetailDTO writePostDetailDTO) { + log.info("새 게시물 생성을 시작합니다. 제목: {}", writePostDetailDTO.getTitle()); + + Post post = modelMapper.map(writePostDetailDTO, Post.class); + + Post newPost = postRepository.save(post); + log.info("새 게시물이 성공적으로 생성되었습니다. 게시물 ID: {}", newPost.getPostId()); + + return modelMapper.map(newPost, ResponsePostDetail.class); } @Transactional @Override - public PostFormDTO modifyPost(Integer postId, PostFormDTO postFormDTO) { + public ResponsePostDetail modifyPost(Integer postId, WritePostDetailDTO writePostDetailDTO) { log.info("게시물 ID {} 수정을 시도합니다.", postId); Post post = postRepository.findById(postId) .orElseThrow(() -> new PostNotFoundException("게시물 ID를 찾을 수 없습니다: " + postId)); log.info("게시물 ID {}에 해당하는 게시물을 찾았습니다. 수정을 진행합니다.", postId); - modelMapper.map(postFormDTO, post); + modelMapper.map(writePostDetailDTO, post); Post updatedPost = postRepository.save(post); log.info("게시물 ID {}이(가) 성공적으로 수정되었습니다.", postId); - return modelMapper.map(updatedPost, PostFormDTO.class); + return modelMapper.map(updatedPost, ResponsePostDetail.class); } @Transactional @Override public void removePost(Integer postId) { log.info("게시물 ID {} (소프트)삭제를 시작합니다.", postId); + postRepository.deleteById(postId); log.info("게시물 ID {}이(가) 성공적으로 삭제되었습니다.", postId); } @@ -101,6 +112,7 @@ public List viewMyPosts(String memberId) { List posts = postRepository.findByMemberId(memberId); log.info("맴버 ID {} 확인 되었습니다.", memberId); + return posts.stream() .map(post -> modelMapper.map(post, MyPostListDTO.class)) .collect(Collectors.toList()); From 3bf693e97e8ca2dbdc9be9258df648a725b270bd Mon Sep 17 00:00:00 2001 From: JaewonLee Date: Thu, 11 Apr 2024 23:26:13 +0900 Subject: [PATCH 04/10] =?UTF-8?q?#45=20[remove]=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exceptions/BusinessRuleViolationException.java | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/exceptions/BusinessRuleViolationException.java diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/exceptions/BusinessRuleViolationException.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/exceptions/BusinessRuleViolationException.java deleted file mode 100644 index 8d46fb1..0000000 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/exceptions/BusinessRuleViolationException.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.omoknoone.onionhotsayyo.exceptions; - -public class BusinessRuleViolationException extends RuntimeException { - - public BusinessRuleViolationException(String message) { - super(message); - } -} From 08b2aa72d38fd98b491dc8ff4f6aeccd9abb2d6b Mon Sep 17 00:00:00 2001 From: JaewonLee Date: Thu, 11 Apr 2024 23:26:58 +0900 Subject: [PATCH 05/10] =?UTF-8?q?[feat][test]=20=EC=9E=91=EC=97=85=20?= =?UTF-8?q?=EC=A4=91=EC=9D=B8=20=EC=9D=BC=EB=B6=80=20=EB=B3=80=EB=8F=99=20?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20=EB=A1=9C=EA=B7=B8=20=EA=B8=B0=EB=A1=9D?= =?UTF-8?q?=EC=9A=A9=20=EC=BB=A4=EB=B0=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OnionHotSayYoApplication.java | 13 +- .../exceptions/GlobalExceptionHandler.java | 4 +- .../command/service/PostServiceImplTests.java | 267 +++++++++--------- 3 files changed, 148 insertions(+), 136 deletions(-) diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/OnionHotSayYoApplication.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/OnionHotSayYoApplication.java index 2f135bb..f4e9e18 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/OnionHotSayYoApplication.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/OnionHotSayYoApplication.java @@ -1,6 +1,7 @@ package org.omoknoone.onionhotsayyo; import org.modelmapper.ModelMapper; +import org.modelmapper.config.Configuration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; @@ -13,11 +14,21 @@ public static void main(String[] args) { SpringApplication.run(OnionHotSayYoApplication.class, args); } +// @Bean +// public ModelMapper modelMapper() { +// return new ModelMapper(); +// } @Bean public ModelMapper modelMapper() { - return new ModelMapper(); + ModelMapper modelMapper = new ModelMapper(); + modelMapper.getConfiguration() + .setFieldAccessLevel(Configuration.AccessLevel.PRIVATE) + .setFieldMatchingEnabled(true); + return modelMapper; } @Bean public BCryptPasswordEncoder bCryptPasswordEncoder(){ return new BCryptPasswordEncoder();} } + + diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/exceptions/GlobalExceptionHandler.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/exceptions/GlobalExceptionHandler.java index 6abb6a6..f1145d2 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/exceptions/GlobalExceptionHandler.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/exceptions/GlobalExceptionHandler.java @@ -16,13 +16,13 @@ public class GlobalExceptionHandler { public ResponseEntity handlePostNotFoundException(PostNotFoundException ex) { logger.error("게시물을 찾을 수 없음: {}", ex.getMessage()); return ResponseEntity - .status(HttpStatus.NOT_FOUND).body("요청하신 게시물을 찾을 수 없습니다(유감)."); + .status(HttpStatus.NOT_FOUND).body("요청하신 게시물을 찾을 수 없네요(ㅇㅅㅇ)."); } @ExceptionHandler(Exception.class) public ResponseEntity handleGeneralException(Exception ex) { logger.error("에러 발생: {}", ex.getMessage()); return ResponseEntity - .status(HttpStatus.INTERNAL_SERVER_ERROR).body("서버 내부에서 예상치 못한 에러가 발생했습니다(ㅠ.ㅠ)."); + .status(HttpStatus.INTERNAL_SERVER_ERROR).body("저런ㅋ 서버 내부에서 예상치 못한 에러가 발생했네요(ㅠ.ㅠ)."); } } diff --git a/OnionHotSayYo/src/test/java/org/omoknoone/onionhotsayyo/post/command/service/PostServiceImplTests.java b/OnionHotSayYo/src/test/java/org/omoknoone/onionhotsayyo/post/command/service/PostServiceImplTests.java index 822d3ab..1123721 100644 --- a/OnionHotSayYo/src/test/java/org/omoknoone/onionhotsayyo/post/command/service/PostServiceImplTests.java +++ b/OnionHotSayYo/src/test/java/org/omoknoone/onionhotsayyo/post/command/service/PostServiceImplTests.java @@ -1,150 +1,151 @@ -package org.omoknoone.onionhotsayyo.post.command.service; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.modelmapper.ModelMapper; -import org.omoknoone.onionhotsayyo.post.command.aggregate.Post; -import org.omoknoone.onionhotsayyo.post.command.dto.PostFormDTO; -import org.omoknoone.onionhotsayyo.post.command.repository.PostRepository; -import org.omoknoone.onionhotsayyo.post.command.vo.PostDetailVO; -import org.omoknoone.onionhotsayyo.post.command.vo.PostSummaryVO; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.*; - -@ExtendWith(MockitoExtension.class) -public class PostServiceImplTests { - @Mock - private PostRepository postRepository; - - @Mock - private ModelMapper modelMapper; - - @InjectMocks - private PostServiceImpl postService; - - @Test - void whenViewPostsByCategory_thenReturnsPostSummaryList() { - // Arrange - String categoryId = "testCategory"; - List posts = new ArrayList<>(); - posts.add(new Post()); - when(postRepository.findByCategoryId(categoryId)).thenReturn(posts); - when(modelMapper.map(any(Post.class), eq(PostSummaryVO.class))).thenReturn(new PostSummaryVO()); - - // Act - List result = postService.viewPostsByCategory(categoryId); - - // Assert - assertFalse(result.isEmpty()); - } - - @Test - void whenViewPostById_thenReturnsPostDetail() { - // Arrange - Integer postId = 1; - Post post = new Post(); - when(postRepository.findById(postId)).thenReturn(Optional.of(post)); - when(modelMapper.map(any(Post.class), eq(PostDetailVO.class))).thenReturn(new PostDetailVO()); - - // Act - PostDetailVO result = postService.viewPostById(postId); - - // Assert - assertNotNull(result); - } - - @Test - void whenCreatePost_thenReturnsPostFormDTO() { - // Arrange - PostFormDTO postFormDTO = new PostFormDTO(); - Post post = new Post(); - when(modelMapper.map(any(PostFormDTO.class), eq(Post.class))).thenReturn(post); - when(postRepository.save(any(Post.class))).thenReturn(post); - when(modelMapper.map(any(Post.class), eq(PostFormDTO.class))).thenReturn(postFormDTO); - - // Act - PostFormDTO result = postService.createPost(postFormDTO); - - // Assert - assertNotNull(result); - } - +//package org.omoknoone.onionhotsayyo.post.command.service; +// +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.extension.ExtendWith; +//import org.mockito.InjectMocks; +//import org.mockito.Mock; +//import org.mockito.junit.jupiter.MockitoExtension; +//import org.modelmapper.ModelMapper; +//import org.omoknoone.onionhotsayyo.post.aggregate.Post; +//import org.omoknoone.onionhotsayyo.post.dto.WritePostDetailDTO; +//import org.omoknoone.onionhotsayyo.post.repository.PostRepository; +//import org.omoknoone.onionhotsayyo.post.vo.ResponsePostDetail; +//import org.omoknoone.onionhotsayyo.post.service.PostServiceImpl; +//import org.omoknoone.onionhotsayyo.post.vo.ResponsePostListByCategory; +// +//import java.util.ArrayList; +//import java.util.List; +//import java.util.Optional; +// +//import static org.junit.jupiter.api.Assertions.*; +//import static org.mockito.ArgumentMatchers.any; +//import static org.mockito.ArgumentMatchers.eq; +//import static org.mockito.Mockito.*; +// +//@ExtendWith(MockitoExtension.class) +//public class PostServiceImplTests { +// @Mock +// private PostRepository postRepository; +// +// @Mock +// private ModelMapper modelMapper; +// +// @InjectMocks +// private PostServiceImpl postService; +// // @Test -// void whenModifyPostWithExistingPost_thenReturnsUpdatedPostFormDTO() throws Exception { +// void whenViewPostsByCategory_thenReturnsPostSummaryList() { // // Arrange -// Integer postId = 1; -// PostFormDTO postFormDTO = new PostFormDTO(); -// postFormDTO.setTitle("My Updated Title"); -// Post existingPost = new Post(); // 기존 Post 엔티티 준비 -// Post updatedPost = new Post(); // 업데이트된 Post 엔티티 준비 +// String categoryId = "testCategory"; +// List posts = new ArrayList<>(); +// posts.add(new Post()); +// when(postRepository.findByCategoryId(categoryId)).thenReturn(posts); +// when(modelMapper.map(any(Post.class), eq(ResponsePostListByCategory.class))) +// .thenReturn(new ResponsePostListByCategory()); // -// // 리플렉션을 사용하여 updatedPost 객체의 title 필드 값을 설정합니다. -// setTitleUsingReflection(existingPost, "Original Title"); -// setTitleUsingReflection(updatedPost, "My Updated Title"); +// // Act +// List result = postService.viewPostsByCategory(categoryId); // -// when(postRepository.findById(postId)).thenReturn(Optional.of(existingPost)); +// // Assert +// assertFalse(result.isEmpty()); +// } // -//// ModelMapper 스터빙을 수정하여, 정확한 객체 매핑을 보장합니다. -// when(modelMapper.map(any(PostFormDTO.class), eq(Post.class))).thenAnswer(invocation -> { -// PostFormDTO dto = invocation.getArgument(0); -// Post post = existingPost; // 기존 Post 엔티티를 사용합니다. -// // 리플렉션을 사용하여 Post 객체의 title 필드 값을 설정합니다. -// Field field = Post.class.getDeclaredField("title"); -// field.setAccessible(true); -// field.set(post, dto.getTitle()); // DTO에서 제공된 제목으로 Post 엔티티의 title 필드를 업데이트합니다. -// return post; // 업데이트된 Post 엔티티를 반환합니다. -// }); +// @Test +// void whenViewPostById_thenReturnsPostDetail() { +// // Arrange +// Integer postId = 1; +// Post post = new Post(); +// when(postRepository.findById(postId)).thenReturn(Optional.of(post)); +// when(modelMapper.map(any(Post.class), eq(ResponsePostDetail.class))).thenReturn(new ResponsePostDetail()); // -// when(postRepository.save(any(Post.class))).thenReturn(updatedPost); // 업데이트된 Post 엔티티를 저장하고 반환합니다. +// // Act +// ResponsePostDetail result = postService.viewPostById(postId); // -// when(modelMapper.map(any(Post.class), eq(PostFormDTO.class))).thenReturn(postFormDTO); // Post 엔티티를 PostFormDTO로 매핑합니다. +// // Assert +// assertNotNull(result); +// } // -// when(postRepository.save(any(Post.class))).thenReturn(updatedPost); +// @Test +// void whenCreatePost_thenReturnsPostFormDTO() { +// // Arrange +// WritePostDetailDTO postFormDTO = new WritePostDetailDTO(); +// Post post = new Post(); +// when(modelMapper.map(any(WritePostDetailDTO.class), eq(Post.class))).thenReturn(post); +// when(postRepository.save(any(Post.class))).thenReturn(post); +// when(modelMapper.map(any(Post.class), eq(WritePostDetailDTO.class))).thenReturn(postFormDTO); // // // Act -// PostFormDTO result = postService.modifyPost(postId, postFormDTO); +// ResponsePostDetail result = postService.createPost(postFormDTO); // // // Assert -// assertNotNull(result.getTitle()); // 수정된 PostFormDTO의 제목이 null이 아닌지 확인 -// assertEquals("My Updated Title", result.getTitle()); +// assertNotNull(result); +// } // -// // Verify -// verify(postRepository).findById(postId); -//// verify(modelMapper).map(eq(postFormDTO), eq(Post.class)); // 변경 -// verify(postRepository).save(any(Post.class)); +//// @Test +//// void whenModifyPostWithExistingPost_thenReturnsUpdatedPostFormDTO() throws Exception { +//// // Arrange +//// Integer postId = 1; +//// PostFormDTO postFormDTO = new PostFormDTO(); +//// postFormDTO.setTitle("My Updated Title"); +//// Post existingPost = new Post(); // 기존 Post 엔티티 준비 +//// Post updatedPost = new Post(); // 업데이트된 Post 엔티티 준비 +//// +//// // 리플렉션을 사용하여 updatedPost 객체의 title 필드 값을 설정합니다. +//// setTitleUsingReflection(existingPost, "Original Title"); +//// setTitleUsingReflection(updatedPost, "My Updated Title"); +//// +//// when(postRepository.findById(postId)).thenReturn(Optional.of(existingPost)); +//// +////// ModelMapper 스터빙을 수정하여, 정확한 객체 매핑을 보장합니다. +//// when(modelMapper.map(any(PostFormDTO.class), eq(Post.class))).thenAnswer(invocation -> { +//// PostFormDTO dto = invocation.getArgument(0); +//// Post post = existingPost; // 기존 Post 엔티티를 사용합니다. +//// // 리플렉션을 사용하여 Post 객체의 title 필드 값을 설정합니다. +//// Field field = Post.class.getDeclaredField("title"); +//// field.setAccessible(true); +//// field.set(post, dto.getTitle()); // DTO에서 제공된 제목으로 Post 엔티티의 title 필드를 업데이트합니다. +//// return post; // 업데이트된 Post 엔티티를 반환합니다. +//// }); +//// +//// when(postRepository.save(any(Post.class))).thenReturn(updatedPost); // 업데이트된 Post 엔티티를 저장하고 반환합니다. +//// +//// when(modelMapper.map(any(Post.class), eq(PostFormDTO.class))).thenReturn(postFormDTO); // Post 엔티티를 PostFormDTO로 매핑합니다. +//// +//// when(postRepository.save(any(Post.class))).thenReturn(updatedPost); +//// +//// // Act +//// PostFormDTO result = postService.modifyPost(postId, postFormDTO); +//// +//// // Assert +//// assertNotNull(result.getTitle()); // 수정된 PostFormDTO의 제목이 null이 아닌지 확인 +//// assertEquals("My Updated Title", result.getTitle()); +//// +//// // Verify +//// verify(postRepository).findById(postId); +////// verify(modelMapper).map(eq(postFormDTO), eq(Post.class)); // 변경 +//// verify(postRepository).save(any(Post.class)); +//// +//// } +//// +//// // 헬퍼 메소드: Post 객체의 title 필드에 값을 설정합니다. +//// private void setTitleUsingReflection(Post testPost, String title) +//// throws NoSuchFieldException, IllegalAccessException { +//// Field field = Post.class.getDeclaredField("title"); +//// field.setAccessible(true); +//// field.set(testPost, title); +//// +//// } // -// } +// @Test +// void whenRemovePost_thenPostIsDeleted() { +// // Arrange +// Integer postId = 1; +// doNothing().when(postRepository).deleteById(postId); // -// // 헬퍼 메소드: Post 객체의 title 필드에 값을 설정합니다. -// private void setTitleUsingReflection(Post testPost, String title) -// throws NoSuchFieldException, IllegalAccessException { -// Field field = Post.class.getDeclaredField("title"); -// field.setAccessible(true); -// field.set(testPost, title); +// // Act +// postService.removePost(postId); // +// // Assert +// verify(postRepository).deleteById(postId); // } - - @Test - void whenRemovePost_thenPostIsDeleted() { - // Arrange - Integer postId = 1; - doNothing().when(postRepository).deleteById(postId); - - // Act - postService.removePost(postId); - - // Assert - verify(postRepository).deleteById(postId); - } -} +//} From 0ea1bd6269af2d4e3780dc650aad7eea9a932dd5 Mon Sep 17 00:00:00 2001 From: JaeWon Lee Date: Fri, 12 Apr 2024 12:22:14 +0900 Subject: [PATCH 06/10] =?UTF-8?q?#44=20[refactor]=20postman=EB=A1=9C=20con?= =?UTF-8?q?troller=20=EC=9E=91=EB=8F=99=20=ED=99=95=EC=9D=B8=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4=20default=20=EA=B0=92=EC=9D=84=20=EC=9E=84?= =?UTF-8?q?=EC=9D=98=EB=A1=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onionhotsayyo/post/aggregate/Language.java | 2 +- .../omoknoone/onionhotsayyo/post/aggregate/Post.java | 12 +++++++----- .../post/dto/PostListByCategoryDTO.java | 2 +- .../onionhotsayyo/post/dto/WritePostDetailDTO.java | 3 ++- .../onionhotsayyo/post/vo/ResponsePostDetail.java | 4 ++-- .../post/vo/ResponsePostListByCategory.java | 1 - 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Language.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Language.java index 80a10aa..6498461 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Language.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Language.java @@ -13,5 +13,5 @@ public class Language { @Id @Column(name = "language") - private String language; + private String language = "KO"; } diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Post.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Post.java index 7b085cb..d552acb 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Post.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/aggregate/Post.java @@ -12,7 +12,6 @@ @NoArgsConstructor @AllArgsConstructor @Getter -@Setter @ToString @Entity @Table(name = "post") @@ -48,16 +47,19 @@ public class Post { private boolean isDeleted = false; // 초기 삭제 상태는 false 삭제 되지 않음으로 설정 @JoinColumn(name = "category_id") - private String categoryId; + private Integer categoryId; @JoinColumn(name = "member_id") - private String memberId; + private String memberId = "member1"; @Column(name = "image") private String image; - @JoinColumn(name = "location") - private String location; + @JoinColumn(name = "language") + private String language = "KO"; // 초기 상태 한국어로 설정 + + @JoinColumn(name = "location_id") + private String locationId; // 조회수 증가 public void increaseHits() { diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/PostListByCategoryDTO.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/PostListByCategoryDTO.java index 22cde61..4105314 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/PostListByCategoryDTO.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/PostListByCategoryDTO.java @@ -11,7 +11,7 @@ @ToString public class PostListByCategoryDTO { - private String categoryId; + private Integer categoryId; private String title; private LocalDateTime postedDate; private int hits; diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/WritePostDetailDTO.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/WritePostDetailDTO.java index 0e10875..da97f62 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/WritePostDetailDTO.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/dto/WritePostDetailDTO.java @@ -14,5 +14,6 @@ public class WritePostDetailDTO { private String content; private String categoryId; private String image; - private String location; // Location 엔티티로부터 location을 사용하기 위한 설정 + private String locationId; +// private String location; // Location 엔티티로부터 location을 사용하기 위한 설정 } diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponsePostDetail.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponsePostDetail.java index 2892862..0b2d847 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponsePostDetail.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponsePostDetail.java @@ -21,8 +21,8 @@ public class ResponsePostDetail { private int hits = 0; // 초기 조회수는 0으로 설정됨 private LocalDateTime lastModifiedDate; private boolean isDeleted = false; // 초기 삭제 상태는 false 삭제 되지 않음으로 설정 - private String categoryId; + private Integer categoryId; private String memberId; private String image; - private String location; + private String locationId; } diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponsePostListByCategory.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponsePostListByCategory.java index 2ba12c9..db2070a 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponsePostListByCategory.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/vo/ResponsePostListByCategory.java @@ -3,7 +3,6 @@ import lombok.*; import org.omoknoone.onionhotsayyo.post.dto.PostListByCategoryDTO; -import java.time.LocalDateTime; import java.util.List; From b9b11a10311e5749bbb76179717174711271d914 Mon Sep 17 00:00:00 2001 From: JaeWon Lee Date: Fri, 12 Apr 2024 12:29:07 +0900 Subject: [PATCH 07/10] =?UTF-8?q?#24=20#46=20[test]=20postman=20=ED=99=9C?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EC=97=AC=20=EA=B5=AC=ED=98=84=EB=90=9C=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=9E=91=EB=8F=99=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onionhotsayyo/OnionHotSayYoApplication.java | 4 ---- .../post/controller/PostController.java | 14 ++++++++++---- .../post/repository/PostRepository.java | 2 +- .../onionhotsayyo/post/service/PostService.java | 3 ++- .../post/service/PostServiceImpl.java | 9 ++++++--- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/OnionHotSayYoApplication.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/OnionHotSayYoApplication.java index f4e9e18..6d7f317 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/OnionHotSayYoApplication.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/OnionHotSayYoApplication.java @@ -14,10 +14,6 @@ public static void main(String[] args) { SpringApplication.run(OnionHotSayYoApplication.class, args); } -// @Bean -// public ModelMapper modelMapper() { -// return new ModelMapper(); -// } @Bean public ModelMapper modelMapper() { ModelMapper modelMapper = new ModelMapper(); diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/controller/PostController.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/controller/PostController.java index 727bacb..327dda6 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/controller/PostController.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/controller/PostController.java @@ -1,6 +1,7 @@ package org.omoknoone.onionhotsayyo.post.controller; import org.omoknoone.onionhotsayyo.post.dto.MyPostListDTO; +import org.omoknoone.onionhotsayyo.post.dto.PostListByCategoryDTO; import org.omoknoone.onionhotsayyo.post.dto.WritePostDetailDTO; import org.omoknoone.onionhotsayyo.post.service.PostService; import org.omoknoone.onionhotsayyo.post.vo.ResponsePostDetail; @@ -30,12 +31,15 @@ public PostController(PostService postService) { // 카테고리별 게시글 목록 조회 @GetMapping("/list/{categoryId}") - public ResponseEntity> viewPostListByCategory(@PathVariable String categoryId) { + public ResponseEntity viewPostListByCategory(@PathVariable Integer categoryId) { logger.info("카테고리별 게시글 목록 조회 요청: 카테고리 ID {}", categoryId); - List categoryPosts = postService.viewPostsByCategory(categoryId); + + List categoryPosts = postService.viewPostsByCategory(categoryId); + logger.info("카테고리 ID {}에 대한 게시글 {}개 발견", categoryId, categoryPosts.size()); + ResponsePostListByCategory myPostList = new ResponsePostListByCategory(categoryPosts); - return ResponseEntity.ok(categoryPosts); + return ResponseEntity.ok(myPostList); } // 게시글 상세 조회 @@ -55,7 +59,7 @@ public ResponseEntity viewPostById(@PathVariable Integer pos // 게시글 작성 @PostMapping("/create") public ResponseEntity createPost(@RequestBody WritePostDetailDTO writePostDetailDTO) { - logger.info("새 게시글 작성 요청: 제목 {}", writePostDetailDTO.getTitle()); + logger.info("새 게시글 작성 요청: 제목 - {}", writePostDetailDTO.getTitle()); ResponsePostDetail response = postService.createPost(writePostDetailDTO); logger.info("게시글 생성 완료: 게시글 ID {}", response.getPostId()); @@ -94,7 +98,9 @@ public ResponseEntity removePost(@PathVariable Integer postId) { @GetMapping("/list/mypost/{memberId}") public ResponseEntity viewMyPosts(@PathVariable String memberId) { logger.info("나의 게시글 리스트 요청: 맴버 ID {}", memberId); + List myPosts = postService.viewMyPosts(memberId); + logger.info("나의 게시물 리스트 조회 완료 {}", myPosts); ResponseMyPostList myPostList = new ResponseMyPostList(myPosts); diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/repository/PostRepository.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/repository/PostRepository.java index 52654e4..b4e55c0 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/repository/PostRepository.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/repository/PostRepository.java @@ -9,7 +9,7 @@ public interface PostRepository extends JpaRepository { // 카테고리 ID에 해당하는 게시물 목록 조회 메소드 - List findByCategoryId(String categoryId); + List findByCategoryId(Integer categoryId); // JPQL // @Query("SELECT new org.omoknoone.onionhotsayyo.post.command.dto.PostWithCategoryNameDTO(p.postId, p.title, p.content, c.categoryName) " + diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/service/PostService.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/service/PostService.java index 6500801..6a0b2e1 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/service/PostService.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/service/PostService.java @@ -1,6 +1,7 @@ package org.omoknoone.onionhotsayyo.post.service; import org.omoknoone.onionhotsayyo.post.dto.MyPostListDTO; +import org.omoknoone.onionhotsayyo.post.dto.PostListByCategoryDTO; import org.omoknoone.onionhotsayyo.post.dto.WritePostDetailDTO; import org.omoknoone.onionhotsayyo.post.vo.ResponsePostDetail; import org.omoknoone.onionhotsayyo.post.vo.ResponsePostListByCategory; @@ -10,7 +11,7 @@ public interface PostService { // 카테고리별 게시글 목록 조회 - List viewPostsByCategory(String categoryId); + List viewPostsByCategory(Integer categoryId); // 게시글 상세 조회 ResponsePostDetail viewPostById(Integer postId); diff --git a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/service/PostServiceImpl.java b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/service/PostServiceImpl.java index adb5b07..131e897 100644 --- a/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/service/PostServiceImpl.java +++ b/OnionHotSayYo/src/main/java/org/omoknoone/onionhotsayyo/post/service/PostServiceImpl.java @@ -1,11 +1,13 @@ package org.omoknoone.onionhotsayyo.post.service; import org.modelmapper.ModelMapper; +import org.modelmapper.convention.MatchingStrategies; import org.omoknoone.onionhotsayyo.exceptions.PostNotFoundException; import org.omoknoone.onionhotsayyo.member.dto.MemberDTO; import org.omoknoone.onionhotsayyo.member.service.MemberService; import org.omoknoone.onionhotsayyo.post.aggregate.Post; import org.omoknoone.onionhotsayyo.post.dto.MyPostListDTO; +import org.omoknoone.onionhotsayyo.post.dto.PostListByCategoryDTO; import org.omoknoone.onionhotsayyo.post.dto.WritePostDetailDTO; import org.omoknoone.onionhotsayyo.post.repository.PostRepository; import org.omoknoone.onionhotsayyo.post.vo.ResponsePostDetail; @@ -37,13 +39,13 @@ public PostServiceImpl(PostRepository postRepository, ModelMapper modelMapper, M @Transactional(readOnly = true) @Override - public List viewPostsByCategory(String categoryId) { + public List viewPostsByCategory(Integer categoryId) { log.info("카테고리 ID {}에 해당하는 게시물 목록 조회를 시작합니다.", categoryId); List posts = postRepository.findByCategoryId(categoryId); - List CategoryPostList = posts.stream() - .map(post -> modelMapper.map(post, ResponsePostListByCategory.class)) + List CategoryPostList = posts.stream() + .map(post -> modelMapper.map(post, PostListByCategoryDTO.class)) .collect(Collectors.toList()); log.info("카테고리 ID {}에 해당하는 게시물 목록 조회를 완료했습니다." + " 조회된 게시물 수: {}", categoryId, CategoryPostList.size()); @@ -69,6 +71,7 @@ public ResponsePostDetail viewPostById(Integer postId) { public ResponsePostDetail createPost(WritePostDetailDTO writePostDetailDTO) { log.info("새 게시물 생성을 시작합니다. 제목: {}", writePostDetailDTO.getTitle()); + modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); Post post = modelMapper.map(writePostDetailDTO, Post.class); Post newPost = postRepository.save(post); From 9184ce0dd61f38f31f18e472a862139f50e0a6f1 Mon Sep 17 00:00:00 2001 From: JaeWon Lee Date: Fri, 12 Apr 2024 12:29:48 +0900 Subject: [PATCH 08/10] =?UTF-8?q?#46=20[test]=20postman=EC=9D=84=20?= =?UTF-8?q?=ED=99=9C=EC=9A=A9=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=B4=20por?= =?UTF-8?q?t=208888=20=EC=9E=84=EC=8B=9C=EB=A1=9C=20=ED=99=9C=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OnionHotSayYo/src/main/resources/application.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OnionHotSayYo/src/main/resources/application.yml b/OnionHotSayYo/src/main/resources/application.yml index 9676701..19caf7d 100644 --- a/OnionHotSayYo/src/main/resources/application.yml +++ b/OnionHotSayYo/src/main/resources/application.yml @@ -1,3 +1,5 @@ + + spring: application: name: onion-hot-say-yo @@ -28,4 +30,6 @@ deepl: #logging: # level: +server: + port: 8888 # root: debug \ No newline at end of file From 4fddb9038335f759c98d6590859876c5531d0112 Mon Sep 17 00:00:00 2001 From: JaeWon Lee Date: Fri, 12 Apr 2024 12:32:53 +0900 Subject: [PATCH 09/10] =?UTF-8?q?Revert=20"#46=20[test]=20postman=EC=9D=84?= =?UTF-8?q?=20=ED=99=9C=EC=9A=A9=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=B4=20?= =?UTF-8?q?port=208888=20=EC=9E=84=EC=8B=9C=EB=A1=9C=20=ED=99=9C=EC=9A=A9"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 9184ce0dd61f38f31f18e472a862139f50e0a6f1. --- OnionHotSayYo/src/main/resources/application.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/OnionHotSayYo/src/main/resources/application.yml b/OnionHotSayYo/src/main/resources/application.yml index 19caf7d..9676701 100644 --- a/OnionHotSayYo/src/main/resources/application.yml +++ b/OnionHotSayYo/src/main/resources/application.yml @@ -1,5 +1,3 @@ - - spring: application: name: onion-hot-say-yo @@ -30,6 +28,4 @@ deepl: #logging: # level: -server: - port: 8888 # root: debug \ No newline at end of file From 148ccba55ea885feab7b8518945fe987b59d12f0 Mon Sep 17 00:00:00 2001 From: JaeWon_LEE <152199695+jlee38266@users.noreply.github.com> Date: Fri, 12 Apr 2024 12:37:11 +0900 Subject: [PATCH 10/10] Delete OnionHotSayYo/src/main/resources/application.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit develop merge를 위한 삭제 --- .../src/main/resources/application.yml | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 OnionHotSayYo/src/main/resources/application.yml diff --git a/OnionHotSayYo/src/main/resources/application.yml b/OnionHotSayYo/src/main/resources/application.yml deleted file mode 100644 index 9676701..0000000 --- a/OnionHotSayYo/src/main/resources/application.yml +++ /dev/null @@ -1,31 +0,0 @@ -spring: - application: - name: onion-hot-say-yo - datasource: - driver-class-name: org.mariadb.jdbc.Driver - url: jdbc:mariadb://192.168.0.138/onionhotsayyo - # username: master - # password: master - username: root - password: mariadb - - jpa: - generate-ddl: false - show-sql: true - database: mysql - properties: - hibernate: - '[format_sql]': true - -token: - access-expiration-time: 43200000 # 12H - refresh-expiration-time: 604800000 # 7D - secret: iW50hkbOkPd92kEi4Z+hdBtNlGoaUwI0Aa9UY+Fb5jZyQK7Sm1dbEIaRauzhHyu6NVOT6bUZwXk3tOhiBuggnA== # ??? ? - -deepl: - api-key: 5de79c27-6426-4a36-8c08-f06e9f425d08:fx - - -#logging: -# level: -# root: debug \ No newline at end of file