37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
|
|
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,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|