Add update and get-by-tag for schedules

This commit is contained in:
Tobias Reisinger 2022-04-03 18:39:31 +02:00
parent 2af71a8d84
commit e157a5d02d
10 changed files with 107 additions and 18 deletions
src/db

View file

@ -3,7 +3,7 @@ use diesel::prelude::*;
use crate::db::errors::DatabaseError;
use crate::db::{get_connection};
use crate::db::{get_connection, schema};
use crate::db::models::*;
use crate::db::schema::tags::dsl::tags;
use crate::db::schema::junction_tag::dsl::junction_tag;
@ -29,6 +29,17 @@ pub fn create_tag(new_tag: &str) -> Result<Tag, DatabaseError> {
Ok(result)
}
pub fn get_tag(target_tag: &str) -> Result<Tag, DatabaseError> {
let connection = get_connection();
let result = tags
.filter(schema::tags::tag.eq(target_tag))
.first::<Tag>(&connection)
.or(Err(DatabaseError::NotFound))?;
Ok(result)
}
pub fn create_junction_tag(target_tag: Tag, target_relay: Option<&Relay>, target_schedule: Option<&Schedule>) -> Result<JunctionTag, DatabaseError> {
let connection = get_connection();