[이민권] 쿠폰

- 유효번호 쿠폰 사용 안 되는 이슈 수정
- 유효번호 쿠폰이 사용 불가여도 사용 처리 되는 이슈 수정
This commit is contained in:
2024-02-26 15:51:49 +09:00
committed by mountain
parent f734ef099b
commit 2076fb1b81

View File

@ -197,7 +197,12 @@ func downloadCoupons(mongoClient gocommon.MongoClient, w http.ResponseWriter, r
roundnum := binary.BigEndian.Uint32(roundObj[:])
var coupons []string
for _, uid := range coupon.Remains {
coupons = append(coupons, makeCouponKey(roundnum, []byte(uid)))
decUid, err := hex.DecodeString(uid)
if err != nil {
logger.Println("downloadCoupons Fail", err)
continue
}
coupons = append(coupons, makeCouponKey(roundnum, decUid))
}
enc := json.NewEncoder(w)
@ -274,8 +279,8 @@ func useCoupon(mongoClient gocommon.MongoClient, w http.ResponseWriter, r *http.
round, _ = coupon.MakeCouponRoundHash(code)
}
// 1. 내가 이 라운드의 쿠폰을 쓴 적이 있나
already, err := mongoClient.Exists(CollectionCouponUse, bson.M{
// 쿠폰 사용 유무 검사
alreadyused, err := mongoClient.Exists(CollectionCouponUse, bson.M{
"_id": acc,
"rounds": round,
})
@ -285,7 +290,7 @@ func useCoupon(mongoClient gocommon.MongoClient, w http.ResponseWriter, r *http.
return
}
if already {
if alreadyused {
// 이미 이 라운드의 쿠폰을 사용한 적이 있다.
w.WriteHeader(http.StatusConflict)
return
@ -311,7 +316,8 @@ func useCoupon(mongoClient gocommon.MongoClient, w http.ResponseWriter, r *http.
} else {
// 2. 쿠폰을 하나 꺼냄
matched, _, err := mongoClient.Update(CollectionCoupon, bson.M{
"_id": roundObj,
"_id": roundObj,
"remains": key,
}, bson.M{
"$pull": bson.M{"remains": key},
})
@ -339,6 +345,12 @@ func useCoupon(mongoClient gocommon.MongoClient, w http.ResponseWriter, r *http.
}
}
if coupon.Expire < time.Now().Unix() {
// 쿠폰 만료시간 경과
w.WriteHeader(http.StatusInternalServerError)
return
}
if len(coupon.Effect) == 0 {
// 쿠폰이 없네?
w.WriteHeader(http.StatusBadRequest)