Spaces:
Sleeping
Sleeping
nishantcoder108 commited on
Commit ·
e04bde8
1
Parent(s): c19a362
func: implement model for items and users, what to stored and what to response
Browse files- src/models.rs +54 -0
src/models.rs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
use chrono::{DateTime, Utc};
|
| 2 |
+
use serde::Serialize;
|
| 3 |
+
use sqlx::FromRow;
|
| 4 |
+
use uuid::Uuid;
|
| 5 |
+
|
| 6 |
+
#[derive(Debug, Clone, FromRow)]
|
| 7 |
+
pub struct UserRecord {
|
| 8 |
+
pub id: Uuid,
|
| 9 |
+
pub first_name: String,
|
| 10 |
+
pub email: String,
|
| 11 |
+
pub username: String,
|
| 12 |
+
pub password_hash: String,
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
#[derive(Debug, Clone, Serialize)]
|
| 16 |
+
#[serde(rename_all = "camelCase")]
|
| 17 |
+
pub struct AuthUser {
|
| 18 |
+
pub id: Uuid,
|
| 19 |
+
pub first_name: String,
|
| 20 |
+
pub email: String,
|
| 21 |
+
pub username: String,
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
impl From<UserRecord> for AuthUser {
|
| 25 |
+
fn from(value: UserRecord) -> Self {
|
| 26 |
+
Self {
|
| 27 |
+
id: value.id,
|
| 28 |
+
first_name: value.first_name,
|
| 29 |
+
email: value.email,
|
| 30 |
+
username: value.username,
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
#[derive(Debug, Clone, FromRow, Serialize)]
|
| 36 |
+
#[serde(rename_all = "camelCase")]
|
| 37 |
+
pub struct ItemRecord {
|
| 38 |
+
pub id: Uuid,
|
| 39 |
+
pub user_id: Uuid,
|
| 40 |
+
pub youtube_url: String,
|
| 41 |
+
pub youtube_video_id: String,
|
| 42 |
+
pub title: String,
|
| 43 |
+
pub label: String,
|
| 44 |
+
pub is_favorite: bool,
|
| 45 |
+
pub created_at: DateTime<Utc>,
|
| 46 |
+
pub updated_at: DateTime<Utc>,
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
#[derive(Debug, Clone, FromRow, Serialize)]
|
| 50 |
+
#[serde(rename_all = "camelCase")]
|
| 51 |
+
pub struct LabelSummary {
|
| 52 |
+
pub label: String,
|
| 53 |
+
pub item_count: i64,
|
| 54 |
+
}
|