@@ -154,6 +154,21 @@ pub mod api {
154154 self . api = self . api . bind ( "/application.get" , Method :: POST , handler) ;
155155 self
156156 }
157+
158+ pub fn bind_applications_list < F , T , R > ( mut self , handler : F ) -> Self
159+ where
160+ F : Handler < T , R > ,
161+ T : FromRequest + ' static ,
162+ R : Future <
163+ Output = Result <
164+ super :: paths:: applications_list:: Response ,
165+ super :: paths:: applications_list:: Error ,
166+ > ,
167+ > + ' static ,
168+ {
169+ self . api = self . api . bind ( "/applications.list" , Method :: POST , handler) ;
170+ self
171+ }
157172 }
158173}
159174
@@ -509,6 +524,12 @@ pub mod components {
509524 #[ from]
510525 pub error : ApplicationGetError ,
511526 }
527+
528+ #[ derive( Debug , Serialize ) ]
529+ pub struct ApplicationsListSuccess {
530+ pub installed : Vec < super :: schemas:: Application > ,
531+ pub available : Vec < super :: schemas:: Application > ,
532+ }
512533 }
513534
514535 pub mod request_bodies {
@@ -1222,4 +1243,64 @@ pub mod paths {
12221243 }
12231244 }
12241245 }
1246+
1247+ pub mod applications_list {
1248+ use actix_swagger:: ContentType ;
1249+ use actix_web:: http:: StatusCode ;
1250+ use actix_web:: { HttpRequest , HttpResponse , Responder , ResponseError } ;
1251+ use serde:: Serialize ;
1252+
1253+ use super :: responses;
1254+
1255+ #[ derive( Debug , Serialize ) ]
1256+ #[ serde( untagged) ]
1257+ pub enum Response {
1258+ Ok ( responses:: ApplicationsListSuccess ) ,
1259+ }
1260+
1261+ #[ derive( Debug , Serialize , thiserror:: Error ) ]
1262+ #[ serde( untagged) ]
1263+ pub enum Error {
1264+ #[ error( transparent) ]
1265+ InternalServerError (
1266+ #[ from]
1267+ #[ serde( skip) ]
1268+ eyre:: Report ,
1269+ ) ,
1270+ }
1271+
1272+ impl Responder for Response {
1273+ fn respond_to ( self , _: & HttpRequest ) -> HttpResponse {
1274+ match self {
1275+ Response :: Ok ( r) => HttpResponse :: build ( StatusCode :: OK ) . json ( r) ,
1276+ }
1277+ }
1278+ }
1279+
1280+ impl ResponseError for Error {
1281+ fn status_code ( & self ) -> StatusCode {
1282+ match self {
1283+ Error :: InternalServerError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
1284+ }
1285+ }
1286+
1287+ fn error_response ( & self ) -> HttpResponse {
1288+ let content_type = match self {
1289+ Self :: InternalServerError ( _) => Some ( ContentType :: Json ) ,
1290+ } ;
1291+
1292+ let mut res = & mut HttpResponse :: build ( self . status_code ( ) ) ;
1293+ if let Some ( content_type) = content_type {
1294+ res = res. content_type ( content_type. to_string ( ) ) ;
1295+
1296+ match content_type {
1297+ ContentType :: Json => res. body ( serde_json:: to_string ( self ) . unwrap ( ) ) ,
1298+ ContentType :: FormData => res. body ( serde_plain:: to_string ( self ) . unwrap ( ) ) ,
1299+ }
1300+ } else {
1301+ HttpResponse :: build ( self . status_code ( ) ) . finish ( )
1302+ }
1303+ }
1304+ }
1305+ }
12251306}
0 commit comments