mirror of
https://github.com/actix/examples
synced 2025-06-29 02:10:36 +02:00
upgrade to 2.0 alpha.3
This commit is contained in:
@ -1,28 +1,19 @@
|
||||
use actix_web::{web, Error, HttpResponse};
|
||||
use futures::{future::ok as fut_ok, Future};
|
||||
|
||||
use crate::common::{Part, Product};
|
||||
|
||||
pub fn get_parts(
|
||||
query: web::Query<Option<Part>>,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||
fut_ok(HttpResponse::Ok().finish())
|
||||
pub async fn get_parts(query: web::Query<Option<Part>>) -> Result<HttpResponse, Error> {
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
pub fn add_part(
|
||||
new_part: web::Json<Product>,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||
fut_ok(HttpResponse::Ok().finish())
|
||||
pub async fn add_part(new_part: web::Json<Product>) -> Result<HttpResponse, Error> {
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
pub fn get_part_detail(
|
||||
id: web::Path<String>,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||
fut_ok(HttpResponse::Ok().finish())
|
||||
pub async fn get_part_detail(id: web::Path<String>) -> Result<HttpResponse, Error> {
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
pub fn remove_part(
|
||||
id: web::Path<String>,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||
fut_ok(HttpResponse::Ok().finish())
|
||||
pub async fn remove_part(id: web::Path<String>) -> Result<HttpResponse, Error> {
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
@ -1,45 +1,39 @@
|
||||
use actix_web::{web, Error, HttpResponse};
|
||||
use futures::{future::ok as fut_ok, Future};
|
||||
|
||||
use crate::common::{Part, Product};
|
||||
|
||||
pub fn get_products(
|
||||
pub async fn get_products(
|
||||
query: web::Query<Option<Part>>,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||
fut_ok(HttpResponse::Ok().finish())
|
||||
) -> Result<HttpResponse, Error> {
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
pub fn add_product(
|
||||
pub async fn add_product(
|
||||
new_product: web::Json<Product>,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||
fut_ok(HttpResponse::Ok().finish())
|
||||
) -> Result<HttpResponse, Error> {
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
pub fn get_product_detail(
|
||||
id: web::Path<String>,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||
fut_ok(HttpResponse::Ok().finish())
|
||||
pub async fn get_product_detail(id: web::Path<String>) -> Result<HttpResponse, Error> {
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
pub fn remove_product(
|
||||
id: web::Path<String>,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||
fut_ok(HttpResponse::Ok().finish())
|
||||
pub async fn remove_product(id: web::Path<String>) -> Result<HttpResponse, Error> {
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::appconfig::config_app;
|
||||
use actix_service::Service;
|
||||
use actix_web::{
|
||||
http::{header, StatusCode},
|
||||
test, web, App, HttpRequest, HttpResponse,
|
||||
test, App,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_add_product() {
|
||||
let mut app = test::init_service(App::new().configure(config_app));
|
||||
#[actix_rt::test]
|
||||
async fn test_add_product() {
|
||||
let mut app = test::init_service(App::new().configure(config_app)).await;
|
||||
|
||||
let payload = r#"{"id":12345,"product_type":"fancy","name":"test"}"#.as_bytes();
|
||||
|
||||
@ -49,7 +43,7 @@ mod tests {
|
||||
.set_payload(payload)
|
||||
.to_request();
|
||||
|
||||
let resp = test::block_on(app.call(req)).unwrap();
|
||||
let resp = app.call(req).await.unwrap();
|
||||
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
}
|
||||
|
Reference in New Issue
Block a user