Added account member API.

This commit is contained in:
2026-10-11 10:00:04 +02:00
parent 6ee0317186
commit 21f0c17af9
27 changed files with 994 additions and 8 deletions
+88
View File
@@ -0,0 +1,88 @@
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::domain;
#[derive(Debug, Clone, Deserialize)]
pub struct AccountMemberRequest {
pub user_id: Uuid,
}
impl AccountMemberRequest {
pub fn into_domain(
self,
id: Uuid,
account_id: Uuid,
) -> Result<domain::AccountMember, domain::DomainError> {
Ok(domain::AccountMember {
id,
account_id,
user_id: self.user_id,
})
}
}
#[derive(Debug, Clone, Serialize)]
pub struct AccountMemberResponse {
pub id: Uuid,
pub user_id: Uuid,
}
impl From<domain::AccountMember> for AccountMemberResponse {
fn from(member: domain::AccountMember) -> Self {
Self {
id: member.id,
user_id: member.user_id,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
fn request() -> AccountMemberRequest {
AccountMemberRequest {
user_id: Uuid::nil(),
}
}
#[test]
fn serializes_account_member_response() {
let id = Uuid::new_v4();
let member = request().into_domain(id, Uuid::new_v4()).unwrap();
let response = serde_json::to_value(AccountMemberResponse::from(member)).unwrap();
assert_eq!(response["id"], id.to_string());
assert_eq!(response["user_id"], Uuid::nil().to_string());
assert!(response.get("account_id").is_none());
}
#[test]
fn deserializes_account_member_response_as_request() {
let member = request()
.into_domain(Uuid::new_v4(), Uuid::new_v4())
.unwrap();
let response = serde_json::to_value(AccountMemberResponse::from(member)).unwrap();
let request: AccountMemberRequest = serde_json::from_value(response).unwrap();
assert_eq!(request.user_id, Uuid::nil());
}
#[test]
fn converts_between_dto_and_domain() {
let id = Uuid::new_v4();
let account_id = Uuid::new_v4();
let user_id = Uuid::new_v4();
let member = AccountMemberRequest { user_id }
.into_domain(id, account_id)
.unwrap();
assert_eq!(member.id, id);
assert_eq!(member.account_id, account_id);
assert_eq!(member.user_id, user_id);
let response = AccountMemberResponse::from(member);
assert_eq!(response.id, id);
assert_eq!(response.user_id, user_id);
}
}