예제 #1
0
    def borrows(self, data_list):
        successful_borrows = []
        user = User.get_by_id(data_list[0]["user"]["user_id"])

        with database.atomic():
            num_book_borrowing = BookCirculation.select().where(
                (BookCirculation.user == user)
                & (BookCirculation.return_time.is_null(True))).count()

            if num_book_borrowing + len(data_list) > 5:
                raise BorrowingExceededError()

            for data in data_list:
                book = Book.get_by_id(data["book"]["book_id"])
                data['book'] = book
                data['user'] = user

                if BookCirculation.select().where(
                    (BookCirculation.book == book) &
                    (BookCirculation.return_time.is_null(True))).count() != 0:
                    raise AlreadyBorrowedError()

                successful_borrows.append(BookCirculation.create(**data))

        SendBorrowNotification(successful_borrows).start()

        return successful_borrows
예제 #2
0
    def search_history(self, keyword: str):
        user_query = self.__search_user(keyword)
        book_query = self.__search_book(keyword)

        return DatabaseManager.get_list(BookCirculation.select().where(
            (BookCirculation.user << user_query)
            | (BookCirculation.book << book_query)))
예제 #3
0
    def search_borrowing(self, keyword: str):
        user_query = self.__search_user(keyword)
        book_query = self.__search_book(keyword)

        return DatabaseManager.get_list(BookCirculation.select().where(
            ((BookCirculation.user << user_query)
             | (BookCirculation.book << book_query))
            & BookCirculation.return_time.is_null(True)))
예제 #4
0
 def get_all_being_borrowed(self):
     return DatabaseManager.get_list(BookCirculation.select().where(
         BookCirculation.return_time.is_null(True)))
예제 #5
0
 def get_complete_history(self):
     return DatabaseManager.get_list(BookCirculation.select())