Added pool_recycle to create_engine. Added logic to add shelves.
This commit is contained in:
33
main.py
33
main.py
@@ -21,12 +21,22 @@ class Book(Base):
|
||||
__tablename__ = 'Book'
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
userid = Column(Integer)
|
||||
locationid = Column(Integer)
|
||||
Title = 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
|
||||
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()
|
||||
|
||||
Session = sessionmaker(bind=engine)
|
||||
@@ -42,10 +52,14 @@ async def root():
|
||||
|
||||
|
||||
@app.post('/checkin/')
|
||||
async def checkin(isbn: str = Form(...)):
|
||||
async def checkin(isbn: str = Form(...), locationid: int = Form(...)):
|
||||
info = await getMeta(isbn)
|
||||
session.add(Book(userid=1, Title=info['Title'], Author=info['Authors']))
|
||||
session.commit()
|
||||
session.add(Book(userid=1, Title=info['Title'], Author=info['Authors'], locationid=locationid))
|
||||
try:
|
||||
session.commit()
|
||||
except:
|
||||
session.rollback()
|
||||
raise
|
||||
return {"Checked in": info['Title']}
|
||||
|
||||
|
||||
@@ -71,6 +85,17 @@ async def lookup(isbn: str = Form(...)):
|
||||
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):
|
||||
info = meta(isbn, service='wiki')
|
||||
return info
|
||||
|
||||
Reference in New Issue
Block a user