Compare commits
2 Commits
f734ef099b
...
e38e8a91e5
| Author | SHA1 | Date | |
|---|---|---|---|
| e38e8a91e5 | |||
| 2076fb1b81 |
@ -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
|
||||||
@ -311,7 +316,8 @@ func useCoupon(mongoClient gocommon.MongoClient, w http.ResponseWriter, r *http.
|
|||||||
} else {
|
} else {
|
||||||
// 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},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user