@@ -13,8 +13,6 @@ use crate::views::EncodableOwner;
1313use crate :: { App , app:: AppState } ;
1414use crate :: { auth:: AuthCheck , email:: Email } ;
1515use axum:: Json ;
16- use axum_extra:: json;
17- use axum_extra:: response:: ErasedJson ;
1816use chrono:: Utc ;
1917use crates_io_github:: { GitHubClient , GitHubError } ;
2018use diesel:: prelude:: * ;
@@ -26,27 +24,37 @@ use oauth2::AccessToken;
2624use secrecy:: { ExposeSecret , SecretString } ;
2725use thiserror:: Error ;
2826
27+ #[ derive( Debug , Serialize , utoipa:: ToSchema ) ]
28+ pub struct UsersResponse {
29+ pub users : Vec < EncodableOwner > ,
30+ }
31+
2932/// List crate owners.
3033#[ utoipa:: path(
3134 get,
3235 path = "/api/v1/crates/{name}/owners" ,
3336 params( CratePath ) ,
3437 tag = "owners" ,
35- responses( ( status = 200 , description = "Successful Response" ) ) ,
38+ responses( ( status = 200 , description = "Successful Response" , body = inline ( UsersResponse ) ) ) ,
3639) ]
37- pub async fn list_owners ( state : AppState , path : CratePath ) -> AppResult < ErasedJson > {
40+ pub async fn list_owners ( state : AppState , path : CratePath ) -> AppResult < Json < UsersResponse > > {
3841 let mut conn = state. db_read ( ) . await ?;
3942
4043 let krate = path. load_crate ( & mut conn) . await ?;
4144
42- let owners = krate
45+ let users = krate
4346 . owners ( & mut conn)
4447 . await ?
4548 . into_iter ( )
4649 . map ( Owner :: into)
4750 . collect :: < Vec < EncodableOwner > > ( ) ;
4851
49- Ok ( json ! ( { "users" : owners } ) )
52+ Ok ( Json ( UsersResponse { users } ) )
53+ }
54+
55+ #[ derive( Debug , Serialize , utoipa:: ToSchema ) ]
56+ pub struct TeamsResponse {
57+ pub teams : Vec < EncodableOwner > ,
5058}
5159
5260/// List team owners of a crate.
@@ -55,19 +63,19 @@ pub async fn list_owners(state: AppState, path: CratePath) -> AppResult<ErasedJs
5563 path = "/api/v1/crates/{name}/owner_team" ,
5664 params( CratePath ) ,
5765 tag = "owners" ,
58- responses( ( status = 200 , description = "Successful Response" ) ) ,
66+ responses( ( status = 200 , description = "Successful Response" , body = inline ( TeamsResponse ) ) ) ,
5967) ]
60- pub async fn get_team_owners ( state : AppState , path : CratePath ) -> AppResult < ErasedJson > {
68+ pub async fn get_team_owners ( state : AppState , path : CratePath ) -> AppResult < Json < TeamsResponse > > {
6169 let mut conn = state. db_read ( ) . await ?;
6270 let krate = path. load_crate ( & mut conn) . await ?;
6371
64- let owners = Team :: owning ( & krate, & mut conn)
72+ let teams = Team :: owning ( & krate, & mut conn)
6573 . await ?
6674 . into_iter ( )
6775 . map ( Owner :: into)
6876 . collect :: < Vec < EncodableOwner > > ( ) ;
6977
70- Ok ( json ! ( { " teams" : owners } ) )
78+ Ok ( Json ( TeamsResponse { teams } ) )
7179}
7280
7381/// List user owners of a crate.
@@ -76,20 +84,30 @@ pub async fn get_team_owners(state: AppState, path: CratePath) -> AppResult<Eras
7684 path = "/api/v1/crates/{name}/owner_user" ,
7785 params( CratePath ) ,
7886 tag = "owners" ,
79- responses( ( status = 200 , description = "Successful Response" ) ) ,
87+ responses( ( status = 200 , description = "Successful Response" , body = inline ( UsersResponse ) ) ) ,
8088) ]
81- pub async fn get_user_owners ( state : AppState , path : CratePath ) -> AppResult < ErasedJson > {
89+ pub async fn get_user_owners ( state : AppState , path : CratePath ) -> AppResult < Json < UsersResponse > > {
8290 let mut conn = state. db_read ( ) . await ?;
8391
8492 let krate = path. load_crate ( & mut conn) . await ?;
8593
86- let owners = User :: owning ( & krate, & mut conn)
94+ let users = User :: owning ( & krate, & mut conn)
8795 . await ?
8896 . into_iter ( )
8997 . map ( Owner :: into)
9098 . collect :: < Vec < EncodableOwner > > ( ) ;
9199
92- Ok ( json ! ( { "users" : owners } ) )
100+ Ok ( Json ( UsersResponse { users } ) )
101+ }
102+
103+ #[ derive( Debug , Serialize , utoipa:: ToSchema ) ]
104+ pub struct ModifyResponse {
105+ /// A message describing the result of the operation.
106+ #[ schema( example = "user ghost has been invited to be an owner of crate serde" ) ]
107+ pub msg : String ,
108+
109+ #[ schema( example = true ) ]
110+ pub ok : bool ,
93111}
94112
95113/// Add crate owners.
@@ -102,14 +120,14 @@ pub async fn get_user_owners(state: AppState, path: CratePath) -> AppResult<Eras
102120 ( "cookie" = [ ] ) ,
103121 ) ,
104122 tag = "owners" ,
105- responses( ( status = 200 , description = "Successful Response" ) ) ,
123+ responses( ( status = 200 , description = "Successful Response" , body = inline ( ModifyResponse ) ) ) ,
106124) ]
107125pub async fn add_owners (
108126 app : AppState ,
109127 path : CratePath ,
110128 parts : Parts ,
111129 Json ( body) : Json < ChangeOwnersRequest > ,
112- ) -> AppResult < ErasedJson > {
130+ ) -> AppResult < Json < ModifyResponse > > {
113131 modify_owners ( app, path. name , parts, body, true ) . await
114132}
115133
@@ -123,14 +141,14 @@ pub async fn add_owners(
123141 ( "cookie" = [ ] ) ,
124142 ) ,
125143 tag = "owners" ,
126- responses( ( status = 200 , description = "Successful Response" ) ) ,
144+ responses( ( status = 200 , description = "Successful Response" , body = inline ( ModifyResponse ) ) ) ,
127145) ]
128146pub async fn remove_owners (
129147 app : AppState ,
130148 path : CratePath ,
131149 parts : Parts ,
132150 Json ( body) : Json < ChangeOwnersRequest > ,
133- ) -> AppResult < ErasedJson > {
151+ ) -> AppResult < Json < ModifyResponse > > {
134152 modify_owners ( app, path. name , parts, body, false ) . await
135153}
136154
@@ -146,7 +164,7 @@ async fn modify_owners(
146164 parts : Parts ,
147165 body : ChangeOwnersRequest ,
148166 add : bool ,
149- ) -> AppResult < ErasedJson > {
167+ ) -> AppResult < Json < ModifyResponse > > {
150168 let logins = body. owners ;
151169
152170 // Bound the number of invites processed per request to limit the cost of
@@ -166,7 +184,7 @@ async fn modify_owners(
166184
167185 let user = auth. user ( ) ;
168186
169- let ( comma_sep_msg , emails) = conn
187+ let ( msg , emails) = conn
170188 . transaction ( |conn| {
171189 let app = app. clone ( ) ;
172190 async move {
@@ -281,7 +299,7 @@ async fn modify_owners(
281299 }
282300 }
283301
284- Ok ( json ! ( { " msg" : comma_sep_msg , "ok" : true } ) )
302+ Ok ( Json ( ModifyResponse { msg, ok : true } ) )
285303}
286304
287305/// Invite `login` as an owner of this crate, returning the created
0 commit comments