Added pool_recycle to create_engine. Added logic to add shelves.

This commit is contained in:
dan
2021-06-09 16:12:51 -04:00
parent 041fc7cb0b
commit 58382d6a6c
2 changed files with 40 additions and 4 deletions

View File

@@ -7,6 +7,9 @@
<button>Submit</button> <button>Submit</button>
</form> </form>
<form action="http://127.0.0.1:8000/checkin" method="POST"> <form action="http://127.0.0.1:8000/checkin" method="POST">
<label for="locationid">Location<br></label>
<input name="locationid" id="location" value=" ">
<br>
<label for="isbn">Add Book<br></label> <label for="isbn">Add Book<br></label>
<input name="isbn" id="isbn" value=" "> <input name="isbn" id="isbn" value=" ">
<button>Submit</button> <button>Submit</button>
@@ -14,6 +17,14 @@
<form action="http://127.0.0.1:8000/getbooks/1" method="GET"> <form action="http://127.0.0.1:8000/getbooks/1" method="GET">
<button>Get Books</button> <button>Get Books</button>
</form> </form>
<form action="http://127.0.0.1:8000/AddLocation" method="POST">
<label for="BookCase">Bookcase</label>
<input name="BookCase" id="Bookcase" value=" "><br>
<label for="Shelf">Shelf</label>
<input name="Shelf" id="Shelf" value=" ">
<button>Submit</button>
</form>
</div> </div>
<div> <div>

33
main.py
View File

@@ -21,12 +21,22 @@ class Book(Base):
__tablename__ = 'Book' __tablename__ = 'Book'
id = Column(Integer, primary_key=True, autoincrement=True) id = Column(Integer, primary_key=True, autoincrement=True)
userid = Column(Integer) userid = Column(Integer)
locationid = Column(Integer)
Title = Column(TEXT) Title = Column(TEXT)
Author = Column(TEXT) Author = Column(TEXT)
class Location(Base):
__tablename__ = 'Location'
id = Column(Integer, primary_key=True, autoincrement=True)
userid = Column(Integer)
Bookcase = Column(Integer)
Shelf = Column(Integer)
# Connect to database and establish a session # Connect to database and establish a session
engine = create_engine('mysql+pymysql://library:jdSCAd6KEqfbpzh9NT4x@db.dandembinski.com:3306/Library') engine = create_engine('mysql+pymysql://library:jdSCAd6KEqfbpzh9NT4x@db.dandembinski.com:3306/Library',
pool_recycle=3600)
# engine.connect() # engine.connect()
Session = sessionmaker(bind=engine) Session = sessionmaker(bind=engine)
@@ -42,10 +52,14 @@ async def root():
@app.post('/checkin/') @app.post('/checkin/')
async def checkin(isbn: str = Form(...)): async def checkin(isbn: str = Form(...), locationid: int = Form(...)):
info = await getMeta(isbn) info = await getMeta(isbn)
session.add(Book(userid=1, Title=info['Title'], Author=info['Authors'])) session.add(Book(userid=1, Title=info['Title'], Author=info['Authors'], locationid=locationid))
session.commit() try:
session.commit()
except:
session.rollback()
raise
return {"Checked in": info['Title']} return {"Checked in": info['Title']}
@@ -71,6 +85,17 @@ async def lookup(isbn: str = Form(...)):
return {"Title": info['Title']} return {"Title": info['Title']}
@app.post('/AddLocation/')
async def checkin(BookCase: str = Form(...), Shelf: str = Form(...)):
location = []
session.add(Location(userid=1, Bookcase=BookCase, Shelf=Shelf))
session.commit()
location.append(BookCase)
location.append(Shelf)
return {"Location Added": location}
async def getMeta(isbn): async def getMeta(isbn):
info = meta(isbn, service='wiki') info = meta(isbn, service='wiki')
return info return info