Skip to content

Commit

Permalink
changed the project structure (DHBW-FN-TIT20#18)
Browse files Browse the repository at this point in the history
* changed the project structure

Renamend Location and Restaurant schemes

removed copy of gapi

Renamend Filter

moved gapi.py to tools

moved gapi.py to tools

created own file for exceptions

added docstring

added pre commit functions

some import restrukture

renamend requirements-dev

added pre-commits

pre-commit check

changed name

renamend example confs

updated dev and none dev requirements

* Updated Readme

* Updated Readme
  • Loading branch information
Floskinner authored Jan 27, 2022
1 parent fbb7ea8 commit c6d4037
Show file tree
Hide file tree
Showing 26 changed files with 906 additions and 194 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-validation.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Our first GitHub Action
name: Black and flake validation

on:
push:
Expand All @@ -26,7 +26,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f dev_requirements.txt ]; then pip install -r dev_requirements.txt; fi
if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ dmypy.json

# Ignore all Configuration Files
*.conf
!example*.conf
tests/test_db.db

# Ignore Logs
Expand Down
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
types:
- "python"
- id: trailing-whitespace
types:
- "python"
- repo: https://github.com/psf/black
rev: 19.3b0
hooks:
- id: black
exclude: |
(?x)^(
static|
templates
)$
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.7.1
hooks:
- id: reorder-python-imports
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Essensfindung
Student project for DHBW-Friedrichshafen to search for restaurant or recipe suggestions.

# Usage
To run the application install the requirements:
```console
pip install requirements.txt
```
OR
```console
poetry install --no-dev
```
You also need the configuration files in the `configuration` Folder.<br>
Just copy the examples in the Folder and fill in the Data.
# Developing
Python-Verison 3.9 or higher<br>
You can use [pyenv](https://github.com/pyenv/pyenv) to manage you virtual envioremnts.
Expand All @@ -12,6 +23,16 @@ pyenv global 3.9.7

Please formatt your Code with [black](https://github.com/psf/black) and validate it with [flake8](https://pypi.org/project/flake8/) and [pylint](https://pypi.org/project/pylint/).

## Pre-Commit
If you use git on console the [pre-commit](https://pre-commit.com) will take affect automatically. This will format the code to reduce merge conflicts and ensure some type of standards.<br>
To activate the automaticall validation type:
```console
pre-commit install
```
If you want to manuall start the pre-commit check run:
```console
pre-commit run --all-files
```
## Dependencies
To develop on this project we recommend to use [venv](https://docs.python.org/3/library/venv.html).<br>
You can use some extra tools like:
Expand All @@ -26,15 +47,17 @@ poetry install
To add a **developer** only dependencies do:
```console
poetry add -D [Package] [Package]...
poetry export --dev -f requirements.txt -o requirements-dev.txt
```
To add a **production** dependencies do:
```console
poetry add [Package] [Package]...
poetry export -f requirements.txt -o requirements.txt
```

### pip
To install the requierd dependencies via pip:
```console
pip install -r dev_requirements.txt
pip install -r requirements_dev.txt
```
Here you have to manuel manage the requirements.txt files. Use a fixed versions only.
4 changes: 3 additions & 1 deletion configuration/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from configparser import ConfigParser
from . import PATH_GOOGLE, PATH_DB

from . import PATH_DB
from . import PATH_GOOGLE


def get_google_api_key() -> str:
Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 13 additions & 12 deletions db/crud.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""CRUD comes from: Create, Read, Update, and Delete... for the Database"""
from typing import List, Union
from typing import List
from typing import Union

import sqlalchemy

from schemes import scheme_rest, scheme_user
from sqlalchemy.orm import Session
from tools.hashing import Hasher

from . import db_models
from schemes import scheme_rest
from schemes import scheme_user
from tools.hashing import Hasher


def get_restaurant_by_id(db: Session, place_id: str) -> db_models.Restaurant:
Expand Down Expand Up @@ -37,12 +38,12 @@ def get_all_restaurants(db: Session, skip: int = 0, limit: int = 100) -> List[db
return db.query(db_models.Restaurant).offset(skip).limit(limit).all()


def create_restaurant(db: Session, rest: scheme_rest.BaseRestaurant) -> db_models.Restaurant:
def create_restaurant(db: Session, rest: scheme_rest.RestaurantBase) -> db_models.Restaurant:
"""Create / Add a Restaurant to the DB
Args:
db (Session): Session to the DB
rest (scheme_rest.BaseRestaurant): The Restaurant with the place_id required
rest (scheme_rest.RestaurantBase): The Restaurant with the place_id required
Returns:
db_models.Restaurant: Return if success
Expand All @@ -54,12 +55,12 @@ def create_restaurant(db: Session, rest: scheme_rest.BaseRestaurant) -> db_model
return db_rest


def delete_restaurant(db: Session, rest: scheme_rest.BaseRestaurant) -> int:
def delete_restaurant(db: Session, rest: scheme_rest.RestaurantBase) -> int:
"""Delete one restaurant from the DB with the specific place_id
Args:
db (Session): Session to the DB
rest (BaseRestaurant): Restaurant with the place_id
rest (RestaurantBase): Restaurant with the place_id
Returns:
int: Number of effected rows
Expand All @@ -70,14 +71,14 @@ def delete_restaurant(db: Session, rest: scheme_rest.BaseRestaurant) -> int:


def get_bewertung_from_user_to_rest(
db: Session, user: scheme_user.UserBase, rest: scheme_rest.BaseRestaurant
db: Session, user: scheme_user.UserBase, rest: scheme_rest.RestaurantBase
) -> db_models.Bewertung:
"""Return a specific bewertung from a user to only one restaurant
Args:
db (Session): Session to the DB
user (scheme_user.UserBase): Specifie the User
rest (scheme_rest.BaseRestaurant): Specifie the restauranat
rest (scheme_rest.RestaurantBase): Specifie the restauranat
Returns:
db_models.Bewertung: Return one bewertung that match the restaurant - user
Expand Down Expand Up @@ -161,13 +162,13 @@ def update_bewertung(
return get_bewertung_from_user_to_rest(db, new_bewertung.person, new_bewertung.restaurant)


def delete_bewertung(db: Session, user: scheme_user.UserBase, rest: scheme_rest.BaseRestaurant) -> int:
def delete_bewertung(db: Session, user: scheme_user.UserBase, rest: scheme_rest.RestaurantBase) -> int:
"""Delete one Bewertung
Args:
db (Session): Session to the db
user (scheme_user.User): The owner of the Bewertung
rest (scheme_rest.BaseRestaurant): The corrosponding Restaurant
rest (scheme_rest.RestaurantBase): The corrosponding Restaurant
Returns:
int: Number of effected rows
Expand Down
3 changes: 2 additions & 1 deletion db/database.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Create the connection to the Database"""
from typing import Generator

from configuration import config
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

from configuration import config

conf = config.get_db_conf()
SQLALCHEMY_DATABASE_URL = f"postgresql://{conf['username']}:{conf['password']}@{conf['host']}/{conf['database']}"

Expand Down
9 changes: 7 additions & 2 deletions db/db_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
"""SQLAlchemy uses the term "model" to refer to these classes and instances that interact with the database"""
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, Table
from sqlalchemy.sql import func
from sqlalchemy import Column
from sqlalchemy import DateTime
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func

from db.database import Base

Expand Down
103 changes: 0 additions & 103 deletions infrastructure/gapi.py

This file was deleted.

3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

from db import db_models
from db.database import engine
from views import home, restaurant
from views import home
from views import restaurant

app = fastapi.FastAPI()

Expand Down
Loading

0 comments on commit c6d4037

Please sign in to comment.