@@ -7,8 +7,7 @@ use crate::controllers::krate::CratePath;
77use crate :: models:: { Crate , Follow } ;
88use crate :: schema:: * ;
99use crate :: util:: errors:: { AppResult , crate_not_found} ;
10- use axum_extra:: json;
11- use axum_extra:: response:: ErasedJson ;
10+ use axum:: Json ;
1211use diesel:: prelude:: * ;
1312use diesel_async:: { AsyncPgConnection , RunQueryDsl } ;
1413use http:: request:: Parts ;
@@ -74,20 +73,26 @@ pub async fn unfollow_crate(app: AppState, path: CratePath, req: Parts) -> AppRe
7473 Ok ( OkResponse :: new ( ) )
7574}
7675
76+ #[ derive( Debug , Serialize , utoipa:: ToSchema ) ]
77+ pub struct FollowingResponse {
78+ /// Whether the authenticated user is following the crate.
79+ pub following : bool ,
80+ }
81+
7782/// Check if a crate is followed.
7883#[ utoipa:: path(
7984 get,
8085 path = "/api/v1/crates/{name}/following" ,
8186 params( CratePath ) ,
8287 security( ( "cookie" = [ ] ) ) ,
8388 tag = "crates" ,
84- responses( ( status = 200 , description = "Successful Response" ) ) ,
89+ responses( ( status = 200 , description = "Successful Response" , body = inline ( FollowingResponse ) ) ) ,
8590) ]
8691pub async fn get_following_crate (
8792 app : AppState ,
8893 path : CratePath ,
8994 req : Parts ,
90- ) -> AppResult < ErasedJson > {
95+ ) -> AppResult < Json < FollowingResponse > > {
9196 use diesel:: dsl:: exists;
9297
9398 let mut conn = app. db_read_prefer_primary ( ) . await ?;
@@ -98,8 +103,8 @@ pub async fn get_following_crate(
98103
99104 let follow = follow_target ( & path. name , & mut conn, user_id) . await ?;
100105 let following = diesel:: select ( exists ( follows:: table. find ( follow. id ( ) ) ) )
101- . get_result :: < bool > ( & mut conn)
106+ . get_result ( & mut conn)
102107 . await ?;
103108
104- Ok ( json ! ( { "following" : following } ) )
109+ Ok ( Json ( FollowingResponse { following } ) )
105110}
0 commit comments