Added code to update last_login
All checks were successful
Rust Build / Check (pull_request) Successful in 1m0s
Rust Build / Test Suite (pull_request) Successful in 1m18s
Rust Build / Rustfmt (pull_request) Successful in 31s
Rust Build / Clippy (pull_request) Successful in 55s
Rust Build / build (pull_request) Successful in 1m24s
All checks were successful
Rust Build / Check (pull_request) Successful in 1m0s
Rust Build / Test Suite (pull_request) Successful in 1m18s
Rust Build / Rustfmt (pull_request) Successful in 31s
Rust Build / Clippy (pull_request) Successful in 55s
Rust Build / build (pull_request) Successful in 1m24s
This commit is contained in:
@@ -51,13 +51,16 @@ pub mod endpoint {
|
|||||||
let (token_literal, duration) = token_stuff::create_token(&key).unwrap();
|
let (token_literal, duration) = token_stuff::create_token(&key).unwrap();
|
||||||
|
|
||||||
if token_stuff::verify_token(&key, &token_literal) {
|
if token_stuff::verify_token(&key, &token_literal) {
|
||||||
|
let current_time = time::OffsetDateTime::now_utc();
|
||||||
|
let _ = repo::user::update_last_login(&pool, &user, ¤t_time).await;
|
||||||
|
|
||||||
(
|
(
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
Json(response::Response {
|
Json(response::Response {
|
||||||
message: String::from("Successful"),
|
message: String::from("Successful"),
|
||||||
data: vec![icarus_models::login_result::LoginResult {
|
data: vec![icarus_models::login_result::LoginResult {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
username: user.username,
|
username: user.username.clone(),
|
||||||
token: token_literal,
|
token: token_literal,
|
||||||
token_type: String::from(token_stuff::TOKENTYPE),
|
token_type: String::from(token_stuff::TOKENTYPE),
|
||||||
expiration: duration,
|
expiration: duration,
|
||||||
|
@@ -45,19 +45,32 @@ pub mod user {
|
|||||||
pub async fn update_last_login(
|
pub async fn update_last_login(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
user: &icarus_models::user::User,
|
user: &icarus_models::user::User,
|
||||||
|
time: &time::OffsetDateTime,
|
||||||
) -> Result<time::OffsetDateTime, sqlx::Error> {
|
) -> Result<time::OffsetDateTime, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
UPDATE "user" SET last_login = $1 WHERE id = $2
|
UPDATE "user" SET last_login = $1 WHERE id = $2 RETURNING last_login
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.bind(user.last_login)
|
.bind(time)
|
||||||
.bind(user.id)
|
.bind(user.id)
|
||||||
.fetch_optional(pool)
|
.fetch_optional(pool)
|
||||||
.await;
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
eprintln!("Error updating time: {}", e);
|
||||||
|
e
|
||||||
|
});
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(row) => Ok(user.last_login.unwrap()),
|
Ok(row) => match row {
|
||||||
|
Some(r) => {
|
||||||
|
let last_login: time::OffsetDateTime = r
|
||||||
|
.try_get("last_login")
|
||||||
|
.map_err(|_e| sqlx::Error::RowNotFound)?;
|
||||||
|
Ok(last_login)
|
||||||
|
}
|
||||||
|
None => Err(sqlx::Error::RowNotFound),
|
||||||
|
},
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user