Open psy-choi opened 10 months ago
@app.get("/api/matching/status") def checkingMatchingProcessing(payload : dict() = Depends(verify_jwt_token)): userId = payload["userId"] new_set = Redis.MessageSet("matching:" + userId) if new_set.exist(): return CheckingResponse(1, "매칭 요청이 진행중입니다.", "ENQUEUED") current_time = datetime.datetime.now() ten_minutes_ago = current_time - datetime.timedelta(minutes=10) collection = mongodb.client["jariBeanProd"]["matching"] query = { "matchingTime": {"$lt": current_time, "$gte": ten_minutes_ago}, "userId": userId, "status" : "PROCESS" } data = collection.find_one(query) if data == None: return CheckingResponse(1, "매칭이 진행중입니다.", "PROCESSING", str(data._id), str(data.cafe._id)) return CheckingResponse(1, "매칭이 진행중이지 않습니다.", "NORMAL")
def CheckingResponse(code : int, msg : str, status : str, matchingId : str = None, cafeId : str = None): return {"code" : code, "msg" : msg, "data" : {"code":code, "msg": msg, "status": status, "matchingId" : matchingId, "cafeId" : str}}
1) 만일 redis에 없을 경우에는 ENQUEUED로 응답 2) 만일 MongoDB 에 매칭이 없는 경우에는 PROCESS로 응답(더불어서 매칭의 요소도 함께 전달) 3) 만일 둘 다 해당하지 않을 경우에는 NORMAL로 요청
목적
해결
1) 만일 redis에 없을 경우에는 ENQUEUED로 응답 2) 만일 MongoDB 에 매칭이 없는 경우에는 PROCESS로 응답(더불어서 매칭의 요소도 함께 전달) 3) 만일 둘 다 해당하지 않을 경우에는 NORMAL로 요청