data export implemented
This commit is contained in:
parent
08ae8e6443
commit
910a3d5845
6 changed files with 31 additions and 6 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2013,6 +2013,7 @@ dependencies = [
|
|||
"rocket_codegen",
|
||||
"rocket_http",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"state",
|
||||
"tempfile",
|
||||
"time",
|
||||
|
|
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
rocket = { version = "0.5.1", features = ["secrets"] }
|
||||
rocket = { version = "0.5.1", features = ["secrets", "json"] }
|
||||
rocket_dyn_templates = { version = "0.2.0", features = ["tera"] }
|
||||
rocket_db_pools = { version = "0.2.0", features = ["sqlx_postgres"] }
|
||||
sqlx = { version = "0.7", default-features = false, features = [
|
||||
|
|
|
@ -24,5 +24,4 @@ a profile is
|
|||
- p2: saving register form as it gets filled / re-display it with partial values
|
||||
- account
|
||||
- p2: optional email for forgotten password i guess
|
||||
- ability to delete the whole account (incl. all registered tags)
|
||||
- deleting a tag keeping the account allows to re-use the tag later on. no one else can use it still
|
||||
|
|
|
@ -38,6 +38,7 @@ fn rocket() -> _ {
|
|||
account::confirm_delete,
|
||||
account::ask_terminate_account,
|
||||
account::confirm_terminate_account,
|
||||
account::export_data,
|
||||
],
|
||||
)
|
||||
.mount(
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
use rocket::{http::CookieJar, response::Redirect};
|
||||
use rocket::{
|
||||
http::CookieJar,
|
||||
response::Redirect,
|
||||
serde::{json::Json, Serialize},
|
||||
};
|
||||
use rocket_dyn_templates::{context, Template};
|
||||
use sqlx::Acquire;
|
||||
|
||||
|
@ -6,13 +10,13 @@ use crate::{
|
|||
auth::session,
|
||||
db::{
|
||||
doll,
|
||||
schema::{DollTagsDb, User},
|
||||
schema::{DollProfile, DollTagsDb, User},
|
||||
user,
|
||||
},
|
||||
pages::CommonTemplateState,
|
||||
};
|
||||
|
||||
use super::error_handlers::PageResult;
|
||||
use super::error_handlers::{PageResult, RawResult};
|
||||
|
||||
#[get("/")]
|
||||
pub async fn index(mut db: DollTagsDb, user: User, meta: CommonTemplateState) -> PageResult {
|
||||
|
@ -36,6 +40,26 @@ pub fn show_settings(user: User, meta: CommonTemplateState) -> Template {
|
|||
Template::render("account/settings", context! {user,meta})
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
pub struct DataDump {
|
||||
account: User,
|
||||
tags: Vec<DollProfile>,
|
||||
reserved_tags: Vec<i32>,
|
||||
}
|
||||
|
||||
#[get("/data_dump")]
|
||||
pub async fn export_data(mut db: DollTagsDb, user: User) -> RawResult<Json<DataDump>> {
|
||||
let tags = doll::list(&mut *db, &user.id).await?;
|
||||
let reserved_tags = doll::list_archived(&mut *db, &user.id).await?;
|
||||
|
||||
Ok(Json(DataDump {
|
||||
account: user,
|
||||
tags,
|
||||
reserved_tags,
|
||||
}))
|
||||
}
|
||||
|
||||
#[get("/delete/<id>")]
|
||||
pub async fn ask_delete(
|
||||
mut db: DollTagsDb,
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
<p>You can export all your account's data using this button.</p>
|
||||
<p>It will be provided in a JSON file whose structure is documented.</p>
|
||||
<!-- TODO: Link structure documentation. -->
|
||||
<a href="/account/export" class="btn">Export all my data</a>
|
||||
<a href="/account/data_dump" class="btn">Export all my data</a>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
|
|
Loading…
Add table
Reference in a new issue