Skip loading owner of character for API.
This commit is contained in:
parent
2e2cf30755
commit
6156bba34d
|
@ -42,9 +42,6 @@ pub(crate) trait Dao {
|
||||||
async fn update_character_sheet<'a>(&self, character: &'a Character) -> sqlx::Result<()>;
|
async fn update_character_sheet<'a>(&self, character: &'a Character) -> sqlx::Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO is:
|
|
||||||
// - use compile time queries
|
|
||||||
// - find replacement for diesel migrations
|
|
||||||
#[rocket::async_trait]
|
#[rocket::async_trait]
|
||||||
impl Dao for SqlitePool {
|
impl Dao for SqlitePool {
|
||||||
async fn load_user_by_id(&self, user_id: i32) -> sqlx::Result<Option<User>> {
|
async fn load_user_by_id(&self, user_id: i32) -> sqlx::Result<Option<User>> {
|
||||||
|
|
|
@ -30,13 +30,13 @@ async fn load_character(
|
||||||
character_id: i32,
|
character_id: i32,
|
||||||
) -> Result<Character, Error> {
|
) -> Result<Character, Error> {
|
||||||
let logged_in_user = logged_in_user.ok_or(Error::NotLoggedIn)?;
|
let logged_in_user = logged_in_user.ok_or(Error::NotLoggedIn)?;
|
||||||
let owner = conn.load_user(&owner).await?.ok_or(Error::NotFound)?;
|
|
||||||
let character: Character = conn
|
let character: Character = conn
|
||||||
.load_character(character_id)
|
.load_character(character_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(Error::NotFound)?;
|
.ok_or(Error::NotFound)?;
|
||||||
|
|
||||||
if logged_in_user != &owner {
|
if logged_in_user.username != owner {
|
||||||
return Err(Error::NoPermission);
|
return Err(Error::NoPermission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue