Add fetch owned, public and specific bots for #8.

This commit is contained in:
Paul
2021-08-12 13:40:03 +01:00
parent 9f749cfdf8
commit a71bfa908c
6 changed files with 131 additions and 27 deletions

22
src/routes/bots/fetch.rs Normal file
View File

@@ -0,0 +1,22 @@
use crate::database::*;
use crate::util::result::{Error, Result};
use serde_json::Value;
#[get("/<target>")]
pub async fn fetch_bot(user: User, target: Ref) -> Result<Value> {
let bot = target.fetch_bot().await?;
if !bot.public {
if bot.owner != user.id {
return Err(Error::BotIsPrivate);
}
}
let user = Ref::from_unchecked(bot.id.clone()).fetch_user().await?;
Ok(json!({
"bot": bot,
"user": user
}))
}