Compare commits

..

3 commits

Author SHA1 Message Date
ec018a3f72 Merge remote-tracking branch 'origin/fast-api-rework' into fast-api-rework
# Conflicts:
#	old_src/activity.php
#	old_src/config.php
#	old_src/http.php
#	old_src/index.php
#	old_src/storage.php
#	old_src/streaks.php
#	old_src/templates.php
2024-03-11 01:35:41 +01:00
8b3af73f90 Initial FastApi, Peewee setup 2024-03-11 01:35:06 +01:00
5875a5ebd5 Initial FastApi, Peewee setup 2024-03-11 01:34:50 +01:00
19 changed files with 84 additions and 0 deletions

BIN
db.sqlite3 Normal file

Binary file not shown.

3
requirements.txt Normal file
View file

@ -0,0 +1,3 @@
fastapi
uvicorn[standard]
peewee

0
src/__init__.py Normal file
View file

1
src/config.py Normal file
View file

@ -0,0 +1 @@
DATABASE = "./db.sqlite3"

View file

View file

View file

@ -0,0 +1,12 @@
from typing import List
from fastapi import APIRouter
from ..storage import Streak
router = APIRouter()
@router.get("/list", tags=["streak"])
def get_streaks() -> str:
return "Hellow"

21
src/main.py Normal file
View file

@ -0,0 +1,21 @@
from fastapi import FastAPI
from .config import DATABASE
from .storage import *
from .endpoints.streak_api import router as streak_router
import os
# Setup database
def create_database():
with database:
database.create_tables([Activity, ActivityRecord, Streak, StreakRecord])
if not os.path.exists(DATABASE):
create_database()
app = FastAPI()
app.include_router(streak_router, prefix="/streak", tags=["streak"])

3
src/storage/__init__.py Normal file
View file

@ -0,0 +1,3 @@
from .activity import Activity, ActivityRecord
from .streak import Streak, StreakRecord
from .database import database

15
src/storage/activity.py Normal file
View file

@ -0,0 +1,15 @@
from .database import BaseModel
from peewee import BooleanField, TextField, DateTimeField, ForeignKeyField
class Activity(BaseModel):
name = TextField()
description = TextField()
is_available = BooleanField()
is_working = BooleanField()
class ActivityRecord(BaseModel):
started_at = DateTimeField()
activity = ForeignKeyField(Activity, backref='records')

12
src/storage/database.py Normal file
View file

@ -0,0 +1,12 @@
from peewee import Model, SqliteDatabase, UUIDField
from ..config import DATABASE
database = SqliteDatabase(DATABASE)
class BaseModel(Model):
id = UUIDField(primary_key=True)
class Meta:
database = database

17
src/storage/streak.py Normal file
View file

@ -0,0 +1,17 @@
from datetime import date
from .database import BaseModel
from peewee import TextField, ForeignKeyField, FloatField, BooleanField, DateField
class Streak(BaseModel):
name = TextField()
description = TextField
class StreakRecord(BaseModel):
reference_date = DateField(default=date.today)
is_achieved = BooleanField()
value = FloatField()
streak = ForeignKeyField(Streak, backref='records')