Skip to content

Commit 611c5db

Browse files
committed
controllers::user::other: Use json! macro to simplify JSON serialization code
1 parent 103f23c commit 611c5db

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

src/controllers/user/other.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ pub fn show(req: &mut dyn RequestExt) -> EndpointResult {
1616
.order(id.desc())
1717
.first(&*conn)?;
1818

19-
#[derive(Serialize)]
20-
struct R {
21-
user: EncodablePublicUser,
22-
}
23-
Ok(req.json(&R { user: user.into() }))
19+
Ok(req.json(&json!({ "user": EncodablePublicUser::from(user) })))
2420
}
2521

2622
/// Handles the `GET /users/:user_id/stats` route.
@@ -39,11 +35,5 @@ pub fn stats(req: &mut dyn RequestExt) -> EndpointResult {
3935
.first::<Option<i64>>(&*conn)?
4036
.unwrap_or(0);
4137

42-
#[derive(Serialize)]
43-
struct R {
44-
total_downloads: i64,
45-
}
46-
Ok(req.json(&R {
47-
total_downloads: data,
48-
}))
38+
Ok(req.json(&json!({ "total_downloads": data })))
4939
}

0 commit comments

Comments
 (0)