feat: include links on post /users

This commit is contained in:
Orion Kindel 2023-07-16 15:58:27 -04:00
parent 92b1326265
commit 74701aa0c5
Signed by untrusted user who does not match committer: orion
GPG Key ID: 6D4165AE4C928719
2 changed files with 11 additions and 5 deletions

View File

@ -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>,
}

View File

@ -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>