Skip to content

Commit 2a5b022

Browse files
feat(user page): Recently published
1 parent b65bdf2 commit 2a5b022

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

api/src/api/users.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ use crate::util::ApiResult;
1313
use crate::util::RequestIdExt;
1414

1515
use super::ApiError;
16+
use super::ApiPackage;
1617
use super::ApiScope;
1718
use super::ApiUser;
1819

1920
pub fn users_router() -> Router<Body, ApiError> {
2021
Router::builder()
2122
.get("/:id", util::json(get_handler))
2223
.get("/:id/scopes", util::json(get_scopes_handler))
24+
.get("/:id/packages", util::json(get_packages_handler))
2325
.build()
2426
.unwrap()
2527
}
@@ -54,3 +56,20 @@ pub async fn get_scopes_handler(
5456

5557
Ok(scopes.into_iter().map(ApiScope::from).collect())
5658
}
59+
60+
#[instrument(name = "GET /api/users/:id/packages", skip(req), err, fields(id))]
61+
pub async fn get_packages_handler(
62+
req: Request<Body>,
63+
) -> ApiResult<Vec<ApiPackage>> {
64+
let id = req.param_uuid("id")?;
65+
Span::current().record("id", field::display(id));
66+
67+
let db = req.data::<Database>().unwrap();
68+
db.get_user_public(id)
69+
.await?
70+
.ok_or(ApiError::UserNotFound)?;
71+
72+
let packages = db.get_recent_packages_by_user(&id).await?;
73+
74+
Ok(packages.into_iter().map(ApiPackage::from).collect())
75+
}

0 commit comments

Comments
 (0)