···11+use axum::extract::Path;
22+use axum::Json;
33+44+use crate::api::error::{internal_server_error, respond_internal_server_error};
55+use crate::dto::*;
66+77+#[derive(serde::Serialize, utoipa::ToSchema)]
88+pub struct ListFieldsResponse {
99+ fields: Vec<Field>,
1010+}
1111+1212+#[utoipa::path(
1313+ get,
1414+ path = "/api/v1/players/{player_id}/fields",
1515+ description = "List player fields.",
1616+ tag = "Player",
1717+ responses(
1818+ (status = OK, description = "Successfully listed all fields.", body = ListFieldsResponse),
1919+ ),
2020+ params(
2121+ ("player_id" = AccountIdOrMe, Path, description = "The ID of the player whose fields to list.")
2222+ )
2323+)]
2424+pub async fn list_fields(
2525+ db: axum::Extension<sqlx::PgPool>,
2626+ Path(player_id): Path<AccountIdOrMe>,
2727+) -> axum::response::Result<Json<ListFieldsResponse>> {
2828+ let AccountIdOrMe::AccountId(account_id) = player_id else {
2929+ respond_internal_server_error!("unimplemented");
3030+ };
3131+ let mut conn = db.acquire().await.map_err(internal_server_error)?;
3232+ let fields = sqlx::query_as!(
3333+ Field,
3434+ "SELECT id, name FROM fields WHERE account_id = $1",
3535+ account_id,
3636+ )
3737+ .fetch_all(&mut *conn)
3838+ .await
3939+ .map_err(internal_server_error)?;
4040+ Ok(Json(ListFieldsResponse { fields }))
4141+}
+10
src/api/operations/mod.rs
···11+mod get_banner;
22+mod list_banners;
33+pub use get_banner::*;
44+pub use list_banners::*;
55+66+mod list_card_types;
77+pub use list_card_types::*;
88+99+mod list_fields;
1010+pub use list_fields::*;