|
1 | 1 | use crate::auth::AuthCheck; |
2 | 2 | use axum::Json; |
3 | | -use axum_extra::json; |
4 | | -use axum_extra::response::ErasedJson; |
5 | 3 | use diesel::prelude::*; |
6 | 4 | use diesel_async::RunQueryDsl; |
7 | 5 | use futures_util::FutureExt; |
@@ -69,15 +67,33 @@ pub async fn get_authenticated_user(app: AppState, req: Parts) -> AppResult<Json |
69 | 67 | })) |
70 | 68 | } |
71 | 69 |
|
| 70 | +#[derive(Debug, Serialize, utoipa::ToSchema)] |
| 71 | +pub struct UpdatesResponse { |
| 72 | + /// The list of recent versions of crates that the authenticated user follows. |
| 73 | + pub versions: Vec<EncodableVersion>, |
| 74 | + |
| 75 | + #[schema(inline)] |
| 76 | + pub meta: UpdatesResponseMeta, |
| 77 | +} |
| 78 | + |
| 79 | +#[derive(Debug, Serialize, utoipa::ToSchema)] |
| 80 | +pub struct UpdatesResponseMeta { |
| 81 | + /// Whether there are more versions to be loaded. |
| 82 | + pub more: bool, |
| 83 | +} |
| 84 | + |
72 | 85 | /// List versions of crates that the authenticated user follows. |
73 | 86 | #[utoipa::path( |
74 | 87 | get, |
75 | 88 | path = "/api/v1/me/updates", |
76 | 89 | security(("cookie" = [])), |
77 | 90 | tag = "versions", |
78 | | - responses((status = 200, description = "Successful Response")), |
| 91 | + responses((status = 200, description = "Successful Response", body = inline(UpdatesResponse))), |
79 | 92 | )] |
80 | | -pub async fn get_authenticated_user_updates(app: AppState, req: Parts) -> AppResult<ErasedJson> { |
| 93 | +pub async fn get_authenticated_user_updates( |
| 94 | + app: AppState, |
| 95 | + req: Parts, |
| 96 | +) -> AppResult<Json<UpdatesResponse>> { |
81 | 97 | let mut conn = app.db_read_prefer_primary().await?; |
82 | 98 | let auth = AuthCheck::only_cookie().check(&req, &mut conn).await?; |
83 | 99 |
|
@@ -109,8 +125,8 @@ pub async fn get_authenticated_user_updates(app: AppState, req: Parts) -> AppRes |
109 | 125 | }) |
110 | 126 | .collect::<Vec<_>>(); |
111 | 127 |
|
112 | | - Ok(json!({ |
113 | | - "versions": versions, |
114 | | - "meta": { "more": more }, |
| 128 | + Ok(Json(UpdatesResponse { |
| 129 | + versions, |
| 130 | + meta: UpdatesResponseMeta { more }, |
115 | 131 | })) |
116 | 132 | } |
0 commit comments