feat(bots): implement bot routes
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
use revolt_quark::Result;
|
||||
|
||||
use serde_json::Value;
|
||||
use revolt_quark::{
|
||||
models::{Bot, User},
|
||||
Db, Error, Ref, Result,
|
||||
};
|
||||
use rocket::serde::json::Json;
|
||||
|
||||
#[get("/<target>")]
|
||||
pub async fn fetch_bot(/*user: UserRef, target: Ref*/ target: String) -> Result<Value> {
|
||||
todo!()
|
||||
pub async fn fetch_bot(db: &Db, user: User, target: Ref) -> Result<Json<Bot>> {
|
||||
if user.bot.is_some() {
|
||||
return Err(Error::IsBot);
|
||||
}
|
||||
|
||||
let bot = target.as_bot(db).await?;
|
||||
if bot.owner != user.id {
|
||||
return Err(Error::NotFound);
|
||||
}
|
||||
|
||||
Ok(Json(bot))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user