Add WIP relays to database and api
This commit is contained in:
parent
4e3df272c3
commit
734f8b291c
14 changed files with 387 additions and 88 deletions
emgauwa-lib/src/db
|
@ -7,7 +7,7 @@ use sqlx::Sqlite;
|
|||
|
||||
use crate::db::errors::DatabaseError;
|
||||
use crate::db::model_utils::Period;
|
||||
use crate::db::tag::Tag;
|
||||
use crate::db::Tag;
|
||||
use crate::db::types::ScheduleUid;
|
||||
|
||||
#[derive(Debug, Serialize, Clone)]
|
||||
|
@ -34,7 +34,7 @@ impl Schedule {
|
|||
|
||||
pub async fn get(
|
||||
conn: &mut PoolConnection<Sqlite>,
|
||||
id: &i64,
|
||||
id: i64,
|
||||
) -> Result<Schedule, DatabaseError> {
|
||||
sqlx::query_as!(
|
||||
Schedule,
|
||||
|
@ -127,7 +127,7 @@ impl Schedule {
|
|||
.execute(conn.deref_mut())
|
||||
.await?;
|
||||
|
||||
Schedule::get_by_uid(conn, &self.uid).await
|
||||
Schedule::get(conn, self.id).await
|
||||
}
|
||||
|
||||
pub async fn get_tags(
|
||||
|
@ -149,16 +149,7 @@ impl Schedule {
|
|||
.await?;
|
||||
|
||||
for new_tag in new_tags {
|
||||
let tag: Option<Tag> =
|
||||
sqlx::query_as!(Tag, "SELECT * FROM tags WHERE tag = ?", new_tag)
|
||||
.fetch_optional(conn.deref_mut())
|
||||
.await?;
|
||||
|
||||
let tag = match tag {
|
||||
Some(id) => id,
|
||||
None => Tag::create(conn, new_tag).await?,
|
||||
};
|
||||
|
||||
let tag: Tag = Tag::get_by_tag_or_create(conn, new_tag).await?;
|
||||
tag.link_schedule(conn, self).await?;
|
||||
}
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue