Skip to content

Commit 263c2d1

Browse files
committed
controllers::krate::follow: Use json! macro to simplify JSON serialization code
1 parent 7c843f2 commit 263c2d1

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/controllers/krate/follow.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,8 @@ pub fn following(req: &mut dyn RequestExt) -> EndpointResult {
4949
let user_id = req.authenticate()?.forbid_api_token_auth()?.user_id();
5050
let conn = req.db_read_only()?;
5151
let follow = follow_target(req, &conn, user_id)?;
52-
let following = diesel::select(exists(follows::table.find(follow.id()))).get_result(&*conn)?;
52+
let following =
53+
diesel::select(exists(follows::table.find(follow.id()))).get_result::<bool>(&*conn)?;
5354

54-
#[derive(Serialize)]
55-
struct R {
56-
following: bool,
57-
}
58-
Ok(req.json(&R { following }))
55+
Ok(req.json(&json!({ "following": following })))
5956
}

0 commit comments

Comments
 (0)