Skip to content

Commit

Permalink
chore: remove JetBrains format comments
Browse files Browse the repository at this point in the history
  • Loading branch information
litsynp committed Oct 10, 2023
1 parent 37b5ac0 commit a596990
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 34 deletions.
3 changes: 1 addition & 2 deletions src/auth/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ static ACCESS_EXPIRY: usize = 60 * 60 * 100000000;
static REFRESH_EXPIRY: usize = 24 * 60 * 60 * 100000000;

/// Get tokens for login
// @formatter:off
#[utoipa::path(
post,
operation_id = "get_tokens",
Expand All @@ -21,7 +20,7 @@ static REFRESH_EXPIRY: usize = 24 * 60 * 60 * 100000000;
(status = 200, description = "Login succeeded", body = TokenView),
(status = 400, description = "Login failed", body = ApiError)
)
)] // @formatter:on
)]
pub async fn get_tokens(
State(store): State<AuthState>,
Json(request): Json<LoginRequest>,
Expand Down
3 changes: 1 addition & 2 deletions src/common/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ pub struct PaginationParams {
}

#[derive(Serialize, ToSchema)]
// @formatter:off
#[aliases(
PaginatedTodoView = PaginatedView<TodoView>,
)] // @formatter:on
)]
pub struct PaginatedView<T> {
pub page: i32,
pub size: i32,
Expand Down
19 changes: 10 additions & 9 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ use utoipa_rapidoc::RapiDoc;
// use utoipa_redoc::{Redoc, Servable}; // Uncomment to enable Redoc
use utoipa_swagger_ui::SwaggerUi;

use rust_todo_api::{auth::{self, models::JWT_SECRET}, common, common::middlewares::{auth_middleware, AuthState}, todo, user};
use rust_todo_api::{
auth::{self, models::JWT_SECRET},
common,
common::middlewares::{auth_middleware, AuthState},
todo, user,
};

pub fn build_routes(pool: Pool<Postgres>) -> Router {
#[derive(OpenApi)]
// @formatter:off
#[openapi(
paths(
auth::handlers::get_tokens,
Expand Down Expand Up @@ -62,7 +66,6 @@ pub fn build_routes(pool: Pool<Postgres>) -> Router {
(name = "todo", description = "Todo API")
)
)]
// @formatter:on
struct ApiDoc;

struct SecurityAddon;
Expand Down Expand Up @@ -110,13 +113,11 @@ pub fn build_routes(pool: Pool<Postgres>) -> Router {
Router::new()
.route(
"/",
get(user::handlers::find_user_by_email)
.route_layer(middleware::from_fn_with_state(
auth_state.clone(),
auth_middleware,
)),
get(user::handlers::find_user_by_email).route_layer(
middleware::from_fn_with_state(auth_state.clone(), auth_middleware),
),
)
.route("/", post(user::handlers::register_user), ),
.route("/", post(user::handlers::register_user)),
);

Router::new()
Expand Down
28 changes: 11 additions & 17 deletions src/todo/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ use axum::{
Json,
};

use crate::common::pagination::PaginatedView;
use crate::{
common::{errors::ApiError, middlewares::AuthState, pagination::PaginationParams},
todo::{
service as todo_service,
views::{EditTodoRequest, NewTodoRequest, TodoView},
},
};
use crate::common::pagination::PaginatedView;

/// Create todo
// @formatter:off
#[utoipa::path(
post,
operation_id = "create_todo",
Expand All @@ -26,7 +25,7 @@ use crate::common::pagination::PaginatedView;
(status = 500, description = "Todo creation failed", body = ApiError)
),
security(("api_key" = []))
)] // @formatter:on
)]
pub async fn create_todo(
State(state): State<AuthState>,
Json(todo): Json<NewTodoRequest>,
Expand All @@ -40,7 +39,6 @@ pub async fn create_todo(
}

/// Find todos
// @formatter:off
#[utoipa::path(
get,
operation_id = "find_todos",
Expand All @@ -53,7 +51,7 @@ pub async fn create_todo(
(status = 500, description = "Todos not found", body = ApiError)
),
security(("api_key" = []))
)] // @formatter:on
)]
pub async fn find_todos(
State(state): State<AuthState>,
Query(query): Query<PaginationParams>,
Expand All @@ -63,18 +61,16 @@ pub async fn find_todos(
let todos = todo_service::find_todos(state.pool, page, size).await;

match todos {
Ok(todos) => Ok(Json(
PaginatedView {
page,
size,
items: todos.into_iter().map(TodoView::from).collect(),
})),
Ok(todos) => Ok(Json(PaginatedView {
page,
size,
items: todos.into_iter().map(TodoView::from).collect(),
})),
Err(e) => Err(ApiError::new_internal(e.to_string())),
}
}

/// Find todo by id
// @formatter:off
#[utoipa::path(
get,
operation_id = "find_todo_by_id",
Expand All @@ -90,7 +86,7 @@ pub async fn find_todos(
(status = 500, description = "Todo not found", body = ApiError)
),
security(("api_key" = []))
)] // @formatter:on
)]
pub async fn find_todo_by_id(
State(state): State<AuthState>,
Path(id): Path<i32>,
Expand All @@ -110,7 +106,6 @@ pub async fn find_todo_by_id(
}

/// Edit todo by id
// @formatter:off
#[utoipa::path(
put,
operation_id = "edit_todo_by_id",
Expand All @@ -127,7 +122,7 @@ pub async fn find_todo_by_id(
(status = 500, description = "Todo not found", body = ApiError)
),
security(("api_key" = []))
)] // @formatter:on
)]
pub async fn edit_todo_by_id(
State(state): State<AuthState>,
Path(id): Path<i32>,
Expand All @@ -148,7 +143,6 @@ pub async fn edit_todo_by_id(
}

/// Delete todo by id
// @formatter:off
#[utoipa::path(
delete,
operation_id = "delete_todo_by_id",
Expand All @@ -163,7 +157,7 @@ pub async fn edit_todo_by_id(
(status = 500, description = "Todo not found", body = ApiError)
),
security(("api_key" = []))
)] // @formatter:on
)]
pub async fn delete_todo_by_id(
State(state): State<AuthState>,
Path(id): Path<i32>,
Expand Down
6 changes: 2 additions & 4 deletions src/user/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::{
};

/// Register user
// @formatter:off
#[utoipa::path(
post,
operation_id = "register_user",
Expand All @@ -26,7 +25,7 @@ use crate::{
(status = 409, description = "User already exists", body = ApiError),
(status = 500, description = "User creation failed", body = ApiError)
)
)] // @formatter:on
)]
pub async fn register_user(
State(state): State<AuthState>,
Json(request): Json<NewUserRequest>,
Expand Down Expand Up @@ -56,7 +55,6 @@ pub struct FindUserQuery {
}

/// Find user by email
// @formatter:off
#[utoipa::path(
get,
operation_id = "find_user_by_email",
Expand All @@ -69,7 +67,7 @@ pub struct FindUserQuery {
(status = 404, description = "User not found", body = ApiError),
),
security(("api_key" = []))
)] // @formatter:on
)]
pub async fn find_user_by_email(
State(state): State<AuthState>,
Query(query): Query<FindUserQuery>,
Expand Down

0 comments on commit a596990

Please sign in to comment.