some
This commit is contained in:
@@ -11,6 +11,8 @@ pub mod crud {
|
|||||||
type Higher: Sized + Send + Sync + 'static;
|
type Higher: Sized + Send + Sync + 'static;
|
||||||
type Info: Sized + Send + Sync + 'static;
|
type Info: Sized + Send + Sync + 'static;
|
||||||
|
|
||||||
|
fn new_id() -> Self::Id;
|
||||||
|
|
||||||
async fn create(
|
async fn create(
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
pool: &sqlite::Pool,
|
pool: &sqlite::Pool,
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ impl<'a> view::View for List<'a> {
|
|||||||
{
|
{
|
||||||
@for todo in self.todos {
|
@for todo in self.todos {
|
||||||
@let state = input.edit_todo
|
@let state = input.edit_todo
|
||||||
.map(|id| if todo.id == id {
|
.map(|id| if todo.id == super::Id::new(id) {
|
||||||
super::UiState::Edit
|
super::UiState::Edit
|
||||||
} else {
|
} else {
|
||||||
super::UiState::Default
|
super::UiState::Default
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ impl From<State> for bool {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Todo {
|
pub struct Todo {
|
||||||
pub id: Uuid,
|
pub id: Id,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub state: State,
|
pub state: State,
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ impl TryFrom<TodoRow> for Todo {
|
|||||||
|
|
||||||
fn try_from(row: TodoRow) -> Result<Self, Self::Error> {
|
fn try_from(row: TodoRow) -> Result<Self, Self::Error> {
|
||||||
Ok(Todo {
|
Ok(Todo {
|
||||||
id: Uuid::try_parse(&row.id)?,
|
id: Id::new(Uuid::try_parse(&row.id)?),
|
||||||
description: row.description,
|
description: row.description,
|
||||||
state: row.done.into(),
|
state: row.done.into(),
|
||||||
})
|
})
|
||||||
@@ -92,10 +92,7 @@ impl crud::Higher for Higher {
|
|||||||
type Reference = Reference;
|
type Reference = Reference;
|
||||||
|
|
||||||
fn with_id(&self, id: Self::Id) -> Self::Reference {
|
fn with_id(&self, id: Self::Id) -> Self::Reference {
|
||||||
Reference {
|
Reference { id, higher: *self }
|
||||||
id,
|
|
||||||
higher: self.clone(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +111,7 @@ impl From<(Uuid, Uuid)> for Reference {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub struct Id(Uuid);
|
pub struct Id(Uuid);
|
||||||
|
|
||||||
impl std::fmt::Display for Id {
|
impl std::fmt::Display for Id {
|
||||||
@@ -129,12 +126,6 @@ impl Id {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(Uuid, Uuid)> for Id {
|
|
||||||
fn from((_trip_id, todo_id): (Uuid, Uuid)) -> Self {
|
|
||||||
Self(todo_id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Todo {
|
impl Todo {
|
||||||
pub fn is_done(&self) -> bool {
|
pub fn is_done(&self) -> bool {
|
||||||
self.state == State::Done
|
self.state == State::Done
|
||||||
@@ -230,6 +221,10 @@ impl crud::Create for Todo {
|
|||||||
type Higher = Higher;
|
type Higher = Higher;
|
||||||
type Info = TodoNew;
|
type Info = TodoNew;
|
||||||
|
|
||||||
|
fn new_id() -> Self::Id {
|
||||||
|
Id::new(Uuid::new_v4())
|
||||||
|
}
|
||||||
|
|
||||||
async fn create(
|
async fn create(
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
pool: &sqlite::Pool,
|
pool: &sqlite::Pool,
|
||||||
@@ -237,7 +232,7 @@ impl crud::Create for Todo {
|
|||||||
info: Self::Info,
|
info: Self::Info,
|
||||||
) -> Result<Self::Id, Error> {
|
) -> Result<Self::Id, Error> {
|
||||||
let user_id = ctx.user.id.to_string();
|
let user_id = ctx.user.id.to_string();
|
||||||
let id = Uuid::new_v4();
|
let id = Self::new_id();
|
||||||
tracing::info!("adding new todo with id {id}");
|
tracing::info!("adding new todo with id {id}");
|
||||||
let id_param = id.to_string();
|
let id_param = id.to_string();
|
||||||
let trip_id_param = higher.trip_id.to_string();
|
let trip_id_param = higher.trip_id.to_string();
|
||||||
@@ -263,7 +258,7 @@ impl crud::Create for Todo {
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(components::trips::todos::Id(id))
|
Ok(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user