feat: include user in responses when creating and editing bots

This commit is contained in:
Paul Makles
2024-06-26 19:49:26 +01:00
parent ce20e689cc
commit d6bcb844db
9 changed files with 38 additions and 17 deletions

View File

@@ -14,7 +14,7 @@ pub async fn create_bot(
db: &State<Database>,
user: User,
info: Json<v0::DataCreateBot>,
) -> Result<Json<v0::Bot>> {
) -> Result<Json<v0::BotWithUserResponse>> {
let info = info.into_inner();
info.validate().map_err(|error| {
create_error!(FailedValidation {
@@ -22,8 +22,11 @@ pub async fn create_bot(
})
})?;
let bot = Bot::create(db, info.name, &user, None).await?;
Ok(Json(bot.into()))
let (bot, user) = Bot::create(db, info.name, &user, None).await?;
Ok(Json(v0::BotWithUserResponse {
bot: bot.into(),
user: user.into_self(false).await,
}))
}
#[cfg(test)]