-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/295 assigned coupon #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
df2a034
feat: ์ง์ ์ปคํผ์ฟ ํฐ ์ด๋ฒคํธ ์๋น์ค ์ถ๊ฐ
YEJIRYOO 5c433d9
test: ์ง์ ์ปคํผ ์ฟ ํฐ ์๋น์ค, ๋ฆฌ์ค๋ ํ
์คํธ
YEJIRYOO 6a57908
chore: ์ฝ๋ ์ ๋ ฌ
YEJIRYOO 87bc9e6
refactor: watchdog ํ์ฑํ, pin bodyํ ๋ฐ npe ๊ฒ์ฆ ์ถ๊ฐ
YEJIRYOO 8b8a6b4
refactor: assigedcoupon ๋ฒํธ, ์ด๋ฆ blank ๊ฒ์ฆ ์ถ๊ฐ
YEJIRYOO db4d8ab
test: watchdog ํ์ฑํ ๋ฐ blank ๊ฒ์ฆ ์ผ์ด์ค ์ถ๊ฐ
YEJIRYOO a4ad598
refactor: assignedcoupon ์ธํฐ๋ฝํธ global ํ
YEJIRYOO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
...va/com/soongsil/CoffeeChat/domain/assignedcoupon/controller/AssignedCouponController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| package com.soongsil.CoffeeChat.domain.assignedcoupon.controller; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import com.soongsil.CoffeeChat.domain.assignedcoupon.dto.*; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.core.Authentication; | ||
| import org.springframework.web.ErrorResponse; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import com.soongsil.CoffeeChat.domain.assignedcoupon.service.AssignedCouponService; | ||
| import com.soongsil.CoffeeChat.global.api.ApiResponse; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.media.Content; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/v2/assigned-coupons") | ||
| @Tag(name = "ASSIGNED COUPON", description = "์ถ์ ์ ์ฉ ์ง์ ์ปคํผ ์ฟ ํฐ ๊ด๋ จ API") | ||
| public class AssignedCouponController { | ||
|
|
||
| private final AssignedCouponService assignedCouponService; | ||
|
|
||
| // ์ ์ - ๋ณด๊ดํจ ์ง์ ์ ๋ฐ๊ธ ์๊ฒฉ ํ์ธ | ||
| @GetMapping("/eligibility") | ||
| @Operation( | ||
| summary = "์ง์ ์ฟ ํฐ ๋ฐ๊ธ ์๊ฒฉ ํ์ธ", | ||
| description = | ||
| "๋ณด๊ดํจ ์ง์ ์ ํธ์ถํฉ๋๋ค. ๋ณธ์ธ์ name + phoneNum ์ด ์ฌ์ ๋ฑ๋ก๋ ๋์์ ๋ช ๋จ๊ณผ ์ผ์นํ๋์ง ํ์ธํฉ๋๋ค." | ||
| + " ๋ฐ๊ธ ์ด๋ ฅ์ด ์๋ ๊ฒฝ์ฐ ๋ฐ๊ธ ์ ๋ณด๋ฅผ ๋ฐํํฉ๋๋ค.") | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse( | ||
| responseCode = "200", | ||
| description = "์กฐํ ์ฑ๊ณต (result.eligible=true && !alreadyIssued ์ผ ๋๋ง ๋ฐ๊ธ ๋ฒํผ ํ์ฑํ)") | ||
| public ResponseEntity<ApiResponse<AssignedCouponCheckResponse>> checkEligibility( | ||
| Authentication authentication) { | ||
| return ResponseEntity.ok() | ||
| .body( | ||
| ApiResponse.onSuccessOK( | ||
| assignedCouponService.checkEligibility( | ||
| authentication.getName()))); | ||
| } | ||
|
|
||
| // ์ ์ - ๋งค์ฅ PIN ์ธ์ฆ์ผ๋ก ์ง์ ์ฟ ํฐ ๋ฐ๊ธ (=์ฌ์ฉ ์ฒ๋ฆฌ) | ||
| @PostMapping("/coupons") | ||
| @Operation( | ||
| summary = "์ง์ ์ฟ ํฐ ๋ฐ๊ธ (๋งค์ฅ PIN ์ธ์ฆ)", | ||
| description = "๋งค์ฅ ์ง์์ ํ ๋ฒํธ๋ฅผ ์ ๋ ฅ๋ฐ์ ์ต์ข ๊ฒ์ฆ ํ ์ฟ ํฐ์ ๋ฐ๊ธํฉ๋๋ค. ๋ฐ๊ธ๊ณผ ๋์์ ์ฌ์ฉ ์ฒ๋ฆฌ๋์ด ์ฌ์ฌ์ฉ ๋ถ๊ฐํฉ๋๋ค.") | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse( | ||
| responseCode = "200", | ||
| description = "๋ฐ๊ธ๋ ์ฟ ํฐ ์ ๋ณด ๋ฐํ") | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse( | ||
| responseCode = "400", | ||
| description = "EVENT_400_1: ํ ๋ฒํธ ๋ถ์ผ์น | ASSIGNED_COUPON_400: ์ ํ๋ฒํธ ๋ฏธ๋ฑ๋ก", | ||
| content = @Content(schema = @Schema(implementation = ErrorResponse.class))) | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse( | ||
| responseCode = "404", | ||
| description = "ASSIGNED_COUPON_404: ๋ฐ๊ธ ๋์์ ์๋", | ||
| content = @Content(schema = @Schema(implementation = ErrorResponse.class))) | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse( | ||
| responseCode = "409", | ||
| description = "ASSIGNED_COUPON_409: ์ด๋ฏธ ๋ฐ๊ธ๋ ์ฟ ํฐ", | ||
| content = @Content(schema = @Schema(implementation = ErrorResponse.class))) | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse( | ||
| responseCode = "503", | ||
| description = "EVENT_503: ๋์์ฑ ์ฒ๋ฆฌ ์ค๋ฅ", | ||
| content = @Content(schema = @Schema(implementation = ErrorResponse.class))) | ||
| public ResponseEntity<ApiResponse<AssignedCouponResponse>> issueCoupon( | ||
| @RequestParam String storePin, Authentication authentication) { | ||
| return ResponseEntity.ok() | ||
| .body( | ||
| ApiResponse.onSuccessOK( | ||
| assignedCouponService.issueCoupon( | ||
| authentication.getName(), storePin))); | ||
| } | ||
|
|
||
| // ************ ๊ด๋ฆฌ์์ฉ api ************ | ||
|
|
||
| @PostMapping("/admin/register") | ||
| @Operation( | ||
| summary = "์ง์ ์ฟ ํฐ ๋์์ ์ผ๊ด ๋ฑ๋ก (๊ด๋ฆฌ์)", | ||
| description = "๋์์(์ด๋ฆ + ์ ํ๋ฒํธ) ๋ชฉ๋ก์ ๋ฐ์ Redis์ ๋ฑ๋กํฉ๋๋ค. ์ ํ๋ฒํธ๋ ํ์ดํ ์ ๋ฌด ๋ฌด๊ด.") | ||
| public ResponseEntity<ApiResponse<AssignedCouponRegisterResult>> registerTargets( | ||
| @RequestBody List<AssignedCouponTargetRequest> targets) { | ||
| return ResponseEntity.ok() | ||
| .body(ApiResponse.onSuccessOK(assignedCouponService.registerTargets(targets))); | ||
| } | ||
|
|
||
| @PostMapping("/admin/register/one") | ||
| @Operation(summary = "์ง์ ์ฟ ํฐ ๋์์ ๋จ๊ฑด ๋ฑ๋ก (๊ด๋ฆฌ์)") | ||
| public ResponseEntity<ApiResponse<AssignedCouponRegisterResult>> registerOneTarget( | ||
| @RequestBody AssignedCouponTargetRequest target) { | ||
| return ResponseEntity.ok() | ||
| .body( | ||
| ApiResponse.onSuccessOK( | ||
| assignedCouponService.registerTargets(List.of(target)))); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| } | ||
30 changes: 30 additions & 0 deletions
30
...n/java/com/soongsil/CoffeeChat/domain/assignedcoupon/dto/AssignedCouponCheckResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package com.soongsil.CoffeeChat.domain.assignedcoupon.dto; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| @AllArgsConstructor | ||
| public class AssignedCouponCheckResponse { | ||
|
|
||
| private boolean eligible; | ||
| private boolean alreadyIssued; | ||
| private String name; | ||
| private String couponNumber; | ||
| private String status; | ||
| private LocalDateTime issuedAt; | ||
| private LocalDateTime usedAt; | ||
|
|
||
| public static AssignedCouponCheckResponse notEligible() { | ||
| return AssignedCouponCheckResponse.builder() | ||
| .eligible(false) | ||
| .alreadyIssued(false) | ||
| .build(); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
.../java/com/soongsil/CoffeeChat/domain/assignedcoupon/dto/AssignedCouponRegisterResult.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.soongsil.CoffeeChat.domain.assignedcoupon.dto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record AssignedCouponRegisterResult( | ||
| int totalRequested, | ||
| int newlyRegistered, | ||
| int duplicated, | ||
| List<String> failedPhoneNums) { | ||
| } |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/soongsil/CoffeeChat/domain/assignedcoupon/dto/AssignedCouponResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.soongsil.CoffeeChat.domain.assignedcoupon.dto; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| @AllArgsConstructor | ||
| public class AssignedCouponResponse { | ||
|
|
||
| private String couponNumber; | ||
| private String name; | ||
| private String status; | ||
| private LocalDateTime issuedAt; | ||
| private LocalDateTime usedAt; | ||
| } |
4 changes: 4 additions & 0 deletions
4
...n/java/com/soongsil/CoffeeChat/domain/assignedcoupon/dto/AssignedCouponTargetRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package com.soongsil.CoffeeChat.domain.assignedcoupon.dto; | ||
|
|
||
| public record AssignedCouponTargetRequest(String name, String phoneNum) { | ||
| } |
45 changes: 45 additions & 0 deletions
45
...m/soongsil/CoffeeChat/domain/assignedcoupon/message/AssignedCouponIssueEventListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.soongsil.CoffeeChat.domain.assignedcoupon.message; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.event.EventListener; | ||
| import org.springframework.scheduling.annotation.Async; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.soongsil.CoffeeChat.infra.aws.s3.service.AmazonS3Service; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class AssignedCouponIssueEventListener { | ||
|
|
||
| private final AmazonS3Service amazonS3Service; | ||
| private final ObjectMapper objectMapper; | ||
|
|
||
| @Value("${cloud.aws.s3.bucket}") | ||
| private String bucket; | ||
|
|
||
| @Async | ||
| @EventListener | ||
| public void handleAssignedCouponIssuedEvent(AssignedCouponIssuedEvent event) { | ||
| try { | ||
| // AssignedCouponIssuedEvent JSON ์ง๋ ฌํ | ||
| String logJson = objectMapper.writeValueAsString(event); | ||
|
|
||
| String fileNamePrefix = "assigned-coupon-" + event.couponNumber(); | ||
|
|
||
| // event-logs/assigned-coupon ๋๋ ํ ๋ฆฌ์ ์ ์ฅ | ||
| String fileUrl = | ||
| amazonS3Service.uploadJsonFile( | ||
| logJson, "event-logs/assigned-coupon", fileNamePrefix); | ||
|
|
||
| log.info("S3 ์ง์ ์ฟ ํฐ ๋ฐ๊ธ ๋ก๊ทธ ์ ๋ก๋ ์๋ฃ: {} (URL: {})", fileNamePrefix, fileUrl); | ||
|
|
||
| } catch (Exception e) { | ||
| log.error("S3 ์ง์ ์ฟ ํฐ ๋ฐ๊ธ ๋ก๊ทธ ์ ๋ก๋ ์คํจ. couponNumber: {}", event.couponNumber(), e); | ||
| } | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...java/com/soongsil/CoffeeChat/domain/assignedcoupon/message/AssignedCouponIssuedEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.soongsil.CoffeeChat.domain.assignedcoupon.message; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| // ์ง์ ์ฟ ํฐ ๋น๋๊ธฐ ๋ก๊น ์ฉ dto | ||
| public record AssignedCouponIssuedEvent( | ||
| String username, | ||
| String name, | ||
| String phoneNum, | ||
| String couponNumber, | ||
| LocalDateTime issuedAt) { | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.