feat: minimum working comments app
Python Lint CI / ty (push) Successful in 58s
TS Lint / ESLint (push) Successful in 58s
Python Lint CI / ruff (push) Successful in 58s
Python Lint CI / ruff-format-check (push) Successful in 58s
TS Lint / TypeScript (push) Successful in 3m28s
TS Lint / Oxlint (push) Successful in 3m28s

This commit is contained in:
2026-07-01 18:19:25 +02:00
parent c93a74b0f4
commit 92d2e7c3a0
7 changed files with 143 additions and 14 deletions
+8 -2
View File
@@ -25,9 +25,15 @@ class Database:
)
def init(self) -> typing.Self:
self.logger.info("Initializing database")
tortoise.run_async(tortoise.Tortoise.init(config=self.config))
self.logger.info("Migrating database")
tortoise.run_async(tortoise.migrations.api.migrate(config=self.config))
self.logger.info("Initializing database")
tortoise.run_async(
tortoise.Tortoise.init(config=self.config, _enable_global_fallback=True)
)
self.logger.info("Database ready")
return self
def __enter__(self) -> typing.Self:
return self
+19 -1
View File
@@ -1,9 +1,11 @@
import logging
import typing
import flask
import gunicorn.app.base
from app import PKG_NAME
from app.models.comment import Comment
if typing.TYPE_CHECKING:
from app.params import Parameters
@@ -21,6 +23,7 @@ class Server(gunicorn.app.base.BaseApplication):
PKG_NAME, static_folder="dist/assets", template_folder="dist"
)
self._index_content: str | None = None
self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)
super().__init__()
def register_routes(self) -> typing.Self:
@@ -28,6 +31,16 @@ class Server(gunicorn.app.base.BaseApplication):
def index() -> str:
return flask.render_template("index.html")
@self.app.route("/api/comments", methods=["GET"])
async def get_comments() -> list:
return await Comment.all().order_by("created_at").values()
@self.app.route("/api/comments", methods=["POST"])
async def post_comment() -> tuple[str, int]:
data = flask.request.get_json()
await Comment.create(content=data["content"])
return ("", 204)
return self
@typing.override
@@ -48,5 +61,10 @@ class Server(gunicorn.app.base.BaseApplication):
self.run()
else:
self.app.run(
host=self.bind, port=self.port, debug=self.debug, load_dotenv=False
host=self.bind,
port=self.port,
debug=self.debug,
load_dotenv=False,
use_evalex=False,
use_reloader=False,
)
+1 -1
View File
@@ -5,7 +5,7 @@ description = ""
readme = "README.md"
requires-python = ">=3.14"
dependencies = [
"flask>=3.1.3,<4.0.0",
"flask[async]>=3.1.3,<4.0.0",
"gunicorn>=26.0.0,<27.0.0",
"tortoise-orm[asyncpg]>=1.1.7,<2.0.0",
]
+79 -8
View File
@@ -1,7 +1,36 @@
<script setup lang="ts">
import { ref, onMounted } from "vue";
import { ref, onMounted, onBeforeMount } from "vue";
import { getComments, postComment } from "@/api/comments";
import type { Comment } from "@/types";
const visible = ref<boolean>(false);
const comments = ref<Comment[]>([]);
const commentInput = ref<string>("");
function fetchComments() {
getComments()
.then((data: Comment[]) => {
comments.value = data;
})
.catch(() => {
//ignore
});
}
function sendComment() {
if (commentInput.value.trim()) {
postComment(commentInput.value.trim())
.finally(() => {
commentInput.value = "";
fetchComments();
})
.catch(() => {
//ignore
});
}
}
onBeforeMount(fetchComments);
onMounted(() => {
setTimeout(() => {
@@ -15,13 +44,55 @@ onMounted(() => {
<div class="hero bg-base-200 min-h-screen">
<div class="hero-content text-center">
<div class="max-w-md">
<h1 class="text-5xl font-bold">Hello there</h1>
<p class="py-6">
Provident cupiditate voluptatem et in. Quaerat fugiat ut
assumenda excepturi exercitationem quasi. In deleniti
eaque aut repudiandae et a id nisi.
</p>
<button class="btn btn-primary">Get Started</button>
<ul class="list bg-base-100 rounded-box shadow-md">
<li class="p-4 pb-2 text-xl opacity-60 tracking-wide">
Comments
</li>
<li
v-for="comment in comments"
:key="comment.id"
class="list-row"
>
<div class="avatar avatar-placeholder">
<div
class="bg-neutral text-neutral-content size-10 rounded-box"
>
<span class="text-xs">{{
comment.content[0]
}}</span>
</div>
</div>
<div>
<div class="text-xs opacity-60">
{{ comment.created_at }}
</div>
<div class="font-semibold">
{{ comment.content }}
</div>
</div>
</li>
<li class="list-row">
<div>
<input
v-model="commentInput"
type="text"
placeholder="Type here"
class="input"
@keyup.enter="sendComment"
/>
</div>
<div>
<button
class="btn"
:disabled="commentInput.trim().length === 0"
@click="sendComment"
>
Send
</button>
</div>
</li>
</ul>
</div>
</div>
</div>
+14
View File
@@ -0,0 +1,14 @@
import type { Comment } from "@/types";
export async function getComments(): Promise<Comment[]> {
const response = await fetch("/api/comments");
return await response.json();
}
export async function postComment(content: string): Promise<void> {
await fetch("/api/comments", {
method: "POST",
body: JSON.stringify({ content }),
headers: { "Content-Type": "application/json" },
});
}
+6
View File
@@ -0,0 +1,6 @@
export interface Comment {
id: string;
created_at: string;
updated_at: string;
content: string;
}
Generated
+16 -2
View File
@@ -23,6 +23,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/b0/7b/90df4a0a816d98d6ea26f559d87836d494a2cf1fcf063be67df50a7bcc30/anyio-4.14.1-py3-none-any.whl", hash = "sha256:4e5533c5b8ff0a24f5d7a176cbe6877129cd183893f66b537f8f227d10527d72", size = 124875, upload-time = "2026-06-24T20:56:04.413Z" },
]
[[package]]
name = "asgiref"
version = "3.11.1"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/63/40/f03da1264ae8f7cfdbf9146542e5e7e8100a4c66ab48e791df9a03d3f6c0/asgiref-3.11.1.tar.gz", hash = "sha256:5f184dc43b7e763efe848065441eac62229c9f7b0475f41f80e207a114eda4ce", size = 38550, upload-time = "2026-02-03T13:30:14.33Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/5c/0a/a72d10ed65068e115044937873362e6e32fab1b7dce0046aeb224682c989/asgiref-3.11.1-py3-none-any.whl", hash = "sha256:e8667a091e69529631969fd45dc268fa79b99c92c5fcdda727757e52146ec133", size = 24345, upload-time = "2026-02-03T13:30:13.039Z" },
]
[[package]]
name = "asyncpg"
version = "0.31.0"
@@ -133,6 +142,11 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/7f/9c/34f6962f9b9e9c71f6e5ed806e0d0ff03c9d1b0b2340088a0cf4bce09b18/flask-3.1.3-py3-none-any.whl", hash = "sha256:f4bcbefc124291925f1a26446da31a5178f9483862233b23c0c96a20701f670c", size = 103424, upload-time = "2026-02-19T05:00:56.027Z" },
]
[package.optional-dependencies]
async = [
{ name = "asgiref" },
]
[[package]]
name = "gunicorn"
version = "26.0.0"
@@ -325,7 +339,7 @@ name = "tout-doux"
version = "0.0.0"
source = { editable = "." }
dependencies = [
{ name = "flask" },
{ name = "flask", extra = ["async"] },
{ name = "gunicorn" },
{ name = "tortoise-orm", extra = ["asyncpg"] },
]
@@ -340,7 +354,7 @@ dev = [
[package.metadata]
requires-dist = [
{ name = "flask", specifier = ">=3.1.3,<4.0.0" },
{ name = "flask", extras = ["async"], specifier = ">=3.1.3,<4.0.0" },
{ name = "gunicorn", specifier = ">=26.0.0,<27.0.0" },
{ name = "tortoise-orm", extras = ["asyncpg"], specifier = ">=1.1.7,<2.0.0" },
]