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

Commit

Permalink
add personality game
Browse files Browse the repository at this point in the history
  • Loading branch information
ImSoZRious committed Aug 3, 2023
1 parent 9550982 commit 337ab32
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 20 deletions.
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use utoipa::{
crate::handler::auth::refresh_token,
crate::handler::file::upload,
crate::handler::user::update,
crate::handler::user::update_personality,
crate::handler::group::find_one,
crate::handler::group::find_by_token,
crate::handler::group::join,
Expand Down Expand Up @@ -59,6 +60,7 @@ use utoipa::{
crate::dto::CheckinResponse,
crate::dto::RedeemItemResponse,
crate::dto::HasRedeemItemResponse,
crate::dto::UpdatePersonality
)),
info(
title = "RPKM66",
Expand Down
9 changes: 8 additions & 1 deletion src/dto/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct User {
is_verify: bool,
baan_id: String,
is_got_ticket: bool,
personality_game: String,
}

into_dto!(
Expand Down Expand Up @@ -52,7 +53,8 @@ into_dto!(
can_select_baan,
is_verify,
baan_id,
is_got_ticket
is_got_ticket,
personality_game
);

#[derive(serde::Deserialize, ToSchema)]
Expand All @@ -74,6 +76,11 @@ pub struct UpdateUser {
want_bottle: bool,
}

#[derive(serde::Deserialize, ToSchema)]
pub struct UpdatePersonality {
pub personality: String,
}

impl UpdateUser {
pub fn into_proto(
self,
Expand Down
33 changes: 32 additions & 1 deletion src/handler/user.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use axum::{extract::State, response::IntoResponse, Json};

use crate::{dto::UpdateUser, middleware::auth::Cred};
use crate::{
dto::{UpdatePersonality, UpdateUser},
middleware::auth::Cred,
};

#[derive(Clone)]
pub struct Handler {
Expand Down Expand Up @@ -40,3 +43,31 @@ pub async fn update(
.await
.map(Json)
}

#[utoipa::path(
patch,
path = "/user/personality",
tag = "User",
request_body = UpdatePersonality,
responses(
(status = 200, description = "Success", body = User),
(status = 400, description = "Bad format"),
(status = 401, description = "Unauthorized"),
),
security(
("api_key" = []),
),
)]
pub async fn update_personality(
State(handler): State<Handler>,
cred: Cred,
Json(updated_personality): Json<UpdatePersonality>,
) -> impl IntoResponse {
let user_id = cred.user_id;

handler
.service
.update_personality(user_id, updated_personality.personality)
.await
.map(Json)
}
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ async fn main() {
let group_svc = service::group::Service::new(group_client.clone());
let ci_staff_svc = service::staff::Service::new(ci_staff_client.clone());
let ci_user_svc = service::ci_user::Service::new(ci_user_client.clone());
let estamp_svc = service::estamp::Service::new(event_client.clone(), ci_user_client.clone());
let estamp_svc = service::estamp::Service::new(
event_client.clone(),
ci_user_client.clone(),
config.app.clone(),
);
let checkin_svc = service::checkin::Service::new(ci_user_client.clone(), config.app.clone());

let auth_hdr = handler::auth::Handler::new(auth_svc.clone(), user_svc.clone());
Expand Down Expand Up @@ -155,6 +159,10 @@ async fn main() {
.route("/auth/refreshToken", post(handler::auth::refresh_token))
.route("/file/upload", post(handler::file::upload))
.route("/user", patch(handler::user::update))
.route(
"/user/personality",
patch(handler::user::update_personality),
)
.route("/group", get(handler::group::find_one))
.route("/group/:token", get(handler::group::find_by_token))
.route("/group/:token", post(handler::group::join))
Expand Down
17 changes: 17 additions & 0 deletions src/service/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,21 @@ impl Service {
.user
.ok_or(Error::InternalServer)
}

pub async fn update_personality(
&self,
user_id: String,
updated_personality: String,
) -> Result<User> {
self.client
.clone()
.update_personality_game(UpdatePersonalityGameRequest {
id: user_id,
personality_game: updated_personality,
})
.await?
.into_inner()
.user
.ok_or(Error::InternalServer)
}
}

0 comments on commit 337ab32

Please sign in to comment.