From 2076fb1b81240f08c64f56d30f23617ab961609e Mon Sep 17 00:00:00 2001 From: mklee Date: Mon, 26 Feb 2024 15:51:49 +0900 Subject: [PATCH] =?UTF-8?q?[=EC=9D=B4=EB=AF=BC=EA=B6=8C]=20=EC=BF=A0?= =?UTF-8?q?=ED=8F=B0=20-=20=EC=9C=A0=ED=9A=A8=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EC=BF=A0=ED=8F=B0=20=EC=82=AC=EC=9A=A9=20=EC=95=88=20=EB=90=98?= =?UTF-8?q?=EB=8A=94=20=EC=9D=B4=EC=8A=88=20=EC=88=98=EC=A0=95=20-=20?= =?UTF-8?q?=EC=9C=A0=ED=9A=A8=EB=B2=88=ED=98=B8=20=EC=BF=A0=ED=8F=B0?= =?UTF-8?q?=EC=9D=B4=20=EC=82=AC=EC=9A=A9=20=EB=B6=88=EA=B0=80=EC=97=AC?= =?UTF-8?q?=EB=8F=84=20=EC=82=AC=EC=9A=A9=20=EC=B2=98=EB=A6=AC=20=EB=90=98?= =?UTF-8?q?=EB=8A=94=20=EC=9D=B4=EC=8A=88=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/api_coupon.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/core/api_coupon.go b/core/api_coupon.go index 1d1f4a8..23b99b7 100644 --- a/core/api_coupon.go +++ b/core/api_coupon.go @@ -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)