-
Notifications
You must be signed in to change notification settings - Fork 68
/
book.py
38 lines (30 loc) · 991 Bytes
/
book.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
"""Book domain"""
from typing import Optional
from .isbn import Isbn
class Book:
"""Book represents your collection of books as an entity."""
def __init__(
self,
book_id: str,
isbn: Isbn,
title: str,
page: int,
read_page: int = 0,
created_at: Optional[int] = None,
updated_at: Optional[int] = None,
):
self.book_id: str = book_id
self.isbn: Isbn = isbn
self.title: str = title
self.page: int = page
self.read_page: int = read_page
self.created_at: Optional[int] = created_at
self.updated_at: Optional[int] = updated_at
def __eq__(self, obj: object) -> bool:
if isinstance(obj, Book):
return self.book_id == obj.book_id
return False
def is_already_read(self) -> bool:
"""Return True if the message has already been read, False otherwise."""
return self.page == self.read_page