Ejemplo n.º 1
0
from flask.blueprints import Blueprint

from genius.util.serialize import jsonify_bookofuser
from genius.util.view_util import gen_bp_id_rquired
from genius.db.model import Book

book_api = Blueprint('book_api', __name__, url_prefix='/b/api')

book_api.cors = True
book_api.url_pattern = book_api.url_prefix + '/*'

book_api_id_required = gen_bp_id_rquired(book_api)


@book_api_id_required(id_label='book_id')
@jsonify_bookofuser
def book_copies(book_id):
    book = Book.query.get_or_404(book_id)
    return book.copies
Ejemplo n.º 2
0
from genius.db import db
from genius.db.model import UsersLendBook, User, BookOfUser, Book, UserCollection
from genius.db.file_model import UserBookImage, BookThumbnail, UserAvator
from genius.util.http import api_abort

from genius.util.serialize import jsonify_userlendbook, jsonify_bookofuser, jsonify_usercollection, user_logined
from .forms import fill_form, new_genius_form_schema, new_genius_form
from genius.util.schemas import user_schema, bookofuser_schema

from sqlalchemy import or_


user_api_bp = Blueprint('user_api', __name__, url_prefix="/user/api")
user_api_bp.cors = True
user_api_bp.url_pattern = user_api_bp.url_prefix + '/*'


def query_current_user_lendbooks(*criterions):
    return UsersLendBook.query.filter(UsersLendBook.id == current_user.id, *criterions)


@user_api_bp.route('/borrow_history')
@jsonify_userlendbook
def borrow_history():
    history = query_current_user_lendbooks(not UsersLendBook.is_borrowing).all()
    return history


@user_api_bp.route('/borrowing')
@jsonify_userlendbook