fix parsing

This commit is contained in:
2025-10-09 17:40:54 -06:00
parent 4e981a69a8
commit 7cad512010
14 changed files with 520 additions and 214 deletions

View File

@@ -0,0 +1,45 @@
import logging as logging;
import orm as orm;
import uuid as uuid;
import webapp.models as models;
#[derive(DeepCopy, Debug, PartialEq)]
type TodoGetParams struct {
#[validate(format="short")]
pub id: uuid.UUID;
}
#[derive(DeepCopy, Debug, PartialEq, Serialize)]
type TodoResponse struct {
#[validate(format="short")]
pub id: uuid.UUID;
#[validate(format="short")]
pub user_id: uuid.UUID;
#[validate(min_length=1, max_length=256)]
pub title: String;
#[validate(min_length=1, max_length=1000000)]
pub description: String;
pub created_at: DateTime;
pub updated_at: DateTime;
}
impl Into<TodoResponse> for models.Todo {
fn into(self: Self): TodoResponse {
return TodoResponse{..self};
}
}
type Router struct {
logger: logging::Logger;
db: orm::DB;
pub fn new(logger: logging::Logger, db: orm::DB): Router {
return Self{logger: logger, db: db};
}
pub fn get_todo(self: Self, req: http.Request[TodoGetParams, http::NoQuery, http::NoBody]): IO[Result[http::JsonResponse[TodoResponse], http::Error]] {
let id = req.params.id;
let instance = models::Todo::select().filter(models::Todo::Id::equals(id)).first(self.db)??;
return http::JsonResponse<TodoResponse>::ok(instance.into());
}
}