@@ -13,45 +13,62 @@ pub struct App {
1313 pub main_file : String ,
1414 pub lang : String ,
1515}
16-
17- pub fn fetch_app ( token : String , id : u128 ) -> Result < App , FetchError > {
18- #[ derive( Deserialize ) ]
19- struct AppResponse {
20- pub apps : App ,
21- }
22- let client = reqwest:: blocking:: Client :: new ( ) ;
23- let req = client
24- . get ( crate :: api_url!( format!( "/app/{}" , id) ) )
25- . header ( "api-token" , token) ;
26- match req. send ( ) {
27- Ok ( res) => {
28- if res. status ( ) . is_success ( ) {
29- Ok ( res. json :: < AppResponse > ( ) . unwrap ( ) . apps )
30- } else {
31- Err ( FetchError :: APIReturnedError ( res. status ( ) . as_u16 ( ) ) )
16+ impl App {
17+ pub fn fetch_all ( token : String ) -> Result < Vec < App > , FetchError > {
18+ #[ derive( Deserialize ) ]
19+ struct AppsResponse {
20+ pub apps : Vec < App > ,
21+ }
22+ let client = reqwest:: blocking:: Client :: new ( ) ;
23+ let req = client
24+ . get ( crate :: api_url!( "/app/all" ) )
25+ . header ( "api-token" , token) ;
26+ match req. send ( ) {
27+ Ok ( res) => {
28+ if res. status ( ) . is_success ( ) {
29+ Ok ( res. json :: < AppsResponse > ( ) . unwrap ( ) . apps )
30+ } else {
31+ Err ( FetchError :: APIReturnedError ( res. status ( ) . as_u16 ( ) ) )
32+ }
3233 }
34+ Err ( err) => Err ( FetchError :: FailedToConnect ( err) ) ,
3335 }
34- Err ( err) => Err ( FetchError :: FailedToConnect ( err) ) ,
3536 }
36- }
37-
38- pub fn fetch_apps ( token : String ) -> Result < Vec < App > , FetchError > {
39- #[ derive( Deserialize ) ]
40- struct AppsResponse {
41- pub apps : Vec < App > ,
37+
38+ pub fn fetch ( token : String , id : u128 ) -> Result < App , FetchError > {
39+ #[ derive( Deserialize ) ]
40+ struct AppResponse {
41+ pub apps : App ,
42+ }
43+ let client = reqwest:: blocking:: Client :: new ( ) ;
44+ let req = client
45+ . get ( crate :: api_url!( format!( "/app/{}" , id) ) )
46+ . header ( "api-token" , token) ;
47+ match req. send ( ) {
48+ Ok ( res) => {
49+ if res. status ( ) . is_success ( ) {
50+ Ok ( res. json :: < AppResponse > ( ) . unwrap ( ) . apps )
51+ } else {
52+ Err ( FetchError :: APIReturnedError ( res. status ( ) . as_u16 ( ) ) )
53+ }
54+ }
55+ Err ( err) => Err ( FetchError :: FailedToConnect ( err) ) ,
56+ }
4257 }
43- let client = reqwest:: blocking:: Client :: new ( ) ;
44- let req = client
45- . get ( crate :: api_url!( "/app/all" ) )
46- . header ( "api-token" , token) ;
47- match req. send ( ) {
48- Ok ( res) => {
49- if res. status ( ) . is_success ( ) {
50- Ok ( res. json :: < AppsResponse > ( ) . unwrap ( ) . apps )
51- } else {
52- Err ( FetchError :: APIReturnedError ( res. status ( ) . as_u16 ( ) ) )
58+ pub fn delete ( token : String , id : u128 ) -> Result < ( ) , FetchError > {
59+ let client = reqwest:: blocking:: Client :: new ( ) ;
60+ let req = client
61+ . delete ( crate :: api_url!( format!( "/app/{}/delete" , id) ) )
62+ . header ( "api-token" , token) ;
63+ match req. send ( ) {
64+ Ok ( res) => {
65+ if res. status ( ) . is_success ( ) {
66+ Ok ( ( ) )
67+ } else {
68+ Err ( FetchError :: APIReturnedError ( res. status ( ) . as_u16 ( ) ) )
69+ }
5370 }
71+ Err ( err) => Err ( FetchError :: FailedToConnect ( err) ) ,
5472 }
55- Err ( err) => Err ( FetchError :: FailedToConnect ( err) ) ,
5673 }
5774}
0 commit comments