BLOG-86 refactor: update UserId struct to encapsulate user ID and improve access method
This commit is contained in:
parent
a72a567d6a
commit
eb7a3cf985
@ -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;
|
||||
|
@ -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()))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user