feat: update bot routes to match old spec

This commit is contained in:
Paul Makles
2022-03-20 18:47:04 +00:00
parent b4d825b9a1
commit e245b272fa
2 changed files with 41 additions and 4 deletions

View File

@@ -3,13 +3,23 @@ use revolt_quark::{
Db, Error, Ref, Result,
};
use rocket::serde::json::Json;
use serde::Serialize;
/// # Bot Response
#[derive(Serialize, JsonSchema)]
pub struct BotResponse {
/// Bot object
bot: Bot,
/// User object
user: User,
}
/// # Fetch Bot
///
/// Fetch details of a bot you own by its id.
#[openapi(tag = "Bots")]
#[get("/<target>")]
pub async fn fetch_bot(db: &Db, user: User, target: Ref) -> Result<Json<Bot>> {
pub async fn fetch_bot(db: &Db, user: User, target: Ref) -> Result<Json<BotResponse>> {
if user.bot.is_some() {
return Err(Error::IsBot);
}
@@ -19,5 +29,8 @@ pub async fn fetch_bot(db: &Db, user: User, target: Ref) -> Result<Json<Bot>> {
return Err(Error::NotFound);
}
Ok(Json(bot))
Ok(Json(BotResponse {
user: db.fetch_user(&bot.id).await?.foreign(),
bot,
}))
}