-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4b4b4b
commit 1836bae
Showing
3 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from datetime import datetime | ||
from typing import List, Optional | ||
from pydantic import BaseModel | ||
|
||
from db import models | ||
|
||
class Book(BaseModel): | ||
isbn: str | ||
title: Optional[str] | ||
author: Optional[str] | ||
thumbnail_url: Optional[str] | ||
published_date: Optional[datetime] | ||
created_at: datetime = None | ||
|
||
class Config: | ||
orm_mode = True | ||
|
||
class Read(BaseModel): | ||
user_id: str | ||
isbn: str | ||
created_at: datetime | ||
|
||
class Config: | ||
orm_mode = True | ||
|
||
class User(BaseModel): | ||
user_id: str | ||
name: str | ||
books: List[Book] | ||
read: List[Read] | ||
|
||
def from_orm_custom(orm: models.User): | ||
user = User.from_orm(orm) | ||
for i, read in enumerate(user.read): | ||
user.books[i].created_at = read.created_at | ||
del user.read | ||
return user | ||
|
||
class Config: | ||
orm_mode = True | ||
|
||
class MockUser(BaseModel): | ||
user_id: str | ||
name: str | ||
books: List[Book] |