diff --git a/src/model/user.rs b/src/model/user.rs index a14bacc..24acda1 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -20,46 +20,6 @@ pub struct User { is_guest: bool, } -pub struct AdminUser { - user: User, -} - -impl TryFrom for AdminUser { - type Error = LoginError; - - fn try_from(user: User) -> Result { - if user.is_admin { - Ok(AdminUser { user }) - } else { - Err(LoginError::NotAnAdmin) - } - } -} - -pub struct CoxUser { - user: User, -} - -impl Deref for CoxUser { - type Target = User; - - fn deref(&self) -> &Self::Target { - &self.user - } -} - -impl TryFrom for CoxUser { - type Error = LoginError; - - fn try_from(user: User) -> Result { - if user.is_cox { - Ok(CoxUser { user }) - } else { - Err(LoginError::NotACox) - } - } -} - #[derive(Debug)] pub enum LoginError { SqlxError(sqlx::Error), @@ -202,8 +162,32 @@ impl<'r> FromRequest<'r> for User { } } +pub struct CoxUser { + user: User, +} + +impl Deref for CoxUser { + type Target = User; + + fn deref(&self) -> &Self::Target { + &self.user + } +} + +impl TryFrom for CoxUser { + type Error = LoginError; + + fn try_from(user: User) -> Result { + if user.is_cox { + Ok(CoxUser { user }) + } else { + Err(LoginError::NotACox) + } + } +} + #[async_trait] -impl<'r> FromRequest<'r> for AdminUser { +impl<'r> FromRequest<'r> for CoxUser { type Error = LoginError; async fn from_request(req: &'r Request<'_>) -> request::Outcome { @@ -220,8 +204,24 @@ impl<'r> FromRequest<'r> for AdminUser { } } +pub struct AdminUser { + user: User, +} + +impl TryFrom for AdminUser { + type Error = LoginError; + + fn try_from(user: User) -> Result { + if user.is_admin { + Ok(AdminUser { user }) + } else { + Err(LoginError::NotAnAdmin) + } + } +} + #[async_trait] -impl<'r> FromRequest<'r> for CoxUser { +impl<'r> FromRequest<'r> for AdminUser { type Error = LoginError; async fn from_request(req: &'r Request<'_>) -> request::Outcome { diff --git a/src/rest/mod.rs b/src/rest/mod.rs index 0ab9548..daa2e7c 100644 --- a/src/rest/mod.rs +++ b/src/rest/mod.rs @@ -65,8 +65,6 @@ async fn join(db: &State, trip_details_id: i64, user: User) -> Flash #[get("/remove/")] async fn remove(db: &State, trip_details_id: i64, user: User) -> Flash { - //TODO: Check if > 2 hrs to event - UserTrip::delete(db, user.id, trip_details_id).await; Flash::success(Redirect::to("/"), "Erfolgreich abgemeldet!")