Update
This commit is contained in:
parent
143b795b92
commit
b2c5dc2917
3 changed files with 16 additions and 2 deletions
|
@ -10,6 +10,7 @@ pub struct Schoolyear {
|
|||
pub id: i32,
|
||||
pub untis_id: i32,
|
||||
pub name: String,
|
||||
pub active: bool,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: Option<NaiveDateTime>,
|
||||
}
|
||||
|
@ -19,6 +20,7 @@ pub struct Schoolyear {
|
|||
pub struct NewSchoolyear<'a> {
|
||||
pub untis_id: i32,
|
||||
pub name: &'a str,
|
||||
pub active: bool,
|
||||
}
|
||||
|
||||
#[derive(Identifiable, Queryable, Associations, Debug)]
|
||||
|
|
|
@ -13,6 +13,7 @@ diesel::table! {
|
|||
id -> Integer,
|
||||
untis_id -> Integer,
|
||||
name -> VarChar,
|
||||
active -> Bool,
|
||||
created_at -> Timestamp,
|
||||
updated_at -> Nullable<Timestamp>,
|
||||
}
|
||||
|
|
|
@ -24,15 +24,26 @@ async fn fetch_schoolyears(client: &untis::Client, db_conn: &mut PgConnection) -
|
|||
.map(|y| db::models::NewSchoolyear {
|
||||
untis_id: y.id,
|
||||
name: &y.name,
|
||||
active: false,
|
||||
})
|
||||
.collect::<Vec<db::models::NewSchoolyear>>(),
|
||||
)
|
||||
.execute(db_conn)?;
|
||||
|
||||
Ok(db::schema::schoolyears::table
|
||||
let id = db::schema::schoolyears::table
|
||||
.filter(db::schema::schoolyears::untis_id.eq(client.current_schoolyear().await?.id))
|
||||
.select(db::schema::schoolyears::id)
|
||||
.first(db_conn)?)
|
||||
.first(db_conn)?;
|
||||
|
||||
diesel::update(db::schema::schoolyears::table)
|
||||
.set(db::schema::schoolyears::active.eq(false))
|
||||
.execute(db_conn)?;
|
||||
diesel::update(db::schema::schoolyears::table)
|
||||
.filter(db::schema::schoolyears::id.eq(id))
|
||||
.set(db::schema::schoolyears::active.eq(true))
|
||||
.execute(db_conn)?;
|
||||
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
async fn fetch_current_tenant(
|
||||
|
|
Loading…
Reference in a new issue