Add tags for schedules
This commit is contained in:
parent
f3f3d36eed
commit
75f8afd624
10 changed files with 375 additions and 184 deletions
src/db
|
@ -2,10 +2,17 @@ use diesel::sql_types::Binary;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use crate::db::model_utils::Period;
|
||||
|
||||
use super::schema::schedules;
|
||||
use super::schema::*;
|
||||
use crate::types::EmgauwaUid;
|
||||
|
||||
#[derive(Serialize, Queryable)]
|
||||
#[derive(Debug, Serialize, Identifiable, Queryable)]
|
||||
pub struct Relay {
|
||||
#[serde(skip)]
|
||||
pub id: i32,
|
||||
// TODO
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Identifiable, Queryable)]
|
||||
pub struct Schedule {
|
||||
#[serde(skip)]
|
||||
pub id: i32,
|
||||
|
@ -27,7 +34,7 @@ pub struct NewSchedule<'a> {
|
|||
#[sql_type = "Binary"]
|
||||
pub struct Periods(pub(crate) Vec<Period>);
|
||||
|
||||
#[derive(Serialize, Queryable)]
|
||||
#[derive(Debug, Serialize, Identifiable, Queryable, Clone)]
|
||||
pub struct Tag {
|
||||
pub id: i32,
|
||||
pub tag: String,
|
||||
|
@ -39,9 +46,22 @@ pub struct NewTag<'a> {
|
|||
pub tag: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[table_name = "junction_tag_schedule"]
|
||||
pub struct NewJunctionTagSchedule<'a> {
|
||||
#[derive(Queryable, Associations, Identifiable)]
|
||||
#[belongs_to(Relay)]
|
||||
#[belongs_to(Schedule)]
|
||||
#[belongs_to(Tag)]
|
||||
#[table_name = "junction_tag"]
|
||||
pub struct JunctionTag {
|
||||
pub id: i32,
|
||||
pub tag_id: i32,
|
||||
pub schedule_id: i32,
|
||||
pub relay_id: Option<i32>,
|
||||
pub schedule_id: Option<i32>,
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[table_name = "junction_tag"]
|
||||
pub struct NewJunctionTag {
|
||||
pub tag_id: i32,
|
||||
pub relay_id: Option<i32>,
|
||||
pub schedule_id: Option<i32>,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue