From 6935130f77ef5016bf18056f4b2833fd3891b42d Mon Sep 17 00:00:00 2001 From: Yunkeun Date: Thu, 28 Apr 2022 18:34:17 +0900 Subject: [PATCH 01/21] =?UTF-8?q?feat:=20post=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=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 --- .../search/controller/SearchController.java | 23 +++++++++++++++++++ .../domain/search/dto/PostResponse.java | 13 +++++++++++ .../search/repository/SearchRepository.java | 8 +++++++ .../domain/search/service/SearchService.java | 20 ++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java create mode 100644 backend/src/main/java/com/hjjang/backend/domain/search/dto/PostResponse.java create mode 100644 backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java create mode 100644 backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java new file mode 100644 index 0000000..9c7163f --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java @@ -0,0 +1,23 @@ +package com.hjjang.backend.domain.search.controller; + +import com.hjjang.backend.domain.search.dto.PostResponse; +import com.hjjang.backend.domain.search.service.SearchService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/search") +public class SearchController { + + private final SearchService searchService; + + @GetMapping + public ResponseEntity getAllPosts() { + PostResponse posts = searchService.findAll(); + return ResponseEntity.ok(posts); + } +} diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/dto/PostResponse.java b/backend/src/main/java/com/hjjang/backend/domain/search/dto/PostResponse.java new file mode 100644 index 0000000..6547d94 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/domain/search/dto/PostResponse.java @@ -0,0 +1,13 @@ +package com.hjjang.backend.domain.search.dto; + +import com.hjjang.backend.domain.post.entity.Post; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class PostResponse { + + private List posts; +} diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java b/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java new file mode 100644 index 0000000..58be8ea --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java @@ -0,0 +1,8 @@ +package com.hjjang.backend.domain.search.repository; + +import com.hjjang.backend.domain.post.entity.Post; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface SearchRepository extends JpaRepository { + +} diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java new file mode 100644 index 0000000..e442001 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java @@ -0,0 +1,20 @@ +package com.hjjang.backend.domain.search.service; + +import com.hjjang.backend.domain.post.entity.Post; +import com.hjjang.backend.domain.search.dto.PostResponse; +import com.hjjang.backend.domain.search.repository.SearchRepository; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class SearchService { + + private final SearchRepository searchRepository; + + public PostResponse findAll() { + List posts = searchRepository.findAll(); + return new PostResponse(posts); + } +} From a8c392a1f7a8eeaba04300451643255ac5174c5d Mon Sep 17 00:00:00 2001 From: Yunkeun Date: Thu, 28 Apr 2022 18:40:01 +0900 Subject: [PATCH 02/21] =?UTF-8?q?chore:=20swagger=20config=EC=97=90=20sear?= =?UTF-8?q?chApi=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hjjang/backend/global/config/SwaggerConfig.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/src/main/java/com/hjjang/backend/global/config/SwaggerConfig.java b/backend/src/main/java/com/hjjang/backend/global/config/SwaggerConfig.java index eca1d3c..5f1915b 100644 --- a/backend/src/main/java/com/hjjang/backend/global/config/SwaggerConfig.java +++ b/backend/src/main/java/com/hjjang/backend/global/config/SwaggerConfig.java @@ -27,6 +27,14 @@ public GroupedOpenApi mailApi() { .build(); } + @Bean + public GroupedOpenApi searchApi() { + return GroupedOpenApi.builder() + .group("search") + .pathsToMatch("/api/search/**") + .build(); + } + @Bean public OpenAPI bauctionOpenAPI() { return new OpenAPI() From 483aa1d0d0782f80162a661c02a3bff1c7e83a3a Mon Sep 17 00:00:00 2001 From: Yunkeun Date: Sat, 30 Apr 2022 00:45:43 +0900 Subject: [PATCH 03/21] =?UTF-8?q?feat:=20title=EC=97=90=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=EC=96=B4=EA=B0=80=20=ED=8F=AC=ED=95=A8=EB=90=9C=20pos?= =?UTF-8?q?ts=EB=A7=8C=20=EA=B2=80=EC=83=89=ED=95=98=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=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 --- .../search/controller/SearchController.java | 13 +++++-- .../domain/search/dto/PostResponse.java | 2 +- .../search/repository/SearchRepository.java | 4 ++- .../domain/search/service/SearchService.java | 16 ++------- .../search/service/SearchServiceImpl.java | 35 +++++++++++++++++++ 5 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java index 9c7163f..b0a14f7 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java @@ -1,11 +1,12 @@ package com.hjjang.backend.domain.search.controller; import com.hjjang.backend.domain.search.dto.PostResponse; -import com.hjjang.backend.domain.search.service.SearchService; +import com.hjjang.backend.domain.search.service.SearchServiceImpl; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -13,11 +14,17 @@ @RequestMapping("/api/search") public class SearchController { - private final SearchService searchService; + private final SearchServiceImpl searchService; - @GetMapping + @GetMapping("/all") public ResponseEntity getAllPosts() { PostResponse posts = searchService.findAll(); return ResponseEntity.ok(posts); } + + @GetMapping + public ResponseEntity searchPostsByKeyword(@RequestParam String keyword) { + PostResponse posts = searchService.findByKeyword(keyword); + return ResponseEntity.ok(posts); + } } diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/dto/PostResponse.java b/backend/src/main/java/com/hjjang/backend/domain/search/dto/PostResponse.java index 6547d94..a7a8709 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/dto/PostResponse.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/dto/PostResponse.java @@ -1,6 +1,6 @@ package com.hjjang.backend.domain.search.dto; -import com.hjjang.backend.domain.post.entity.Post; +import com.hjjang.backend.domain.post.domain.entity.Post; import java.util.List; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java b/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java index 58be8ea..2c33e0d 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java @@ -1,8 +1,10 @@ package com.hjjang.backend.domain.search.repository; -import com.hjjang.backend.domain.post.entity.Post; +import com.hjjang.backend.domain.post.domain.entity.Post; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; public interface SearchRepository extends JpaRepository { + List findByTitleContaining(String keyword); } diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java index e442001..0034f58 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java @@ -1,20 +1,10 @@ package com.hjjang.backend.domain.search.service; -import com.hjjang.backend.domain.post.entity.Post; import com.hjjang.backend.domain.search.dto.PostResponse; -import com.hjjang.backend.domain.search.repository.SearchRepository; -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -@Service -@RequiredArgsConstructor -public class SearchService { +public interface SearchService { - private final SearchRepository searchRepository; + PostResponse findAll(); - public PostResponse findAll() { - List posts = searchRepository.findAll(); - return new PostResponse(posts); - } + PostResponse findByKeyword(String keyword); } diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java new file mode 100644 index 0000000..11f5739 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java @@ -0,0 +1,35 @@ +package com.hjjang.backend.domain.search.service; + +import com.hjjang.backend.domain.post.domain.entity.Post; +import com.hjjang.backend.domain.search.dto.PostResponse; +import com.hjjang.backend.domain.search.repository.SearchRepository; +import java.util.ArrayList; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class SearchServiceImpl implements SearchService { + + private final SearchRepository searchRepository; + + public PostResponse findAll() { + List posts = searchRepository.findAll(); + return new PostResponse(posts); + } + + public PostResponse findByKeyword(String keyword) { + List posts = new ArrayList<>(); + List keywords = parseKeyword(keyword); + keywords.forEach(word -> { + List searchedPosts = searchRepository.findByTitleContaining(word); + posts.addAll(posts.size(), searchedPosts); + }); + return new PostResponse(posts); + } + + private List parseKeyword(String keyword) { + return List.of(keyword.split(" ")); + } +} From b6628661f84911fe28abd05b208fe83493834f67 Mon Sep 17 00:00:00 2001 From: Yunkeun Date: Sat, 7 May 2022 15:39:34 +0900 Subject: [PATCH 04/21] =?UTF-8?q?build:=20=EC=8A=A4=ED=94=84=EB=A7=81?= =?UTF-8?q?=EB=B6=80=ED=8A=B8=20=EB=B2=84=EC=A0=84=20=EB=8B=A4=EC=9A=B4?= =?UTF-8?q?=EA=B7=B8=EB=A0=88=EC=9D=B4=EB=93=9C=202.6.6=20->=202.6.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/build.gradle b/backend/build.gradle index e66b88a..c2678e3 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.springframework.boot' version '2.6.6' + id 'org.springframework.boot' version '2.6.4' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'org.asciidoctor.convert' version '1.5.8' id 'java' From f2cb2bc8881df391da27749edd7a8363eb211379 Mon Sep 17 00:00:00 2001 From: Yunkeun Date: Sat, 7 May 2022 16:02:31 +0900 Subject: [PATCH 05/21] =?UTF-8?q?feat:=20=EA=B2=80=EC=83=89=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20Post=20=EC=A4=91=EB=B3=B5=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/search/controller/SearchController.java | 11 ++++++----- .../backend/domain/search/dto/PostResponse.java | 13 ------------- .../domain/search/service/SearchService.java | 7 ++++--- .../domain/search/service/SearchServiceImpl.java | 13 ++++++------- 4 files changed, 16 insertions(+), 28 deletions(-) delete mode 100644 backend/src/main/java/com/hjjang/backend/domain/search/dto/PostResponse.java diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java index b0a14f7..8753601 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java @@ -1,7 +1,8 @@ package com.hjjang.backend.domain.search.controller; -import com.hjjang.backend.domain.search.dto.PostResponse; +import com.hjjang.backend.domain.post.domain.entity.Post; import com.hjjang.backend.domain.search.service.SearchServiceImpl; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -17,14 +18,14 @@ public class SearchController { private final SearchServiceImpl searchService; @GetMapping("/all") - public ResponseEntity getAllPosts() { - PostResponse posts = searchService.findAll(); + public ResponseEntity> getAllPosts() { + List posts = searchService.findAll(); return ResponseEntity.ok(posts); } @GetMapping - public ResponseEntity searchPostsByKeyword(@RequestParam String keyword) { - PostResponse posts = searchService.findByKeyword(keyword); + public ResponseEntity> searchPostsByKeyword(@RequestParam String keyword) { + List posts = searchService.findByKeyword(keyword); return ResponseEntity.ok(posts); } } diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/dto/PostResponse.java b/backend/src/main/java/com/hjjang/backend/domain/search/dto/PostResponse.java deleted file mode 100644 index a7a8709..0000000 --- a/backend/src/main/java/com/hjjang/backend/domain/search/dto/PostResponse.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.hjjang.backend.domain.search.dto; - -import com.hjjang.backend.domain.post.domain.entity.Post; -import java.util.List; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public class PostResponse { - - private List posts; -} diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java index 0034f58..0b1446c 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java @@ -1,10 +1,11 @@ package com.hjjang.backend.domain.search.service; -import com.hjjang.backend.domain.search.dto.PostResponse; +import com.hjjang.backend.domain.post.domain.entity.Post; +import java.util.List; public interface SearchService { - PostResponse findAll(); + List findAll(); - PostResponse findByKeyword(String keyword); + List findByKeyword(String keyword); } diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java index 11f5739..f489d4f 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java @@ -1,10 +1,10 @@ package com.hjjang.backend.domain.search.service; import com.hjjang.backend.domain.post.domain.entity.Post; -import com.hjjang.backend.domain.search.dto.PostResponse; import com.hjjang.backend.domain.search.repository.SearchRepository; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -14,19 +14,18 @@ public class SearchServiceImpl implements SearchService { private final SearchRepository searchRepository; - public PostResponse findAll() { - List posts = searchRepository.findAll(); - return new PostResponse(posts); + public List findAll() { + return searchRepository.findAll(); } - public PostResponse findByKeyword(String keyword) { + public List findByKeyword(String keyword) { List posts = new ArrayList<>(); List keywords = parseKeyword(keyword); keywords.forEach(word -> { List searchedPosts = searchRepository.findByTitleContaining(word); - posts.addAll(posts.size(), searchedPosts); + posts.addAll(searchedPosts); }); - return new PostResponse(posts); + return posts.stream().distinct().collect(Collectors.toList()); } private List parseKeyword(String keyword) { From 3bff61ed32b9b4616aafdcccb0e963eac0763ce8 Mon Sep 17 00:00:00 2001 From: Yunkeun Date: Sat, 7 May 2022 17:36:51 +0900 Subject: [PATCH 06/21] =?UTF-8?q?feat:=20=EA=B2=80=EC=83=89=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20pagination=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../search/controller/SearchController.java | 11 +++++----- .../search/repository/SearchRepository.java | 3 ++- .../domain/search/service/SearchService.java | 7 ++++--- .../search/service/SearchServiceImpl.java | 20 ++++++++++++++----- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java index 8753601..3270421 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java @@ -2,8 +2,9 @@ import com.hjjang.backend.domain.post.domain.entity.Post; import com.hjjang.backend.domain.search.service.SearchServiceImpl; -import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -18,14 +19,14 @@ public class SearchController { private final SearchServiceImpl searchService; @GetMapping("/all") - public ResponseEntity> getAllPosts() { - List posts = searchService.findAll(); + public ResponseEntity> getAllPosts(Pageable pageable) { + Page posts = searchService.findAll(pageable); return ResponseEntity.ok(posts); } @GetMapping - public ResponseEntity> searchPostsByKeyword(@RequestParam String keyword) { - List posts = searchService.findByKeyword(keyword); + public ResponseEntity> searchPostsByKeyword(@RequestParam String keyword, Pageable pageable) { + Page posts = searchService.findByKeyword(keyword, pageable); return ResponseEntity.ok(posts); } } diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java b/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java index 2c33e0d..591e3a6 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java @@ -2,9 +2,10 @@ import com.hjjang.backend.domain.post.domain.entity.Post; import java.util.List; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; public interface SearchRepository extends JpaRepository { - List findByTitleContaining(String keyword); + List findByTitleContaining(String keyword, Pageable pageable); } diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java index 0b1446c..7b8c688 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java @@ -1,11 +1,12 @@ package com.hjjang.backend.domain.search.service; import com.hjjang.backend.domain.post.domain.entity.Post; -import java.util.List; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; public interface SearchService { - List findAll(); + Page findAll(Pageable pageable); - List findByKeyword(String keyword); + Page findByKeyword(String keyword, Pageable pageable); } diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java index f489d4f..053750a 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java @@ -6,6 +6,9 @@ import java.util.List; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @Service @@ -14,18 +17,25 @@ public class SearchServiceImpl implements SearchService { private final SearchRepository searchRepository; - public List findAll() { - return searchRepository.findAll(); + public Page findAll(Pageable pageable) { + return searchRepository.findAll(pageable); } - public List findByKeyword(String keyword) { + public Page findByKeyword(String keyword, Pageable pageable) { List posts = new ArrayList<>(); List keywords = parseKeyword(keyword); keywords.forEach(word -> { - List searchedPosts = searchRepository.findByTitleContaining(word); + List searchedPosts = searchRepository.findByTitleContaining(word, pageable); posts.addAll(searchedPosts); }); - return posts.stream().distinct().collect(Collectors.toList()); + List distinctPosts = posts.stream().distinct().collect(Collectors.toList()); + return getPostPage(pageable, distinctPosts); + } + + private PageImpl getPostPage(Pageable pageable, List posts) { + int start = (int) pageable.getOffset(); + int end = Math.min((start + pageable.getPageSize()), posts.size()); + return new PageImpl<>(posts.subList(start, end), pageable, posts.size()); } private List parseKeyword(String keyword) { From 3564a2f29cd5f98f1ed3e2efe586e23afeb6898b Mon Sep 17 00:00:00 2001 From: Yunkeun Date: Sat, 7 May 2022 22:19:45 +0900 Subject: [PATCH 07/21] =?UTF-8?q?feat:=20=EA=B2=80=EC=83=89=20filter=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../search/controller/SearchController.java | 15 ++++++++++----- .../search/repository/SearchRepository.java | 3 +++ .../domain/search/service/SearchService.java | 4 ++-- .../domain/search/service/SearchServiceImpl.java | 9 ++++++--- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java index 3270421..d24c32c 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java @@ -13,20 +13,25 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/search") +@RequestMapping("/api/searches") public class SearchController { private final SearchServiceImpl searchService; @GetMapping("/all") - public ResponseEntity> getAllPosts(Pageable pageable) { - Page posts = searchService.findAll(pageable); + public ResponseEntity> searchPosts( + @RequestParam(required = false) String filter, + Pageable pageable) { + Page posts = searchService.findAll(filter, pageable); return ResponseEntity.ok(posts); } @GetMapping - public ResponseEntity> searchPostsByKeyword(@RequestParam String keyword, Pageable pageable) { - Page posts = searchService.findByKeyword(keyword, pageable); + public ResponseEntity> searchPostsByKeyword( + @RequestParam String keyword, + @RequestParam(required = false) String filter, + Pageable pageable) { + Page posts = searchService.findByKeyword(keyword, filter, pageable); return ResponseEntity.ok(posts); } } diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java b/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java index 591e3a6..13a86c4 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java @@ -2,10 +2,13 @@ import com.hjjang.backend.domain.post.domain.entity.Post; import java.util.List; +import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; public interface SearchRepository extends JpaRepository { + Page findByIsSaleCompletion(String IsSaleCompletion, Pageable pageable); + List findByTitleContaining(String keyword, Pageable pageable); } diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java index 7b8c688..40043b1 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java @@ -6,7 +6,7 @@ public interface SearchService { - Page findAll(Pageable pageable); + Page findAll(String filter, Pageable pageable); - Page findByKeyword(String keyword, Pageable pageable); + Page findByKeyword(String keyword, String filter, Pageable pageable); } diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java index 053750a..b57cec3 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java @@ -17,11 +17,14 @@ public class SearchServiceImpl implements SearchService { private final SearchRepository searchRepository; - public Page findAll(Pageable pageable) { - return searchRepository.findAll(pageable); + public Page findAll(String filter, Pageable pageable) { + if (filter == null) { + return searchRepository.findAll(pageable); + } + return searchRepository.findByIsSaleCompletion(filter, pageable); } - public Page findByKeyword(String keyword, Pageable pageable) { + public Page findByKeyword(String keyword, String filter, Pageable pageable) { List posts = new ArrayList<>(); List keywords = parseKeyword(keyword); keywords.forEach(word -> { From 2c3e1ccaaaaf17a019cfa784362c5010bd58cfd6 Mon Sep 17 00:00:00 2001 From: Yunkeun Date: Sun, 8 May 2022 16:51:47 +0900 Subject: [PATCH 08/21] =?UTF-8?q?feat:=20=EA=B2=80=EC=83=89=20=EC=8B=9C=20?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=20=EC=88=9C=EC=9C=BC=EB=A1=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=20=ED=9B=84=20=EC=9D=91=EB=8B=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/search/controller/SearchController.java | 6 ++++-- .../domain/search/service/SearchServiceImpl.java | 12 ++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java index d24c32c..b36f28d 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java @@ -5,6 +5,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort.Direction; +import org.springframework.data.web.PageableDefault; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -21,7 +23,7 @@ public class SearchController { @GetMapping("/all") public ResponseEntity> searchPosts( @RequestParam(required = false) String filter, - Pageable pageable) { + @PageableDefault(sort = "time", direction = Direction.DESC) Pageable pageable) { Page posts = searchService.findAll(filter, pageable); return ResponseEntity.ok(posts); } @@ -30,7 +32,7 @@ public ResponseEntity> searchPosts( public ResponseEntity> searchPostsByKeyword( @RequestParam String keyword, @RequestParam(required = false) String filter, - Pageable pageable) { + @PageableDefault(sort = "time", direction = Direction.DESC) Pageable pageable) { Page posts = searchService.findByKeyword(keyword, filter, pageable); return ResponseEntity.ok(posts); } diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java index b57cec3..c36668d 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java @@ -3,6 +3,7 @@ import com.hjjang.backend.domain.post.domain.entity.Post; import com.hjjang.backend.domain.search.repository.SearchRepository; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @@ -31,8 +32,7 @@ public Page findByKeyword(String keyword, String filter, Pageable pageable List searchedPosts = searchRepository.findByTitleContaining(word, pageable); posts.addAll(searchedPosts); }); - List distinctPosts = posts.stream().distinct().collect(Collectors.toList()); - return getPostPage(pageable, distinctPosts); + return getPostPage(pageable, sortAndDistinctPosts(posts)); } private PageImpl getPostPage(Pageable pageable, List posts) { @@ -41,6 +41,14 @@ private PageImpl getPostPage(Pageable pageable, List posts) { return new PageImpl<>(posts.subList(start, end), pageable, posts.size()); } + private List sortAndDistinctPosts(List posts) { + List distinctPosts = posts.stream().distinct().collect(Collectors.toList()); + return distinctPosts + .stream() + .sorted(Comparator.comparing(Post::getTime).reversed()) + .collect(Collectors.toList()); + } + private List parseKeyword(String keyword) { return List.of(keyword.split(" ")); } From 61f6c31ca61d4bcfde81260f39ddd535f2b28d8c Mon Sep 17 00:00:00 2001 From: Yunkeun Date: Wed, 11 May 2022 18:42:16 +0900 Subject: [PATCH 09/21] =?UTF-8?q?feat:=20=EC=9D=91=EB=8B=B5=EC=97=90=20Api?= =?UTF-8?q?Response=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../search/controller/SearchController.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java index b36f28d..869ca21 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java @@ -1,9 +1,10 @@ package com.hjjang.backend.domain.search.controller; -import com.hjjang.backend.domain.post.domain.entity.Post; +import com.hjjang.backend.domain.post.dto.PostMapper; import com.hjjang.backend.domain.search.service.SearchServiceImpl; +import com.hjjang.backend.global.dto.ApiResponse; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort.Direction; import org.springframework.data.web.PageableDefault; @@ -19,21 +20,35 @@ public class SearchController { private final SearchServiceImpl searchService; + private final PostMapper postMapper; @GetMapping("/all") - public ResponseEntity> searchPosts( + public ResponseEntity searchPosts( @RequestParam(required = false) String filter, @PageableDefault(sort = "time", direction = Direction.DESC) Pageable pageable) { - Page posts = searchService.findAll(filter, pageable); - return ResponseEntity.ok(posts); + return ResponseEntity.ok( + ApiResponse.success( + "searchPosts", + searchService.findAll(filter, pageable) + .stream() + .map(postMapper::fromEntity) + .collect(Collectors.toList())) + ); } @GetMapping - public ResponseEntity> searchPostsByKeyword( + public ResponseEntity searchPostsByKeyword( @RequestParam String keyword, @RequestParam(required = false) String filter, @PageableDefault(sort = "time", direction = Direction.DESC) Pageable pageable) { - Page posts = searchService.findByKeyword(keyword, filter, pageable); - return ResponseEntity.ok(posts); + return ResponseEntity.ok( + ApiResponse.success( + "searchPostsByKeyword", + searchService.findByKeyword(keyword, filter, pageable) + .stream() + .map(postMapper::fromEntity) + .collect(Collectors.toList()) + ) + ); } } From cebbb22c14d6be3347de67f961e292502cfbfc6a Mon Sep 17 00:00:00 2001 From: Yunkeun Date: Wed, 11 May 2022 21:26:42 +0900 Subject: [PATCH 10/21] =?UTF-8?q?feat:=20University=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/university/entity/University.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 backend/src/main/java/com/hjjang/backend/domain/university/entity/University.java diff --git a/backend/src/main/java/com/hjjang/backend/domain/university/entity/University.java b/backend/src/main/java/com/hjjang/backend/domain/university/entity/University.java new file mode 100644 index 0000000..c6bfb4f --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/domain/university/entity/University.java @@ -0,0 +1,39 @@ +package com.hjjang.backend.domain.university.entity; + +import static javax.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@Entity +@NoArgsConstructor(access = PROTECTED) +@Table(name = "university") +public class University { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "id", nullable = false) + private Long id; + + @Column(name = "name", nullable = false) + private String name; + + @Column(name = "mail", nullable = false) + private String mail; + + @Builder + public University(String name, String mail) { + this.name = name; + this.mail = mail; + } +} From 946a0f82ac56cb1a62fe21bcccf75704e2e945fc Mon Sep 17 00:00:00 2001 From: Yunkeun Date: Thu, 12 May 2022 02:55:39 +0900 Subject: [PATCH 11/21] =?UTF-8?q?feat:=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=20=EC=97=AC=EB=B6=80=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=9D=BC=20=ED=95=99=EA=B5=90=20=EA=B2=8C=EC=8B=9C=EA=B8=80?= =?UTF-8?q?=EB=A7=8C=20=EA=B2=80=EC=83=89=EB=90=98=EA=B2=8C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../search/controller/SearchController.java | 6 +- .../search/repository/SearchRepository.java | 10 ++- .../domain/search/service/SearchService.java | 5 +- .../search/service/SearchServiceImpl.java | 76 ++++++++++++++++--- 4 files changed, 81 insertions(+), 16 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java index 869ca21..f528c59 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java @@ -3,6 +3,7 @@ import com.hjjang.backend.domain.post.dto.PostMapper; import com.hjjang.backend.domain.search.service.SearchServiceImpl; import com.hjjang.backend.global.dto.ApiResponse; +import com.hjjang.backend.global.util.UserUtil; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; @@ -21,6 +22,7 @@ public class SearchController { private final SearchServiceImpl searchService; private final PostMapper postMapper; + private final UserUtil userUtil; @GetMapping("/all") public ResponseEntity searchPosts( @@ -29,7 +31,7 @@ public ResponseEntity searchPosts( return ResponseEntity.ok( ApiResponse.success( "searchPosts", - searchService.findAll(filter, pageable) + searchService.findAll(filter, pageable, userUtil.getLoginUserByToken()) .stream() .map(postMapper::fromEntity) .collect(Collectors.toList())) @@ -44,7 +46,7 @@ public ResponseEntity searchPostsByKeyword( return ResponseEntity.ok( ApiResponse.success( "searchPostsByKeyword", - searchService.findByKeyword(keyword, filter, pageable) + searchService.findByKeyword(keyword, filter, pageable, userUtil.getLoginUserByToken()) .stream() .map(postMapper::fromEntity) .collect(Collectors.toList()) diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java b/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java index 13a86c4..db09ae3 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java @@ -8,7 +8,15 @@ public interface SearchRepository extends JpaRepository { - Page findByIsSaleCompletion(String IsSaleCompletion, Pageable pageable); + List findByIsSaleCompletion(String IsSaleCompletion, Pageable pageable); + + Page findAllByIsSaleCompletion(String IsSaleCompletion, Pageable pageable); List findByTitleContaining(String keyword, Pageable pageable); + + Page findByUnivId(Long univId, Pageable pageable); + + List findByIsSaleCompletionAndUnivId(String IsSaleCompletion, Long univId, Pageable pageable); + + Page findAllByIsSaleCompletionAndUnivId(String IsSaleCompletion, Long univId, Pageable pageable); } diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java index 40043b1..9061bfa 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java @@ -1,12 +1,13 @@ package com.hjjang.backend.domain.search.service; import com.hjjang.backend.domain.post.domain.entity.Post; +import com.hjjang.backend.domain.user.entity.User; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; public interface SearchService { - Page findAll(String filter, Pageable pageable); + Page findAll(String filter, Pageable pageable, User user); - Page findByKeyword(String keyword, String filter, Pageable pageable); + Page findByKeyword(String keyword, String filter, Pageable pageable, User user); } diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java index c36668d..7d83a25 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java @@ -2,9 +2,11 @@ import com.hjjang.backend.domain.post.domain.entity.Post; import com.hjjang.backend.domain.search.repository.SearchRepository; +import com.hjjang.backend.domain.user.entity.User; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -18,26 +20,78 @@ public class SearchServiceImpl implements SearchService { private final SearchRepository searchRepository; - public Page findAll(String filter, Pageable pageable) { - if (filter == null) { - return searchRepository.findAll(pageable); + public Page findAll(String filter, Pageable pageable, User user) { + // TODO::이메일 인증된 유저로 대체 + if (true) { + return searchByFilterInUniversity(filter, pageable, user.getUnivId()); + } + return searchByFilter(filter, pageable); + } + + public Page findByKeyword(String keyword, String filter, Pageable pageable, User user) { + // TODO::이메일 인증된 유저로 대체 + if (true) { + return searchByFilterAndKeywordInUniversity(keyword, filter, user.getUnivId(), pageable); } - return searchRepository.findByIsSaleCompletion(filter, pageable); + return searchByFilterAndKeyword(keyword, filter, pageable); } - public Page findByKeyword(String keyword, String filter, Pageable pageable) { + private Page searchByFilterAndKeyword(String keyword, String filter, Pageable pageable) { List posts = new ArrayList<>(); List keywords = parseKeyword(keyword); - keywords.forEach(word -> { - List searchedPosts = searchRepository.findByTitleContaining(word, pageable); - posts.addAll(searchedPosts); - }); + keywords.forEach(word -> addSearchedPosts(pageable, posts, word)); + if (filter == null) { + return getPostPage(pageable, sortAndDistinctPosts(posts)); + } + posts.retainAll(searchRepository.findByIsSaleCompletion(filter, pageable)); return getPostPage(pageable, sortAndDistinctPosts(posts)); } + private void addSearchedPosts(Pageable pageable, List posts, String word) { + posts.addAll(searchRepository.findByTitleContaining(word, pageable)); + } + + private Page searchByFilterAndKeywordInUniversity(String keyword, String filter, Long univId, Pageable pageable) { + List keywords = parseKeyword(keyword); + List posts = new ArrayList<>(); + keywords.forEach(word -> + getPostsInUniversity( + univId, + searchRepository.findByTitleContaining(word, pageable), + posts) + ); + if (filter == null) { + return getPostPage(pageable, sortAndDistinctPosts(posts)); + } + posts.retainAll(searchRepository.findByIsSaleCompletionAndUnivId(filter, univId, pageable)); + return getPostPage(pageable, sortAndDistinctPosts(posts)); + } + + private void getPostsInUniversity(Long univId, List searchedPosts, List searchedPostsInUniv) { + searchedPosts.forEach(post -> { + if (Objects.equals(post.getUnivId(), univId)) { + searchedPostsInUniv.add(post); + } + }); + } + + private Page searchByFilterInUniversity(String filter, Pageable pageable, Long univId) { + if (filter == null) { + return searchRepository.findByUnivId(univId, pageable); + } + return searchRepository.findAllByIsSaleCompletionAndUnivId(filter, univId, pageable); + } + + private Page searchByFilter(String filter, Pageable pageable) { + if (filter == null) { + searchRepository.findAll(pageable); + } + return searchRepository.findAllByIsSaleCompletion(filter, pageable); + } + private PageImpl getPostPage(Pageable pageable, List posts) { - int start = (int) pageable.getOffset(); - int end = Math.min((start + pageable.getPageSize()), posts.size()); + final int start = (int) pageable.getOffset(); + final int end = Math.min((start + pageable.getPageSize()), posts.size()); return new PageImpl<>(posts.subList(start, end), pageable, posts.size()); } From 08c1f04adef1513fd374b5868d061198a2b781e0 Mon Sep 17 00:00:00 2001 From: Gnu-Kenny Date: Tue, 24 May 2022 21:44:56 +0900 Subject: [PATCH 12/21] =?UTF-8?q?fix:=20Post,=20User=20Entity=EC=97=90=20J?= =?UTF-8?q?oinColumn=20'univ=5Fid'=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/controller/PostController.java | 28 +++++++----- .../domain/post/domain/entity/Post.java | 43 ++++++++++++++----- .../backend/domain/post/dto/PostMapper.java | 11 ++--- .../domain/post/dto/PostResponseDto.java | 3 +- .../domain/post/service/PostServiceImpl.java | 15 ++++--- .../search/repository/SearchRepository.java | 12 +++--- .../search/service/SearchServiceImpl.java | 32 ++++++++------ .../backend/domain/user/entity/User.java | 31 ++++++++----- 8 files changed, 111 insertions(+), 64 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/controller/PostController.java b/backend/src/main/java/com/hjjang/backend/domain/post/controller/PostController.java index 72cbec6..d9566e8 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/controller/PostController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/controller/PostController.java @@ -1,20 +1,28 @@ package com.hjjang.backend.domain.post.controller; +import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.ResponseEntity.*; + +import java.util.stream.Collectors; + +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + import com.hjjang.backend.domain.post.dto.PostMapper; import com.hjjang.backend.domain.post.dto.PostRequestDto; -import com.hjjang.backend.domain.post.dto.PostResponseDto; import com.hjjang.backend.domain.post.service.PostServiceImpl; import com.hjjang.backend.global.dto.ApiResponse; import com.hjjang.backend.global.util.UserUtil; -import lombok.RequiredArgsConstructor; -import org.springframework.http.ResponseEntity; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.util.stream.Collectors; -import static org.springframework.http.HttpStatus.*; -import static org.springframework.http.ResponseEntity.*; +import lombok.RequiredArgsConstructor; @RequiredArgsConstructor @RequestMapping("/api/posts") @@ -33,7 +41,7 @@ public ResponseEntity createItem(@Validated @RequestBody PostReques postMapper.fromEntity( postService.save( postMapper.toEntity( - postRequestDto, userUtil.getLoginUserByToken() + postRequestDto, userUtil.getLoginUserByToken().getUniversity() ) ) ) diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java b/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java index b3bfcdc..78ba94a 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java @@ -1,14 +1,31 @@ package com.hjjang.backend.domain.post.domain.entity; -import com.hjjang.backend.domain.post.dto.PostRequestDto; -import com.hjjang.backend.domain.user.entity.User; -import lombok.*; -import org.hibernate.annotations.CreationTimestamp; +import static com.hjjang.backend.domain.post.domain.entity.PostDefaultValue.*; -import javax.persistence.*; import java.time.LocalDateTime; -import static com.hjjang.backend.domain.post.domain.entity.PostDefaultValue.*; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import org.hibernate.annotations.CreationTimestamp; + +import com.hjjang.backend.domain.post.dto.PostRequestDto; +import com.hjjang.backend.domain.university.entity.University; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; @Getter //@Builder @@ -22,9 +39,13 @@ public class Post { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne - @JoinColumn(name = "user_id") - private User user; + // @ManyToOne + // @JoinColumn(name = "user_id") + // private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "univ_id") + private University university; @Column(name = "title", nullable = false) private String title; @@ -59,8 +80,8 @@ public class Post { private LocalDateTime time; @Builder - public Post(User user, String title, String content, int itemPrice) { - this.user = user; + public Post(University university, String title, String content, int itemPrice) { + this.university = university; this.title = title; this.content = content; this.itemPrice = itemPrice; diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostMapper.java b/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostMapper.java index 37b9602..2d8c978 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostMapper.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostMapper.java @@ -1,15 +1,16 @@ package com.hjjang.backend.domain.post.dto; -import com.hjjang.backend.domain.post.domain.entity.Post; -import com.hjjang.backend.domain.user.entity.User; import org.springframework.stereotype.Service; +import com.hjjang.backend.domain.post.domain.entity.Post; +import com.hjjang.backend.domain.university.entity.University; + @Service public class PostMapper { - public Post toEntity(PostRequestDto postRequestDto, User user) { + public Post toEntity(PostRequestDto postRequestDto, University university) { return Post.builder() - .user(user) + .university(university) .title(postRequestDto.getTitle()) .content(postRequestDto.getContent()) .itemPrice(postRequestDto.getPrice()) @@ -19,7 +20,7 @@ public Post toEntity(PostRequestDto postRequestDto, User user) { public PostResponseDto fromEntity(Post post) { return PostResponseDto.builder() .id(post.getId()) - .user_id(post.getUser().getId()) + .univ_id(post.getUniversity().getId()) .title(post.getTitle()) .content(post.getContent()) .item_price(post.getItemPrice()) diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostResponseDto.java b/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostResponseDto.java index 992d8c8..c936db0 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostResponseDto.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostResponseDto.java @@ -1,6 +1,5 @@ package com.hjjang.backend.domain.post.dto; -import com.hjjang.backend.domain.post.domain.entity.Post; import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -12,7 +11,7 @@ public class PostResponseDto { private Long id; - private Long user_id; + private Long univ_id; private String title; diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/service/PostServiceImpl.java b/backend/src/main/java/com/hjjang/backend/domain/post/service/PostServiceImpl.java index 1ce00d9..13dcc6b 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/service/PostServiceImpl.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/service/PostServiceImpl.java @@ -1,16 +1,16 @@ package com.hjjang.backend.domain.post.service; +import java.util.List; + +import org.springframework.stereotype.Service; + import com.hjjang.backend.domain.post.domain.entity.Post; import com.hjjang.backend.domain.post.domain.repository.PostRepository; import com.hjjang.backend.domain.post.dto.PostRequestDto; import com.hjjang.backend.domain.post.exception.PostNotFoundException; import com.hjjang.backend.domain.user.entity.User; -import com.hjjang.backend.domain.user.exception.UserNotMatchException; -import com.hjjang.backend.global.response.code.ErrorCode; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import java.util.List; +import lombok.RequiredArgsConstructor; @RequiredArgsConstructor @Service @@ -32,8 +32,9 @@ public Post findOneById(Long id) { public Post updateOneById(Long id, PostRequestDto postRequestDto, User user) { Post foundPost = findOneById(id); - if (user == foundPost.getUser()) return save(foundPost.update(postRequestDto)); - throw new UserNotMatchException("사용자 정보가 일치하지 않습니다.", ErrorCode.NO_AUTHORITY); + return save(foundPost.update(postRequestDto)); + // if (user == foundPost.getUser()) return + // throw new UserNotMatchException("사용자 정보가 일치하지 않습니다.", ErrorCode.NO_AUTHORITY); } public void deleteOneById(Long id) { diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java b/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java index db09ae3..95f86fa 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java @@ -1,11 +1,14 @@ package com.hjjang.backend.domain.search.repository; -import com.hjjang.backend.domain.post.domain.entity.Post; import java.util.List; + import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import com.hjjang.backend.domain.post.domain.entity.Post; +import com.hjjang.backend.domain.university.entity.University; + public interface SearchRepository extends JpaRepository { List findByIsSaleCompletion(String IsSaleCompletion, Pageable pageable); @@ -14,9 +17,8 @@ public interface SearchRepository extends JpaRepository { List findByTitleContaining(String keyword, Pageable pageable); - Page findByUnivId(Long univId, Pageable pageable); - - List findByIsSaleCompletionAndUnivId(String IsSaleCompletion, Long univId, Pageable pageable); + Page findByUniversity(University university, Pageable pageable); - Page findAllByIsSaleCompletionAndUnivId(String IsSaleCompletion, Long univId, Pageable pageable); + List findByIsSaleCompletionAndUniversity(String IsSaleCompletion, University university, Pageable pageable); + Page findAllByIsSaleCompletionAndUniversity(String IsSaleCompletion, University university, Pageable pageable); } diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java index 7d83a25..b68fe51 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java @@ -1,19 +1,23 @@ package com.hjjang.backend.domain.search.service; -import com.hjjang.backend.domain.post.domain.entity.Post; -import com.hjjang.backend.domain.search.repository.SearchRepository; -import com.hjjang.backend.domain.user.entity.User; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -import lombok.RequiredArgsConstructor; + import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import com.hjjang.backend.domain.post.domain.entity.Post; +import com.hjjang.backend.domain.search.repository.SearchRepository; +import com.hjjang.backend.domain.university.entity.University; +import com.hjjang.backend.domain.user.entity.User; + +import lombok.RequiredArgsConstructor; + @Service @RequiredArgsConstructor public class SearchServiceImpl implements SearchService { @@ -23,7 +27,7 @@ public class SearchServiceImpl implements SearchService { public Page findAll(String filter, Pageable pageable, User user) { // TODO::이메일 인증된 유저로 대체 if (true) { - return searchByFilterInUniversity(filter, pageable, user.getUnivId()); + return searchByFilterInUniversity(filter, pageable, user.getUniversity()); } return searchByFilter(filter, pageable); } @@ -31,7 +35,7 @@ public Page findAll(String filter, Pageable pageable, User user) { public Page findByKeyword(String keyword, String filter, Pageable pageable, User user) { // TODO::이메일 인증된 유저로 대체 if (true) { - return searchByFilterAndKeywordInUniversity(keyword, filter, user.getUnivId(), pageable); + return searchByFilterAndKeywordInUniversity(keyword, filter, user.getUniversity(), pageable); } return searchByFilterAndKeyword(keyword, filter, pageable); } @@ -51,35 +55,35 @@ private void addSearchedPosts(Pageable pageable, List posts, String word) posts.addAll(searchRepository.findByTitleContaining(word, pageable)); } - private Page searchByFilterAndKeywordInUniversity(String keyword, String filter, Long univId, Pageable pageable) { + private Page searchByFilterAndKeywordInUniversity(String keyword, String filter, University university, Pageable pageable) { List keywords = parseKeyword(keyword); List posts = new ArrayList<>(); keywords.forEach(word -> getPostsInUniversity( - univId, + university, searchRepository.findByTitleContaining(word, pageable), posts) ); if (filter == null) { return getPostPage(pageable, sortAndDistinctPosts(posts)); } - posts.retainAll(searchRepository.findByIsSaleCompletionAndUnivId(filter, univId, pageable)); + posts.retainAll(searchRepository.findByIsSaleCompletionAndUniversity(filter, university, pageable)); return getPostPage(pageable, sortAndDistinctPosts(posts)); } - private void getPostsInUniversity(Long univId, List searchedPosts, List searchedPostsInUniv) { + private void getPostsInUniversity(University university, List searchedPosts, List searchedPostsInUniv) { searchedPosts.forEach(post -> { - if (Objects.equals(post.getUnivId(), univId)) { + if (Objects.equals(post.getUniversity().getId(), university)) { searchedPostsInUniv.add(post); } }); } - private Page searchByFilterInUniversity(String filter, Pageable pageable, Long univId) { + private Page searchByFilterInUniversity(String filter, Pageable pageable, University university) { if (filter == null) { - return searchRepository.findByUnivId(univId, pageable); + return searchRepository.findByUniversity(university, pageable); } - return searchRepository.findAllByIsSaleCompletionAndUnivId(filter, univId, pageable); + return searchRepository.findAllByIsSaleCompletionAndUniversity(filter, university, pageable); } private Page searchByFilter(String filter, Pageable pageable) { diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java b/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java index 57f9530..a85ef55 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java @@ -1,17 +1,27 @@ package com.hjjang.backend.domain.user.entity; +import static javax.persistence.EnumType.*; +import static javax.persistence.GenerationType.*; +import static lombok.AccessLevel.*; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import com.hjjang.backend.domain.university.entity.University; import com.hjjang.backend.global.domain.BaseTimeEntity; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import javax.persistence.*; - -import static javax.persistence.EnumType.STRING; -import static javax.persistence.GenerationType.IDENTITY; -import static lombok.AccessLevel.PROTECTED; - @Getter @AllArgsConstructor @Entity @@ -43,8 +53,9 @@ public class User extends BaseTimeEntity { @Column(name = "is_push_agree", nullable = false, length = 10) private Agreement isPushAgree; - @Column(name = "univ_id") - private Long univId; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "univ_id", nullable = true) + private University university; @Column(name = "role", length = 20) @Enumerated(STRING) @@ -58,7 +69,7 @@ public class User extends BaseTimeEntity { @Builder public User(String providerId, String nickName, String email, Long mannerTemperature, - String imageUrl, Agreement isPushAgree, Long univId, RoleType role, Boolean isEmailVerification, + String imageUrl, Agreement isPushAgree, University university, RoleType role, Boolean isEmailVerification, Boolean isBlocked) { this.providerId = providerId; this.nickName = nickName; @@ -66,7 +77,7 @@ public User(String providerId, String nickName, String email, Long mannerTempera this.mannerTemperature = mannerTemperature; this.imageUrl = imageUrl; this.isPushAgree = isPushAgree; - this.univId = univId; + this.university = university; this.role = role; this.isEmailVerification = isEmailVerification; this.isBlocked = isBlocked; From 183a47e285414b3ecbb99ecfee5235de274e21ad Mon Sep 17 00:00:00 2001 From: Gnu-Kenny Date: Tue, 24 May 2022 22:06:47 +0900 Subject: [PATCH 13/21] =?UTF-8?q?fix:=20Post,=20User=20Entity=EC=97=90=20'?= =?UTF-8?q?univ=5Fid'=EB=A5=BC=20'university=5Fid'=EB=A1=9C=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 --- .../java/com/hjjang/backend/domain/post/domain/entity/Post.java | 2 +- .../main/java/com/hjjang/backend/domain/user/entity/User.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java b/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java index 78ba94a..6e6f0ee 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java @@ -44,7 +44,7 @@ public class Post { // private User user; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "univ_id") + @JoinColumn(name = "university_id") private University university; @Column(name = "title", nullable = false) diff --git a/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java b/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java index a85ef55..be12053 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java +++ b/backend/src/main/java/com/hjjang/backend/domain/user/entity/User.java @@ -54,7 +54,7 @@ public class User extends BaseTimeEntity { private Agreement isPushAgree; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "univ_id", nullable = true) + @JoinColumn(name = "university_id", nullable = true) private University university; @Column(name = "role", length = 20) From f2de6bde696077532b99c30575859c16d06586a1 Mon Sep 17 00:00:00 2001 From: Gnu-Kenny Date: Sat, 28 May 2022 00:18:35 +0900 Subject: [PATCH 14/21] =?UTF-8?q?chores:=20=ED=86=B5=ED=95=A9=20Response?= =?UTF-8?q?=20=EA=B0=9D=EC=B2=B4=EB=A1=9C=20return=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/controller/PostController.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/controller/PostController.java b/backend/src/main/java/com/hjjang/backend/domain/post/controller/PostController.java index d9566e8..8d5e982 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/controller/PostController.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/controller/PostController.java @@ -16,10 +16,15 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import com.hjjang.backend.domain.post.domain.entity.Post; import com.hjjang.backend.domain.post.dto.PostMapper; import com.hjjang.backend.domain.post.dto.PostRequestDto; +import com.hjjang.backend.domain.post.dto.PostResponseDto; import com.hjjang.backend.domain.post.service.PostServiceImpl; +import com.hjjang.backend.domain.user.entity.User; import com.hjjang.backend.global.dto.ApiResponse; +import com.hjjang.backend.global.response.code.SuccessCode; +import com.hjjang.backend.global.response.response.SuccessResponse; import com.hjjang.backend.global.util.UserUtil; import lombok.RequiredArgsConstructor; @@ -34,19 +39,11 @@ public class PostController { private final UserUtil userUtil; @PostMapping - public ResponseEntity createItem(@Validated @RequestBody PostRequestDto postRequestDto) { - return status(CREATED) - .body(ApiResponse.success( - "createItem", - postMapper.fromEntity( - postService.save( - postMapper.toEntity( - postRequestDto, userUtil.getLoginUserByToken().getUniversity() - ) - ) - ) - ) - ); + public ResponseEntity createItem(@Validated @RequestBody PostRequestDto postRequestDto) { + User user = userUtil.getLoginUserByToken(); + Post post = postService.save(postMapper.toEntity(postRequestDto, user.getUniversity())); + PostResponseDto postResponseDto = postMapper.fromEntity(post); + return ResponseEntity.ok(SuccessResponse.of(SuccessCode.POST_CREATE_SUCCESS, postResponseDto)); } @GetMapping From a650867e1bfe96425fbb60dac7972914f9313423 Mon Sep 17 00:00:00 2001 From: Gnu-Kenny Date: Sat, 28 May 2022 00:19:13 +0900 Subject: [PATCH 15/21] =?UTF-8?q?chores:=20=EC=95=BD=EC=96=B4=EB=A1=9C=20?= =?UTF-8?q?=EC=9E=91=EB=AA=85=EB=90=9C=20univ=5Fid=20->=20university=5Fid?= =?UTF-8?q?=20=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hjjang/backend/domain/post/dto/PostMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostMapper.java b/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostMapper.java index 2d8c978..2fcd128 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostMapper.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostMapper.java @@ -20,7 +20,7 @@ public Post toEntity(PostRequestDto postRequestDto, University university) { public PostResponseDto fromEntity(Post post) { return PostResponseDto.builder() .id(post.getId()) - .univ_id(post.getUniversity().getId()) + .university_id(post.getUniversity().getId()) .title(post.getTitle()) .content(post.getContent()) .item_price(post.getItemPrice()) From 0591f25e7266858976944b88c6092fb5f099534f Mon Sep 17 00:00:00 2001 From: Gnu-Kenny Date: Sat, 28 May 2022 00:19:19 +0900 Subject: [PATCH 16/21] =?UTF-8?q?chores:=20=EC=95=BD=EC=96=B4=EB=A1=9C=20?= =?UTF-8?q?=EC=9E=91=EB=AA=85=EB=90=9C=20univ=5Fid=20->=20university=5Fid?= =?UTF-8?q?=20=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hjjang/backend/domain/post/dto/PostResponseDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostResponseDto.java b/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostResponseDto.java index c936db0..82f6716 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostResponseDto.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/dto/PostResponseDto.java @@ -11,7 +11,7 @@ public class PostResponseDto { private Long id; - private Long univ_id; + private Long university_id; private String title; From 5ceba444bf626c00449c38873cda0e964085c9a0 Mon Sep 17 00:00:00 2001 From: Gnu-Kenny Date: Sat, 28 May 2022 00:24:54 +0900 Subject: [PATCH 17/21] =?UTF-8?q?fix:=20requestParam=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=EB=90=9C=20=EA=B2=8C=EC=8B=9C=EA=B8=80?= =?UTF-8?q?=EC=9D=98=20=EB=8C=80=ED=95=99=EA=B5=90=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=EC=99=80=20=EB=8C=80=ED=95=99=EA=B5=90=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EB=B9=84=EA=B5=90=20=EC=A4=91=20university=20id=EA=B0=92?= =?UTF-8?q?=EC=9D=B4=20=EB=88=84=EB=9D=BD=EB=90=98=EC=96=B4=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=ED=95=9C=20=EC=97=90=EB=9F=AC=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hjjang/backend/domain/search/service/SearchServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java index b68fe51..0be8755 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java +++ b/backend/src/main/java/com/hjjang/backend/domain/search/service/SearchServiceImpl.java @@ -73,7 +73,7 @@ private Page searchByFilterAndKeywordInUniversity(String keyword, String f private void getPostsInUniversity(University university, List searchedPosts, List searchedPostsInUniv) { searchedPosts.forEach(post -> { - if (Objects.equals(post.getUniversity().getId(), university)) { + if (Objects.equals(post.getUniversity().getId(), university.getId())) { searchedPostsInUniv.add(post); } }); From ef4e7289b82391c8de85d15f2a411e48714b985e Mon Sep 17 00:00:00 2001 From: Gnu-Kenny Date: Sat, 28 May 2022 00:25:05 +0900 Subject: [PATCH 18/21] =?UTF-8?q?refact:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20=EA=B4=80=EB=A0=A8=20enum=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hjjang/backend/global/response/code/SuccessCode.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java b/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java index 506a47c..1a33764 100644 --- a/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java +++ b/backend/src/main/java/com/hjjang/backend/global/response/code/SuccessCode.java @@ -8,8 +8,12 @@ public enum SuccessCode { //User - USER_PROFILE_SUCCESS( "U001", "프로필 조회 완료."),; + USER_PROFILE_SUCCESS( "U001", "프로필 조회 완료."), + //Post + POST_CREATE_SUCCESS( "P001", "게시글 등록 완료.") + + ; private final String code; private final String message; } From bdad271c8d6cad2c2f04b5cf9083750ccfd6da23 Mon Sep 17 00:00:00 2001 From: Gnu-Kenny Date: Sat, 28 May 2022 01:02:05 +0900 Subject: [PATCH 19/21] =?UTF-8?q?refact:=20university=5Fid=EC=9D=98=20?= =?UTF-8?q?=EA=B0=92not=20null=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hjjang/backend/domain/post/domain/entity/Post.java | 4 ++-- .../backend/domain/post/domain/entity/PostDefaultValue.java | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java b/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java index 6e6f0ee..880f2ea 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/Post.java @@ -44,8 +44,8 @@ public class Post { // private User user; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "university_id") - private University university; + @JoinColumn(name = "university_id", nullable = false) + private University university = DEFAULT_UNIVERSITY; @Column(name = "title", nullable = false) private String title; diff --git a/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/PostDefaultValue.java b/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/PostDefaultValue.java index b665a8d..40ad0f1 100644 --- a/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/PostDefaultValue.java +++ b/backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/PostDefaultValue.java @@ -1,5 +1,7 @@ package com.hjjang.backend.domain.post.domain.entity; +import com.hjjang.backend.domain.university.entity.University; + import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -7,6 +9,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) public class PostDefaultValue { + public static final University DEFAULT_UNIVERSITY = new University(1L, "empty", "empty"); public static final int DEFAULT_VIEWS = 0; public static final int DEFAULT_INTEREST_NUMBER = 0; public static final int DEFAULT_CHAT_NUMBER = 0; From b80ba3c66e64461713ac667a3f0d6ec551d3b692 Mon Sep 17 00:00:00 2001 From: Gnu-Kenny Date: Sat, 28 May 2022 01:04:22 +0900 Subject: [PATCH 20/21] =?UTF-8?q?feat:=20=EC=84=9C=EB=B2=84=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=EC=8B=9C=20University=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B6=94=EA=B0=80=ED=95=98?= =?UTF-8?q?=EB=8A=94=20ApplicationListener=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/config/ApplicationStartupTask.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 backend/src/main/java/com/hjjang/backend/global/config/ApplicationStartupTask.java diff --git a/backend/src/main/java/com/hjjang/backend/global/config/ApplicationStartupTask.java b/backend/src/main/java/com/hjjang/backend/global/config/ApplicationStartupTask.java new file mode 100644 index 0000000..e7a5e29 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/global/config/ApplicationStartupTask.java @@ -0,0 +1,22 @@ +package com.hjjang.backend.global.config; + +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.stereotype.Component; + +import com.hjjang.backend.domain.university.entity.University; +import com.hjjang.backend.domain.university.repository.UniversityRepository; + +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +public class ApplicationStartupTask implements ApplicationListener { + private final UniversityRepository universityRepository; + @Override + public void onApplicationEvent(ApplicationReadyEvent event) { + if (!universityRepository.existsById(1L)){ + universityRepository.save(new University("empty", "empty")); + } + } +} From 4c18d4091581fdf4b570cf18b3705db1a6ef5ea2 Mon Sep 17 00:00:00 2001 From: Gnu-Kenny Date: Sat, 28 May 2022 01:05:15 +0900 Subject: [PATCH 21/21] =?UTF-8?q?feat:=20University=20Entity=20JPA=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=EC=B2=B4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../university/repository/UniversityRepository.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 backend/src/main/java/com/hjjang/backend/domain/university/repository/UniversityRepository.java diff --git a/backend/src/main/java/com/hjjang/backend/domain/university/repository/UniversityRepository.java b/backend/src/main/java/com/hjjang/backend/domain/university/repository/UniversityRepository.java new file mode 100644 index 0000000..5f36056 --- /dev/null +++ b/backend/src/main/java/com/hjjang/backend/domain/university/repository/UniversityRepository.java @@ -0,0 +1,10 @@ +package com.hjjang.backend.domain.university.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import com.hjjang.backend.domain.university.entity.University; + +@Repository +public interface UniversityRepository extends JpaRepository { +}