-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding many new controllers and models
- Loading branch information
1 parent
d6a07ff
commit 95330d8
Showing
19 changed files
with
535 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from flask import g, request, jsonify, make_response | ||
from flask_restx import Resource, fields | ||
from api.categories.models import CategoriesModel | ||
|
||
categories_model = g.api.model('Categories', { | ||
'user_id': fields.String(required=True, description='User ID'), | ||
'categories_group_id': fields.String(required=True, description='Categories Group ID'), | ||
'categories_type_id': fields.String(required=True, description='Categories Type ID'), | ||
'name': fields.String(required=True, description='Name') | ||
}) | ||
|
||
@g.api.route('/categories') | ||
class Categories(Resource): | ||
@g.api.expect(categories_model) | ||
def post(self): | ||
data = request.json | ||
user_id = data.get('user_id') | ||
categories_group_id = data.get('categories_group_id') | ||
categories_type_id = data.get('categories_type_id') | ||
name = data.get('name') | ||
|
||
new_categories = CategoriesModel( | ||
user_id=user_id, | ||
categories_group_id=categories_group_id, | ||
categories_type_id=categories_type_id, | ||
name=name | ||
) | ||
new_categories.save() | ||
|
||
return make_response(jsonify({'message': 'Categories created successfully'}), 201) | ||
|
||
def get(self): | ||
categories = CategoriesModel.query.all() | ||
_categories = [] | ||
_categories.append([category.to_dict() for category in categories]) | ||
return make_response(jsonify({'categories': _categories}), 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from app import db | ||
from api.base.models import Base | ||
|
||
# - Categories | ||
# - User ID | ||
# - Categories Group ID | ||
# - Categories Type ID | ||
# - Name | ||
|
||
class CategoriesModel(Base): | ||
__tablename__ = 'categories' | ||
user_id = db.Column('user_id', db.Text, db.ForeignKey('user.id'), nullable=False) | ||
categories_group_id = db.Column('categories_group_id', db.Text, db.ForeignKey('categories_group.id'), nullable=False) | ||
categories_type_id = db.Column('categories_type_id', db.Text, db.ForeignKey('categories_type.id'), nullable=False) | ||
name = db.Column(db.String(255), nullable=False) | ||
|
||
def __init__(self, user_id, categories_group_id, categories_type_id, name): | ||
self.user_id = user_id | ||
self.categories_group_id = categories_group_id | ||
self.categories_type_id = categories_type_id | ||
self.name = name | ||
|
||
def __repr__(self): | ||
return '<Categories %r>' % self.name | ||
|
||
def to_dict(self): | ||
return { | ||
'id': self.id, | ||
'user_id': self.user_id, | ||
'categories_group_id': self.categories_group_id, | ||
'categories_type_id': self.categories_type_id, | ||
'name': self.name, | ||
'created_at': self.created_at, | ||
'updated_at': self.updated_at | ||
} | ||
|
||
def save(self): | ||
db.session.add(self) | ||
db.session.commit() | ||
|
||
def delete(self): | ||
db.session.delete(self) | ||
db.session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from flask import g, request, jsonify, make_response | ||
from flask_restx import Resource, fields | ||
from api.categories_group.models import CategoriesGroupModel | ||
|
||
categories_group_model = g.api.model('CategoriesGroup', { | ||
'user_id': fields.String(required=True, description='User ID'), | ||
'name': fields.String(required=True, description='Name') | ||
}) | ||
|
||
@g.api.route('/categories_group') | ||
class CategoriesGroup(Resource): | ||
@g.api.expect(categories_group_model) | ||
def post(self): | ||
data = request.json | ||
user_id = data.get('user_id') | ||
name = data.get('name') | ||
|
||
new_categories_group = CategoriesGroupModel( | ||
user_id=user_id, | ||
name=name | ||
) | ||
new_categories_group.save() | ||
|
||
return make_response(jsonify({'message': 'Categories Group created successfully'}), 201) | ||
|
||
def get(self): | ||
categories_group = CategoriesGroupModel.query.all() | ||
_categories_group = [] | ||
_categories_group.append([category_group.to_dict() for category_group in categories_group]) | ||
return make_response(jsonify({'categories_group': _categories_group}), 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from app import db | ||
from api.base.models import Base | ||
|
||
class CategoriesGroupModel(Base): | ||
__tablename__ = 'categories_group' | ||
user_id = db.Column('user_id', db.Text, db.ForeignKey('user.id'), nullable=False) | ||
name = db.Column(db.String(255), nullable=False) | ||
|
||
def __init__(self, user_id, name): | ||
self.user_id = user_id | ||
self.name = name | ||
|
||
def __repr__(self): | ||
return '<CategoriesGroup %r>' % self.name | ||
|
||
def to_dict(self): | ||
return { | ||
'id': self.id, | ||
'user_id': self.user_id, | ||
'name': self.name, | ||
'created_at': self.created_at, | ||
'updated_at': self.updated_at | ||
} | ||
|
||
def save(self): | ||
db.session.add(self) | ||
db.session.commit() | ||
|
||
def delete(self): | ||
db.session.delete(self) | ||
db.session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from flask import g, request, jsonify, make_response | ||
from flask_restx import Resource, fields | ||
from api.categories_type.models import CategoriesTypeModel | ||
|
||
categories_type_model = g.api.model('CategoriesType', { | ||
'user_id': fields.String(required=True, description='User ID'), | ||
'name': fields.String(required=True, description='Name') | ||
}) | ||
|
||
@g.api.route('/categories_type') | ||
class CategoriesType(Resource): | ||
@g.api.expect(categories_type_model) | ||
def post(self): | ||
data = request.json | ||
user_id = data.get('user_id') | ||
name = data.get('name') | ||
|
||
new_categories_type = CategoriesTypeModel( | ||
user_id=user_id, | ||
name=name | ||
) | ||
new_categories_type.save() | ||
|
||
return make_response(jsonify({'message': 'Categories Type created successfully'}), 201) | ||
|
||
def get(self): | ||
categories_type = CategoriesTypeModel.query.all() | ||
_categories_type = [] | ||
_categories_type.append([category_type.to_dict() for category_type in categories_type]) | ||
return make_response(jsonify({'categories_type': _categories_type}), 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from app import db | ||
from api.base.models import Base | ||
|
||
|
||
class CategoriesTypeModel(Base): | ||
__tablename__ = 'categories_type' | ||
user_id = db.Column('user_id', db.Text, db.ForeignKey('user.id'), nullable=False) | ||
name = db.Column(db.String(255), nullable=False) | ||
|
||
def __init__(self, user_id, name): | ||
self.user_id = user_id | ||
self.name = name | ||
|
||
def __repr__(self): | ||
return '<CategoriesType %r>' % self.name | ||
|
||
def to_dict(self): | ||
return { | ||
'id': self.id, | ||
'user_id': self.user_id, | ||
'name': self.name, | ||
'created_at': self.created_at, | ||
'updated_at': self.updated_at | ||
} | ||
|
||
def save(self): | ||
db.session.add(self) | ||
db.session.commit() | ||
|
||
def delete(self): | ||
db.session.delete(self) | ||
db.session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from flask import g, request, jsonify, make_response | ||
from flask_restx import Resource, fields | ||
from api.institution_account.models import InstitutionAccountModel | ||
|
||
institution_account_model = g.api.model('InstitutionAccount', { | ||
'institution_id': fields.String(required=True, description='Institution ID'), | ||
'user_id': fields.String(required=True, description='User ID'), | ||
'name': fields.String(required=True, description='Account Name'), | ||
'number': fields.String(required=True, description='Account Number'), | ||
'status': fields.String(required=True, description='Account Status'), | ||
'balance': fields.Float(required=True, description='Account Balance') | ||
}) | ||
|
||
@g.api.route('/institution/account') | ||
class InstitutionAccount(Resource): | ||
@g.api.expect(institution_account_model) | ||
def post(self): | ||
data = request.json | ||
institution_id = data.get('institution_id') | ||
user_id = data.get('user_id') | ||
name = data.get('name') | ||
number = data.get('number') | ||
status = data.get('status') | ||
balance = data.get('balance') | ||
|
||
new_account = InstitutionAccountModel( | ||
institution_id=institution_id, | ||
user_id=user_id, | ||
name=name, | ||
number=number, | ||
status=status, | ||
balance=balance | ||
) | ||
new_account.save() | ||
|
||
return make_response(jsonify({'message': 'Account created successfully'}), 201) | ||
|
||
def get(self): | ||
accounts = InstitutionAccountModel.query.all() | ||
_accounts = [] | ||
_accounts.append([account.to_dict() for account in accounts]) | ||
return make_response(jsonify({'accounts': _accounts}), 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from app import db | ||
from api.base.models import Base | ||
|
||
class InstitutionAccountModel(Base): | ||
__tablename__ = 'account' | ||
institution_id = db.Column('institution_id', db.Text, db.ForeignKey('institution.id'), nullable=False) | ||
user_id = db.Column('user_id', db.Text, db.ForeignKey('user.id'), nullable=False) | ||
name = db.Column(db.String(255), nullable=False) | ||
number = db.Column(db.String(255), nullable=False) | ||
status = db.Column(db.String(255), nullable=False) | ||
balance = db.Column(db.Float, nullable=False) | ||
|
||
def __init__(self, institution_id, user_id, name, number, status, balance): | ||
self.institution_id = institution_id | ||
self.user_id = user_id | ||
self.name = name | ||
self.number = number | ||
self.status = status | ||
self.balance = balance | ||
|
||
def __repr__(self): | ||
return '<Account %r>' % self.name | ||
|
||
def to_dict(self): | ||
return { | ||
'id': self.id, | ||
'institution_id': self.institution_id, | ||
'user_id': self.user_id, | ||
'name': self.name, | ||
'number': self.number, | ||
'status': self.status, | ||
'balance': self.balance, | ||
'created_at': self.created_at, | ||
'updated_at': self.updated_at | ||
} | ||
|
||
def save(self): | ||
db.session.add(self) | ||
db.session.commit() | ||
|
||
def delete(self): | ||
db.session.delete(self) | ||
db.session.commit() | ||
|
||
|
Oops, something went wrong.