Skip to content
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

Merge home-api #167

Closed
wants to merge 184 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
184 commits
Select commit Hold shift + click to select a range
4834346
Initial commit
shaldengeki Sep 14, 2019
8e90735
Add basic Flask schema
shaldengeki Sep 15, 2019
91a693f
Merge pull request #1 from shaldengeki/flask-setup
shaldengeki Sep 15, 2019
a27b932
Remove unnecessary import + template
shaldengeki Sep 15, 2019
927155d
Add React app framework
shaldengeki Sep 15, 2019
b6bee37
Merge pull request #2 from shaldengeki/react-app
shaldengeki Sep 15, 2019
1d19db0
Add Dockerfile
shaldengeki Sep 15, 2019
507b25a
Correctly specify python image
shaldengeki Sep 15, 2019
1272db3
Add docker-compose file
shaldengeki Sep 15, 2019
f2790d5
Correctly provide host + port for home API
shaldengeki Sep 15, 2019
f398f16
Merge pull request #3 from shaldengeki/docker
shaldengeki Sep 15, 2019
91c0aed
Add postgres to docker-compose
shaldengeki Oct 24, 2019
e689607
Add ORM libraries to api for pg
shaldengeki Oct 24, 2019
8764cec
Enable migrations support for pg
shaldengeki Oct 24, 2019
cd8f896
Add build dependencies to alpine image
shaldengeki Oct 24, 2019
83c742c
correct typo
shaldengeki Oct 24, 2019
d55a764
Move migrations directory
shaldengeki Oct 24, 2019
9f05f42
Move API-relevant stuff into api subdir
shaldengeki Oct 24, 2019
dc0ee76
update dockerfile with right path
shaldengeki Oct 24, 2019
45f4e7a
provide correct path to dockerfile in compose
shaldengeki Oct 24, 2019
4cbb774
provide correct schema path too!
shaldengeki Oct 24, 2019
eb056a6
Revert path change?
shaldengeki Oct 24, 2019
fed73db
Correctly mount api dir in API container
shaldengeki Oct 24, 2019
d539429
Add versions to migrations
shaldengeki Oct 24, 2019
4066e59
Add transactions table migration
shaldengeki Oct 24, 2019
98ee46f
Run migration against pg on startup
shaldengeki Oct 24, 2019
636761b
Add transaction model
shaldengeki Oct 25, 2019
7475462
Enable importing of data
shaldengeki Oct 25, 2019
08884dd
Transaction type in GraphQL
shaldengeki Oct 25, 2019
c9fa18a
Import models correctly
shaldengeki Oct 25, 2019
a92967a
Correctly define transaction schema
shaldengeki Oct 25, 2019
aad18ef
Pass database info to flask in dev
shaldengeki Oct 25, 2019
82d468e
Define GraphQLInt
shaldengeki Oct 25, 2019
eb8c0f9
Run migrations
shaldengeki Oct 25, 2019
e469bd7
Resolve datetime to unix epoch time
shaldengeki Oct 25, 2019
a7c14ba
Merge pull request #4 from shaldengeki/pg
shaldengeki Oct 25, 2019
f428386
Oops, fix typo
shaldengeki Oct 25, 2019
2e98b75
Merge pull request #5 from shaldengeki/pg
shaldengeki Oct 25, 2019
b4a7b10
Postgres data should persist between compose runs
shaldengeki Oct 25, 2019
cc23c3d
Persist postgres data locally; ignore them for git's purposes
shaldengeki Oct 25, 2019
25068bc
Merge pull request #6 from shaldengeki/pg
shaldengeki Oct 25, 2019
4c25c0e
Structure GraphQL types
shaldengeki Oct 25, 2019
90ba484
Remove unused code
shaldengeki Oct 25, 2019
02a84ac
Add support for filtering by date
shaldengeki Oct 25, 2019
227825d
correct syntax
shaldengeki Oct 25, 2019
081adfc
Fix taking start, end timestamps
shaldengeki Oct 25, 2019
1b861e7
Merge pull request #7 from shaldengeki/graphql-structure-types
shaldengeki Oct 25, 2019
f0e77e4
Add fields to query by transaction fields
shaldengeki Oct 25, 2019
6bec636
Merge pull request #8 from shaldengeki/transaction-query-fields
shaldengeki Oct 25, 2019
c1d2f69
Provide month aggregation
shaldengeki Oct 25, 2019
fab9d32
Add field to schema
shaldengeki Oct 25, 2019
51bed61
Don't transform datetime again
shaldengeki Oct 25, 2019
9553093
Use namedtuple instead of dict
shaldengeki Oct 25, 2019
b672536
Again, don't double-transform timestamp type
shaldengeki Oct 25, 2019
7709836
Provide formatted date fields
shaldengeki Oct 25, 2019
3c7dd28
Correctly resolve formatted date
shaldengeki Oct 25, 2019
2cb856b
Merge pull request #9 from shaldengeki/transaction-query-fields
shaldengeki Oct 25, 2019
60e2cd1
Dockerfile for frontend
shaldengeki Oct 25, 2019
f66f6a3
Add package.json to Dockerfile
shaldengeki Oct 25, 2019
4f9ac36
Add frontend to docker-compose
shaldengeki Oct 25, 2019
9886656
Mount code into container at appropriate location
shaldengeki Oct 25, 2019
7439f1c
put api env vars into apollo client
shaldengeki Oct 25, 2019
121da39
wip: request graphql api
shaldengeki Oct 25, 2019
2ef0a2c
whitelist all endpoints
shaldengeki Oct 25, 2019
29be670
Correctly set CORS on API for frontend
shaldengeki Oct 25, 2019
fc3a629
add react-hooks dependency
shaldengeki Oct 25, 2019
689f3b0
Update README
shaldengeki Oct 25, 2019
e3aa71d
Correctly camelCase field
shaldengeki Oct 25, 2019
b82a91d
Add TransactionList component
shaldengeki Oct 25, 2019
6264850
Correctly render TransactionList
shaldengeki Oct 25, 2019
2772f0a
Sort transactions by date descending
shaldengeki Oct 25, 2019
88245bb
Remove logo
shaldengeki Oct 25, 2019
86f9d7c
Merge pull request #10 from shaldengeki/frontend
shaldengeki Oct 25, 2019
dd77f90
Add sync server script; remove volume causing upgrade issues; upgrade…
shaldengeki Oct 25, 2019
4afc679
Only watch actual code directories
shaldengeki Oct 25, 2019
d0b1bcf
Add tailwind css to build pipeline
shaldengeki Oct 25, 2019
f9e9385
Merge pull request #11 from shaldengeki/frontend
shaldengeki Oct 26, 2019
86b818c
Render transactions table in a Tailwind-styled table
shaldengeki Oct 26, 2019
d2d0a3e
Add filterable columns in table
shaldengeki Oct 26, 2019
db26abe
Merge pull request #12 from shaldengeki/transaction-table-filters
shaldengeki Oct 26, 2019
a22eedb
Move row-rendering logic to Table
shaldengeki Oct 26, 2019
53ae97d
Correctly move row rendering to table
shaldengeki Oct 26, 2019
65d0849
Merge pull request #13 from shaldengeki/transaction-table-filters
shaldengeki Oct 26, 2019
aa0fbb2
Ensure that transaction table's cols and rows have unique keys for React
shaldengeki Oct 28, 2019
07ece75
Label table keys with actual fieldnames, rather than indices (to prev…
shaldengeki Oct 28, 2019
b1e8f55
Merge pull request #14 from shaldengeki/table-unique-keys
shaldengeki Oct 28, 2019
202cf5d
Add monthly totals chart to transactions listing
shaldengeki Nov 2, 2019
1100ba3
Merge pull request #15 from shaldengeki/transaction-graph
shaldengeki Nov 2, 2019
3c37da3
Expose some ports; update python3 apk dependency
shaldengeki Aug 8, 2020
979b2eb
Create dockerhub action
shaldengeki Aug 8, 2020
0e30d05
Merge pull request #16 from shaldengeki/shaldengeki-dockerhub
shaldengeki Aug 8, 2020
b04f907
Try to build an ARM image...?
shaldengeki Aug 8, 2020
792ad8f
Try using buildx?
shaldengeki Aug 8, 2020
6f231a6
Remove ARM64
shaldengeki Aug 8, 2020
2f92ef1
Merge pull request #17 from shaldengeki/shaldengeki-dockerhub-arm64-1
shaldengeki Aug 8, 2020
e04fa1d
Add frontend build
shaldengeki Aug 8, 2020
78d61df
Remove architectures we don't want
shaldengeki Aug 8, 2020
46315b1
Cache docker layers
shaldengeki Aug 8, 2020
fe4358e
Merge pull request #18 from shaldengeki/shaldengeki-dockerhub-frontend
shaldengeki Aug 8, 2020
bfa60c9
build tailwind in docker image
shaldengeki Aug 8, 2020
fb0a0b5
Merge pull request #19 from shaldengeki/shaldengeki-tailwind-docker
shaldengeki Aug 8, 2020
dac1859
Add account, credit/debit indicators to transaction listing
shaldengeki Aug 8, 2020
4887c42
In transaction chart and list, select last year
shaldengeki Aug 8, 2020
7661f85
Put negative sign in the right place
shaldengeki Aug 8, 2020
cce921e
Merge pull request #21 from shaldengeki/shaldengeki-transaction-filte…
shaldengeki Aug 8, 2020
022a6f0
Merge branch 'master' into shaldengeki-add-account
shaldengeki Aug 8, 2020
a7e841a
Merge pull request #20 from shaldengeki/shaldengeki-add-account
shaldengeki Aug 8, 2020
a7ab7f1
Add DatePicker component to control chart, list data
shaldengeki Aug 9, 2020
d00a920
Correctly import hook
shaldengeki Aug 9, 2020
b85a8b6
Correctly import lodash
shaldengeki Aug 9, 2020
98e45e1
Add DatePicker import
shaldengeki Aug 9, 2020
0c4bbc4
Correctly filter non-dates; convert to seconds
shaldengeki Aug 9, 2020
2a934aa
Correctly provide first dates
shaldengeki Aug 9, 2020
aae7cd1
Correctly subtract one from year
shaldengeki Aug 9, 2020
ecbfe26
Create lint.yaml
shaldengeki Aug 9, 2020
a8fdc6d
Add newlines
shaldengeki Aug 9, 2020
e3a50cf
try removing checkout?
shaldengeki Aug 9, 2020
3dcf5f8
Try using a different action?
shaldengeki Aug 9, 2020
9c13d2b
Try a different root directory?
shaldengeki Aug 9, 2020
5f8887d
Update packages
shaldengeki Aug 9, 2020
1f4d466
Add typescript!
shaldengeki Aug 9, 2020
4c1e34a
add black
shaldengeki Aug 9, 2020
61b6ce8
Add newlines to end of python files
shaldengeki Aug 9, 2020
569281c
Merge branch 'shaldengeki-lint' of github.com:shaldengeki/home-api in…
shaldengeki Aug 9, 2020
a5bcbd1
Pass api path to black
shaldengeki Aug 9, 2020
f5965ff
Correctly pass args
shaldengeki Aug 9, 2020
4bee477
Update to master
shaldengeki Aug 9, 2020
bc24c6a
Have black check!
shaldengeki Aug 9, 2020
649663c
Add black to requirements
shaldengeki Aug 9, 2020
cb4190f
Format files
shaldengeki Aug 9, 2020
601b7df
Merge pull request #23 from shaldengeki/shaldengeki-lint
shaldengeki Aug 9, 2020
a8b254a
Merge remote-tracking branch 'origin' into shaldengeki-date-picker
shaldengeki Aug 9, 2020
d131932
Merge pull request #22 from shaldengeki/shaldengeki-date-picker
shaldengeki Aug 9, 2020
9b18227
Add dateRange field to transactions
shaldengeki Aug 9, 2020
788a7ea
Reformat file with black
shaldengeki Aug 9, 2020
4949dd9
Add amount range
shaldengeki Aug 9, 2020
460d2b9
Add categories to transactions API
shaldengeki Aug 9, 2020
148a05d
Add accounts to transactions API
shaldengeki Aug 9, 2020
3d56bb4
Add types to transactions API
shaldengeki Aug 9, 2020
65550b2
Correctly invoke query API
shaldengeki Aug 9, 2020
866656d
Ensure that timestamps are passed in unix epoch time
shaldengeki Aug 9, 2020
6231e79
Format python with black
shaldengeki Aug 9, 2020
e775927
Update import_data script
shaldengeki Aug 9, 2020
b5a1298
Merge pull request #24 from shaldengeki/shaldengeki-searchbar-fields
shaldengeki Aug 9, 2020
d698c2e
Merge pull request #25 from shaldengeki/shaldengeki-import-data-fixes
shaldengeki Aug 9, 2020
050e2dd
Add multi-value searchbar field support
shaldengeki Aug 9, 2020
1e20db7
Run black linter
shaldengeki Aug 9, 2020
d233334
Merge pull request #26 from shaldengeki/shaldengeki-searchbar-fields
shaldengeki Aug 9, 2020
5cdc88e
Make transaction display three columns
shaldengeki Aug 9, 2020
795bb07
Move DatePicker to TransactionFilters
shaldengeki Aug 9, 2020
7afdf34
Correctly refer to params
shaldengeki Aug 9, 2020
99de43a
Remove tailwind build from npm start
shaldengeki Aug 9, 2020
7e7bf81
Add min, max amount filters
shaldengeki Aug 9, 2020
4fa2ddb
Plug min, max amounts into graphql queries
shaldengeki Aug 9, 2020
aba4b8f
Also pass min/max amounts to transaction list
shaldengeki Aug 9, 2020
9eb01a3
Correctly put day of month into default date
shaldengeki Aug 9, 2020
0927e24
Format chart and list elements in source
shaldengeki Aug 9, 2020
4c20afb
Fetch available transaction types and provide select
shaldengeki Aug 9, 2020
1b7f50f
Return from map fn
shaldengeki Aug 9, 2020
f4a80ea
Pull option element out of loop
shaldengeki Aug 9, 2020
51f043f
Add accounts, categories filters
shaldengeki Aug 9, 2020
744b86d
add some small logging
shaldengeki Aug 9, 2020
a77f60a
Add types logging
shaldengeki Aug 9, 2020
60bfb76
Try parsing selected options directly
shaldengeki Aug 10, 2020
b1d7e4d
correctly refer to select's options
shaldengeki Aug 10, 2020
8bc77d9
Apply correct parsing of multiple select to other fields
shaldengeki Aug 10, 2020
c9e7ed4
Pass multiselect filters into table, chart
shaldengeki Aug 10, 2020
bba3deb
Migrate multiselect to separate component
shaldengeki Aug 10, 2020
bc2449f
Merge pull request #27 from shaldengeki/shaldengeki-three-columns
shaldengeki Aug 10, 2020
a1a8040
Require react-router; parse filters out of url
shaldengeki Aug 10, 2020
0a927c6
Parse categories, types, accounts out of URL
shaldengeki Aug 10, 2020
dfb75ad
Pull start, end out into custom hooks which update URL parameters
shaldengeki Aug 10, 2020
1789a27
Oops, actually update history
shaldengeki Aug 10, 2020
ab50bdd
Store amounts, categories, types, accounts in url too
shaldengeki Aug 10, 2020
f19e16d
Allow for null arrays
shaldengeki Aug 10, 2020
39c8f26
Set array fields to null when empty
shaldengeki Aug 11, 2020
eb33c2e
Default amounts to null
shaldengeki Aug 11, 2020
e3ab2f2
Merge pull request #38 from shaldengeki/shaldengeki-filter-query-params
shaldengeki Aug 11, 2020
01edbad
Don't build container on PR
shaldengeki Aug 11, 2020
fe3dd0a
Correctly get current month
shaldengeki Aug 11, 2020
9704aed
Merge pull request #39 from shaldengeki/shaldengeki-container-on-master
shaldengeki Aug 11, 2020
1ec1809
Merge remote-tracking branch 'home-api/master' into home-api
shaldengeki Jun 23, 2024
c5a3f07
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 23, 2024
60990ae
Fixup imports
shaldengeki Jun 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions home_api/.github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Lint

on:
pull_request:
branches: [ master ]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: eslint
uses: hallee/eslint-action@1.0.3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
source-root: frontend
- name: black
uses: lgeiger/black-action@master
with:
args: "api --check"
136 changes: 136 additions & 0 deletions home_api/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# This is a basic workflow to help you get started with Actions

name: Dockerhub

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
schedule:
- cron: '0 10 * * *' # everyday at 10am
push:
branches: master
tags:
- v*

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
-
name: Set up Docker Buildx
uses: crazy-max/ghaction-docker-buildx@v3
-
name: Cache Docker layers
uses: actions/cache@v2
id: cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
-
name: Prepare API build
id: prepare_api
run: |
DOCKER_IMAGE=shaldengeki/home-api
DOCKER_PLATFORMS=linux/amd64,linux/arm64
VERSION=edge

if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
fi

TAGS="--tag ${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS --tag ${DOCKER_IMAGE}:latest"
fi

echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=version::${VERSION}
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache" \
--build-arg VERSION=${VERSION} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg VCS_REF=${GITHUB_SHA::8} \
${TAGS} --file ./api/Dockerfile ./api
-
name: Prepare frontend build
id: prepare_frontend
run: |
DOCKER_IMAGE=shaldengeki/home-frontend
DOCKER_PLATFORMS=linux/amd64,linux/arm64
VERSION=edge

if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
fi

TAGS="--tag ${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS --tag ${DOCKER_IMAGE}:latest"
fi

echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=version::${VERSION}
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache" \
--build-arg VERSION=${VERSION} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg VCS_REF=${GITHUB_SHA::8} \
${TAGS} --file ./frontend/Dockerfile ./frontend
-
name: Build API image
run: |
docker buildx build --output "type=image,push=false" ${{ steps.prepare_api.outputs.buildx_args }}
-
name: Build frontend image
run: |
docker buildx build --output "type=image,push=false" ${{ steps.prepare_Frontend.outputs.buildx_args }}
-
name: Log in to DockerHub
if: success()
env:
DOCKER_USERNAME: shaldengeki
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}
run: |
echo "${DOCKER_PASSWORD}" | docker login --username "shaldengeki" --password-stdin
-
name: Push API image to DockerHub
if: success()
run: |
docker buildx build --output "type=image,push=true" ${{ steps.prepare_api.outputs.buildx_args }}
-
name: Check API manifest
if: always()
run: |
docker run --rm mplatform/mquery ${{ steps.prepare_api.outputs.docker_image }}:${{ steps.prepare_api.outputs.version }}
-
name: Push frontend image to DockerHub
if: success()
run: |
docker buildx build --output "type=image,push=true" ${{ steps.prepare_frontend.outputs.buildx_args }}
-
name: Check frontend manifest
if: always()
run: |
docker run --rm mplatform/mquery ${{ steps.prepare_frontend.outputs.docker_image }}:${{ steps.prepare_frontend.outputs.version }}
-
name: Clear
if: always()
run: |
rm -f ${HOME}/.docker/config.json
28 changes: 28 additions & 0 deletions home_api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
/postgres-data

.vscode
__pycache__
api/venv

npm-debug.log*
yarn-debug.log*
yarn-error.log*
21 changes: 21 additions & 0 deletions home_api/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Charles Guo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 9 additions & 0 deletions home_api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# home-api
API for home dashboard.

# Running

To start everything:
```bash
docker-compose up
```
1 change: 1 addition & 0 deletions home_api/api/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.7.4
22 changes: 22 additions & 0 deletions home_api/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.7-alpine

EXPOSE 5000/tcp

RUN apk update && \
apk add --virtual build-deps gcc python3-dev musl-dev && \
apk add postgresql-dev

WORKDIR /usr/src/app

ENV FLASK_APP=app.py
ENV PORT=5000
ENV FRONTEND_HOST=home_frontend
ENV FRONTEND_PORT=5001

COPY requirements.txt ./

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD flask run --host 0.0.0.0 --port $PORT
1 change: 1 addition & 0 deletions home_api/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from home_api.app import app
45 changes: 45 additions & 0 deletions home_api/api/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os

from flask import Flask
from flask_cors import CORS
from flask_graphql import GraphQLView
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = (
"postgres://{user}:{password}@{host}/{db}".format(
user=os.getenv("DB_USER", "admin"),
password=os.getenv("DB_PASS", "development"),
host=os.getenv("DB_HOST", "pg"),
db=os.getenv("DB_NAME", "api_development"),
)
)
CORS(
app,
resources={
"/graphql": {
"origins": [
"http://{host}:{port}".format(
host=os.getenv("FRONTEND_HOST", "localhost"),
port=os.getenv("FRONTEND_PORT", 5001),
)
],
}
},
)

db = SQLAlchemy(app)

from . import models

migrate = Migrate(app, db)

from . import graphql

app.add_url_rule(
"/graphql",
view_func=GraphQLView.as_view(
"graphql", schema=graphql.Schema(models), graphiql=True
),
)
1 change: 1 addition & 0 deletions home_api/api/graphql/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .schema import Schema
28 changes: 28 additions & 0 deletions home_api/api/graphql/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from graphql import GraphQLField, GraphQLObjectType, GraphQLSchema, GraphQLString

from .types.transaction import (
accountsField,
amountByMonthField,
amountRangeField,
categoriesField,
dateRangeField,
transactionsField,
typesField,
)


def Schema(models):
return GraphQLSchema(
query=GraphQLObjectType(
name="RootQueryType",
fields={
"transactions": transactionsField(models),
"amountByMonth": amountByMonthField(models),
"accounts": accountsField(models),
"amountRange": amountRangeField(models),
"categories": categoriesField(models),
"dateRange": dateRangeField(models),
"types": typesField(models),
},
)
)
Empty file.
Loading