async def attend(domain_id: str, tid: objectid.ObjectId, uid: int): # TODO(iceboy): check time. try: await document.capped_inc_status(domain_id, document.TYPE_CONTEST, tid, uid, 'attend', 1, 0, 1) except errors.DuplicateKeyError: raise error.ContestAlreadyAttendedError(domain_id, tid, uid) from None return await document.inc(domain_id, document.TYPE_CONTEST, tid, 'attend', 1)
async def attend(domain_id: str, doc_type: int, tid: objectid.ObjectId, uid: int): # TODO(iceboy): check time. if doc_type not in [document.TYPE_CONTEST, document.TYPE_HOMEWORK]: raise error.InvalidArgumentError('doc_type') try: await document.capped_inc_status(domain_id, doc_type, tid, uid, 'attend', 1, 0, 1) except errors.DuplicateKeyError: if doc_type == document.TYPE_CONTEST: raise error.ContestAlreadyAttendedError(domain_id, tid, uid) from None elif doc_type == document.TYPE_HOMEWORK: raise error.HomeworkAlreadyAttendedError(domain_id, tid, uid) from None return await document.inc(domain_id, doc_type, tid, 'attend', 1)