api/routes/test/
common.rs

1use db::models::user::Model as UserModel;
2use validator::Validate;
3
4/// Request body used by POST `/api/test/users` to create-or-update a user.
5///
6/// Notes:
7/// - `admin` defaults to `false` if omitted.
8/// - Plaintext `password` is accepted here only because this is a *test* helper.
9///   Do not mirror this in production APIs.
10#[derive(Debug, serde::Deserialize, Validate)]
11pub struct UpsertUserRequest {
12    #[validate(length(min = 1))]
13    pub username: String,
14    #[validate(email)]
15    pub email: String,
16    #[validate(length(min = 1))]
17    pub password: String,
18    pub admin: Option<bool>,
19}
20
21/// Minimal response payload returned from the test endpoints.
22#[derive(Debug, serde::Serialize)]
23pub struct TestUserResponse {
24    pub id: i64,
25    pub username: String,
26    pub email: String,
27    pub admin: bool,
28}
29
30impl From<UserModel> for TestUserResponse {
31    fn from(u: UserModel) -> Self {
32        Self {
33            id: u.id,
34            username: u.username,
35            email: u.email,
36            admin: u.admin,
37        }
38    }
39}