Compare commits

..

2 Commits

Author SHA1 Message Date
e38e8a91e5 쿠폰 버그 체리픽 2024-03-04 19:26:20 +09:00
2076fb1b81 [이민권] 쿠폰
- 유효번호 쿠폰 사용 안 되는 이슈 수정
- 유효번호 쿠폰이 사용 불가여도 사용 처리 되는 이슈 수정
2024-03-04 19:24:19 +09:00

View File

@ -197,7 +197,12 @@ func downloadCoupons(mongoClient gocommon.MongoClient, w http.ResponseWriter, r
roundnum := binary.BigEndian.Uint32(roundObj[:]) roundnum := binary.BigEndian.Uint32(roundObj[:])
var coupons []string var coupons []string
for _, uid := range coupon.Remains { 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) enc := json.NewEncoder(w)
@ -274,8 +279,8 @@ func useCoupon(mongoClient gocommon.MongoClient, w http.ResponseWriter, r *http.
round, _ = coupon.MakeCouponRoundHash(code) round, _ = coupon.MakeCouponRoundHash(code)
} }
// 1. 내가 이 라운드의 쿠폰을 쓴 적이 있나 // 쿠폰 사용 유무 검사
already, err := mongoClient.Exists(CollectionCouponUse, bson.M{ alreadyused, err := mongoClient.Exists(CollectionCouponUse, bson.M{
"_id": acc, "_id": acc,
"rounds": round, "rounds": round,
}) })
@ -285,7 +290,7 @@ func useCoupon(mongoClient gocommon.MongoClient, w http.ResponseWriter, r *http.
return return
} }
if already { if alreadyused {
// 이미 이 라운드의 쿠폰을 사용한 적이 있다. // 이미 이 라운드의 쿠폰을 사용한 적이 있다.
w.WriteHeader(http.StatusConflict) w.WriteHeader(http.StatusConflict)
return return
@ -312,6 +317,7 @@ func useCoupon(mongoClient gocommon.MongoClient, w http.ResponseWriter, r *http.
// 2. 쿠폰을 하나 꺼냄 // 2. 쿠폰을 하나 꺼냄
matched, _, err := mongoClient.Update(CollectionCoupon, bson.M{ matched, _, err := mongoClient.Update(CollectionCoupon, bson.M{
"_id": roundObj, "_id": roundObj,
"remains": key,
}, bson.M{ }, bson.M{
"$pull": bson.M{"remains": key}, "$pull": bson.M{"remains": key},
}) })