45 lines
1.2 KiB
Rust
45 lines
1.2 KiB
Rust
use std::fmt;
|
|
|
|
use chrono::{DateTime, NaiveDateTime, TimeZone, Utc};
|
|
use diesel::prelude::*;
|
|
|
|
use crate::status::ServerStatus;
|
|
|
|
use crate::schema;
|
|
|
|
#[derive(Queryable, Selectable, Debug)]
|
|
#[diesel(table_name = schema::servers)]
|
|
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
|
pub struct Servers {
|
|
pub name: String,
|
|
pub last_login: Option<NaiveDateTime>,
|
|
pub status: ServerStatus,
|
|
pub redirect_ip: Option<String>,
|
|
pub simple_redirect: bool,
|
|
}
|
|
|
|
|
|
#[derive(Insertable)]
|
|
#[diesel(table_name = schema::servers)]
|
|
pub struct CreateServer<'a> {
|
|
pub name: &'a str,
|
|
pub last_login: Option<NaiveDateTime>,
|
|
pub status: ServerStatus,
|
|
pub redirect_ip: Option<&'a str>
|
|
}
|
|
|
|
|
|
impl fmt::Display for Servers {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
let login = match self.last_login {
|
|
Some(date) => {
|
|
let datetime: DateTime<Utc> = Utc.from_utc_datetime(&date);
|
|
|
|
format!("{}", datetime.format("%d-%m-%Y at %H:%M").to_string())
|
|
},
|
|
None => { "never".to_string() }
|
|
};
|
|
write!(f, "name: {} last_login: {} status: {}", self.name, login, self.status)
|
|
}
|
|
}
|