Skip to content

Commit

Permalink
Merge pull request #31 from it-goats/develop
Browse files Browse the repository at this point in the history
Release 0.1.0
  • Loading branch information
john-sonz committed Apr 29, 2022
2 parents 93f1fe9 + 0e0aa21 commit a477d84
Show file tree
Hide file tree
Showing 72 changed files with 2,636 additions and 197 deletions.
10 changes: 10 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--
- [ ] Provide a summary of the features and changes
- [ ] Assign one or more reviewers
-->

---

#### Resources

<!-- Include links to relevant Jira stories or visual resources. -->
45 changes: 45 additions & 0 deletions .github/workflows/bode_ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "Bode CI"

on:
pull_request:
paths:
- "bode/**"
push:
paths:
- "bode/**"
branches:
- develop
- master

jobs:
ci:
name: "Bode CI - linting & formatting"
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./bode

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.10.4"
- uses: abatilo/actions-poetry@v2.0.0
with:
poetry-version: "1.1.13"

- run: poetry config virtualenvs.in-project true

- name: Install dependencies
run: |
poetry config virtualenvs.in-project true
poetry install
- name: Check formatting
run: poetry run black bode migrations --check --verbose

- name: Lint
run: poetry run flake8 bode migrations --verbose

- name: Check sorting
run: poetry run isort bode migrations --check
38 changes: 38 additions & 0 deletions .github/workflows/cabra_ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "Cabra CI"

on:
pull_request:
paths:
- "cabra/**"
push:
paths:
- "cabra/**"
branches:
- develop
- master

jobs:
ci:
name: "Cabra CI - linting, formatting & type checking"
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./cabra

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "16.14.2"

- name: Install Dependencies
run: npm ci

- name: Check formatting
run: npm run format:check

- name: Check types
run: npm run types:check

- name: Lint
run: npm run lint:check
15 changes: 15 additions & 0 deletions .github/workflows/pr_jira_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "PR Jira check"
on:
pull_request:
branches:
- develop
types: [opened, edited, reopened, synchronize]

jobs:
check-jira-presence:
name: "Verify PR title starts with [NOJIRA] or [PROJECT-123]"
runs-on: ubuntu-latest
env:
PR_TITLE: ${{ github.event.pull_request.title }}
steps:
- run: egrep '^\[(NOJIRA|([[:upper:]]{3,}\-[[:digit:]]+[[:blank:],]+)*[[:upper:]]{3,}\-[[:digit:]]+)\]' <<< ${PR_TITLE}
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.vscode/
node_modules/
.vscode/*
!.vscode/extensions.json

node_modules/
.env
17 changes: 17 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"amatiasq.sort-imports",
"bradlc.vscode-tailwindcss",
"dsznajder.es7-react-js-snippets",
"wix.glean",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-azuretools.vscode-docker",
"ms-vscode-remote.remote-containers",
"mhutchie.git-graph",
"eamodio.gitlens",
"oderwat.indent-rainbow"
]
}
61 changes: 50 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ IT-GOATS

## Struktura

| Codebase | Opis |
| :-------------------- | :-----------------------: |
| [bode](bode) | Flask API |
| [cabra](cabra) | React Frontend |
| Codebase | Opis |
| :------------- | :------------: |
| [bode](bode) | Flask API |
| [cabra](cabra) | React Frontend |

## Uruchomienie projektu

### Wymagania (zalecane):

- [Docker](https://docs.docker.com/get-docker/) + [docker-compose](https://docs.docker.com/compose/) dla Linux'a lub [Docker Desktop](https://docs.docker.com/get-docker/) dla OSX/Windows'a
- [WSL2](https://docs.microsoft.com/en-us/windows/wsl/install) w przypadku Windows'a
- [asdf](https://github.com/asdf-vm/asdf)

### Wymagania (alternatywne i niezalecane):

- [PostgreSQL](https://www.postgresql.org/) w rozsądnej wersji
- [Node.js + npm](https://nodejs.org/en/) najlepiej w wersji 16.14.12
- [Node.js + npm](https://nodejs.org/en/) najlepiej w wersji 16.14.2
- [Poetry](https://python-poetry.org/) najlepiej w wersji 1.1.13
- [Python](https://www.python.org/downloads/) najlepiej w wersji 3.10.4

Expand All @@ -28,46 +30,55 @@ Do pracy nad projektem najlepiej wykorzystać UNIX'owe środowisko.
OSX, jakiś Linux lub WSL2 pod Windows'em sprawdzą się w sam raz. W takim środowisku potrzebujemy mieć Docker'a z Compose'em (patrz linki w wymaganiach) oraz [asdf'a](https://asdf-vm.com/guide/getting-started.html).

Mając gotowe te dwie rzeczy, sklonowane repo (w przypadku WSL'a repo klonujemy do niego zamiast do Windowsa) i trochę szczęścia projekt powinien wstać po odpaleniu [skryptu](setup.sh):

```
$ ./setup.sh
```

Skrypt po kolei:

- zainstaluje potrzebne narzędzia przez asdf'a
- doda do gita hooki sprawdzające kod przed każdym commit'em (gdy będziemy mieć wybór, które hooki zainstalować to wybieramy spacją tylko `pre-commit` i potwierdzamy)
- zainstaluje potrzebne zależności w bode i cabrze
- uruchomi kontenery z bazą danych, backend'em i frontend'em

Po tym wszystkim aplikacja będzie dostępna po adresem http://localhost:3000.
Po tym wszystkim aplikacja będzie dostępna po adresem http://localhost:3000. API jest dostępne pod adresem http://localhost:4000/api/v1.

Setup wystarczy wykonać pomyślnie tylko raz, potem aplikację stawiamy:

- na Linuxie

```
docker-compose up
```

- na Macu/WSL:

```
docker compose up
```

### Alternatywna i niezalecana instrukcja:

Można spróbować uruchomić projekt bez Docker'a i/lub asdf'a. Wtedy trzeba samemu zapewnić, że wszystkie wymagane narzędzia są zainstalowane i serwer PostgreSQL jest uruchomiony. Następnie należy uruchamiać kolejne kroki z [setup.sh](setup.sh) pomijając ostatni oraz ręcznie ustawić w powłoce zmienne środowiskowe z pliku [.env.example](.env.example).
Można spróbować uruchomić projekt bez Docker'a i/lub asdf'a. Wtedy trzeba samemu zapewnić, że wszystkie wymagane narzędzia są zainstalowane i serwer PostgreSQL jest uruchomiony. Następnie należy uruchamiać kolejne kroki z [setup.sh](setup.sh) pomijając ostatni oraz ręcznie ustawić w powłoce zmienne środowiskowe z pliku [.env.example](.env.example).

Po tym wszystkim uruchamiamy w jednym terminalu bode:

```
cd bode && poetry run flask run --port=$FLASK_PORT
```

A w drugim cabrę:

```
cd cabra && npm run dev
```

W tym przypadku aplikacja też będzie dostępna po adresem http://localhost:3000.

### Możliwe problemy
Jeśli w trakcie instalacji zależności przez poetry pojawi się błąd dotyczący `psycopg2` to konieczne może być doinstalowanie odpowiednich pakietów zgodnie ze [stackiem](https://stackoverflow.com/questions/11618898/pg-config-executable-not-found).

Jeśli w trakcie instalacji zależności przez poetry pojawi się błąd dotyczący `psycopg2` to konieczne może być doinstalowanie odpowiednich pakietów zgodnie ze [stackiem](https://stackoverflow.com/questions/11618898/pg-config-executable-not-found).

## Przygotowanie VS Code

Expand All @@ -79,10 +90,14 @@ VS Code lepiej działa mając dodane foldery z poszczególnymi częściami aplik

### Interpreter pythona

VS Code będzie chciał żeby podać mu ścieżkę do używanego przez interpretera pythona. Wtedy wskazujemy ten w katalogu `bode/.venv`.

VS Code będzie chciał żeby podać mu ścieżkę do używanego przez nas interpretera pythona. Wtedy wskazujemy ten w katalogu `bode/.venv`.

### Lista fajnych i przydatnych dla naszego projektu dodatków:

Poniższe rozszerzenia znajdują się w rekomendacjach dla projektu. Przy uruchomieniu projektu powinno się wyświetlić powiadomienie z opcją ich instalacji.

Rozszerzenie [Remote - WSL](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl) należy zainstalować manualnie, jeśli korzystasz z WSL.

- Frontend/React/Tailwind
- [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) **MUST HAVE**
- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) **MUST HAVE**
Expand All @@ -95,9 +110,33 @@ VS Code będzie chciał żeby podać mu ścieżkę do używanego przez interpret
- [Pylance](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance) **MUST HAVE**
- DevOps
- [Docker](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker)
- [Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
- [Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
- [Remote - WSL](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl) **MUST HAVE** przy WSL
- Inne
- [Git Graph](https://marketplace.visualstudio.com/items?itemName=mhutchie.git-graph) - ładnie pokazuje drzewo gita
- [Git Lens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens) - można łatwo wyklikiwać rzeczy związane z gitem
- [indent-rainbow](https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow) - koloruje wcięcia

## Materiały dotyczące używanych technologii i bibliotek

### Dostęp do bazy danych

- ORM
- [SQLAlchemy](https://docs.sqlalchemy.org/en/14/)
- [Flask-SQLAlchemy](https://flask-sqlalchemy.palletsprojects.com/en/2.x/)
- Migracje
- [Flask-Migrate](https://flask-migrate.readthedocs.io/en/latest/)
- [Alembic](https://alembic.sqlalchemy.org/en/latest/)

### REST API

- [flask-smorest](https://flask-smorest.readthedocs.io/en/latest/)
- [marshmallow](https://marshmallow.readthedocs.io/en/stable/)

### Frontend

- [React](https://beta.reactjs.org/)
- [Typescript](https://www.typescriptlang.org/)
- [Tailwind CSS](https://tailwindcss.com/)
- [react-query](https://react-query.tanstack.com/)
- [react-hook-form](https://react-hook-form.com/)
2 changes: 2 additions & 0 deletions bode/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 120
5 changes: 4 additions & 1 deletion bode/bode/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from .config import Config
from .extensions import api, db, migrate
from .resources import tasks
from .resources import tags, task_relations, tasks

CONFIG = Config()

Expand All @@ -19,6 +19,7 @@ def create_app():
app.config["OPENAPI_VERSION"] = "3.0.2"

app.config["SQLALCHEMY_DATABASE_URI"] = CONFIG.DATABASE_URI
app.config["SQLALCHEMY_ECHO"] = True
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

register_extensions(app)
Expand All @@ -42,6 +43,8 @@ def register_extensions(app):
def register_blueprints(app):
api_blueprint = Blueprint("api", "api", url_prefix="/api/v1")
api_blueprint.register_blueprint(tasks.api.blueprint)
api_blueprint.register_blueprint(tags.api.blueprint)
api_blueprint.register_blueprint(task_relations.api.blueprint)

app.register_blueprint(api_blueprint)
return None
2 changes: 0 additions & 2 deletions bode/bode/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ def get_db_uri():
port = os.getenv("POSTGRES_PORT", "5432")
db = os.getenv("POSTGRES_DB", "tasks")

print()

return f"postgresql://{user}:{password}@{host}:{port}/{db}"


Expand Down
37 changes: 37 additions & 0 deletions bode/bode/models/tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import uuid

from sqlalchemy.dialects.postgresql import UUID

from bode.app import db
from bode.models.task_tag import task_tag


class Tag(db.Model):
__tablename__ = "tags"

id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
name = db.Column(db.String(80), unique=True, nullable=False)

task = db.relationship("Task", secondary=task_tag, back_populates="tags")

def create(tag_name):
tag = Tag(name=tag_name)

db.session.add(tag)
db.session.commit()

return tag

def delete(tag_id):
tag = Tag.query.get_or_404(tag_id)

db.session.delete(tag)
db.session.commit()

return tag

def get_by_name(tag_name):
return Tag.query.filter(Tag.name == tag_name).first()

def __repr__(self):
return f'<Tag {self.id} \n name="{self.name}">'
Loading

0 comments on commit a477d84

Please sign in to comment.