BLOG-86 refactor: update UserId struct to encapsulate user ID and improve access method
All checks were successful
Frontend CI / build (push) Successful in 1m9s
Auto Comment On PR / add_improve_comment (pull_request) Successful in 16s
PR Title Check / pr-title-check (pull_request) Successful in 17s

This commit is contained in:
SquidSpirit 2025-08-01 18:05:47 +08:00
parent a72a567d6a
commit eb7a3cf985
2 changed files with 8 additions and 2 deletions

View File

@ -32,7 +32,13 @@ pub async fn auth_middleware(
next.call(req).await
}
pub struct UserId(pub i32);
pub struct UserId(i32);
impl UserId {
pub fn get(&self) -> i32 {
self.0
}
}
impl FromRequest for UserId {
type Error = Error;

View File

@ -102,5 +102,5 @@ async fn logout_handler(session: Session) -> impl Responder {
}
async fn get_logged_in_user_handler(user_id: UserId) -> impl Responder {
HttpResponse::Ok().body(format!("Logged in user ID: {}", user_id.0))
HttpResponse::Ok().body(format!("Logged in user ID: {}", user_id.get()))
}