Skip to content

Commit

Permalink
impl create-user for web
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Dec 30, 2020
1 parent 54da24d commit b61df43
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/web/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,32 @@ async fn create_bookmark(
Ok("".to_string())
}

#[derive(Debug, Deserialize)]
struct CreateUserRequestBody {
secret: String,
}

async fn create_user(
app: web::Data<crate::app::App>,
json: web::Json<CreateUserRequestBody>,
) -> actix_web::Result<String> {
let secret = json
.secret
.parse()
.map_err(|_| actix_web::HttpResponse::BadRequest())?;
app.create_user_use_case()
.create_user(secret)
.map_err(|_| actix_web::HttpResponse::InternalServerError())?;
Ok("".to_string())
}

async fn main(app: crate::app::App) -> Result<()> {
let app_data = web::Data::new(app);
HttpServer::new(move || {
App::new()
.app_data(app_data.clone())
.route("/bookmarks", web::post().to(create_bookmark))
.route("/users", web::post().to(create_user))
})
.bind("127.0.0.1:8080")?
.run()
Expand Down

0 comments on commit b61df43

Please sign in to comment.