2019-09-05 00:04:57 +09:00
|
|
|
use actix_web::{web, Error, HttpResponse};
|
2019-04-09 14:12:07 -04:00
|
|
|
|
|
|
|
use crate::common::{Part, Product};
|
|
|
|
|
2019-12-07 23:59:24 +06:00
|
|
|
pub async fn get_products(
|
2019-04-14 10:34:41 -07:00
|
|
|
query: web::Query<Option<Part>>,
|
2019-12-07 23:59:24 +06:00
|
|
|
) -> Result<HttpResponse, Error> {
|
|
|
|
Ok(HttpResponse::Ok().finish())
|
2019-04-09 14:12:07 -04:00
|
|
|
}
|
|
|
|
|
2019-12-07 23:59:24 +06:00
|
|
|
pub async fn add_product(
|
2019-04-14 10:34:41 -07:00
|
|
|
new_product: web::Json<Product>,
|
2019-12-07 23:59:24 +06:00
|
|
|
) -> Result<HttpResponse, Error> {
|
|
|
|
Ok(HttpResponse::Ok().finish())
|
2019-04-09 14:12:07 -04:00
|
|
|
}
|
|
|
|
|
2019-12-07 23:59:24 +06:00
|
|
|
pub async fn get_product_detail(id: web::Path<String>) -> Result<HttpResponse, Error> {
|
|
|
|
Ok(HttpResponse::Ok().finish())
|
2019-04-09 14:12:07 -04:00
|
|
|
}
|
|
|
|
|
2019-12-07 23:59:24 +06:00
|
|
|
pub async fn remove_product(id: web::Path<String>) -> Result<HttpResponse, Error> {
|
|
|
|
Ok(HttpResponse::Ok().finish())
|
2019-04-10 14:08:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use crate::appconfig::config_app;
|
2019-04-14 10:34:41 -07:00
|
|
|
use actix_service::Service;
|
|
|
|
use actix_web::{
|
|
|
|
http::{header, StatusCode},
|
2019-12-07 23:59:24 +06:00
|
|
|
test, App,
|
2019-04-14 10:34:41 -07:00
|
|
|
};
|
2019-04-10 14:08:10 -04:00
|
|
|
|
2019-12-07 23:59:24 +06:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_add_product() {
|
|
|
|
let mut app = test::init_service(App::new().configure(config_app)).await;
|
2019-04-10 14:08:10 -04:00
|
|
|
|
|
|
|
let payload = r#"{"id":12345,"product_type":"fancy","name":"test"}"#.as_bytes();
|
|
|
|
|
|
|
|
let req = test::TestRequest::post()
|
2019-04-14 10:34:41 -07:00
|
|
|
.uri("/products")
|
|
|
|
.header(header::CONTENT_TYPE, "application/json")
|
|
|
|
.set_payload(payload)
|
|
|
|
.to_request();
|
2019-04-10 14:08:10 -04:00
|
|
|
|
2019-12-07 23:59:24 +06:00
|
|
|
let resp = app.call(req).await.unwrap();
|
2019-04-10 14:08:10 -04:00
|
|
|
|
|
|
|
assert_eq!(resp.status(), StatusCode::OK);
|
|
|
|
}
|
|
|
|
}
|