# Libs from flask import request from flask_restplus import Resource from flask_restplus import abort from sqlalchemy.orm.exc import NoResultFound # Own from baking.main import api from baking.main.database.models import Genre from baking.main.v1.models.business import create_genre, delete_genre, update_genre from baking.main.v1.serializers import genre, genres_with_artists logger = logging.getLogger('baking-api') ns = api.namespace('genres', description='Operations related to genres') @ns.route('/') class GenreCollection(Resource): @api.marshal_list_with(genres_with_artists) def get(self): """ Returns list of genres """ genres = Genre.query.all() return genres @api.response(201, 'Genre successfully created.') @api.expect(genre) def post(self):
# Generic import logging import random # Libs from flask_restplus import Resource from flask import render_template # Own from baking.main import db, api from baking.main.database.models import Song from baking.main.v1.serializers import song logger = logging.getLogger('baking-api') ns = api.namespace('general', description='General API operations') @ns.route('/') class Index(Resource): def get(self): """ Returns Index file for API """ return render_template("index.html") @ns.route('/random') class Random(Resource): @api.marshal_with(song) def get(self):
# Generic import logging from datetime import datetime # Libs from flask_restplus import Resource, abort from sqlalchemy.orm.exc import NoResultFound # Own from baking.main import api, db from baking.main.v1.serializers import artificial_title from baking.main.v1.models.models_manager import ModelsManager from baking.main.database.models import ArtificialTitle, ArtificialSong logger = logging.getLogger('baking-api') ns = api.namespace('artificial_titles', description='Operations related to artificially generated titles') @ns.route('/') class ArtificialTitleCollection(Resource): @ns.marshal_list_with(artificial_title) def get(self): """ Returns list of generated titles """ titles = ArtificialTitle.query.all() return titles @ns.route('/generate/<lang>/song/<int:song_id>/')
from flask import request from flask_restplus import Resource from flask_restplus import abort from sqlalchemy import func from sqlalchemy.orm.exc import NoResultFound # Own from baking.main import api from baking.main.database.models import Artist from baking.main.v1.models.business import create_artist, update_artist, delete_artist from baking.main.v1.parsers import pagination_arguments from baking.main.v1.serializers import artist, page_of_artists logger = logging.getLogger('baking-api') ns = api.namespace('artists', description='Operations related to artists') @ns.route('/') class ArtistsCollection(Resource): @api.expect(pagination_arguments) @api.marshal_with(page_of_artists) def get(self): """ Returns list of artist artists. """ args = pagination_arguments.parse_args(request) page = args.get('page', 1) per_page = args.get('per_page', 10) artists_query = Artist.query
import logging # Libs from flask import request from flask_restplus import Resource from flask_restplus import abort from sqlalchemy.orm.exc import NoResultFound # Own from baking.main import api from baking.main.database.models import Song from baking.main.v1.models.business import create_song, update_song, delete_song from baking.main.v1.serializers import song logger = logging.getLogger('baking-api') ns = api.namespace('songs', description='Operations related to songs') @ns.route('/') class SongCollection(Resource): @ns.marshal_list_with(song) def get(self): """ Returns list of songs """ songs = Song.query.all() return songs @ns.response(201, 'Song successfully created.') @ns.expect(song) def post(self):