feat: include links on post /users
This commit is contained in:
parent
92b1326265
commit
74701aa0c5
@ -4,5 +4,6 @@ use std::collections::HashMap;
|
||||
pub struct RepPayload<T> {
|
||||
#[serde(flatten)]
|
||||
pub t: T,
|
||||
#[serde(skip_serializing_if = "HashMap::is_empty")]
|
||||
pub links: HashMap<String, String>,
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use naan::prelude::*;
|
||||
use toad::net::Addrd;
|
||||
use toad::resp::code::{self, BAD_REQUEST, CHANGED, CONTENT, CREATED};
|
||||
@ -7,6 +9,7 @@ use toad_msg::{Code, ContentFormat, MessageOptions, Type};
|
||||
use crate::app::App;
|
||||
use crate::err::{ToE, E};
|
||||
use crate::model::{Actor, UserId, UserInsert, UserPatch, UserRepoError};
|
||||
use crate::rep_payload::RepPayload;
|
||||
use crate::repo::{Del, Insert, Page, Patch, ReadMany, ReadOne};
|
||||
use crate::req_payload::ReqPayload;
|
||||
|
||||
@ -34,11 +37,13 @@ pub fn get_user<A>(app: &A,
|
||||
where A: App
|
||||
{
|
||||
let user = app.user().get(&actor, &id).map_err(UserRepoError::into_e)?;
|
||||
Ok(Some(
|
||||
Message::builder(Type::Ack, CONTENT).token(req.data().token)
|
||||
.content_format(ContentFormat::Json)
|
||||
.payload(serde_json::to_vec(&user).map_err(ToE::to_e)?)
|
||||
.build()))
|
||||
let rep = RepPayload { t: user,
|
||||
links: HashMap::from([("login".into(), "user_sessions/".into())]) };
|
||||
|
||||
Ok(Some(Message::builder(Type::Ack, CONTENT).token(req.data().token)
|
||||
.content_format(ContentFormat::Json)
|
||||
.payload(serde_json::to_vec(&rep).map_err(ToE::to_e)?)
|
||||
.build()))
|
||||
}
|
||||
|
||||
pub fn get_users<A>(app: &A, actor: &Actor, req: Addrd<&Message>) -> Result<Option<Message>, E>
|
||||
|
Loading…
Reference in New Issue
Block a user