fish_lib/models/
pond.rs

1use crate::traits::model::Model;
2use chrono::{DateTime, Utc};
3use diesel::{AsChangeset, Insertable, Queryable, Selectable};
4use serde::{Deserialize, Serialize};
5
6#[derive(
7    Debug, Default, Serialize, Deserialize, Clone, PartialEq, Queryable, Selectable, AsChangeset,
8)]
9#[diesel(table_name = crate::schema::fish_ponds)]
10#[diesel(check_for_backend(diesel::pg::Pg))]
11pub struct Pond {
12    /// Primary key of this pond in the database
13    pub id: i64,
14    /// The primary key of the user this pond belongs to
15    pub user_id: i64,
16    /// When the dataset was created
17    pub created_at: DateTime<Utc>,
18    /// When the dataset was last updated
19    pub updated_at: DateTime<Utc>,
20    /// How many specimen fit in this pond
21    pub capacity: i32,
22}
23
24impl Model for Pond {
25    type Table = crate::schema::fish_ponds::table;
26    type PrimaryKeyType = i64;
27    type InsertType = NewPond;
28
29    fn table() -> Self::Table {
30        crate::schema::fish_ponds::table
31    }
32
33    fn id(&self) -> Self::PrimaryKeyType {
34        self.id
35    }
36}
37
38#[derive(Insertable)]
39#[diesel(table_name = crate::schema::fish_ponds)]
40#[diesel(check_for_backend(diesel::pg::Pg))]
41pub struct NewPond {
42    pub user_id: i64,
43    pub capacity: i32,
44}