#routes/book.py
from bottle import Bottle, redirect
from controllers.login import checkLogged
import bottle
bottle.BaseRequest.MEMFILE_MAX = 1024 * 1024
app = Bottle()
@app.route('/')
def index():
if checkLogged.call():
from controllers.dashboard.book import get
return get.call()
else:
redirect('/')
@app.route('/', method='post')
def create():
if checkLogged.call():
from controllers.dashboard.book import create
return create.call()
else:
redirect('/')
#controllers/dashboard/book/create.py
import uuid
from bottle import request, redirect
from models.postdb import createdb
def call():
title = request.forms.getunicode('title')
thumb = request.forms.getunicode('thumb')
datetime = request.forms.getunicode('datetime')
edit = request.forms.getunicode('editid')
content = request.forms.getunicode('content')
chapter = request.forms.getunicode('chapter')
entries = request.forms.getunicode('entries')
bookTitle = request.forms.getunicode('book_title')
if not edit:
id = uuid.uuid4().hex
else:
id = edit
createdb.call(title, thumb, datetime, id, edit, content, chapter, entries, bookTitle)
return redirect('/dashboard/book')
#models/bookdb/createdb.py
import setConnection
def call(title, thumb, datetime, id, edit, content, chapter, entries, bookTitle):
cursor, connection = setConnection.call()
if not edit:
sql = "INSERT INTO book VALUES(?, ?, ?, ?, ?, ?, ?, ?)"
cursor.execute(sql, (title, thumb, datetime, id, content, chapter, entries, bookTitle))
else:
sql = """UPDATE book SET
title = ?,
thumb = ?,
datetime = ?,
content = ?,
category = ?,
entries = ?,
bookTitle = ?
WHERE id = ? """
cursor.execute(sql, (title, thumb, datetime, content, chapter, entries, bookTitle, id))
connection.commit()
cursor.close()
GitHub: https://github.com/Sokhavuth/REST-API
Vercel: https://rest-api-zeta.vercel.app