push
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
use std::ops::Deref;
|
||||
|
||||
use argon2::{password_hash::SaltString, Argon2, PasswordHasher};
|
||||
use chrono::{Datelike, Local, NaiveDate};
|
||||
use rocket::{
|
||||
async_trait,
|
||||
http::{Cookie, Status},
|
||||
@ -12,6 +13,8 @@ use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use sqlx::{FromRow, SqlitePool};
|
||||
|
||||
use super::{planned_event::PlannedEvent, Day};
|
||||
|
||||
#[derive(FromRow, Debug, Serialize, Deserialize)]
|
||||
pub struct User {
|
||||
pub id: i64,
|
||||
@ -168,6 +171,46 @@ ORDER BY last_access DESC
|
||||
.await
|
||||
.unwrap(); //Okay, because we can only create a User of a valid id
|
||||
}
|
||||
|
||||
pub async fn get_days(&self, db: &SqlitePool) -> Vec<Day> {
|
||||
let mut days = Vec::new();
|
||||
for i in 0..self.amount_days_to_show() {
|
||||
let date = (Local::now() + chrono::Duration::days(i)).date_naive();
|
||||
|
||||
if self.is_guest {
|
||||
days.push(Day::new_guest(db, date, false).await);
|
||||
} else {
|
||||
days.push(Day::new(db, date, false).await);
|
||||
}
|
||||
}
|
||||
|
||||
for date in PlannedEvent::pinned_days(db, self.amount_days_to_show()).await {
|
||||
if self.is_guest {
|
||||
let day = Day::new_guest(db, date, true).await;
|
||||
if !day.planned_events.is_empty() {
|
||||
days.push(day);
|
||||
}
|
||||
} else {
|
||||
days.push(Day::new(db, date, true).await);
|
||||
}
|
||||
}
|
||||
days
|
||||
}
|
||||
|
||||
fn amount_days_to_show(&self) -> i64 {
|
||||
if self.is_cox {
|
||||
let end_of_year = NaiveDate::from_ymd_opt(Local::now().year(), 12, 31).unwrap(); //Ok,
|
||||
//december
|
||||
//has 31
|
||||
//days
|
||||
end_of_year
|
||||
.signed_duration_since(Local::now().date_naive())
|
||||
.num_days()
|
||||
+ 1
|
||||
} else {
|
||||
6
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
Reference in New Issue
Block a user