ci: add deployment workflow and automated tests
Deploy TodoList / deploy (push) Failing after 2s

This commit is contained in:
2026-07-31 09:38:39 +08:00
parent 1e142f1de4
commit 2fedb6736a
10 changed files with 713 additions and 4 deletions
+35 -3
View File
@@ -1,6 +1,8 @@
from typing import Self
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from pydantic import BaseModel, Field, field_validator, model_validator
from sqlalchemy import select
from sqlalchemy.exc import SQLAlchemyError
@@ -18,13 +20,43 @@ app.add_middleware(
class todocreate(BaseModel):
task: str
task: str = Field(min_length=1, max_length=200)
@field_validator("task")
@classmethod
def task_must_not_be_blank(cls, value: str) -> str:
if not value.strip():
raise ValueError("task must not be blank")
return value
class todoupdate(BaseModel):
completion: bool | None = None
task: str | None = None
task: str | None = Field(
default=None,
min_length=1,
max_length=200,
)
@field_validator("task")
@classmethod
def task_must_not_be_blank(
cls,
value: str | None,
) -> str | None:
if value is not None and not value.strip():
raise ValueError("task must not be blank")
return value
@model_validator(mode="after")
def at_least_one_field_must_be_provided(self) -> Self:
if self.task is None and self.completion is None:
raise ValueError(
"task or completion must be provided"
)
return self
class todoresponse(BaseModel):
id: int