This repository has been archived by the owner on Aug 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4833c24
commit 34ca5f9
Showing
10 changed files
with
170 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use utoipa::ToSchema; | ||
|
||
use super::IntoDto; | ||
|
||
#[derive(serde::Serialize, ToSchema)] | ||
pub struct HasCheckinResponse { | ||
has_checkin: bool, | ||
} | ||
|
||
impl From<bool> for HasCheckinResponse { | ||
fn from(value: bool) -> Self { | ||
Self { has_checkin: value } | ||
} | ||
} | ||
|
||
impl IntoDto for HasCheckinResponse { | ||
type Target = HasCheckinResponse; | ||
|
||
fn into_dto(self) -> Self::Target { | ||
self | ||
} | ||
} | ||
|
||
#[derive(serde::Serialize, ToSchema)] | ||
pub struct CheckinResponse { | ||
success: bool, | ||
} | ||
|
||
impl From<bool> for CheckinResponse { | ||
fn from(value: bool) -> Self { | ||
Self { success: value } | ||
} | ||
} | ||
|
||
impl IntoDto for CheckinResponse { | ||
type Target = CheckinResponse; | ||
|
||
fn into_dto(self) -> Self::Target { | ||
self | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use axum::{extract::State, response::IntoResponse}; | ||
|
||
use crate::{dto::IntoDto, middleware::auth::Cred}; | ||
|
||
#[derive(Clone)] | ||
pub struct Handler { | ||
service: crate::service::checkin::Service, | ||
} | ||
|
||
impl Handler { | ||
pub fn new(service: crate::service::checkin::Service) -> Self { | ||
Self { service } | ||
} | ||
} | ||
|
||
/// Has checkin | ||
/// | ||
/// Check whether user has checkin or not | ||
#[utoipa::path( | ||
get, | ||
path = "/checkin", | ||
tag = "Check in", | ||
responses( | ||
(status = 200, description = "Success", body = HasCheckinResponse), | ||
(status = 401, description = "Unauthorized"), | ||
), | ||
security( | ||
("api_key" = []), | ||
), | ||
)] | ||
pub async fn has_checkin(State(hdr): State<Handler>, cred: Cred) -> impl IntoResponse { | ||
hdr.service | ||
.has_checkin(cred.user_id) | ||
.await | ||
.map(crate::dto::HasCheckinResponse::from) | ||
.map(IntoDto::into_response) | ||
} | ||
|
||
#[utoipa::path( | ||
post, | ||
path = "/checkin", | ||
tag = "Check in", | ||
responses( | ||
(status = 200, description = "Success", body = CheckinResponse), | ||
(status = 401, description = "Unauthorized"), | ||
(status = 409, description = "Duplicated"), | ||
), | ||
security( | ||
("api_key" = []), | ||
), | ||
)] | ||
pub async fn checkin(State(hdr): State<Handler>, cred: Cred) -> impl IntoResponse { | ||
hdr.service | ||
.checkin(cred.user_id) | ||
.await | ||
.map(crate::dto::CheckinResponse::from) | ||
.map(IntoDto::into_response) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod auth; | ||
pub mod baan; | ||
pub mod checkin; | ||
pub mod ci_user; | ||
pub mod estamp; | ||
pub mod file; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use crate::Result; | ||
use rpkm66_rust_proto::rpkm66::checkin::user::v1::{ | ||
user_service_client::UserServiceClient, AddEventRequest, GetUserEventByEventIdRequest, | ||
}; | ||
use tonic::transport::Channel; | ||
|
||
#[derive(Clone)] | ||
pub struct Service { | ||
client: UserServiceClient<Channel>, | ||
config: crate::config::AppConfig, | ||
} | ||
|
||
impl Service { | ||
pub fn new(client: UserServiceClient<Channel>, config: crate::config::AppConfig) -> Self { | ||
Service { client, config } | ||
} | ||
|
||
pub async fn has_checkin(&self, user_id: String) -> Result<bool> { | ||
Ok(self | ||
.client | ||
.clone() | ||
.get_user_event_by_event_id(GetUserEventByEventIdRequest { | ||
user_id, | ||
event_id: self.get_checkin_event_id(), | ||
}) | ||
.await? | ||
.into_inner() | ||
.user_event | ||
.is_some()) | ||
} | ||
|
||
pub async fn checkin(&self, user_id: String) -> Result<bool> { | ||
Ok(self | ||
.client | ||
.clone() | ||
.add_event(AddEventRequest { | ||
user_id, | ||
token: self.get_checkin_event_id(), | ||
}) | ||
.await? | ||
.into_inner() | ||
.event | ||
.is_some()) | ||
} | ||
|
||
fn get_checkin_event_id(&self) -> String { | ||
format!("checkin-day-{}", self.config.event_day) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod auth; | ||
pub mod baan; | ||
pub mod checkin; | ||
pub mod ci_user; | ||
pub mod estamp; | ||
pub mod file; | ||
|