rusty_api/core/
user.rs

1/*!
2 * User module
3 * 
4 * This module defines the many structs related to user management, including
5 * user registration, login, and the user model itself.
6 */
7use serde::{Deserialize, Serialize};
8
9/**
10 * User struct
11 *
12 * This struct represents a user in the system, containing fields for the user's
13 * ID, username, and password hash. The user database can contain more fields, but
14 * these are the essential ones for authentication and identification.
15 */
16#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)]
17pub struct User {
18    pub id: i32,
19    pub username: String,
20    pub password_hash: String,
21}
22
23/**
24 * Input struct for user registration
25 *
26 * This struct is used to deserialize the input data for user registration.
27 * It contains fields for the username and password.
28 */
29#[derive(Debug, Deserialize)]
30pub struct RegisterInput {
31    pub username: String,
32    pub password: String,
33}
34
35/**
36 * Input struct for user login
37 *
38 * This struct is used to deserialize the input data for user login.
39 * It contains fields for the username and password.
40 */
41#[derive(Debug, Deserialize)]
42pub struct LoginInput {
43    pub username: String,
44    pub password: String,
45}
46
47
48/**
49 * Response struct for user registration
50 *
51 * This struct is used to serialize the response data for user registration.
52 * It contains a field for the users token, which is used for authentication.
53 */
54#[derive(Serialize)]
55pub struct LoginResponse {
56    pub token: String,
57}