예제 #1
0
 def fetch(self, filteredByQuestionIDs: list = None, filteredByUUIDs: list = None, filteredByTime: list = None,
           filteredByVote: list = None, filteredByStatuses: list = None):
     data = []
     if filteredByUUIDs is not None:
         for uuid in filteredByUUIDs:
             if str(type(uuid)) == "<class 'str'>": uuid = UUID(uuid)
             for a in self.db:
                 if uuid.toRepresent() == a['answerID']:
                     data.append(a)
     elif filteredByQuestionIDs is not None:
         for uuid in filteredByQuestionIDs:
             if str(type(uuid)) == "<class 'str'>": uuid = UUID(uuid)
             for a in self.db:
                 if uuid.toRepresent() == a['questionID']:
                     data.append(a)
     else:
         data = self.db
     result = []
     for q in data:
         comments = Repositories.commentRepository.fetch(filteredByUUIDs=q['comments']) if 'comments' in q else None
         result.append(Answer(
             answerID=UUID(q['answerID']) if 'answerID' in q else None,
             body=Body(q['body']) if 'body' in q else None,
             createdAt=Time(q['createdAt']) if 'createdAt' in q else None,
             votes=Vote(q['votes']) if 'votes' in q else None,
             status=AnswerStatus(q['status']) if 'status' in q else None,
             comments=comments,
         ))
     return result
예제 #2
0
class BestAnswer:
    def __init__(self, answerID):
        self.ANSWER_ID = UUID(answerID)
        self.DATE = Time(time.time())

    def toRepresent(self):
        return {
            f'{self.ANSWER_ID=}'.split('=')[0].split('.')[1].lower():
            self.ANSWER_ID.toRepresent(),
            f'{self.DATE=}'.split('=')[0].split('.')[1].lower():
            self.DATE.toRepresent()
        }