#routes/user.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.user import get
        return get.call()
    else:
        redirect('/')

@app.route('/', method='post')
def index():
    if checkLogged.call():
        from controllers.dashboard.user import create
        return create.call()
    else:
        redirect('/')

@app.route('/edit/<id>')
def edit(id):
    if checkLogged.call():
        from controllers.dashboard.user import edit
        return edit.call(id)
    else:
        redirect('/')

@app.route('/delete/<id>')
def delete(id):
    if checkLogged.call():
        from controllers.dashboard.user import delete
        return delete.call(id)
    else:
        redirect('/')

@app.route('/paginate/<page>')
def paginate(page):
    if checkLogged.call():
        from controllers.dashboard.user import paginate
        return paginate.call(int(page))
    else:
        redirect('/')

 

#controllers/dashboard/user/paginate.py
import config
from bottle import request
from copy import deepcopy
from models.userdb import paginatedb

def call(page):
    kdict = deepcopy(config.kdict)
    users = paginatedb.call(page, kdict['maxItemList'])
    
    return {'items':users}

 

#models/userdb/paginatedb.py
import setConnection

def call(page, amount):
    cursor, connection = setConnection.call()

    sql = "SELECT * FROM users ORDER BY DATETIME(datetime) DESC, rowid DESC LIMIT ? OFFSET ?"
    cursor.execute(sql, (amount, page*amount))
    users = cursor.fetchall()
    users = [list(user) for user in users]
    Users = []
    for user in users:
        user[5] = str(user[5])
        Users.append(user)

    cursor.close()

    return Users

 

GitHub: https://github.com/Sokhavuth/REST-API

Vercel: https://rest-api-zeta.vercel.app