This repository was archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
chore: refactor app dir & add .devcontainer
#74
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,26 @@ | ||
| { | ||
| "name": "fastapi-app", | ||
| "dockerComposeFile": ["../docker-compose.yml"], | ||
| "service": "api", | ||
| "workspaceFolder": "/app", | ||
| "customizations": { | ||
| "vscode": { | ||
| "extensions": [ | ||
| "ms-python.python", | ||
| "ms-python.flake8", | ||
| "ms-python.black-formatter", | ||
| "ms-vscode-remote.remote-containers" | ||
| ], | ||
| "settings": { | ||
| "files.encoding": "utf8", | ||
| "files.eol": "\n", | ||
| "editor.formatOnSave": true, | ||
| "[python]": { | ||
| "editor.defaultFormatter": "ms-python.black-formatter" | ||
| }, | ||
| "flake8.args": ["--max-line-length=88", "--ignore=E203,W503,W504"] | ||
| } | ||
| } | ||
| }, | ||
| "forwardPorts": [8000] | ||
| } |
This file contains hidden or 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,10 +1,3 @@ | ||
| ## Description | ||
|
|
||
| - | ||
|
|
||
| ## Related Issues | ||
|
|
||
| <!-- | ||
| Link to the issue that is fixed by this PR (if there is one) | ||
| e.g. Fixes #1234, Addresses #1234, Related to #1234, etc. | ||
| --> |
This file contains hidden or 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 hidden or 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 hidden or 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 +0,0 @@ | ||
| from .provider import * | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,2 +0,0 @@ | ||
| # database module | ||
| from .query import query_get, query_put, query_update | ||
This file contains hidden or 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,64 @@ | ||
| from fastapi import HTTPException, status | ||
| import os | ||
| import pymysql.cursors | ||
| from pymysql import converters | ||
|
|
||
|
|
||
| class DatabaseConnector: | ||
| def __init__(self): | ||
| self.host = os.getenv("DATABASE_HOST") | ||
| self.user = os.getenv("DATABASE_USERNAME") | ||
| self.password = os.getenv("DATABASE_PASSWORD") | ||
| self.database = os.getenv("DATABASE") | ||
| self.port = int(os.getenv("DATABASE_PORT")) | ||
| self.conversions = converters.conversions | ||
| self.conversions[pymysql.FIELD_TYPE.BIT] = ( | ||
| lambda x: False if x == b"\x00" else True | ||
| ) | ||
qlawmarq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if not self.host: | ||
| raise EnvironmentError("DATABASE_HOST environment variable not found") | ||
| if not self.user: | ||
| raise EnvironmentError("DATABASE_USERNAME environment variable not found") | ||
| if not self.password: | ||
| raise EnvironmentError("DATABASE_PASSWORD environment variable not found") | ||
| if not self.database: | ||
| raise EnvironmentError("DATABASE environment variable not found") | ||
qlawmarq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def get_connection(self): | ||
| connection = pymysql.connect( | ||
| host=self.host, | ||
| port=self.port, | ||
| user=self.user, | ||
| password=self.password, | ||
| database=self.database, | ||
| cursorclass=pymysql.cursors.DictCursor, | ||
| conv=self.conversions, | ||
| ) | ||
| return connection | ||
|
|
||
| def query_get(self, sql, param): | ||
| try: | ||
| connection = self.get_connection() | ||
| with connection: | ||
| with connection.cursor() as cursor: | ||
| cursor.execute(sql, param) | ||
| return cursor.fetchall() | ||
| except Exception as e: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, | ||
| detail="Database error: " + str(e), | ||
| ) | ||
|
|
||
| def query_put(self, sql, param): | ||
| try: | ||
| connection = self.get_connection() | ||
| with connection: | ||
| with connection.cursor() as cursor: | ||
| cursor.execute(sql, param) | ||
| connection.commit() | ||
| return cursor.lastrowid | ||
| except Exception as e: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, | ||
| detail="Database error: " + str(e), | ||
qlawmarq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.