1
1
use std:: collections:: HashMap ;
2
2
3
- use jiosaavn:: { services:: module_service:: get_modules, utils:: parse_bool} ;
3
+ use axum:: extract:: Query ;
4
+ use jiosaavn:: handlers:: { modules_handler, ModulesParams } ;
4
5
use serde_json:: json;
5
6
use url:: Url ;
6
- use vercel_runtime:: { run, Body , Error , Request , Response , StatusCode } ;
7
+ use vercel_runtime:: { run, Body , Error , Request , Response } ;
7
8
8
9
#[ tokio:: main]
9
10
async fn main ( ) -> Result < ( ) , Error > {
@@ -17,24 +18,15 @@ pub async fn handler(req: Request) -> Result<Response<Body>, Error> {
17
18
. into_owned ( )
18
19
. collect ( ) ;
19
20
20
- let lang = hash_query
21
- . get ( "lang" )
22
- . unwrap_or ( & "hindi,english" . to_string ( ) )
23
- . to_owned ( ) ;
24
- let raw = hash_query
25
- . get ( "raw" )
26
- . unwrap_or ( & "false" . to_string ( ) )
27
- . to_owned ( ) ;
21
+ let lang = hash_query. get ( "lang" ) . cloned ( ) ;
22
+ let raw = hash_query. get ( "raw" ) . cloned ( ) ;
23
+ let camel = hash_query. get ( "camel" ) . cloned ( ) ;
28
24
29
- let camel = hash_query
30
- . get ( "camel" )
31
- . unwrap_or ( & "false" . to_string ( ) )
32
- . to_owned ( ) ;
33
-
34
- let modules = json ! ( get_modules( lang, parse_bool( raw) , parse_bool( camel) ) . await ) ;
25
+ let params = ModulesParams { lang, raw, camel } ;
26
+ let ( status, payload) = modules_handler ( Query ( params) ) . await ;
35
27
36
28
Ok ( Response :: builder ( )
37
- . status ( StatusCode :: OK )
29
+ . status ( status )
38
30
. header ( "Content-Type" , "application/json" )
39
- . body ( modules . to_string ( ) . into ( ) ) ?)
31
+ . body ( json ! ( payload . 0 ) . to_string ( ) . into ( ) ) ?)
40
32
}
0 commit comments