Skip to content

Commit 362dd9e

Browse files
authored
Merge pull request #5 from MicrosoftLearning/AddPython
Add Python labs for initial update lab 2, 3, 4, 5
2 parents 6999896 + 90adf59 commit 362dd9e

137 files changed

Lines changed: 9299 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from dataclasses import dataclass
2+
3+
@dataclass
4+
class Author:
5+
id: int
6+
name: str
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from dataclasses import dataclass
2+
from typing import Optional
3+
from .author import Author
4+
5+
@dataclass
6+
class Book:
7+
id: int
8+
title: str
9+
author_id: int
10+
genre: str
11+
image_name: str
12+
isbn: str
13+
author: Optional[Author] = None
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from dataclasses import dataclass
2+
from typing import Optional
3+
from datetime import datetime
4+
from .book import Book
5+
6+
@dataclass
7+
class BookItem:
8+
id: int
9+
book_id: int
10+
acquisition_date: datetime
11+
condition: Optional[str] = None
12+
book: Optional[Book] = None
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from dataclasses import dataclass
2+
from typing import Optional
3+
from datetime import datetime
4+
from .patron import Patron
5+
from .book_item import BookItem
6+
7+
@dataclass
8+
class Loan:
9+
id: int
10+
book_item_id: int
11+
patron_id: int
12+
patron: Optional[Patron] = None
13+
loan_date: datetime = None
14+
due_date: datetime = None
15+
return_date: Optional[datetime] = None
16+
book_item: Optional[BookItem] = None
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from dataclasses import dataclass, field
2+
from typing import List, Optional
3+
from datetime import datetime
4+
# from .loan import Loan # Use string annotation to avoid circular import
5+
6+
@dataclass
7+
class Patron:
8+
id: int
9+
name: str
10+
membership_end: datetime
11+
membership_start: datetime
12+
image_name: Optional[str] = None
13+
loans: List['Loan'] = field(default_factory=list)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from enum import Enum
2+
3+
class LoanExtensionStatus(Enum):
4+
SUCCESS = 'Book loan extension was successful.'
5+
LOAN_NOT_FOUND = 'Loan not found.'
6+
LOAN_EXPIRED = 'Cannot extend book loan as it already has expired. Return the book instead.'
7+
MEMBERSHIP_EXPIRED = "Cannot extend book loan due to expired patron's membership."
8+
LOAN_RETURNED = 'Cannot extend book loan as the book is already returned.'
9+
ERROR = 'Cannot extend book loan due to an error.'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from enum import Enum
2+
3+
class LoanReturnStatus(Enum):
4+
SUCCESS = 'Book was successfully returned.'
5+
LOAN_NOT_FOUND = 'Loan not found.'
6+
ALREADY_RETURNED = 'Cannot return book as the book is already returned.'
7+
ERROR = 'Cannot return book due to an error.'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from enum import Enum
2+
3+
class MembershipRenewalStatus(Enum):
4+
SUCCESS = 'Membership renewal was successful.'
5+
PATRON_NOT_FOUND = 'Patron not found.'
6+
TOO_EARLY_TO_RENEW = 'It is too early to renew the membership.'
7+
LOAN_NOT_RETURNED = 'Cannot renew membership due to an outstanding loan.'
8+
ERROR = 'Cannot renew membership due to an error.'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from abc import ABC, abstractmethod
2+
from typing import Optional
3+
from ..entities.loan import Loan
4+
5+
class ILoanRepository(ABC):
6+
@abstractmethod
7+
def get_loan(self, loan_id: int) -> Optional[Loan]:
8+
pass
9+
10+
@abstractmethod
11+
def update_loan(self, loan: Loan) -> None:
12+
pass
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from abc import ABC, abstractmethod
2+
from ..enums.loan_return_status import LoanReturnStatus
3+
from ..enums.loan_extension_status import LoanExtensionStatus
4+
5+
class ILoanService(ABC):
6+
@abstractmethod
7+
def return_loan(self, loan_id: int) -> LoanReturnStatus:
8+
pass
9+
10+
@abstractmethod
11+
def extend_loan(self, loan_id: int) -> LoanExtensionStatus:
12+
pass

0 commit comments

Comments
 (0)