-
Notifications
You must be signed in to change notification settings - Fork 0
Implementation and test of api namespaces for time entries #13 #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| from time_tracker_api.database import CRUDDao | ||
|
|
||
|
|
||
| class ActivitiesDao(CRUDDao): | ||
| pass | ||
|
|
||
|
|
||
| def create_dao() -> ActivitiesDao: | ||
| from time_tracker_api.sql_repository import db | ||
| from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel, SQLModel | ||
|
|
||
| class ActivitySQLModel(db.Model, SQLModel, AuditedSQLModel): | ||
| __tablename__ = 'activity' | ||
| id = db.Column(db.Integer, primary_key=True) | ||
|
|
||
| class ActivitiesSQLDao(SQLCRUDDao): | ||
| def __init__(self): | ||
| SQLCRUDDao.__init__(self, ActivitySQLModel) | ||
|
|
||
| return ActivitiesSQLDao() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,23 +46,7 @@ def __call__(self, *args, **kwargs): | |
|
|
||
|
|
||
| class DatabaseModel: | ||
|
||
| def to_dto(self): | ||
| return self | ||
|
|
||
|
|
||
| def convert_result_to_dto(f): | ||
| def convert_if_necessary(result): | ||
| if hasattr(result, 'to_dto'): | ||
| return result.to_dto() | ||
| elif issubclass(type(result), list): | ||
| return list(map(convert_if_necessary, result)) | ||
| return result | ||
|
|
||
| def to_dto(*args, **kw): | ||
| result = f(*args, **kw) | ||
| return convert_if_necessary(result) | ||
|
|
||
| return to_dto | ||
| pass | ||
|
|
||
|
|
||
| seeder: Seeder = None | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,12 @@ | |
| from flask import Flask | ||
| from flask_sqlalchemy import SQLAlchemy | ||
|
|
||
| from time_tracker_api.database import CRUDDao, Seeder, DatabaseModel, convert_result_to_dto | ||
| from time_tracker_api.database import CRUDDao, Seeder, DatabaseModel | ||
| from time_tracker_api.security import current_user_id | ||
|
|
||
| LIST_SEPARATOR_CHAR = ";" | ||
|
|
||
|
|
||
| db: SQLAlchemy = None | ||
| SQLModel = None | ||
| AuditedSQLModel = None | ||
|
|
@@ -27,12 +30,7 @@ def init_app(app: Flask) -> None: | |
| db = SQLAlchemy(app) | ||
|
|
||
| global SQLModel | ||
|
|
||
| class SQLModelClass(DatabaseModel): | ||
| def to_dto(self): | ||
| return self | ||
|
|
||
| SQLModel = SQLModelClass | ||
| SQLModel = DatabaseModel | ||
|
||
|
|
||
| global AuditedSQLModel | ||
|
|
||
|
|
@@ -85,19 +83,15 @@ class SQLCRUDDao(CRUDDao): | |
| def __init__(self, model: type): | ||
| self.repository = SQLRepository(model) | ||
|
|
||
| @convert_result_to_dto | ||
| def get_all(self) -> list: | ||
| return self.repository.find_all() | ||
|
|
||
| @convert_result_to_dto | ||
| def get(self, id): | ||
| return self.repository.find(id) | ||
|
|
||
| @convert_result_to_dto | ||
| def create(self, element: dict): | ||
| return self.repository.create(element) | ||
|
|
||
| @convert_result_to_dto | ||
| def update(self, id, data: dict): | ||
| return self.repository.update(id, data) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,58 @@ | ||
| from flask import Flask | ||
| from sqlalchemy_utils import ScalarListType | ||
|
|
||
| from time_tracker_api.database import CRUDDao | ||
|
|
||
| COMMENTS_MAX_NUMBER_CHARS = 500 | ||
|
|
||
|
|
||
| class TimeEntriesDao(CRUDDao): | ||
| pass | ||
|
|
||
|
|
||
| def create_dao(app: Flask) -> TimeEntriesDao: | ||
| # TODO Create implementation(s) | ||
| return TimeEntriesDao() | ||
| def create_dao() -> TimeEntriesDao: | ||
| from time_tracker_api.sql_repository import db | ||
| from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel, SQLModel | ||
|
|
||
| class TimeEntrySQLModel(db.Model, SQLModel, AuditedSQLModel): | ||
| __tablename__ = 'time_entry' | ||
| id = db.Column(db.Integer, primary_key=True) | ||
| description = db.Column(db.String(COMMENTS_MAX_NUMBER_CHARS)) | ||
| start_date = db.Column(db.DateTime, server_default=db.func.now()) | ||
| end_date = db.Column(db.DateTime) | ||
| project_id = db.Column(db.Integer, | ||
| db.ForeignKey('project.id'), | ||
| nullable=False) | ||
| activity_id = db.Column(db.Integer, | ||
| db.ForeignKey('activity.id'), | ||
| nullable=False) | ||
|
|
||
| technologies = db.Column(ScalarListType()) | ||
|
|
||
| @property | ||
| def running(self): | ||
| return self.end_date == None | ||
|
|
||
| # @property | ||
| # def technologies(self): | ||
| # return [str(x) for x in self._technologies.split(';')] | ||
| # | ||
| # @technologies.setter | ||
| # def technologies(self, value): | ||
| # if value is Iterable: | ||
| # self._technologies = LIST_SEPARATOR_CHAR.join(value) | ||
| # elif type(value) == str: | ||
| # self._technologies = value | ||
| # else: | ||
| # raise UnprocessableEntity | ||
|
|
||
| def __repr__(self): | ||
| return '<Time Entry %r>' % self.start_date | ||
|
|
||
| def __str___(self): | ||
| return "Time Entry started in \"%s\"" % self.start_date | ||
|
|
||
| class TimeEntriesSQLDao(SQLCRUDDao): | ||
| def __init__(self): | ||
| SQLCRUDDao.__init__(self, TimeEntrySQLModel) | ||
|
|
||
| return TimeEntriesSQLDao() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how the two last imports are being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I will remove them