-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/#111-approve-payment
- Loading branch information
Showing
99 changed files
with
3,879 additions
and
5,389 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
proxy_pass_header Server; | ||
proxy_http_version 1.1; | ||
proxy_set_header Host $http_host; | ||
proxy_set_header Connection $connection_upgrade; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection $connection_upgrade; | ||
proxy_set_header Upgrade $http_upgrade; | ||
|
||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
server { | ||
listen 443 ssl; | ||
server_name ${SERVER_DOMAIN}; | ||
server_name ${SERVER_DOMAIN}; | ||
|
||
ssl_certificate /etc/letsencrypt/live/${SERVER_DOMAIN}/fullchain.pem; | ||
ssl_certificate /etc/letsencrypt/live/${SERVER_DOMAIN}/fullchain.pem; | ||
ssl_certificate_key /etc/letsencrypt/live/${SERVER_DOMAIN}/privkey.pem; | ||
include /etc/letsencrypt/options-ssl-nginx.conf; | ||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; | ||
|
||
location / { | ||
location / { | ||
proxy_pass http://backend; | ||
} | ||
} |
This file contains 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
This file contains 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
91 changes: 91 additions & 0 deletions
91
src/main/java/com/moabam/api/application/coupon/CouponManageService.java
This file contains 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,91 @@ | ||
package com.moabam.api.application.coupon; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.moabam.api.domain.coupon.Coupon; | ||
import com.moabam.api.domain.coupon.CouponWallet; | ||
import com.moabam.api.domain.coupon.repository.CouponManageRepository; | ||
import com.moabam.api.domain.coupon.repository.CouponRepository; | ||
import com.moabam.api.domain.coupon.repository.CouponWalletRepository; | ||
import com.moabam.global.auth.model.AuthMember; | ||
import com.moabam.global.common.util.ClockHolder; | ||
import com.moabam.global.error.exception.BadRequestException; | ||
import com.moabam.global.error.model.ErrorMessage; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class CouponManageService { | ||
|
||
private static final long ISSUE_SIZE = 10; | ||
|
||
private final ClockHolder clockHolder; | ||
|
||
private final CouponRepository couponRepository; | ||
private final CouponManageRepository couponManageRepository; | ||
private final CouponWalletRepository couponWalletRepository; | ||
|
||
@Scheduled(fixedDelay = 1000) | ||
public void issue() { | ||
LocalDate now = clockHolder.date(); | ||
Optional<Coupon> isCoupon = couponRepository.findByStartAt(now); | ||
|
||
if (!canIssue(isCoupon)) { | ||
return; | ||
} | ||
|
||
Coupon coupon = isCoupon.get(); | ||
Set<Long> membersId = couponManageRepository.popMinQueue(coupon.getName(), ISSUE_SIZE); | ||
|
||
membersId.forEach(memberId -> { | ||
int nextStock = couponManageRepository.increaseIssuedStock(coupon.getName()); | ||
|
||
if (coupon.getStock() < nextStock) { | ||
return; | ||
} | ||
|
||
CouponWallet couponWallet = CouponWallet.create(memberId, coupon); | ||
couponWalletRepository.save(couponWallet); | ||
}); | ||
} | ||
|
||
public void register(AuthMember authMember, String couponName) { | ||
double registerTime = System.currentTimeMillis(); | ||
validateRegister(couponName); | ||
couponManageRepository.addIfAbsentQueue(couponName, authMember.id(), registerTime); | ||
} | ||
|
||
public void deleteCouponManage(String couponName) { | ||
couponManageRepository.deleteQueue(couponName); | ||
couponManageRepository.deleteIssuedStock(couponName); | ||
} | ||
|
||
private void validateRegister(String couponName) { | ||
LocalDate now = clockHolder.date(); | ||
Optional<Coupon> coupon = couponRepository.findByStartAt(now); | ||
|
||
if (coupon.isEmpty() || !coupon.get().getName().equals(couponName)) { | ||
throw new BadRequestException(ErrorMessage.INVALID_COUPON_PERIOD); | ||
} | ||
} | ||
|
||
private boolean canIssue(Optional<Coupon> coupon) { | ||
if (coupon.isEmpty()) { | ||
return false; | ||
} | ||
|
||
Coupon currentCoupon = coupon.get(); | ||
int currentStock = couponManageRepository.getIssuedStock(currentCoupon.getName()); | ||
int maxStock = currentCoupon.getStock(); | ||
|
||
return currentStock < maxStock; | ||
} | ||
} |
This file contains 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
36 changes: 0 additions & 36 deletions
36
src/main/java/com/moabam/api/application/coupon/CouponQueueService.java
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.