Skip to content

Commit 1cf697a

Browse files
committed
Fixed issue at create_dev rust-lang/rust#64960 (comment)
1 parent b93de21 commit 1cf697a

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

backend/Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ edition = "2018"
66

77
[dependencies]
88
tokio = { version = "0.2", features = ["full"] }
9+
reqwest = { version = "0.10", features = ["json", "blocking"] }
910
warp = "0.2"
1011
serde = { version = "1.0", features = ["derive"] }
1112
serde_json = "1.0"
12-
reqwest = { version = "0.10", features = ["json"] }
1313
diesel = { version = "1.4", features = ["postgres"] }
1414
dotenv = "0.15"

backend/src/bin/main.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ async fn main() {
99
.and_then(backend::controllers::dev::index)
1010
.clone();
1111

12-
// let create_dev = warp::path!("devs")
13-
// .and(warp::post())
14-
// .and(warp::body::json())
15-
// .and_then(backend::controllers::dev::store)
16-
// .clone();
12+
let create_dev = warp::path!("devs")
13+
.and(warp::post())
14+
.and(warp::body::json())
15+
.and_then(backend::controllers::dev::store)
16+
.clone();
1717

1818
let search_dev = warp::path!("search")
1919
.and(warp::get())
2020
.and(warp::query::<SearchQuery>())
2121
.and_then(backend::controllers::search::search)
2222
.clone();
2323

24-
let routes = list_devs.or(search_dev);
24+
let routes = list_devs.or(create_dev).or(search_dev);
2525
warp::serve(routes).run(([127, 0, 0, 1], 3333)).await;
2626
}

backend/src/controllers/dev.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ pub async fn store(input: DevRequest) -> Result<impl warp::Reply, Rejection> {
2727
return Ok(warp::reply::json(&dev));
2828
}
2929

30+
let url = format!("https://api.github.com/users/{}", input.github);
3031
let github_user: GitHubUser = reqwest::Client::new()
31-
.get(format!("https://api.github.com/users/{}", input.github).as_str())
32+
.get(url.as_str())
3233
.header(USER_AGENT, "github.com/leocavalcante/rustancean-radar")
33-
.send().await
34-
.unwrap()
35-
.json::<GitHubUser>().await
36-
.unwrap();
34+
.send().await.unwrap()
35+
.json::<GitHubUser>().await.unwrap();
3736

3837
let techs = crate::utils::csv_to_vec(input.techs.to_string());
3938

backend/src/controllers/search.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::convert::Infallible;
2-
31
use diesel::expression::sql_literal::sql;
42
use diesel::prelude::*;
53
use warp::Rejection;

web/src/components/dev_form.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ impl Component for DevForm {
4242
let request = Request::post("http://localhost:3333/devs")
4343
.header("Content-Type", "application/json")
4444
.body(NewDev {
45-
github: "".to_string(),
46-
techs: "".to_string(),
47-
lat: 0.0,
48-
lng: 0.0,
45+
github: "leocavalcante".to_string(),
46+
techs: "rust".to_string(),
47+
lat: 123.0,
48+
lng: 456.0,
4949
})
5050
.expect("Failed to build request.");
5151

0 commit comments

Comments
 (0)