reorg: separate db::records from insertable models
This commit is contained in:
37
kordophone-db/src/models/db/participant.rs
Normal file
37
kordophone-db/src/models/db/participant.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use diesel::prelude::*;
|
||||
use crate::models::Participant;
|
||||
use crate::schema::conversation_participants;
|
||||
|
||||
#[derive(Queryable, Selectable, AsChangeset, Clone, PartialEq, Debug, Identifiable)]
|
||||
#[diesel(table_name = crate::schema::participants)]
|
||||
pub struct Record {
|
||||
pub id: i32,
|
||||
pub display_name: String
|
||||
}
|
||||
|
||||
#[derive(Identifiable, Selectable, Queryable, Associations, Debug)]
|
||||
#[diesel(belongs_to(super::conversation::Record, foreign_key = conversation_id))]
|
||||
#[diesel(belongs_to(Record, foreign_key = participant_id))]
|
||||
#[diesel(table_name = conversation_participants)]
|
||||
#[diesel(primary_key(conversation_id, participant_id))]
|
||||
pub struct ConversationParticipant {
|
||||
pub conversation_id: String,
|
||||
pub participant_id: i32,
|
||||
}
|
||||
|
||||
impl From<Record> for Participant {
|
||||
fn from(record: Record) -> Self {
|
||||
Participant {
|
||||
display_name: record.display_name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Participant> for Record {
|
||||
fn from(participant: Participant) -> Self {
|
||||
Record {
|
||||
id: 0, // This will be set by the database
|
||||
display_name: participant.display_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user