Compare commits
3 commits
master
...
fast-api-r
Author | SHA1 | Date | |
---|---|---|---|
ec018a3f72 | |||
8b3af73f90 | |||
5875a5ebd5 |
19 changed files with 84 additions and 0 deletions
BIN
db.sqlite3
Normal file
BIN
db.sqlite3
Normal file
Binary file not shown.
3
requirements.txt
Normal file
3
requirements.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fastapi
|
||||||
|
uvicorn[standard]
|
||||||
|
peewee
|
0
src/__init__.py
Normal file
0
src/__init__.py
Normal file
1
src/config.py
Normal file
1
src/config.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DATABASE = "./db.sqlite3"
|
0
src/endpoints/__init__.py
Normal file
0
src/endpoints/__init__.py
Normal file
0
src/endpoints/activity_api.py
Normal file
0
src/endpoints/activity_api.py
Normal file
12
src/endpoints/streak_api.py
Normal file
12
src/endpoints/streak_api.py
Normal 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
21
src/main.py
Normal 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
3
src/storage/__init__.py
Normal 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
15
src/storage/activity.py
Normal 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
12
src/storage/database.py
Normal 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
17
src/storage/streak.py
Normal 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')
|
Loading…
Reference in a new issue