Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
staff get user
Browse files Browse the repository at this point in the history
  • Loading branch information
ImSoZRious committed Aug 6, 2023
1 parent 6f8ff90 commit c5de5c3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use utoipa::{
crate::handler::baan::get_user_baan,
crate::handler::staff::is_staff,
crate::handler::staff::checkin_freshy_night,
crate::handler::staff::get_user,
crate::handler::ci_user::is_freshy_night_ticket_redeemed,
crate::handler::estamp::get_all_estamps,
crate::handler::estamp::get_user_estamps,
Expand Down
2 changes: 1 addition & 1 deletion src/dto/auth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use utoipa::{ToSchema, IntoParams};
use utoipa::{IntoParams, ToSchema};

#[derive(serde::Deserialize, ToSchema)]
pub struct VerifyTicket {
Expand Down
42 changes: 39 additions & 3 deletions src/handler/staff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ use axum::{
response::IntoResponse,
};

use crate::{dto::IntoDto, middleware::auth::Cred};
use crate::{dto::IntoDto, error::Error, middleware::auth::Cred};

#[derive(Clone)]
pub struct Handler {
service: crate::service::staff::Service,
user_service: crate::service::user::Service,
}

impl Handler {
pub fn new(service: crate::service::staff::Service) -> Self {
Self { service }
pub fn new(
service: crate::service::staff::Service,
user_service: crate::service::user::Service,
) -> Self {
Self {
service,
user_service,
}
}
}

Expand Down Expand Up @@ -60,3 +67,32 @@ pub async fn checkin_freshy_night(
.map(crate::dto::CheckingFreshyNightResponse::from)
.map(IntoDto::into_response)
}

#[utoipa::path(
get,
path = "/staff/user/{user_id}",
tag = "Staff",
responses(
(status = 200, description = "Success", body = User),
(status = 400, description = "Bad request"),
(status = 401, description = "Unauthorized"),
(status = 401, description = "Not Found"),
),
security(
("api_key" = []),
),
)]
pub async fn get_user(
State(hdr): State<Handler>,
cred: Cred,
Path(user_id): Path<String>,
) -> impl IntoResponse {
if !hdr.service.is_staff(cred.user_id).await? {
return Err(Error::Forbidden);
}

hdr.user_service
.find_one(user_id)
.await
.map(IntoDto::into_response)
}
13 changes: 10 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async fn main() {
let file_hdr = handler::file::Handler::new(file_svc.clone());
let user_hdr = handler::user::Handler::new(user_svc.clone());
let group_hdr = handler::group::Handler::new(group_svc.clone());
let ci_staff_hdr = handler::staff::Handler::new(ci_staff_svc.clone());
let ci_staff_hdr = handler::staff::Handler::new(ci_staff_svc.clone(), user_svc.clone());
let ci_user_hdr = handler::ci_user::Handler::new(ci_user_svc.clone());
let estamp_hdr = handler::estamp::Handler::new(estamp_svc.clone());
let checkin_hdr = handler::checkin::Handler::new(checkin_svc.clone());
Expand Down Expand Up @@ -156,8 +156,14 @@ async fn main() {
.route("/", get(health_check))
.route("/auth/verify", post(handler::auth::verify_ticket))
.route("/auth/me", get(handler::auth::validate))
.route("/auth/google", get(handler::auth::get_google_oauth_redirect_uri))
.route("/auth/google", post(handler::auth::get_token_from_google_oauth_code))
.route(
"/auth/google",
get(handler::auth::get_google_oauth_redirect_uri),
)
.route(
"/auth/google",
post(handler::auth::get_token_from_google_oauth_code),
)
.route("/auth/refreshToken", post(handler::auth::refresh_token))
.route("/file/upload", post(handler::file::upload))
.route("/user", patch(handler::user::update))
Expand All @@ -182,6 +188,7 @@ async fn main() {
"/staff/checkin_freshy_night/:user_id",
post(handler::staff::checkin_freshy_night),
)
.route("/staff/user/:user_id", get(handler::staff::get_user))
.route(
"/freshy_night",
get(handler::ci_user::is_freshy_night_ticket_redeemed),
Expand Down

0 comments on commit c5de5c3

Please sign in to comment.