Skip to content

Commit 21d39a5

Browse files
author
Rahul Bhardwaj
committed
Api for Task assigned
1 parent 397ffc3 commit 21d39a5

27 files changed

+9971
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/venv
2+
__pycache__

.idea/encodings.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/saavn-test.iml

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 416 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.pythonPath": "venv/bin/python"
3+
}

app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from flask import Blueprint
2+
from flask_restful import Api
3+
from resources.User import UserResource
4+
from resources.Task import TaskResource, TaskIdResource
5+
6+
api_bp = Blueprint('api', __name__)
7+
api = Api(api_bp)
8+
9+
# Route For user endpoints
10+
api.add_resource(UserResource, '/users')
11+
12+
# #Route for File Upload endpoints
13+
api.add_resource(TaskResource, '/upload')
14+
api.add_resource(TaskIdResource, '/upload/<task_id>')

config.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
class BaseConfig:
3+
SQLALCHEMY_ECHO = False
4+
SQLALCHEMY_TRACK_MODIFICATIONS = True
5+
SQLALCHEMY_DATABASE_URI = "mysql://root:root@localhost/saavn"
6+
REDIS_HOST = "localhost"
7+
REDIS_PASSWORD = ""
8+
REDIS_PORT = 6379
9+
WTF_CSRF_ENABLED = True
10+
11+
class DevelopmentConfig(BaseConfig):
12+
SQLALCHEMY_DATABASE_URI = "mysql://root:root@localhost/saavn"
13+
14+
class TestingConfig(BaseConfig):
15+
SQLALCHEMY_DATABASE_URI = "mysql://root:root@localhost/saavn"
16+
17+
class ProductionConfig(BaseConfig):
18+
SQLALCHEMY_DATABASE_URI = "mysql://root:root@localhost/saavn"
19+
20+
class WorkerConfig:
21+
REDIS_URL = 'redis://localhost:6379/0'
22+
QUEUES = ['default']
23+
24+
25+
PresentConfig = BaseConfig

migrate.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from flask_script import Manager
2+
from flask_migrate import Migrate, MigrateCommand
3+
from model import db
4+
from run import create_app
5+
from config import PresentConfig
6+
7+
app = create_app(PresentConfig)
8+
9+
migrate = Migrate(app, db)
10+
manager = Manager(app)
11+
manager.add_command('db', MigrateCommand)
12+
13+
14+
if __name__ == '__main__':
15+
manager.run()

migrations/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration.

migrations/alembic.ini

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# template used to generate migration files
5+
# file_template = %%(rev)s_%%(slug)s
6+
7+
# set to 'true' to run the environment during
8+
# the 'revision' command, regardless of autogenerate
9+
# revision_environment = false
10+
11+
12+
# Logging configuration
13+
[loggers]
14+
keys = root,sqlalchemy,alembic
15+
16+
[handlers]
17+
keys = console
18+
19+
[formatters]
20+
keys = generic
21+
22+
[logger_root]
23+
level = WARN
24+
handlers = console
25+
qualname =
26+
27+
[logger_sqlalchemy]
28+
level = WARN
29+
handlers =
30+
qualname = sqlalchemy.engine
31+
32+
[logger_alembic]
33+
level = INFO
34+
handlers =
35+
qualname = alembic
36+
37+
[handler_console]
38+
class = StreamHandler
39+
args = (sys.stderr,)
40+
level = NOTSET
41+
formatter = generic
42+
43+
[formatter_generic]
44+
format = %(levelname)-5.5s [%(name)s] %(message)s
45+
datefmt = %H:%M:%S

migrations/env.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from __future__ import with_statement
2+
from alembic import context
3+
from sqlalchemy import engine_from_config, pool
4+
from logging.config import fileConfig
5+
import logging
6+
7+
# this is the Alembic Config object, which provides
8+
# access to the values within the .ini file in use.
9+
config = context.config
10+
11+
# Interpret the config file for Python logging.
12+
# This line sets up loggers basically.
13+
fileConfig(config.config_file_name)
14+
logger = logging.getLogger('alembic.env')
15+
16+
# add your model's MetaData object here
17+
# for 'autogenerate' support
18+
# from myapp import mymodel
19+
# target_metadata = mymodel.Base.metadata
20+
from flask import current_app
21+
config.set_main_option('sqlalchemy.url',
22+
current_app.config.get('SQLALCHEMY_DATABASE_URI'))
23+
target_metadata = current_app.extensions['migrate'].db.metadata
24+
25+
# other values from the config, defined by the needs of env.py,
26+
# can be acquired:
27+
# my_important_option = config.get_main_option("my_important_option")
28+
# ... etc.
29+
30+
31+
def run_migrations_offline():
32+
"""Run migrations in 'offline' mode.
33+
34+
This configures the context with just a URL
35+
and not an Engine, though an Engine is acceptable
36+
here as well. By skipping the Engine creation
37+
we don't even need a DBAPI to be available.
38+
39+
Calls to context.execute() here emit the given string to the
40+
script output.
41+
42+
"""
43+
url = config.get_main_option("sqlalchemy.url")
44+
context.configure(url=url)
45+
46+
with context.begin_transaction():
47+
context.run_migrations()
48+
49+
50+
def run_migrations_online():
51+
"""Run migrations in 'online' mode.
52+
53+
In this scenario we need to create an Engine
54+
and associate a connection with the context.
55+
56+
"""
57+
58+
# this callback is used to prevent an auto-migration from being generated
59+
# when there are no changes to the schema
60+
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
61+
def process_revision_directives(context, revision, directives):
62+
if getattr(config.cmd_opts, 'autogenerate', False):
63+
script = directives[0]
64+
if script.upgrade_ops.is_empty():
65+
directives[:] = []
66+
logger.info('No changes in schema detected.')
67+
68+
engine = engine_from_config(config.get_section(config.config_ini_section),
69+
prefix='sqlalchemy.',
70+
poolclass=pool.NullPool)
71+
72+
connection = engine.connect()
73+
context.configure(connection=connection,
74+
target_metadata=target_metadata,
75+
process_revision_directives=process_revision_directives,
76+
**current_app.extensions['migrate'].configure_args)
77+
78+
try:
79+
with context.begin_transaction():
80+
context.run_migrations()
81+
except Exception as exception:
82+
logger.error(exception)
83+
raise exception
84+
finally:
85+
connection.close()
86+
87+
if context.is_offline_mode():
88+
run_migrations_offline()
89+
else:
90+
run_migrations_online()

migrations/script.py.mako

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""${message}
2+
3+
Revision ID: ${up_revision}
4+
Revises: ${down_revision | comma,n}
5+
Create Date: ${create_date}
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
${imports if imports else ""}
11+
12+
# revision identifiers, used by Alembic.
13+
revision = ${repr(up_revision)}
14+
down_revision = ${repr(down_revision)}
15+
branch_labels = ${repr(branch_labels)}
16+
depends_on = ${repr(depends_on)}
17+
18+
19+
def upgrade():
20+
${upgrades if upgrades else "pass"}
21+
22+
23+
def downgrade():
24+
${downgrades if downgrades else "pass"}

migrations/versions/b13657a9aa69_.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""empty message
2+
3+
Revision ID: b13657a9aa69
4+
Revises: eb02b3ae6795
5+
Create Date: 2019-01-23 12:22:53.698744
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = 'b13657a9aa69'
14+
down_revision = 'eb02b3ae6795'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.create_table('users',
22+
sa.Column('id', sa.Integer(), nullable=False),
23+
sa.Column('user_id', sa.String(), nullable=True),
24+
sa.Column('platform', sa.String(length=20), nullable=True),
25+
sa.PrimaryKeyConstraint('id')
26+
)
27+
# ### end Alembic commands ###
28+
29+
30+
def downgrade():
31+
# ### commands auto generated by Alembic - please adjust! ###
32+
op.drop_table('users')
33+
# ### end Alembic commands ###

migrations/versions/e0fcd2b6edb2_.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""empty message
2+
3+
Revision ID: e0fcd2b6edb2
4+
Revises:
5+
Create Date: 2019-01-23 10:12:28.399873
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = 'e0fcd2b6edb2'
14+
down_revision = None
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.create_table('users',
22+
sa.Column('id', sa.Integer(), nullable=False),
23+
sa.Column('user_id', sa.Integer(), nullable=True),
24+
sa.Column('platform', sa.String(length=20), nullable=True),
25+
sa.PrimaryKeyConstraint('id')
26+
)
27+
# ### end Alembic commands ###
28+
29+
30+
def downgrade():
31+
# ### commands auto generated by Alembic - please adjust! ###
32+
op.drop_table('users')
33+
# ### end Alembic commands ###

migrations/versions/eb02b3ae6795_.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""empty message
2+
3+
Revision ID: eb02b3ae6795
4+
Revises: e0fcd2b6edb2
5+
Create Date: 2019-01-23 12:10:01.469884
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = 'eb02b3ae6795'
14+
down_revision = 'e0fcd2b6edb2'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.create_table('users',
22+
sa.Column('id', sa.Integer(), nullable=False),
23+
sa.Column('user_id', sa.String(length=20), nullable=True),
24+
sa.Column('platform', sa.String(length=20), nullable=True),
25+
sa.PrimaryKeyConstraint('id')
26+
)
27+
# ### end Alembic commands ###
28+
29+
30+
def downgrade():
31+
# ### commands auto generated by Alembic - please adjust! ###
32+
op.drop_table('users')
33+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)