forked from jmug/stoatchat
feat(delta): example implementation of new core models
This commit is contained in:
41
Cargo.lock
generated
41
Cargo.lock
generated
@@ -2186,15 +2186,6 @@ dependencies = [
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "optional_struct"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/insertish/OptionalStruct?rev=ee56427cee1f007839825d93d07fffd5a5e038c7#ee56427cee1f007839825d93d07fffd5a5e038c7"
|
||||
dependencies = [
|
||||
"quote 0.3.15",
|
||||
"syn 0.11.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "os_info"
|
||||
version = "3.4.0"
|
||||
@@ -2835,8 +2826,8 @@ dependencies = [
|
||||
"log",
|
||||
"mongodb",
|
||||
"nanoid",
|
||||
"optional_struct",
|
||||
"revolt-result",
|
||||
"revolt_optional_struct",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
@@ -2864,6 +2855,7 @@ dependencies = [
|
||||
"regex",
|
||||
"reqwest",
|
||||
"revolt-database",
|
||||
"revolt-models",
|
||||
"revolt-quark",
|
||||
"revolt_rocket_okapi",
|
||||
"rocket",
|
||||
@@ -2881,6 +2873,11 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "revolt-models"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"revolt-database",
|
||||
"schemars",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "revolt-quark"
|
||||
@@ -2909,13 +2906,14 @@ dependencies = [
|
||||
"nanoid",
|
||||
"num_enum",
|
||||
"once_cell",
|
||||
"optional_struct",
|
||||
"pretty_env_logger",
|
||||
"rand 0.8.5",
|
||||
"redis-kiss",
|
||||
"regex",
|
||||
"reqwest",
|
||||
"revolt-result",
|
||||
"revolt_okapi",
|
||||
"revolt_optional_struct",
|
||||
"revolt_rocket_okapi",
|
||||
"rocket",
|
||||
"rocket_cors",
|
||||
@@ -2934,6 +2932,7 @@ dependencies = [
|
||||
name = "revolt-result"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"schemars",
|
||||
"serde",
|
||||
]
|
||||
|
||||
@@ -2949,6 +2948,16 @@ dependencies = [
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "revolt_optional_struct"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d342739658623fe9d72b42f7a36ba19094d1d9bf9b423c3e337ab203c15d53e"
|
||||
dependencies = [
|
||||
"quote 0.3.15",
|
||||
"syn 0.11.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "revolt_rocket_okapi"
|
||||
version = "0.9.1"
|
||||
@@ -3408,9 +3417,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.152"
|
||||
version = "1.0.160"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
|
||||
checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
@@ -3426,13 +3435,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.152"
|
||||
version = "1.0.160"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
|
||||
checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote 1.0.26",
|
||||
"syn 1.0.107",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -57,6 +57,7 @@ revolt-quark = { path = "../quark" }
|
||||
|
||||
# core
|
||||
revolt-database = { path = "../core/database" }
|
||||
revolt-models = { path = "../core/models", features = [ "schemas" ] }
|
||||
|
||||
[build-dependencies]
|
||||
vergen = "7.5.0"
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use revolt_quark::{
|
||||
models::{Bot, User},
|
||||
Db, Error, Ref, Result,
|
||||
};
|
||||
use rocket::serde::json::Json;
|
||||
use revolt_database::Database;
|
||||
use revolt_models::Bot;
|
||||
use revolt_quark::{models::User, Db, Error, Ref, Result};
|
||||
use rocket::{serde::json::Json, State};
|
||||
use serde::Serialize;
|
||||
|
||||
/// # Bot Response
|
||||
/// TODO: move to revolt-models
|
||||
#[derive(Serialize, JsonSchema)]
|
||||
pub struct BotResponse {
|
||||
/// Bot object
|
||||
@@ -19,18 +19,23 @@ pub struct BotResponse {
|
||||
/// 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<BotResponse>> {
|
||||
pub async fn fetch_bot(
|
||||
legacy_db: &Db,
|
||||
db: &State<Database>,
|
||||
user: User,
|
||||
target: Ref,
|
||||
) -> Result<Json<BotResponse>> {
|
||||
if user.bot.is_some() {
|
||||
return Err(Error::IsBot);
|
||||
}
|
||||
|
||||
let bot = target.as_bot(db).await?;
|
||||
let bot = db.fetch_bot(&target.id).await.map_err(Error::from_core)?;
|
||||
if bot.owner != user.id {
|
||||
return Err(Error::NotFound);
|
||||
}
|
||||
|
||||
Ok(Json(BotResponse {
|
||||
user: db.fetch_user(&bot.id).await?.foreign(),
|
||||
bot,
|
||||
user: legacy_db.fetch_user(&bot.id).await?.foreign(),
|
||||
bot: bot.into(),
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -1,44 +1,32 @@
|
||||
use revolt_quark::{
|
||||
models::{File, User},
|
||||
Db, Error, Ref, Result,
|
||||
};
|
||||
use revolt_database::Database;
|
||||
use revolt_models::PublicBot;
|
||||
use revolt_quark::{models::User, Db, Error, Ref, Result};
|
||||
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// # Public Bot
|
||||
#[derive(Serialize, Deserialize, JsonSchema)]
|
||||
pub struct PublicBot {
|
||||
/// Bot Id
|
||||
#[serde(rename = "_id")]
|
||||
id: String,
|
||||
/// Bot Username
|
||||
username: String,
|
||||
/// Profile Avatar
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
avatar: Option<File>,
|
||||
/// Profile Description
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
description: Option<String>,
|
||||
}
|
||||
use rocket::State;
|
||||
|
||||
/// # Fetch Public Bot
|
||||
///
|
||||
/// Fetch details of a public (or owned) bot by its id.
|
||||
#[openapi(tag = "Bots")]
|
||||
#[get("/<target>/invite")]
|
||||
pub async fn fetch_public_bot(db: &Db, user: Option<User>, target: Ref) -> Result<Json<PublicBot>> {
|
||||
let bot = target.as_bot(db).await?;
|
||||
pub async fn fetch_public_bot(
|
||||
legacy_db: &Db,
|
||||
db: &State<Database>,
|
||||
user: Option<User>,
|
||||
target: Ref,
|
||||
) -> Result<Json<PublicBot>> {
|
||||
let bot = db.fetch_bot(&target.id).await.map_err(Error::from_core)?;
|
||||
if !bot.public && user.map_or(true, |x| x.id != bot.owner) {
|
||||
return Err(Error::NotFound);
|
||||
}
|
||||
|
||||
let user = db.fetch_user(&bot.id).await?;
|
||||
let user = legacy_db.fetch_user(&bot.id).await?;
|
||||
|
||||
Ok(Json(PublicBot {
|
||||
id: bot.id,
|
||||
username: user.username,
|
||||
avatar: user.avatar,
|
||||
description: user.profile.and_then(|p| p.content),
|
||||
}))
|
||||
Ok(Json(PublicBot::from(
|
||||
bot,
|
||||
user.username,
|
||||
user.avatar.map(|f| f.id),
|
||||
user.profile.and_then(|p| p.content),
|
||||
)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user