From bd80043a344fa7212c9a2ee9b2a71b65ed738420 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Sun, 14 Jul 2024 15:01:39 +0900 Subject: [PATCH 01/14] feat: diciontary DTO --- .../controller/DictionaryController.java | 4 +++ .../controller/api/DictionaryApi.java | 4 +++ .../dictionary/dto/DictionaryResponseDTO.java | 25 +++++++++++++++++++ .../dictionary/service/DictionaryService.java | 4 +++ 4 files changed, 37 insertions(+) create mode 100644 src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java create mode 100644 src/main/java/com/example/fiurinee/domain/dictionary/controller/api/DictionaryApi.java create mode 100644 src/main/java/com/example/fiurinee/domain/dictionary/dto/DictionaryResponseDTO.java create mode 100644 src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java diff --git a/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java b/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java new file mode 100644 index 0000000..238eedc --- /dev/null +++ b/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java @@ -0,0 +1,4 @@ +package com.example.fiurinee.domain.dictionary.controller; + +public class DictionaryController { +} diff --git a/src/main/java/com/example/fiurinee/domain/dictionary/controller/api/DictionaryApi.java b/src/main/java/com/example/fiurinee/domain/dictionary/controller/api/DictionaryApi.java new file mode 100644 index 0000000..b416a8f --- /dev/null +++ b/src/main/java/com/example/fiurinee/domain/dictionary/controller/api/DictionaryApi.java @@ -0,0 +1,4 @@ +package com.example.fiurinee.domain.dictionary.controller.api; + +public class DictionaryApi { +} diff --git a/src/main/java/com/example/fiurinee/domain/dictionary/dto/DictionaryResponseDTO.java b/src/main/java/com/example/fiurinee/domain/dictionary/dto/DictionaryResponseDTO.java new file mode 100644 index 0000000..1bad4a0 --- /dev/null +++ b/src/main/java/com/example/fiurinee/domain/dictionary/dto/DictionaryResponseDTO.java @@ -0,0 +1,25 @@ +package com.example.fiurinee.domain.dictionary.dto; + +import com.example.fiurinee.domain.flower.entity.Flower; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class DictionaryResponseDTO { + private String flower; + private String period; + private String flowerLanguage; + private String explain; + private String image; + + public static DictionaryResponseDTO of(Flower flower) { + return DictionaryResponseDTO.builder() + .flower(flower.getName()) + .period(String.format("%02d", flower.getPeriod() / 100)) + .flowerLanguage(flower.getFlowerLanguage()) + .explain(flower.getExplain()) + .image(flower.getImage().toString()) + .build(); + } +} diff --git a/src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java b/src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java new file mode 100644 index 0000000..27fe75e --- /dev/null +++ b/src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java @@ -0,0 +1,4 @@ +package com.example.fiurinee.domain.dictionary.service; + +public class DictionaryService { +} From 22d12f3413c0a63af7a974b74c293d5c1cd917a6 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Sun, 14 Jul 2024 15:18:19 +0900 Subject: [PATCH 02/14] =?UTF-8?q?feat:=20=EA=BD=83=20=EA=B2=80=EC=83=89=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DictionaryController.java | 29 ++++++++++++++- .../controller/api/DictionaryApi.java | 35 ++++++++++++++++++- .../dictionary/service/DictionaryService.java | 30 ++++++++++++++++ .../flower/repository/FlowerRepository.java | 8 +++++ 4 files changed, 100 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java b/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java index 238eedc..b98c872 100644 --- a/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java +++ b/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java @@ -1,4 +1,31 @@ package com.example.fiurinee.domain.dictionary.controller; -public class DictionaryController { +import com.example.fiurinee.domain.dictionary.controller.api.DictionaryApi; +import com.example.fiurinee.domain.dictionary.dto.DictionaryResponseDTO; +import com.example.fiurinee.domain.dictionary.service.DictionaryService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequiredArgsConstructor +public class DictionaryController implements DictionaryApi { + private final DictionaryService dictionaryService; + + @Override + public ResponseEntity> getAllFlowers(int page) { + int size = 8; // 한 페이지에 보여줄 꽃의 개수 + List flowers = dictionaryService.getAllFlowers(page, size); + return ResponseEntity.ok(flowers); + } + + @Override + public ResponseEntity> searchFlowers(String name) { + List flowers = dictionaryService.searchFlowersByName(name); + return ResponseEntity.ok(flowers); + } + } + diff --git a/src/main/java/com/example/fiurinee/domain/dictionary/controller/api/DictionaryApi.java b/src/main/java/com/example/fiurinee/domain/dictionary/controller/api/DictionaryApi.java index b416a8f..4978420 100644 --- a/src/main/java/com/example/fiurinee/domain/dictionary/controller/api/DictionaryApi.java +++ b/src/main/java/com/example/fiurinee/domain/dictionary/controller/api/DictionaryApi.java @@ -1,4 +1,37 @@ package com.example.fiurinee.domain.dictionary.controller.api; -public class DictionaryApi { +import com.example.fiurinee.domain.dictionary.dto.DictionaryResponseDTO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +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 java.util.List; + +@Tag(name = "Dictionary", description = "사전 관련 API") +@RequestMapping("/dictionary") +public interface DictionaryApi { + @Operation( + summary = "모든 꽃 조회", + description = "페이지 단위로 모든 꽃을 조회합니다.", + security = @SecurityRequirement(name = "bearerAuth") + ) + @ApiResponse(responseCode = "200", description = "꽃 조회 성공") + @ApiResponse(responseCode = "401", description = "인증 실패") + @GetMapping + ResponseEntity> getAllFlowers(@RequestParam int page); + + @Operation( + summary = "꽃 이름으로 검색", + description = "이름에 특정 단어가 포함된 꽃을 검색합니다.", + security = @SecurityRequirement(name = "bearerAuth") + ) + @ApiResponse(responseCode = "200", description = "꽃 검색 성공") + @ApiResponse(responseCode = "401", description = "인증 실패") + @GetMapping("/search") + ResponseEntity> searchFlowers(@RequestParam String name); } diff --git a/src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java b/src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java index 27fe75e..821d7fe 100644 --- a/src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java +++ b/src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java @@ -1,4 +1,34 @@ package com.example.fiurinee.domain.dictionary.service; + +import com.example.fiurinee.domain.dictionary.dto.DictionaryResponseDTO; +import com.example.fiurinee.domain.flower.entity.Flower; +import com.example.fiurinee.domain.flower.repository.FlowerRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor public class DictionaryService { + private final FlowerRepository flowerRepository; + + public List getAllFlowers(int page, int size) { + PageRequest pageRequest = PageRequest.of(page - 1, size); + Page flowers = flowerRepository.findDistinctAll(pageRequest); + return flowers.stream() + .map(DictionaryResponseDTO::of) + .collect(Collectors.toList()); + } + + public List searchFlowersByName(String name) { + List flowers = flowerRepository.findDistinctByNameContaining(name); + return flowers.stream() + .map(DictionaryResponseDTO::of) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java b/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java index ecca8e9..336e876 100644 --- a/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java +++ b/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java @@ -1,6 +1,8 @@ package com.example.fiurinee.domain.flower.repository; import com.example.fiurinee.domain.flower.entity.Flower; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -18,4 +20,10 @@ public interface FlowerRepository extends JpaRepository { List findByNameAndFlowerLanguage(String name,String flowerLanguage); List findByName(String name); + + @Query("SELECT DISTINCT f FROM Flower f WHERE f.name LIKE %:name%") + List findDistinctByNameContaining(@Param("name") String name); + + @Query("SELECT DISTINCT f FROM Flower f") + Page findDistinctAll(Pageable pageable); } From 96120b0d8084d7566c73949a8f335c0bd3d09e00 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Sun, 14 Jul 2024 15:27:33 +0900 Subject: [PATCH 03/14] =?UTF-8?q?chore:=20=EB=B9=84=ED=9A=8C=EC=9B=90=20se?= =?UTF-8?q?curity=20url=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/fiurinee/global/security/config/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java b/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java index bf08140..d886f89 100644 --- a/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java +++ b/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java @@ -79,7 +79,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .requestMatchers("/oauth2/login", "/login/oauth2/code/**", "/oauth2/authorization/**","/login/oauth2/code/google","/member/*/refresh","/model/test", "/swagger-ui/index.html", "/swagger-ui/**", "/v3/api-docs/**","/swagger-resources/**", "/v3/api-docs").permitAll() //비회원 전용 api - .requestMatchers("/main/today","/main/season","/model/ment","/model/*/non").permitAll() + .requestMatchers("/main/today","/main/season","/model/ment","/model/*/non", "/dictionary", "dictionary/search").permitAll() //sms api .requestMatchers("/sms/prove/*","/sms/send").permitAll() //ALB From 9b3544e714fa15aa92b8d9e8555d1c0f8a5c795a Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Sun, 14 Jul 2024 15:32:09 +0900 Subject: [PATCH 04/14] =?UTF-8?q?fix:=20url=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/fiurinee/global/security/config/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java b/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java index d886f89..fb26fe5 100644 --- a/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java +++ b/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java @@ -79,7 +79,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .requestMatchers("/oauth2/login", "/login/oauth2/code/**", "/oauth2/authorization/**","/login/oauth2/code/google","/member/*/refresh","/model/test", "/swagger-ui/index.html", "/swagger-ui/**", "/v3/api-docs/**","/swagger-resources/**", "/v3/api-docs").permitAll() //비회원 전용 api - .requestMatchers("/main/today","/main/season","/model/ment","/model/*/non", "/dictionary", "dictionary/search").permitAll() + .requestMatchers("/main/today","/main/season","/model/ment","/model/*/non", "/dictionary/**", "dictionary/search/**").permitAll() //sms api .requestMatchers("/sms/prove/*","/sms/send").permitAll() //ALB From eeeeba4252d9fdb35409fffbe7c9aa3643c4f8cf Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Sun, 14 Jul 2024 15:37:15 +0900 Subject: [PATCH 05/14] =?UTF-8?q?fix:=20jwtfilter=20=EB=B9=84=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=20url=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fiurinee/global/security/filter/JwtVerifyFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java b/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java index 383ac20..1f33a4d 100644 --- a/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java +++ b/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java @@ -29,7 +29,7 @@ public class JwtVerifyFilter extends OncePerRequestFilter { //Swagger "/swagger-ui/index.html", "/swagger-ui/**", "/v3/api-docs/**", "/swagger-resources/**", "/v3/api-docs", //비회원 전용 api - "/main/today","/main/season","/model/ment","/model/*/non", + "/main/today","/main/season","/model/ment","/model/*/non", "/dictionary/**", "dictionary/search/**", //sms api "/sms/prove/*","/sms/send", //ALB From bc0de723d263ba94a99a1f88db2f6630af35f23c Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Sun, 14 Jul 2024 15:44:20 +0900 Subject: [PATCH 06/14] =?UTF-8?q?fix:=20url=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/fiurinee/global/security/config/SecurityConfig.java | 2 +- .../fiurinee/global/security/filter/JwtVerifyFilter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java b/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java index fb26fe5..d421f1c 100644 --- a/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java +++ b/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java @@ -79,7 +79,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .requestMatchers("/oauth2/login", "/login/oauth2/code/**", "/oauth2/authorization/**","/login/oauth2/code/google","/member/*/refresh","/model/test", "/swagger-ui/index.html", "/swagger-ui/**", "/v3/api-docs/**","/swagger-resources/**", "/v3/api-docs").permitAll() //비회원 전용 api - .requestMatchers("/main/today","/main/season","/model/ment","/model/*/non", "/dictionary/**", "dictionary/search/**").permitAll() + .requestMatchers("/main/today","/main/season","/model/ment","/model/*/non", "/dictionary/**", "dictionary/search/**", "/dictionary", "dictionary/search").permitAll() //sms api .requestMatchers("/sms/prove/*","/sms/send").permitAll() //ALB diff --git a/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java b/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java index 1f33a4d..88d3b53 100644 --- a/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java +++ b/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java @@ -29,7 +29,7 @@ public class JwtVerifyFilter extends OncePerRequestFilter { //Swagger "/swagger-ui/index.html", "/swagger-ui/**", "/v3/api-docs/**", "/swagger-resources/**", "/v3/api-docs", //비회원 전용 api - "/main/today","/main/season","/model/ment","/model/*/non", "/dictionary/**", "dictionary/search/**", + "/main/today","/main/season","/model/ment","/model/*/non", "/dictionary/**", "dictionary/search/**", "/dictionary", "dictionary/search", //sms api "/sms/prove/*","/sms/send", //ALB From 0bc0f0084f5faed5509c4f592e2f1c94964f4f6e Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Sun, 14 Jul 2024 16:07:10 +0900 Subject: [PATCH 07/14] =?UTF-8?q?fix:=20=EC=A4=91=EB=B3=B5=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fiurinee/domain/flower/repository/FlowerRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java b/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java index 336e876..c93c60f 100644 --- a/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java +++ b/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java @@ -21,9 +21,9 @@ public interface FlowerRepository extends JpaRepository { List findByName(String name); - @Query("SELECT DISTINCT f FROM Flower f WHERE f.name LIKE %:name%") + @Query(value = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY name ORDER BY flower_id) as row_num FROM flower) as flowers WHERE row_num = 1 AND name LIKE %:name%", nativeQuery = true) List findDistinctByNameContaining(@Param("name") String name); - @Query("SELECT DISTINCT f FROM Flower f") + @Query(value = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY name ORDER BY flower_id) as row_num FROM flower) as flowers WHERE row_num = 1", nativeQuery = true) Page findDistinctAll(Pageable pageable); } From 8228316fceb1439830e61ded0c4902bfad5b3b55 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Sun, 14 Jul 2024 16:55:32 +0900 Subject: [PATCH 08/14] =?UTF-8?q?chore:=20=ED=95=9C=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=EC=97=90=20=EB=93=A4=EC=96=B4=EA=B0=88=20=EA=BD=83=20?= =?UTF-8?q?=EA=B0=9C=EC=88=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/dictionary/controller/DictionaryController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java b/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java index b98c872..3c70f1e 100644 --- a/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java +++ b/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java @@ -16,7 +16,7 @@ public class DictionaryController implements DictionaryApi { @Override public ResponseEntity> getAllFlowers(int page) { - int size = 8; // 한 페이지에 보여줄 꽃의 개수 + int size = 12; // 한 페이지에 보여줄 꽃의 개수 List flowers = dictionaryService.getAllFlowers(page, size); return ResponseEntity.ok(flowers); } From 26de33b4995682488f3719ff9556d91738b284e9 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Sun, 14 Jul 2024 17:10:38 +0900 Subject: [PATCH 09/14] =?UTF-8?q?chore:=20=EC=B4=9D=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EC=88=98=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dictionary/controller/DictionaryController.java | 6 ++++++ .../dictionary/controller/api/DictionaryApi.java | 11 +++++++++++ .../domain/dictionary/service/DictionaryService.java | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java b/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java index 3c70f1e..1d0db86 100644 --- a/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java +++ b/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java @@ -27,5 +27,11 @@ public ResponseEntity> searchFlowers(String name) { return ResponseEntity.ok(flowers); } + @Override + public ResponseEntity getTotalPages(int size) { + int totalPages = dictionaryService.getTotalPages(size); + return ResponseEntity.ok(totalPages); + } + } diff --git a/src/main/java/com/example/fiurinee/domain/dictionary/controller/api/DictionaryApi.java b/src/main/java/com/example/fiurinee/domain/dictionary/controller/api/DictionaryApi.java index 4978420..2006747 100644 --- a/src/main/java/com/example/fiurinee/domain/dictionary/controller/api/DictionaryApi.java +++ b/src/main/java/com/example/fiurinee/domain/dictionary/controller/api/DictionaryApi.java @@ -34,4 +34,15 @@ public interface DictionaryApi { @ApiResponse(responseCode = "401", description = "인증 실패") @GetMapping("/search") ResponseEntity> searchFlowers(@RequestParam String name); + + @Operation( + summary = "총 페이지 수 조회", + description = "전체 꽃 목록의 총 페이지 수를 조회합니다.", + security = @SecurityRequirement(name = "bearerAuth") + ) + @ApiResponse(responseCode = "200", description = "총 페이지 수 조회 성공") + @ApiResponse(responseCode = "401", description = "인증 실패") + @GetMapping("/total-pages") + ResponseEntity getTotalPages(@RequestParam int size); } + diff --git a/src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java b/src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java index 821d7fe..ee4275a 100644 --- a/src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java +++ b/src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java @@ -31,4 +31,9 @@ public List searchFlowersByName(String name) { .map(DictionaryResponseDTO::of) .collect(Collectors.toList()); } + + public int getTotalPages(int size) { + long count = flowerRepository.count(); + return (int) Math.ceil((double) count / size); + } } From 594dd1788be47d1f3d0deedfb723ebe8c5ebe279 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Sun, 14 Jul 2024 17:14:16 +0900 Subject: [PATCH 10/14] =?UTF-8?q?chore:=20url=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/fiurinee/global/security/config/SecurityConfig.java | 2 +- .../fiurinee/global/security/filter/JwtVerifyFilter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java b/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java index d421f1c..53225ba 100644 --- a/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java +++ b/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java @@ -79,7 +79,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .requestMatchers("/oauth2/login", "/login/oauth2/code/**", "/oauth2/authorization/**","/login/oauth2/code/google","/member/*/refresh","/model/test", "/swagger-ui/index.html", "/swagger-ui/**", "/v3/api-docs/**","/swagger-resources/**", "/v3/api-docs").permitAll() //비회원 전용 api - .requestMatchers("/main/today","/main/season","/model/ment","/model/*/non", "/dictionary/**", "dictionary/search/**", "/dictionary", "dictionary/search").permitAll() + .requestMatchers("/main/today","/main/season","/model/ment","/model/*/non", "/total-pages" , "/dictionary", "dictionary/search").permitAll() //sms api .requestMatchers("/sms/prove/*","/sms/send").permitAll() //ALB diff --git a/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java b/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java index 88d3b53..7672b49 100644 --- a/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java +++ b/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java @@ -29,7 +29,7 @@ public class JwtVerifyFilter extends OncePerRequestFilter { //Swagger "/swagger-ui/index.html", "/swagger-ui/**", "/v3/api-docs/**", "/swagger-resources/**", "/v3/api-docs", //비회원 전용 api - "/main/today","/main/season","/model/ment","/model/*/non", "/dictionary/**", "dictionary/search/**", "/dictionary", "dictionary/search", + "/main/today","/main/season","/model/ment","/model/*/non", "/total-pages" , "/dictionary", "dictionary/search", //sms api "/sms/prove/*","/sms/send", //ALB From cf94dac22fa827d2291cb21d23fa2fdb094d20ea Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Sun, 14 Jul 2024 17:22:45 +0900 Subject: [PATCH 11/14] =?UTF-8?q?fix:=20url=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/fiurinee/global/security/config/SecurityConfig.java | 2 +- .../fiurinee/global/security/filter/JwtVerifyFilter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java b/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java index 53225ba..4be896b 100644 --- a/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java +++ b/src/main/java/com/example/fiurinee/global/security/config/SecurityConfig.java @@ -79,7 +79,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .requestMatchers("/oauth2/login", "/login/oauth2/code/**", "/oauth2/authorization/**","/login/oauth2/code/google","/member/*/refresh","/model/test", "/swagger-ui/index.html", "/swagger-ui/**", "/v3/api-docs/**","/swagger-resources/**", "/v3/api-docs").permitAll() //비회원 전용 api - .requestMatchers("/main/today","/main/season","/model/ment","/model/*/non", "/total-pages" , "/dictionary", "dictionary/search").permitAll() + .requestMatchers("/main/today","/main/season","/model/ment","/model/*/non", "/dictionary/**", "dictionary/search/**", "/dictionary", "/dictionary/search", "/dictionary/total-pages", "/dictionary/total-pages/**").permitAll() //sms api .requestMatchers("/sms/prove/*","/sms/send").permitAll() //ALB diff --git a/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java b/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java index 7672b49..7d07c71 100644 --- a/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java +++ b/src/main/java/com/example/fiurinee/global/security/filter/JwtVerifyFilter.java @@ -29,7 +29,7 @@ public class JwtVerifyFilter extends OncePerRequestFilter { //Swagger "/swagger-ui/index.html", "/swagger-ui/**", "/v3/api-docs/**", "/swagger-resources/**", "/v3/api-docs", //비회원 전용 api - "/main/today","/main/season","/model/ment","/model/*/non", "/total-pages" , "/dictionary", "dictionary/search", + "/main/today","/main/season","/model/ment","/model/*/non", "/dictionary/**", "dictionary/search/**", "/dictionary", "/dictionary/search", "/dictionary/total-pages", "/dictionary/total-pages/**", //sms api "/sms/prove/*","/sms/send", //ALB From 42d292c03a6a0edb14a2da59daba093377f8f140 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Sun, 14 Jul 2024 17:29:59 +0900 Subject: [PATCH 12/14] =?UTF-8?q?chore:=20=ED=95=9C=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EA=BD=83=20=EA=B0=9C=EC=88=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/dictionary/controller/DictionaryController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java b/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java index 1d0db86..9161906 100644 --- a/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java +++ b/src/main/java/com/example/fiurinee/domain/dictionary/controller/DictionaryController.java @@ -16,7 +16,7 @@ public class DictionaryController implements DictionaryApi { @Override public ResponseEntity> getAllFlowers(int page) { - int size = 12; // 한 페이지에 보여줄 꽃의 개수 + int size = 30; // 한 페이지에 보여줄 꽃의 개수 List flowers = dictionaryService.getAllFlowers(page, size); return ResponseEntity.ok(flowers); } From 611c6f961943b1bf25e3e0d4648c3f2fa5d22508 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Sun, 14 Jul 2024 17:37:38 +0900 Subject: [PATCH 13/14] =?UTF-8?q?fix:=20=EC=BF=BC=EB=A6=AC=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fiurinee/domain/flower/repository/FlowerRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java b/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java index c93c60f..bb0370d 100644 --- a/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java +++ b/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java @@ -21,9 +21,9 @@ public interface FlowerRepository extends JpaRepository { List findByName(String name); - @Query(value = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY name ORDER BY flower_id) as row_num FROM flower) as flowers WHERE row_num = 1 AND name LIKE %:name%", nativeQuery = true) + @Query(value = "SELECT DISTINCT ON (f.name) f.* FROM flower f WHERE f.name LIKE %:name%", nativeQuery = true) List findDistinctByNameContaining(@Param("name") String name); - @Query(value = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY name ORDER BY flower_id) as row_num FROM flower) as flowers WHERE row_num = 1", nativeQuery = true) + @Query(value = "SELECT DISTINCT ON (f.name) f.* FROM flower f", nativeQuery = true) Page findDistinctAll(Pageable pageable); } From a09a628d24a74234c3bdbfdb0892241ca99c4050 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Sun, 14 Jul 2024 17:45:07 +0900 Subject: [PATCH 14/14] =?UTF-8?q?fix:=EC=BF=BC=EB=A6=AC=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/dictionary/service/DictionaryService.java | 4 ++-- .../fiurinee/domain/flower/repository/FlowerRepository.java | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java b/src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java index ee4275a..9559984 100644 --- a/src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java +++ b/src/main/java/com/example/fiurinee/domain/dictionary/service/DictionaryService.java @@ -19,7 +19,7 @@ public class DictionaryService { public List getAllFlowers(int page, int size) { PageRequest pageRequest = PageRequest.of(page - 1, size); - Page flowers = flowerRepository.findDistinctAll(pageRequest); + List flowers = flowerRepository.findDistinctAll(pageRequest); return flowers.stream() .map(DictionaryResponseDTO::of) .collect(Collectors.toList()); @@ -33,7 +33,7 @@ public List searchFlowersByName(String name) { } public int getTotalPages(int size) { - long count = flowerRepository.count(); + long count = flowerRepository.countDistinctFlowers(); return (int) Math.ceil((double) count / size); } } diff --git a/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java b/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java index bb0370d..6173c34 100644 --- a/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java +++ b/src/main/java/com/example/fiurinee/domain/flower/repository/FlowerRepository.java @@ -25,5 +25,8 @@ public interface FlowerRepository extends JpaRepository { List findDistinctByNameContaining(@Param("name") String name); @Query(value = "SELECT DISTINCT ON (f.name) f.* FROM flower f", nativeQuery = true) - Page findDistinctAll(Pageable pageable); + List findDistinctAll(Pageable pageable); + + @Query(value = "SELECT COUNT(DISTINCT f.name) FROM flower f", nativeQuery = true) + long countDistinctFlowers(); }