forked from Roflin/gamenight
Added Location and location ownership/rights to gamenight.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use diesel::{Insertable, Queryable, PgConnection, RunQueryDsl, insert_into, QueryDsl};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use uuid::Uuid;
|
||||
use crate::schema::gamenight;
|
||||
use chrono::{DateTime, Utc};
|
||||
use diesel::{Insertable, PgConnection, QueryDsl, Queryable, RunQueryDsl, insert_into};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::error::DatabaseError;
|
||||
|
||||
@@ -13,16 +13,22 @@ pub struct Gamenight {
|
||||
pub name: String,
|
||||
pub datetime: DateTime<Utc>,
|
||||
pub owner_id: Uuid,
|
||||
pub location_id: Option<Uuid>,
|
||||
}
|
||||
|
||||
pub fn gamenights(conn: &mut PgConnection) -> Result<Vec::<Gamenight>, DatabaseError> {
|
||||
pub fn gamenights(conn: &mut PgConnection) -> Result<Vec<Gamenight>, DatabaseError> {
|
||||
Ok(gamenight::table.load::<Gamenight>(conn)?)
|
||||
}
|
||||
|
||||
pub fn add_gamenight(conn: &mut PgConnection, gamenight: Gamenight) -> Result<usize, DatabaseError> {
|
||||
Ok(insert_into(gamenight::table).values(&gamenight).execute(conn)?)
|
||||
pub fn add_gamenight(
|
||||
conn: &mut PgConnection,
|
||||
gamenight: Gamenight,
|
||||
) -> Result<usize, DatabaseError> {
|
||||
Ok(insert_into(gamenight::table)
|
||||
.values(&gamenight)
|
||||
.execute(conn)?)
|
||||
}
|
||||
|
||||
pub fn get_gamenight(conn: &mut PgConnection, id: Uuid) -> Result<Gamenight, DatabaseError> {
|
||||
Ok(gamenight::table.find(id).first(conn)?)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user