@@ -59,22 +59,29 @@ pub async fn in_game(instance: &str, context: &State<Arc<Context>>) -> Result<()
59
59
Ok ( ( ) )
60
60
}
61
61
62
- #[ rocket:: get( "/get/<template>" ) ]
63
- pub async fn get ( template : & str , context : & State < Arc < Context > > ) -> Result < String , EpsilonError > {
62
+ #[ rocket:: get( "/get/<instance_name>" ) ]
63
+ pub async fn get (
64
+ instance_name : & str ,
65
+ context : & State < Arc < Context > > ,
66
+ ) -> Result < String , EpsilonError > {
67
+ let instance_provider = context. get_instance_provider ( ) ;
68
+ let instance = instance_provider. get_instance ( instance_name) . await ?;
69
+
70
+ Ok ( serde_json:: to_string ( & instance. to_json ( ) . await ?)
71
+ . map_err ( |_| EpsilonError :: ParseJsonError ) ?)
72
+ }
73
+
74
+ #[ rocket:: get( "/get_all" ) ]
75
+ pub async fn get_all ( context : & State < Arc < Context > > ) -> Result < String , EpsilonError > {
64
76
let instance_provider = context. get_instance_provider ( ) ;
65
77
66
78
let instances = instance_provider
67
- . get_instances ( & InstanceType :: Server , Some ( template ) , None )
79
+ . get_instances ( InstanceType :: Server , None , None )
68
80
. await
69
- . map_err ( |_| {
70
- EpsilonError :: ApiServerError ( format ! (
71
- "Failed to get instance from template {}" ,
72
- template
73
- ) )
74
- } ) ?
81
+ . map_err ( |_| EpsilonError :: ApiServerError ( "Failed to get every instance" . to_string ( ) ) ) ?
75
82
. into_iter ( ) ;
76
83
77
- let mut json_array: Vec < InstanceJson > = Vec :: with_capacity ( instances . len ( ) ) ;
84
+ let mut json_array: Vec < InstanceJson > = Vec :: new ( ) ;
78
85
79
86
for instance in instances {
80
87
let json = instance. to_json ( ) . await ?;
@@ -84,29 +91,25 @@ pub async fn get(template: &str, context: &State<Arc<Context>>) -> Result<String
84
91
Ok ( json ! ( { "instances" : json_array } ) . to_string ( ) )
85
92
}
86
93
87
- #[ rocket:: get( "/get_from_name/<instance_name >" ) ]
88
- pub async fn get_from_name (
89
- instance_name : & str ,
94
+ #[ rocket:: get( "/get_from_template/<template >" ) ]
95
+ pub async fn get_from_template (
96
+ template : & str ,
90
97
context : & State < Arc < Context > > ,
91
98
) -> Result < String , EpsilonError > {
92
99
let instance_provider = context. get_instance_provider ( ) ;
93
- let instance = instance_provider. get_instance ( instance_name) . await ?;
94
-
95
- Ok ( serde_json:: to_string ( & instance. to_json ( ) . await ?)
96
- . map_err ( |_| EpsilonError :: ParseJsonError ) ?)
97
- }
98
-
99
- #[ rocket:: get( "/get_all" ) ]
100
- pub async fn get_all ( context : & State < Arc < Context > > ) -> Result < String , EpsilonError > {
101
- let instance_provider = context. get_instance_provider ( ) ;
102
100
103
101
let instances = instance_provider
104
- . get_instances ( & InstanceType :: Server , None , None )
102
+ . get_instances ( InstanceType :: Server , Some ( template ) , None )
105
103
. await
106
- . map_err ( |_| EpsilonError :: ApiServerError ( "Failed to get every instance" . to_string ( ) ) ) ?
104
+ . map_err ( |_| {
105
+ EpsilonError :: ApiServerError ( format ! (
106
+ "Failed to get instance from template {}" ,
107
+ template
108
+ ) )
109
+ } ) ?
107
110
. into_iter ( ) ;
108
111
109
- let mut json_array: Vec < InstanceJson > = Vec :: new ( ) ;
112
+ let mut json_array: Vec < InstanceJson > = Vec :: with_capacity ( instances . len ( ) ) ;
110
113
111
114
for instance in instances {
112
115
let json = instance. to_json ( ) . await ?;
0 commit comments