From 113014aa13837ec1e9dc3cee8c0ca78ad56b520c Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Sat, 11 Nov 2023 19:15:47 +0900 Subject: [PATCH 01/18] chore: remove common-logging --- build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.gradle b/build.gradle index 3975a96e..cf4ce63f 100644 --- a/build.gradle +++ b/build.gradle @@ -71,6 +71,10 @@ dependencies { implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.7' } +configurations { + all*.exclude group: 'commons-logging', module: 'commons-logging' +} + tasks.named('test') { useJUnitPlatform() } \ No newline at end of file From 9c570843fedf5108c59a58ba441f13746bd3213b Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Sun, 12 Nov 2023 22:35:31 +0900 Subject: [PATCH 02/18] chore: add firebase all key in git-ignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4e5aa9f6..621dfb27 100644 --- a/.gitignore +++ b/.gitignore @@ -50,7 +50,7 @@ out/ src/.DS_Store # Firebase -/src/main/resources/firebase/gifthub-b2dcb-firebase-adminsdk-yj7uq-912097b9ae.json +/src/main/resources/firebase/ # Actions Secrets actions-secrets.yml From 21b6719c8cf75a5d960005b01bc2dce053c344fb Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Sun, 12 Nov 2023 22:37:54 +0900 Subject: [PATCH 03/18] fix: get key-path from application.yml file depending on the env --- .../java/org/swmaestro/repl/gifthub/config/FCMConfig.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/swmaestro/repl/gifthub/config/FCMConfig.java b/src/main/java/org/swmaestro/repl/gifthub/config/FCMConfig.java index d5be1c0a..dd49f5c3 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/config/FCMConfig.java +++ b/src/main/java/org/swmaestro/repl/gifthub/config/FCMConfig.java @@ -4,6 +4,7 @@ import java.io.InputStream; import java.util.List; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; @@ -15,9 +16,12 @@ @Configuration public class FCMConfig { + @Value("${firebase.key-path}") + private String keyPath; + @Bean FirebaseMessaging firebaseMessaging() throws IOException { - ClassPathResource resource = new ClassPathResource("firebase/gifthub-b2dcb-firebase-adminsdk-yj7uq-912097b9ae.json"); + ClassPathResource resource = new ClassPathResource(keyPath); InputStream refreshToken = resource.getInputStream(); From c950feb65200c3c013f57f64a54c09320ff2b70c Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Sun, 12 Nov 2023 22:39:16 +0900 Subject: [PATCH 04/18] chore: remove excluded code lines --- build.gradle | 4 ---- 1 file changed, 4 deletions(-) diff --git a/build.gradle b/build.gradle index cf4ce63f..3975a96e 100644 --- a/build.gradle +++ b/build.gradle @@ -71,10 +71,6 @@ dependencies { implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.7' } -configurations { - all*.exclude group: 'commons-logging', module: 'commons-logging' -} - tasks.named('test') { useJUnitPlatform() } \ No newline at end of file From edac686f793d8c1f50e21a3a794ebf9561f2ebe1 Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Sun, 12 Nov 2023 22:55:30 +0900 Subject: [PATCH 05/18] fix: modify default-image-path --- .../swmaestro/repl/gifthub/vouchers/service/StorageService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/StorageService.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/StorageService.java index e96eddb0..e2db9307 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/StorageService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/StorageService.java @@ -60,7 +60,7 @@ private String getUUidFileName(String fileName) { } public String getDefaultImagePath(String dirName) { - return "https://" + cloudFrontBucketName + "/" + dirName + "/" + defaultImageFile; + return "https://" + cloudFrontBucketName + "/" + defaultImageFile; } public String getPresignedUrlForSaveVoucher(String dirName, String extension) { From 23bd6d7a83788869c1c01ed5381d837ec478ab56 Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Mon, 13 Nov 2023 00:26:57 +0900 Subject: [PATCH 06/18] fix: divide firebase json depending environment in github-actions --- .github/workflows/dev-cd.yml | 2 +- .github/workflows/dev-ci.yml | 2 +- .github/workflows/prod-cd.yml | 4 ++-- .github/workflows/prod-ci.yml | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/dev-cd.yml b/.github/workflows/dev-cd.yml index 52dbd434..7aa58bcd 100644 --- a/.github/workflows/dev-cd.yml +++ b/.github/workflows/dev-cd.yml @@ -66,7 +66,7 @@ jobs: uses: jsdaniell/create-json@v1.2.2 with: name: "./src/main/resources/firebase/gifthub-b2dcb-firebase-adminsdk-yj7uq-912097b9ae.json" - json: ${{ secrets.FIREBASE_JSON }} + json: ${{ secrets.FIREBASE_DEVELOPMENT_JSON }} # Docker 이미지 build 및 push - name: docker build and push diff --git a/.github/workflows/dev-ci.yml b/.github/workflows/dev-ci.yml index edea652f..2ab256b2 100644 --- a/.github/workflows/dev-ci.yml +++ b/.github/workflows/dev-ci.yml @@ -64,7 +64,7 @@ jobs: uses: jsdaniell/create-json@v1.2.2 with: name: "./src/main/resources/firebase/gifthub-b2dcb-firebase-adminsdk-yj7uq-912097b9ae.json" - json: ${{ secrets.FIREBASE_JSON }} + json: ${{ secrets.FIREBASE_DEVELOPMENT_JSON }} # 5. 테스트를 위한 MySQL 설정 - name: Setup MySQL diff --git a/.github/workflows/prod-cd.yml b/.github/workflows/prod-cd.yml index a871d8fd..ec450df8 100644 --- a/.github/workflows/prod-cd.yml +++ b/.github/workflows/prod-cd.yml @@ -65,8 +65,8 @@ jobs: - name: Create Json uses: jsdaniell/create-json@v1.2.2 with: - name: "./src/main/resources/firebase/gifthub-b2dcb-firebase-adminsdk-yj7uq-912097b9ae.json" - json: ${{ secrets.FIREBASE_JSON }} + name: "./src/main/resources/firebase/gifthub-production-3d052-firebase-adminsdk-zkstv-377ec5747b.json" + json: ${{ secrets.FIREBASE_PRODUCTION_JSON }} # Docker 이미지 build 및 push - name: docker build and push diff --git a/.github/workflows/prod-ci.yml b/.github/workflows/prod-ci.yml index b2d3cdd7..02195028 100644 --- a/.github/workflows/prod-ci.yml +++ b/.github/workflows/prod-ci.yml @@ -63,8 +63,8 @@ jobs: - name: Create Json uses: jsdaniell/create-json@v1.2.2 with: - name: "./src/main/resources/firebase/gifthub-b2dcb-firebase-adminsdk-yj7uq-912097b9ae.json" - json: ${{ secrets.FIREBASE_JSON }} + name: "./src/main/resources/firebase/gifthub-production-3d052-firebase-adminsdk-zkstv-377ec5747b.json" + json: ${{ secrets.FIREBASE_PRODUCTION_JSON }} # 5. 테스트를 위한 MySQL 설정 - name: Setup MySQL From 6135c09b36c3ac0b30ce435bc176267bf60211a7 Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Mon, 13 Nov 2023 01:36:33 +0900 Subject: [PATCH 07/18] fix: handle production-ci test fail --- .github/workflows/prod-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/prod-ci.yml b/.github/workflows/prod-ci.yml index 02195028..92b7369b 100644 --- a/.github/workflows/prod-ci.yml +++ b/.github/workflows/prod-ci.yml @@ -63,8 +63,8 @@ jobs: - name: Create Json uses: jsdaniell/create-json@v1.2.2 with: - name: "./src/main/resources/firebase/gifthub-production-3d052-firebase-adminsdk-zkstv-377ec5747b.json" - json: ${{ secrets.FIREBASE_PRODUCTION_JSON }} + name: "./src/main/resources/firebase/gifthub-b2dcb-firebase-adminsdk-yj7uq-912097b9ae.json" + json: ${{ secrets.FIREBASE_DEVELOPMENT_JSON }} # 5. 테스트를 위한 MySQL 설정 - name: Setup MySQL From 7f2173b01a1978e6b8440d68086caa0cb82cfada Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Tue, 14 Nov 2023 09:25:55 +0900 Subject: [PATCH 08/18] fix: modify barcord column-length --- .../org/swmaestro/repl/gifthub/vouchers/entity/Voucher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/Voucher.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/Voucher.java index 3b5bb5b2..73c6f2ef 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/Voucher.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/entity/Voucher.java @@ -37,7 +37,7 @@ public class Voucher extends BaseTimeEntity { @JoinColumn(name = "product_id", nullable = false) private Product product; - @Column(length = 12) + @Column(length = 16) private String barcode; @Column From ce73b627b9c5353f3db7ebe9feb680846fe0ca11 Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Tue, 14 Nov 2023 12:41:54 +0900 Subject: [PATCH 09/18] fix: set image-url certainly --- .../repl/gifthub/vouchers/service/VoucherSaveService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherSaveService.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherSaveService.java index 47a1e0a2..62797437 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherSaveService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherSaveService.java @@ -102,12 +102,12 @@ public Mono handleGptResponse(VoucherAutoSaveRequestDto v public Mono handleSearchResponse(VoucherSaveRequestDto voucherSaveRequestDto, String username, String filename) { return searchService.search(createQuery(productNameProcessor.preprocessing(voucherSaveRequestDto))).flatMap(searchResponseDto -> { + voucherSaveRequestDto.setImageUrl(filename); try { String brandName = searchResponseDto.getHits().getHitsList().get(0).getSource().getBrandName(); String productName = searchResponseDto.getHits().getHitsList().get(0).getSource().getProductName(); voucherSaveRequestDto.setBrandName(brandName); voucherSaveRequestDto.setProductName(productName); - voucherSaveRequestDto.setImageUrl(filename); System.out.println("Search response"); System.out.println(brandName); System.out.println(productName); From 6b1a6934dd5ed1c8c1803ff5c18b096a996ed4e9 Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Tue, 14 Nov 2023 23:00:56 +0900 Subject: [PATCH 10/18] feat: implement voucher-update-response-dto --- .../dto/VoucherUpdateResponseDto.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUpdateResponseDto.java diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUpdateResponseDto.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUpdateResponseDto.java new file mode 100644 index 00000000..59d7b500 --- /dev/null +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUpdateResponseDto.java @@ -0,0 +1,43 @@ +package org.swmaestro.repl.gifthub.vouchers.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) +public class VoucherUpdateResponseDto { + private Long id; + private Long productId; + private String barcode; + private String expiresAt; + private Integer price; + private Integer balance; + private String imageUrl; + @JsonProperty("is_accessible") + private boolean accessible; + @JsonProperty("is_shared") + private boolean shared; + + @Builder + public VoucherUpdateResponseDto(Long id, Long productId, String barcode, String expiresAt, Integer price, + Integer balance, String imageUrl, boolean accessible, boolean shared) { + this.id = id; + this.productId = productId; + this.barcode = barcode; + this.expiresAt = expiresAt; + this.price = price; + this.balance = balance; + this.imageUrl = imageUrl; + this.accessible = accessible; + this.shared = shared; + } +} From 35b1f62ca674a0f227dac39eaebc0e27265aad82 Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Tue, 14 Nov 2023 23:01:47 +0900 Subject: [PATCH 11/18] fix: modify voucher-update-api return value to voucher-update-response-dto --- .../vouchers/controller/VoucherController.java | 3 ++- .../gifthub/vouchers/service/VoucherService.java | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherController.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherController.java index deac3bea..148e680b 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherController.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherController.java @@ -27,6 +27,7 @@ import org.swmaestro.repl.gifthub.vouchers.dto.VoucherShareRequestDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherShareResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUpdateRequestDto; +import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUpdateResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseRequestDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseResponseDto; import org.swmaestro.repl.gifthub.vouchers.service.PendingVoucherService; @@ -132,7 +133,7 @@ public ResponseEntity listVoucher(HttpServletRequest request, @RequestP }) public ResponseEntity updateVoucher(HttpServletRequest request, @PathVariable Long voucherId, @RequestBody VoucherUpdateRequestDto voucherUpdateRequestDto) throws IOException { - VoucherSaveResponseDto updatedVoucher = voucherService.update(voucherId, voucherUpdateRequestDto); + VoucherUpdateResponseDto updatedVoucher = voucherService.update(voucherId, voucherUpdateRequestDto); return ResponseEntity.ok( SuccessMessage.builder() .path(request.getRequestURI()) diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java index 0902770e..6a9d2d2b 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java @@ -22,6 +22,7 @@ import org.swmaestro.repl.gifthub.vouchers.dto.VoucherShareRequestDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherShareResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUpdateRequestDto; +import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUpdateResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseRequestDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseResponseDto; import org.swmaestro.repl.gifthub.vouchers.entity.Brand; @@ -164,7 +165,7 @@ public List list(String username) { /* 기프티콘 정보 수정 메서드 */ - public VoucherSaveResponseDto update(Long voucherId, VoucherUpdateRequestDto voucherUpdateRequestDto) { + public VoucherUpdateResponseDto update(Long voucherId, VoucherUpdateRequestDto voucherUpdateRequestDto) { Voucher voucher = voucherRepository.findById(voucherId) .orElseThrow(() -> new BusinessException("존재하지 않는 상품권 입니다.", StatusEnum.NOT_FOUND)); // Balance 수정 @@ -211,8 +212,18 @@ public VoucherSaveResponseDto update(Long voucherId, VoucherUpdateRequestDto vou voucherRepository.save(voucher); - return VoucherSaveResponseDto.builder() + return VoucherUpdateResponseDto.builder() .id(voucherId) + .accessible(voucher.getDeletedAt() == null) + .id(voucher.getId()) + .productId(voucher.getProduct().getId()) + .barcode(voucher.getBarcode()) + .price(voucher.getProduct().getPrice()) + .balance(voucher.getBalance()) + .expiresAt(voucher.getExpiresAt().toString()) + .imageUrl(voucher.getImageUrl()) + .accessible(voucher.getDeletedAt() == null) + .shared(giftCardService.isExist(voucher.getId())) .build(); } From c91627fc6ec34550df6c4e6d43a95b09ae327638 Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Tue, 14 Nov 2023 23:02:00 +0900 Subject: [PATCH 12/18] test: modify to match dto --- .../gifthub/vouchers/controller/VoucherControllerTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherControllerTest.java b/src/test/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherControllerTest.java index 4d2dfa17..1d3cb1d0 100644 --- a/src/test/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherControllerTest.java +++ b/src/test/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherControllerTest.java @@ -30,6 +30,7 @@ import org.swmaestro.repl.gifthub.vouchers.dto.VoucherShareRequestDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherShareResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUpdateRequestDto; +import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUpdateResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseRequestDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseResponseDto; import org.swmaestro.repl.gifthub.vouchers.service.GptService; @@ -176,20 +177,20 @@ void voucherUpdateTest() throws Exception { .expiresAt("2023-06-15") .build(); - VoucherSaveResponseDto voucherSaveResponseDto = VoucherSaveResponseDto.builder() + VoucherUpdateResponseDto voucherUpdateResponseDto = VoucherUpdateResponseDto.builder() .id(1L) .build(); // when when(jwtProvider.resolveToken(any())).thenReturn("my_awesome_access_token"); when(jwtProvider.getUsername(anyString())).thenReturn("이진우"); - when(voucherService.update(any(), any(VoucherUpdateRequestDto.class))).thenReturn(voucherSaveResponseDto); + when(voucherService.update(any(), any(VoucherUpdateRequestDto.class))).thenReturn(voucherUpdateResponseDto); // then mockMvc.perform(patch("/vouchers/1") .header("Authorization", "Bearer my_awesome_access_token") .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(voucherSaveResponseDto))) + .content(objectMapper.writeValueAsString(voucherUpdateResponseDto))) .andExpect(status().isOk()); } From a02ffaf65e563ce944d67a00b919ae560ec31e05 Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Thu, 16 Nov 2023 23:05:31 +0900 Subject: [PATCH 13/18] fix: add is-checked field --- .../repl/gifthub/vouchers/dto/VoucherUpdateResponseDto.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUpdateResponseDto.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUpdateResponseDto.java index 59d7b500..d2f3aeae 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUpdateResponseDto.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUpdateResponseDto.java @@ -26,10 +26,12 @@ public class VoucherUpdateResponseDto { private boolean accessible; @JsonProperty("is_shared") private boolean shared; + @JsonProperty("is_checked") + private boolean checked; @Builder public VoucherUpdateResponseDto(Long id, Long productId, String barcode, String expiresAt, Integer price, - Integer balance, String imageUrl, boolean accessible, boolean shared) { + Integer balance, String imageUrl, boolean accessible, boolean shared, boolean checked) { this.id = id; this.productId = productId; this.barcode = barcode; @@ -39,5 +41,6 @@ public VoucherUpdateResponseDto(Long id, Long productId, String barcode, String this.imageUrl = imageUrl; this.accessible = accessible; this.shared = shared; + this.checked = checked; } } From 65bd539e3a39aefecfea9d427f9b93343a09a78e Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Thu, 16 Nov 2023 23:05:46 +0900 Subject: [PATCH 14/18] fix: set is-checked field in dto --- .../swmaestro/repl/gifthub/vouchers/service/VoucherService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java index 6a9d2d2b..d2a0ae1a 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java @@ -224,6 +224,7 @@ public VoucherUpdateResponseDto update(Long voucherId, VoucherUpdateRequestDto v .imageUrl(voucher.getImageUrl()) .accessible(voucher.getDeletedAt() == null) .shared(giftCardService.isExist(voucher.getId())) + .checked(voucher.isChecked()) .build(); } From 5ee9b14e0a7c23a3adebd2acd118aa6b8a41c51a Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Sat, 18 Nov 2023 22:55:41 +0900 Subject: [PATCH 15/18] feat: implement webclient-config --- .../repl/gifthub/config/WebClientConfig.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/org/swmaestro/repl/gifthub/config/WebClientConfig.java diff --git a/src/main/java/org/swmaestro/repl/gifthub/config/WebClientConfig.java b/src/main/java/org/swmaestro/repl/gifthub/config/WebClientConfig.java new file mode 100644 index 00000000..9a699b10 --- /dev/null +++ b/src/main/java/org/swmaestro/repl/gifthub/config/WebClientConfig.java @@ -0,0 +1,31 @@ +package org.swmaestro.repl.gifthub.config; + +import java.time.Duration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.reactive.ReactorClientHttpConnector; +import org.springframework.web.reactive.function.client.WebClient; + +import reactor.netty.http.client.HttpClient; +import reactor.netty.resources.ConnectionProvider; + +@Configuration +public class WebClientConfig { + @Bean + public WebClient webClient() { + return WebClient.builder() + .clientConnector(new ReactorClientHttpConnector(httpClient)) + .build(); + } + + HttpClient httpClient = HttpClient.create( + ConnectionProvider.builder("gifthub-connections") + .maxConnections(2) + .maxIdleTime(Duration.ofSeconds(30)) + .pendingAcquireTimeout(Duration.ofSeconds(45)) + .evictInBackground(Duration.ofSeconds(30)) + .lifo() + .build() + ); +} From e88481c47d4e172eb214a4d2352bad27785a4ace Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Sat, 18 Nov 2023 22:57:01 +0900 Subject: [PATCH 16/18] fix: modify to construct injection from webclient config --- .../gifthub/vouchers/service/GptService.java | 16 +++++++------- .../vouchers/service/SearchService.java | 21 +++++-------------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/GptService.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/GptService.java index 066ae0f0..bfcb3765 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/GptService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/GptService.java @@ -5,10 +5,9 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import org.springframework.web.reactive.function.client.WebClient; +import org.swmaestro.repl.gifthub.config.WebClientConfig; import org.swmaestro.repl.gifthub.vouchers.dto.GptResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherAutoSaveRequestDto; @@ -20,19 +19,19 @@ @Service public class GptService { - private final WebClient gptClient; @Value("${openai.api-url}") private String apiUrl; @Value("${openai.api-key}") private String apiKey; private String prompt; - @Autowired private ObjectMapper objectMapper; + private final WebClientConfig webClientConfig; - public GptService(WebClient.Builder webClientBuilder, @Value("/gpt/question.txt") String promptPath) throws IOException { - this.gptClient = webClientBuilder.build(); + public GptService(@Value("/gpt/question.txt") String promptPath, WebClientConfig webClientConfig, ObjectMapper objectMapper) throws IOException { this.prompt = loadQuestionFromFile(promptPath); + this.webClientConfig = webClientConfig; + this.objectMapper = objectMapper; } public Mono getGptResponse(VoucherAutoSaveRequestDto voucherAutoSaveRequestDto) { @@ -47,13 +46,14 @@ public Mono getGptResponse(VoucherAutoSaveRequestDto voucherAuto message.put("role", "assistant"); message.put("content", prompt); - return gptClient.post() + return webClientConfig.webClient().post() .uri(apiUrl) .header("Authorization", "Bearer " + apiKey) .header("Content-Type", "application/json") .body(Mono.just(requestBody), ObjectNode.class) .retrieve() - .bodyToMono(GptResponseDto.class); + .bodyToMono(GptResponseDto.class) + .retry(2); } public String loadQuestionFromFile(String filePath) throws IOException { diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/SearchService.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/SearchService.java index 944eb930..dd85ef8f 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/SearchService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/SearchService.java @@ -2,11 +2,9 @@ import java.util.Base64; -import javax.annotation.PostConstruct; - import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import org.springframework.web.reactive.function.client.WebClient; +import org.swmaestro.repl.gifthub.config.WebClientConfig; import org.swmaestro.repl.gifthub.vouchers.dto.SearchResponseDto; import lombok.RequiredArgsConstructor; @@ -21,25 +19,16 @@ public class SearchService { @Value("${opensearch.password}") private String password; - private String auth; @Value("${opensearch.base-url}") private String baseUrl; - private WebClient openSearchClient; - - @PostConstruct - public void init() { - openSearchClient = WebClient.builder() - .baseUrl(baseUrl) - .build(); - auth = "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); - } + private final WebClientConfig webClientConfig; public Mono search(String query) { - return openSearchClient.post() - .uri("/product/_search") - .header("Authorization", auth) + return webClientConfig.webClient().post() + .uri(baseUrl + "/product/_search") + .header("Authorization", "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes())) .header("Content-Type", "application/json") .bodyValue(query) .retrieve() From 2d31a88cc4b5365cf7df7254e3a0eb16d8d7f316 Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Sat, 18 Nov 2023 22:57:28 +0900 Subject: [PATCH 17/18] fix: modify time-out limit to 5 minutes --- .../repl/gifthub/vouchers/service/VoucherSaveService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherSaveService.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherSaveService.java index 62797437..5659643b 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherSaveService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherSaveService.java @@ -72,8 +72,8 @@ public void execute(VoucherAutoSaveRequestDto voucherAutoSaveRequestDto, String fcmNotificationService.sendNotification("기프티콘 등록 실패", "이미 등록된 기프티콘 입니다.", username); notificationService.save(userService.read(username), null, NotificationType.REGISTERED, "이미 등록된 기프티콘 입니다."); } else { - fcmNotificationService.sendNotification("기프티콘 등록 실패", "자동 등록에 실패했습니다. 수동 등록을 이용해 주세요.", username); - notificationService.save(userService.read(username), null, NotificationType.REGISTERED, "자동 등록에 실패했습니다. 수동 등록을 이용해 주세요."); + fcmNotificationService.sendNotification("기프티콘 등록 실패", "자동 등록에 실패했습니다. 다시 시도해 주세요.", username); + notificationService.save(userService.read(username), null, NotificationType.REGISTERED, "자동 등록에 실패했습니다. 다시 시도해 주세요."); } }); } @@ -83,7 +83,7 @@ public Mono handleGptResponse(VoucherAutoSaveRequestDto v GptTimeoutException { return gptService.getGptResponse(voucherAutoSaveRequestDto) - .timeout(Duration.ofMinutes(15)) + .timeout(Duration.ofMinutes(5)) .onErrorResume(GptTimeoutException.class, throwable -> Mono.error(new GptTimeoutException())) .flatMap(response -> { VoucherSaveRequestDto voucherSaveRequestDto = null; From df7f0ca890a9cdc8b66ebc6f3dacfa921ffadd7d Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Sun, 19 Nov 2023 00:45:47 +0900 Subject: [PATCH 18/18] fix: modify max-connection pending-acquire-max-count default --- .../org/swmaestro/repl/gifthub/config/WebClientConfig.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/swmaestro/repl/gifthub/config/WebClientConfig.java b/src/main/java/org/swmaestro/repl/gifthub/config/WebClientConfig.java index 9a699b10..ef8dd52d 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/config/WebClientConfig.java +++ b/src/main/java/org/swmaestro/repl/gifthub/config/WebClientConfig.java @@ -21,9 +21,10 @@ public WebClient webClient() { HttpClient httpClient = HttpClient.create( ConnectionProvider.builder("gifthub-connections") - .maxConnections(2) + .maxConnections(100) .maxIdleTime(Duration.ofSeconds(30)) .pendingAcquireTimeout(Duration.ofSeconds(45)) + .pendingAcquireMaxCount(-1) .evictInBackground(Duration.ofSeconds(30)) .lifo() .build()