Skip to content

Commit

Permalink
fix backend and register page
Browse files Browse the repository at this point in the history
  • Loading branch information
dani2221 committed Mar 4, 2024
1 parent 05a771f commit 743c2a5
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 58 deletions.
38 changes: 7 additions & 31 deletions backend/app/database.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,26 @@
import os
from collections.abc import AsyncGenerator

from sqlalchemy.ext.asyncio import (
AsyncSession,
async_sessionmaker,
create_async_engine,
AsyncEngine,
)
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine

from app.auth.models import Role # noqa: F401
from app.file_transfer.models import File, Webhook # noqa: F401
from app.models import Base

engine: AsyncEngine | None = None
SQLALCHEMY_DATABASE_URL = os.getenv("DATABASE_URL")


def get_engine() -> AsyncEngine:
global engine # noqa: PLW0603

if SQLALCHEMY_DATABASE_URL is None:
raise ValueError("DATABASE_URL environment variable is not set")

if engine is None:
engine = create_async_engine(SQLALCHEMY_DATABASE_URL, echo=True)
return engine


async_session_maker: None | async_sessionmaker = None


def get_session_maker() -> async_sessionmaker:
global async_session_maker # noqa: PLW0603
if async_session_maker is None:
async_session_maker = async_sessionmaker(
autocommit=False, autoflush=False, bind=get_engine(), expire_on_commit=False
)
return async_session_maker
engine = create_async_engine(SQLALCHEMY_DATABASE_URL, echo=True)
async_session_maker = async_sessionmaker(
autocommit=False, autoflush=False, bind=engine, expire_on_commit=False
)


async def initialize_database() -> None:
async with get_engine().begin() as conn:
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.drop_all)
await conn.run_sync(Base.metadata.create_all)


async def get_async_session() -> AsyncGenerator[AsyncSession, None]:
async with get_session_maker() as session: # type: ignore
async with async_session_maker() as session: # type: ignore
yield session
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ services:
container_name: synthra-frontend
restart: unless-stopped
ports:
- "5002:5000"
- "4173:4173"
80 changes: 55 additions & 25 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@
"typescript": "^5.3.3",
"vite": "^5.0.0"
},
"type": "module"
"type": "module",
"dependencies": {
"@svelteuidev/composables": "^0.15.4",
"@svelteuidev/core": "^0.15.4"
}
}
8 changes: 8 additions & 0 deletions frontend/src/app.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<!doctype html>
<script>
import { SvelteUIProvider } from '@svelteuidev/core';
</script>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand All @@ -7,6 +10,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<style>
body {
margin: 0;
}
</style>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/lib/components/Header.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!-- Header.svelte -->

<header>
<h1>Synthra</h1>
</header>

<style>
header {
text-align: start;
margin: 5;
border-bottom: 1px solid gray;
padding: 10px
}
h1 {
margin: 0;
}
</style>
3 changes: 3 additions & 0 deletions frontend/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
// place files you want to import through the `$lib` alias in this folder.
import Header from './components/Header.svelte'

export {Header}
Loading

0 comments on commit 743c2a5

Please sign in to comment.