Skip to content

Commit

Permalink
changed path
Browse files Browse the repository at this point in the history
  • Loading branch information
Pugma committed Sep 28, 2024
1 parent 06cb8fa commit d30a1bd
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ paths:
'400':
description: Invalid input

/words/{userId}:
/words/users/{userId}:
parameters:
- name: userId
in: path
Expand Down
2 changes: 1 addition & 1 deletion server/apis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ server, you can easily generate a server stub.
To see how to make this your own, look here: [README]((https://openapi-generator.tech))

- API version: 1.0.0
- Build date: 2024-09-27T06:09:41.162329509Z[Etc/UTC]
- Build date: 2024-09-28T01:21:59.130324127Z[Etc/UTC]
- Generator version: 7.8.0


Expand Down
10 changes: 5 additions & 5 deletions server/apis/src/apis/words.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum WordsPostResponse {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[must_use]
#[allow(clippy::large_enum_variant)]
pub enum WordsUserIdGetResponse {
pub enum WordsUsersUserIdGetResponse {
/// Successful retrieval
Status200_SuccessfulRetrieval(models::Words),
/// Not found
Expand Down Expand Up @@ -105,14 +105,14 @@ pub trait Words {

/// 指定したユーザーが登録している単語を閲覧.
///
/// WordsUserIdGet - GET /api/words/{userId}
async fn words_user_id_get(
/// WordsUsersUserIdGet - GET /api/words/users/{userId}
async fn words_users_user_id_get(
&self,
method: Method,
host: Host,
cookies: CookieJar,
path_params: models::WordsUserIdGetPathParams,
) -> Result<WordsUserIdGetResponse, String>;
path_params: models::WordsUsersUserIdGetPathParams,
) -> Result<WordsUsersUserIdGetResponse, String>;

/// 単語の削除.
///
Expand Down
2 changes: 1 addition & 1 deletion server/apis/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub struct WordsPostHeaderParams {

#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct WordsUserIdGetPathParams {
pub struct WordsUsersUserIdGetPathParams {
/// traP ID で指定する
pub user_id: String,
}
Expand Down
30 changes: 17 additions & 13 deletions server/apis/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ where
"/api/words",
get(words_get::<I, A>).post(words_post::<I, A>),
)
.route("/api/words/:user_id", get(words_user_id_get::<I, A>))
.route(
"/api/words/:word_id",
delete(words_word_id_delete::<I, A>).put(words_word_id_put::<I, A>),
)
.route("/api/words/me", get(words_me_get::<I, A>))
.route(
"/api/words/users/:user_id",
get(words_users_user_id_get::<I, A>),
)
.with_state(api_impl)
}

Expand Down Expand Up @@ -1077,30 +1080,31 @@ where
}

#[tracing::instrument(skip_all)]
fn words_user_id_get_validation(
path_params: models::WordsUserIdGetPathParams,
) -> std::result::Result<(models::WordsUserIdGetPathParams,), ValidationErrors> {
fn words_users_user_id_get_validation(
path_params: models::WordsUsersUserIdGetPathParams,
) -> std::result::Result<(models::WordsUsersUserIdGetPathParams,), ValidationErrors> {
path_params.validate()?;

Ok((path_params,))
}
/// WordsUserIdGet - GET /api/words/{userId}
/// WordsUsersUserIdGet - GET /api/words/users/{userId}
#[tracing::instrument(skip_all)]
async fn words_user_id_get<I, A>(
async fn words_users_user_id_get<I, A>(
method: Method,
host: Host,
cookies: CookieJar,
Path(path_params): Path<models::WordsUserIdGetPathParams>,
Path(path_params): Path<models::WordsUsersUserIdGetPathParams>,
State(api_impl): State<I>,
) -> Result<Response, StatusCode>
where
I: AsRef<A> + Send + Sync,
A: apis::words::Words,
{
#[allow(clippy::redundant_closure)]
let validation = tokio::task::spawn_blocking(move || words_user_id_get_validation(path_params))
.await
.unwrap();
let validation =
tokio::task::spawn_blocking(move || words_users_user_id_get_validation(path_params))
.await
.unwrap();

let Ok((path_params,)) = validation else {
return Response::builder()
Expand All @@ -1111,14 +1115,14 @@ where

let result = api_impl
.as_ref()
.words_user_id_get(method, host, cookies, path_params)
.words_users_user_id_get(method, host, cookies, path_params)
.await;

let mut response = Response::builder();

let resp = match result {
Ok(rsp) => match rsp {
apis::words::WordsUserIdGetResponse::Status200_SuccessfulRetrieval(body) => {
apis::words::WordsUsersUserIdGetResponse::Status200_SuccessfulRetrieval(body) => {
let mut response = response.status(200);
{
let mut response_headers = response.headers_mut().unwrap();
Expand All @@ -1141,7 +1145,7 @@ where
.unwrap()?;
response.body(Body::from(body_content))
}
apis::words::WordsUserIdGetResponse::Status404_NotFound => {
apis::words::WordsUsersUserIdGetResponse::Status404_NotFound => {
let mut response = response.status(404);
response.body(Body::empty())
}
Expand Down
16 changes: 9 additions & 7 deletions server/app/src/handler/words.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use axum::http::Method;
use axum_extra::extract::CookieJar;
use openapi::{
apis::words::{
Words, WordsGetResponse, WordsMeGetResponse, WordsPostResponse, WordsUserIdGetResponse,
WordsWordIdDeleteResponse, WordsWordIdPutResponse,
Words, WordsGetResponse, WordsMeGetResponse, WordsPostResponse,
WordsUsersUserIdGetResponse, WordsWordIdDeleteResponse, WordsWordIdPutResponse,
},
models,
};
Expand Down Expand Up @@ -67,18 +67,20 @@ impl Words for Handler {
}
}

async fn words_user_id_get(
async fn words_users_user_id_get(
&self,
_method: Method,
_host: Host,
_cookies: CookieJar,
path_params: models::WordsUserIdGetPathParams,
) -> Result<WordsUserIdGetResponse, String> {
path_params: models::WordsUsersUserIdGetPathParams,
) -> Result<WordsUsersUserIdGetResponse, String> {
let result = self.repo.get_by_user(path_params.user_id).await;

match result {
Ok(words) => Ok(WordsUserIdGetResponse::Status200_SuccessfulRetrieval(words)),
Err(_) => Ok(WordsUserIdGetResponse::Status404_NotFound),
Ok(words) => Ok(WordsUsersUserIdGetResponse::Status200_SuccessfulRetrieval(
words,
)),
Err(_) => Ok(WordsUsersUserIdGetResponse::Status404_NotFound),
}
}

Expand Down

0 comments on commit d30a1bd

Please sign in to comment.