refactor(quark): port get/set_settings, get_unreads

#283
This commit is contained in:
Paul Makles
2024-04-07 18:10:11 +01:00
parent f6a565385e
commit 2de7598f8d
11 changed files with 69 additions and 68 deletions

View File

@@ -1,17 +1,8 @@
use revolt_quark::{
models::{User, UserSettings},
Db, Result,
};
use revolt_database::{Database, User};
use revolt_models::v0;
use revolt_result::Result;
use rocket::serde::json::Json;
use serde::{Deserialize, Serialize};
/// # Fetch Options
#[derive(Serialize, Deserialize, JsonSchema)]
pub struct OptionsFetchSettings {
/// Keys to fetch
keys: Vec<String>,
}
use rocket::State;
/// # Fetch Settings
///
@@ -20,11 +11,11 @@ pub struct OptionsFetchSettings {
/// This will return an object with the requested keys, each value is a tuple of `(timestamp, value)`, the value is the previously uploaded data.
#[openapi(tag = "Sync")]
#[post("/settings/fetch", data = "<options>")]
pub async fn req(
db: &Db,
pub async fn fetch(
db: &State<Database>,
user: User,
options: Json<OptionsFetchSettings>,
) -> Result<Json<UserSettings>> {
options: Json<v0::OptionsFetchSettings>,
) -> Result<Json<v0::UserSettings>> {
db.fetch_user_settings(&user.id, &options.into_inner().keys)
.await
.map(Json)