-
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.
lint: use black and isort as backend standard (#12)
- Added comand for backend linting to pr template and read me - linted everything. literally.
- Loading branch information
Showing
30 changed files
with
243 additions
and
226 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
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 |
---|---|---|
@@ -1,16 +1,18 @@ | ||
from flask import current_app | ||
from flask_graphql import GraphQLView | ||
|
||
from ..models import db | ||
from .schema import schema | ||
from ..services.implementations.entity_service import EntityService | ||
from .schema import schema | ||
from .service import services | ||
|
||
from flask_graphql import GraphQLView | ||
from flask import current_app | ||
|
||
def init_app(app): | ||
app.add_url_rule( | ||
"/graphql", view_func=GraphQLView.as_view( | ||
"graphql", schema=schema, graphiql=True, | ||
context= {"session": db.session}) | ||
"/graphql", | ||
view_func=GraphQLView.as_view( | ||
"graphql", schema=schema, graphiql=True, context={"session": db.session} | ||
), | ||
) | ||
|
||
services["entity"] = EntityService(current_app.logger) |
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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
''' | ||
""" | ||
TODO mutations: | ||
login(email: String!, password: String!): AuthDTO! | ||
refresh: String! | ||
logout(userId: ID!): ID | ||
resetPassword(email: String!): Boolean! | ||
''' | ||
|
||
""" |
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 |
---|---|---|
@@ -1,20 +1,22 @@ | ||
from ..types.entity_type import EntityResponseDTO, EntityRequestDTO | ||
import graphene | ||
|
||
from ..service import services | ||
from ..types.entity_type import EntityRequestDTO, EntityResponseDTO | ||
|
||
import graphene | ||
|
||
class CreateEntity(graphene.Mutation): | ||
class Arguments: | ||
entity_data = EntityRequestDTO(required=True) | ||
|
||
ok = graphene.Boolean() | ||
entity = graphene.Field(lambda: EntityResponseDTO) | ||
|
||
def mutate(root, info, entity_data=None): | ||
entity_response = services["entity"].create_entity(entity_data) | ||
entity_response = services["entity"].create_entity(entity_data) | ||
ok = True | ||
return CreateEntity(entity=entity_response, ok=ok) | ||
|
||
# optional TODO: | ||
|
||
# optional TODO: | ||
# updateEntity(id: ID!, entity: EntityRequestDTO!): EntityResponseDTO! | ||
# deleteEntity(id: ID!): ID | ||
# deleteEntity(id: ID!): ID |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from ..service import services | ||
|
||
|
||
def resolve_entities(root, info, **kwargs): | ||
return services['entity'].get_entities() | ||
return services["entity"].get_entities() |
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
''' | ||
""" | ||
..services.implementations can only be leveraged once the | ||
flask app has started. Create dummy services here that will be | ||
updated with live app loggers during __init__.py | ||
''' | ||
""" | ||
from ..services.implementations.entity_service import EntityService | ||
from ..services.implementations.user_service import UserService | ||
|
||
services = { | ||
"entity": EntityService(), | ||
"user": UserService(), | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,46 +1,45 @@ | ||
from sqlalchemy import inspect | ||
from sqlalchemy.orm.properties import ColumnProperty | ||
|
||
from . import db | ||
from .enum import enum | ||
|
||
# common columns and methods across multiple data models can be added via a Mixin class: | ||
# https://docs.sqlalchemy.org/en/13/orm/extensions/declarative/mixins.html | ||
|
||
# see examples of Mixins in current and past Blueprint projects: | ||
# https://github.com/uwblueprint/dancefest-web/blob/master/db/models.py#L10-L70 | ||
# https://github.com/uwblueprint/plasta/blob/master/backend/app/models/mixins.py#L10-L95 | ||
|
||
|
||
class Entity(db.Model): | ||
# define the entities table | ||
|
||
__tablename__ = "entities" | ||
|
||
id = db.Column(db.Integer, primary_key=True, nullable=False) | ||
string_field = db.Column(db.String, nullable=False) | ||
int_field = db.Column(db.Integer, nullable=False) | ||
enum_field = db.Column(enum, nullable=False) | ||
string_array_field = db.Column(db.ARRAY(db.String), nullable=False) | ||
bool_field = db.Column(db.Boolean, nullable=False) | ||
# must define how to convert to a dict so that Entity can eventually be serialized into JSON | ||
# this would be a good method to include in a base Mixin | ||
def to_dict(self, include_relationships=False): | ||
cls = type(self) | ||
# mapper allows us to grab the columns of a Model | ||
mapper = inspect(cls) | ||
formatted = {} | ||
for column in mapper.attrs: | ||
field = column.key | ||
attr = getattr(self, field) | ||
# if it's a regular column, extract the value | ||
if isinstance(column, ColumnProperty): | ||
formatted[field] = attr | ||
# otherwise, it's a relationship field | ||
# (currently not applicable, but may be useful for entity groups) | ||
elif include_relationships: | ||
# recursively format the relationship | ||
# don't format the relationship's relationships | ||
formatted[field] = [obj.to_dict() for obj in attr] | ||
return formatted | ||
|
||
from sqlalchemy import inspect | ||
from sqlalchemy.orm.properties import ColumnProperty | ||
|
||
from . import db | ||
from .enum import enum | ||
|
||
# common columns and methods across multiple data models can be added via a Mixin class: | ||
# https://docs.sqlalchemy.org/en/13/orm/extensions/declarative/mixins.html | ||
|
||
# see examples of Mixins in current and past Blueprint projects: | ||
# https://github.com/uwblueprint/dancefest-web/blob/master/db/models.py#L10-L70 | ||
# https://github.com/uwblueprint/plasta/blob/master/backend/app/models/mixins.py#L10-L95 | ||
|
||
|
||
class Entity(db.Model): | ||
# define the entities table | ||
|
||
__tablename__ = "entities" | ||
|
||
id = db.Column(db.Integer, primary_key=True, nullable=False) | ||
string_field = db.Column(db.String, nullable=False) | ||
int_field = db.Column(db.Integer, nullable=False) | ||
enum_field = db.Column(enum, nullable=False) | ||
string_array_field = db.Column(db.ARRAY(db.String), nullable=False) | ||
bool_field = db.Column(db.Boolean, nullable=False) | ||
# must define how to convert to a dict so that Entity can eventually be serialized into JSON | ||
# this would be a good method to include in a base Mixin | ||
def to_dict(self, include_relationships=False): | ||
cls = type(self) | ||
# mapper allows us to grab the columns of a Model | ||
mapper = inspect(cls) | ||
formatted = {} | ||
for column in mapper.attrs: | ||
field = column.key | ||
attr = getattr(self, field) | ||
# if it's a regular column, extract the value | ||
if isinstance(column, ColumnProperty): | ||
formatted[field] = attr | ||
# otherwise, it's a relationship field | ||
# (currently not applicable, but may be useful for entity groups) | ||
elif include_relationships: | ||
# recursively format the relationship | ||
# don't format the relationship's relationships | ||
formatted[field] = [obj.to_dict() for obj in attr] | ||
return formatted |
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
Oops, something went wrong.