mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-11-17 05:50:50 +01:00
Refactor account_data to be more similar to other endpoints
This commit is contained in:
parent
60381ddcf4
commit
87fd432527
1 changed files with 8 additions and 7 deletions
|
@ -589,18 +589,19 @@ pub fn get_global_account_data_route(
|
|||
) -> ConduitResult<get_global_account_data::Response> {
|
||||
let user_id = body.user_id.as_ref().expect("user is authenticated");
|
||||
|
||||
db.account_data
|
||||
let event = db
|
||||
.account_data
|
||||
.get(
|
||||
None,
|
||||
user_id,
|
||||
&EventType::try_from(&body.event_type).expect("EventType::try_from can never fail"),
|
||||
)?
|
||||
.and_then(|ev| {
|
||||
serde_json::from_str(ev.json().get())
|
||||
.map(|data| get_global_account_data::Response { account_data: data }.into())
|
||||
.ok()
|
||||
})
|
||||
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))
|
||||
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?;
|
||||
|
||||
let data = serde_json::from_str(event.json().get())
|
||||
.map_err(|_| Error::bad_database("Invalid account data event in db."))?;
|
||||
|
||||
Ok(get_global_account_data::Response { account_data: data }.into())
|
||||
}
|
||||
|
||||
#[put("/_matrix/client/r0/profile/<_user_id>/displayname", data = "<body>")]
|
||||
|
|
Loading…
Reference in a new issue