Skip to content

Commit

Permalink
utoipa: Rename route handler fns to remove operation_id attributes (#…
Browse files Browse the repository at this point in the history
…10207)

... and unify some of the differing naming patterns.
  • Loading branch information
Turbo87 authored Dec 15, 2024
1 parent 31e2ae1 commit 796a568
Show file tree
Hide file tree
Showing 26 changed files with 157 additions and 156 deletions.
9 changes: 3 additions & 6 deletions src/controllers/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ use http::request::Parts;
#[utoipa::path(
get,
path = "/api/v1/categories",
operation_id = "list_categories",
tag = "categories",
responses((status = 200, description = "Successful Response")),
)]
pub async fn index(app: AppState, req: Parts) -> AppResult<ErasedJson> {
pub async fn list_categories(app: AppState, req: Parts) -> AppResult<ErasedJson> {
// FIXME: There are 69 categories, 47 top level. This isn't going to
// grow by an OoM. We need a limit for /summary, but we don't need
// to paginate this.
Expand Down Expand Up @@ -52,11 +51,10 @@ pub async fn index(app: AppState, req: Parts) -> AppResult<ErasedJson> {
#[utoipa::path(
get,
path = "/api/v1/categories/{category}",
operation_id = "get_category",
tag = "categories",
responses((status = 200, description = "Successful Response")),
)]
pub async fn show(state: AppState, Path(slug): Path<String>) -> AppResult<ErasedJson> {
pub async fn find_category(state: AppState, Path(slug): Path<String>) -> AppResult<ErasedJson> {
let mut conn = state.db_read().await?;

let cat: Category = Category::by_slug(&slug).first(&mut conn).await?;
Expand Down Expand Up @@ -92,11 +90,10 @@ pub async fn show(state: AppState, Path(slug): Path<String>) -> AppResult<Erased
#[utoipa::path(
get,
path = "/api/v1/category_slugs",
operation_id = "list_category_slugs",
tag = "categories",
responses((status = 200, description = "Successful Response")),
)]
pub async fn slugs(state: AppState) -> AppResult<ErasedJson> {
pub async fn list_category_slugs(state: AppState) -> AppResult<ErasedJson> {
let mut conn = state.db_read().await?;

let slugs: Vec<Slug> = categories::table
Expand Down
21 changes: 13 additions & 8 deletions src/controllers/crate_owner_invitation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ use std::collections::{HashMap, HashSet};
#[utoipa::path(
get,
path = "/api/v1/me/crate_owner_invitations",
operation_id = "list_crate_owner_invitations_for_user",
tag = "owners",
responses((status = 200, description = "Successful Response")),
)]
pub async fn list(app: AppState, req: Parts) -> AppResult<ErasedJson> {
pub async fn list_crate_owner_invitations_for_user(
app: AppState,
req: Parts,
) -> AppResult<ErasedJson> {
let mut conn = app.db_read().await?;
let auth = AuthCheck::only_cookie().check(&req, &mut conn).await?;

Expand Down Expand Up @@ -72,11 +74,13 @@ pub async fn list(app: AppState, req: Parts) -> AppResult<ErasedJson> {
#[utoipa::path(
get,
path = "/api/private/crate_owner_invitations",
operation_id = "list_crate_owner_invitations",
tag = "owners",
responses((status = 200, description = "Successful Response")),
)]
pub async fn private_list(app: AppState, req: Parts) -> AppResult<Json<PrivateListResponse>> {
pub async fn list_crate_owner_invitations(
app: AppState,
req: Parts,
) -> AppResult<Json<PrivateListResponse>> {
let mut conn = app.db_read().await?;
let auth = AuthCheck::only_cookie().check(&req, &mut conn).await?;

Expand Down Expand Up @@ -283,11 +287,13 @@ struct OwnerInvitation {
#[utoipa::path(
put,
path = "/api/v1/me/crate_owner_invitations/{crate_id}",
operation_id = "handle_crate_owner_invitation",
tag = "owners",
responses((status = 200, description = "Successful Response")),
)]
pub async fn handle_invite(state: AppState, req: BytesRequest) -> AppResult<ErasedJson> {
pub async fn handle_crate_owner_invitation(
state: AppState,
req: BytesRequest,
) -> AppResult<ErasedJson> {
let (parts, body) = req.0.into_parts();

let crate_invite: OwnerInvitation =
Expand Down Expand Up @@ -318,11 +324,10 @@ pub async fn handle_invite(state: AppState, req: BytesRequest) -> AppResult<Eras
#[utoipa::path(
put,
path = "/api/v1/me/crate_owner_invitations/accept/{token}",
operation_id = "accept_crate_owner_invitation_with_token",
tag = "owners",
responses((status = 200, description = "Successful Response")),
)]
pub async fn handle_invite_with_token(
pub async fn accept_crate_owner_invitation_with_token(
state: AppState,
Path(token): Path<String>,
) -> AppResult<ErasedJson> {
Expand Down
10 changes: 6 additions & 4 deletions src/controllers/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ pub struct IndexQuery {
#[utoipa::path(
get,
path = "/api/v1/keywords",
operation_id = "list_keywords",
tag = "keywords",
responses((status = 200, description = "Successful Response")),
)]
pub async fn index(state: AppState, qp: Query<IndexQuery>, req: Parts) -> AppResult<ErasedJson> {
pub async fn list_keywords(
state: AppState,
qp: Query<IndexQuery>,
req: Parts,
) -> AppResult<ErasedJson> {
use crate::schema::keywords;

let mut query = keywords::table.into_boxed();
Expand Down Expand Up @@ -53,11 +56,10 @@ pub async fn index(state: AppState, qp: Query<IndexQuery>, req: Parts) -> AppRes
#[utoipa::path(
get,
path = "/api/v1/keywords/{keyword}",
operation_id = "get_keyword",
tag = "keywords",
responses((status = 200, description = "Successful Response")),
)]
pub async fn show(Path(name): Path<String>, state: AppState) -> AppResult<ErasedJson> {
pub async fn find_keyword(Path(name): Path<String>, state: AppState) -> AppResult<ErasedJson> {
let mut conn = state.db_read().await?;
let kw = Keyword::find_by_keyword(&mut conn, &name).await?;

Expand Down
3 changes: 1 addition & 2 deletions src/controllers/krate/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ const AVAILABLE_AFTER: TimeDelta = TimeDelta::hours(24);
#[utoipa::path(
delete,
path = "/api/v1/crates/{name}",
operation_id = "delete_crate",
tag = "crates",
responses((status = 200, description = "Successful Response")),
)]
pub async fn delete(
pub async fn delete_crate(
Path(name): Path<String>,
parts: Parts,
app: AppState,
Expand Down
6 changes: 4 additions & 2 deletions src/controllers/krate/downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ use std::cmp;
#[utoipa::path(
get,
path = "/api/v1/crates/{name}/downloads",
operation_id = "get_crate_downloads",
tag = "crates",
responses((status = 200, description = "Successful Response")),
)]

pub async fn downloads(state: AppState, Path(crate_name): Path<String>) -> AppResult<ErasedJson> {
pub async fn get_crate_downloads(
state: AppState,
Path(crate_name): Path<String>,
) -> AppResult<ErasedJson> {
let mut conn = state.db_read().await?;

use diesel::dsl::*;
Expand Down
9 changes: 3 additions & 6 deletions src/controllers/krate/follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ async fn follow_target(
#[utoipa::path(
put,
path = "/api/v1/crates/{name}/follow",
operation_id = "follow_crate",
tag = "crates",
responses((status = 200, description = "Successful Response")),
)]
pub async fn follow(
pub async fn follow_crate(
app: AppState,
Path(crate_name): Path<String>,
req: Parts,
Expand All @@ -58,11 +57,10 @@ pub async fn follow(
#[utoipa::path(
delete,
path = "/api/v1/crates/{name}/follow",
operation_id = "unfollow_crate",
tag = "crates",
responses((status = 200, description = "Successful Response")),
)]
pub async fn unfollow(
pub async fn unfollow_crate(
app: AppState,
Path(crate_name): Path<String>,
req: Parts,
Expand All @@ -79,11 +77,10 @@ pub async fn unfollow(
#[utoipa::path(
get,
path = "/api/v1/crates/{name}/following",
operation_id = "get_following_crate",
tag = "crates",
responses((status = 200, description = "Successful Response")),
)]
pub async fn following(
pub async fn get_following_crate(
app: AppState,
Path(crate_name): Path<String>,
req: Parts,
Expand Down
18 changes: 9 additions & 9 deletions src/controllers/krate/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,25 @@ use std::str::FromStr;
#[utoipa::path(
get,
path = "/api/v1/crates/new",
operation_id = "crates_show_new",
tag = "crates",
responses((status = 200, description = "Successful Response")),
)]
pub async fn show_new(app: AppState, req: Parts) -> AppResult<ErasedJson> {
show(app, Path("new".to_string()), req).await
pub async fn find_new_crate(app: AppState, req: Parts) -> AppResult<ErasedJson> {
find_crate(app, Path("new".to_string()), req).await
}

/// Get crate metadata.
#[utoipa::path(
get,
path = "/api/v1/crates/{name}",
operation_id = "get_crate",
tag = "crates",
responses((status = 200, description = "Successful Response")),
)]
pub async fn show(app: AppState, Path(name): Path<String>, req: Parts) -> AppResult<ErasedJson> {
pub async fn find_crate(
app: AppState,
Path(name): Path<String>,
req: Parts,
) -> AppResult<ErasedJson> {
let mut conn = app.db_read().await?;

let include = req
Expand Down Expand Up @@ -248,11 +250,10 @@ impl FromStr for ShowIncludeMode {
#[utoipa::path(
get,
path = "/api/v1/crates/{name}/{version}/readme",
operation_id = "get_version_readme",
tag = "versions",
responses((status = 200, description = "Successful Response")),
)]
pub async fn readme(
pub async fn get_version_readme(
app: AppState,
Path((crate_name, version)): Path<(String, String)>,
req: Parts,
Expand All @@ -269,11 +270,10 @@ pub async fn readme(
#[utoipa::path(
get,
path = "/api/v1/crates/{name}/reverse_dependencies",
operation_id = "list_reverse_dependencies",
tag = "crates",
responses((status = 200, description = "Successful Response")),
)]
pub async fn reverse_dependencies(
pub async fn list_reverse_dependencies(
app: AppState,
Path(name): Path<String>,
req: Parts,
Expand Down
17 changes: 9 additions & 8 deletions src/controllers/krate/owners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ use secrecy::{ExposeSecret, SecretString};
#[utoipa::path(
get,
path = "/api/v1/crates/{name}/owners",
operation_id = "list_owners",
tag = "owners",
responses((status = 200, description = "Successful Response")),
)]
pub async fn owners(state: AppState, Path(crate_name): Path<String>) -> AppResult<ErasedJson> {
pub async fn list_owners(state: AppState, Path(crate_name): Path<String>) -> AppResult<ErasedJson> {
let mut conn = state.db_read().await?;

let krate: Crate = Crate::by_name(&crate_name)
Expand All @@ -48,11 +47,13 @@ pub async fn owners(state: AppState, Path(crate_name): Path<String>) -> AppResul
#[utoipa::path(
get,
path = "/api/v1/crates/{name}/owner_team",
operation_id = "get_team_owners",
tag = "owners",
responses((status = 200, description = "Successful Response")),
)]
pub async fn owner_team(state: AppState, Path(crate_name): Path<String>) -> AppResult<ErasedJson> {
pub async fn get_team_owners(
state: AppState,
Path(crate_name): Path<String>,
) -> AppResult<ErasedJson> {
let mut conn = state.db_read().await?;
let krate: Crate = Crate::by_name(&crate_name)
.first(&mut conn)
Expand All @@ -73,11 +74,13 @@ pub async fn owner_team(state: AppState, Path(crate_name): Path<String>) -> AppR
#[utoipa::path(
get,
path = "/api/v1/crates/{name}/owner_user",
operation_id = "get_user_owners",
tag = "owners",
responses((status = 200, description = "Successful Response")),
)]
pub async fn owner_user(state: AppState, Path(crate_name): Path<String>) -> AppResult<ErasedJson> {
pub async fn get_user_owners(
state: AppState,
Path(crate_name): Path<String>,
) -> AppResult<ErasedJson> {
let mut conn = state.db_read().await?;

let krate: Crate = Crate::by_name(&crate_name)
Expand All @@ -99,7 +102,6 @@ pub async fn owner_user(state: AppState, Path(crate_name): Path<String>) -> AppR
#[utoipa::path(
put,
path = "/api/v1/crates/{name}/owners",
operation_id = "add_owners",
tag = "owners",
responses((status = 200, description = "Successful Response")),
)]
Expand All @@ -116,7 +118,6 @@ pub async fn add_owners(
#[utoipa::path(
delete,
path = "/api/v1/crates/{name}/owners",
operation_id = "delete_owners",
tag = "owners",
responses((status = 200, description = "Successful Response")),
)]
Expand Down
1 change: 0 additions & 1 deletion src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const MAX_DESCRIPTION_LENGTH: usize = 1000;
#[utoipa::path(
put,
path = "/api/v1/crates/new",
operation_id = "publish",
tag = "publish",
responses((status = 200, description = "Successful Response")),
)]
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/krate/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ use crate::util::RequestUtils;
#[utoipa::path(
get,
path = "/api/v1/crates",
operation_id = "crates_list",
tag = "crates",
responses((status = 200, description = "Successful Response")),
)]
pub async fn search(app: AppState, req: Parts) -> AppResult<ErasedJson> {
pub async fn list_crates(app: AppState, req: Parts) -> AppResult<ErasedJson> {
// Notes:
// The different use cases this function covers is handled through passing
// in parameters in the GET request.
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/krate/versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ use crate::views::EncodableVersion;
#[utoipa::path(
get,
path = "/api/v1/crates/{name}/versions",
operation_id = "list_crate_versions",
tag = "versions",
responses((status = 200, description = "Successful Response")),
)]
pub async fn versions(
pub async fn list_versions(
state: AppState,
Path(crate_name): Path<String>,
req: Parts,
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/site_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ use axum_extra::json;
#[utoipa::path(
get,
path = "/api/v1/site_metadata",
operation_id = "get_site_metadata",
tag = "other",
responses((status = 200, description = "Successful Response")),
)]
pub async fn show_deployed_sha(state: AppState) -> impl IntoResponse {
pub async fn get_site_metadata(state: AppState) -> impl IntoResponse {
let read_only = state.config.db.are_all_read_only();

let deployed_sha =
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ use std::future::Future;
#[utoipa::path(
get,
path = "/api/v1/summary",
operation_id = "get_summary",
tag = "other",
responses((status = 200, description = "Successful Response")),
)]
pub async fn summary(state: AppState) -> AppResult<ErasedJson> {
pub async fn get_summary(state: AppState) -> AppResult<ErasedJson> {
let mut conn = state.db_read().await?;

let config = &state.config;
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/team.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ use diesel_async::RunQueryDsl;
#[utoipa::path(
get,
path = "/api/v1/teams/{team}",
operation_id = "get_team",
tag = "teams",
responses((status = 200, description = "Successful Response")),
)]
pub async fn show_team(state: AppState, Path(name): Path<String>) -> AppResult<ErasedJson> {
pub async fn find_team(state: AppState, Path(name): Path<String>) -> AppResult<ErasedJson> {
use crate::schema::teams::dsl::{login, teams};

let mut conn = state.db_read().await?;
Expand Down
Loading

0 comments on commit 796a568

Please sign in to comment.