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(
|
2020-04-03 16:14:30 +09: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(
|
2020-04-03 16:14:30 +09: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
|
|
|
}
|
|
|
|
|
2020-04-03 16:14:30 +09:00
|
|
|
pub async fn get_product_detail(_id: web::Path<String>) -> Result<HttpResponse, Error> {
|
2019-12-07 23:59:24 +06:00
|
|
|
Ok(HttpResponse::Ok().finish())
|
2019-04-09 14:12:07 -04:00
|
|
|
}
|
|
|
|
|
2020-04-03 16:14:30 +09:00
|
|
|
pub async fn remove_product(_id: web::Path<String>) -> Result<HttpResponse, Error> {
|
2019-12-07 23:59:24 +06:00
|
|
|
Ok(HttpResponse::Ok().finish())
|
2019-04-10 14:08:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use crate::appconfig::config_app;
|
2022-01-30 21:51:32 +00:00
|
|
|
use actix_web::dev::Service;
|
2019-04-14 10:34:41 -07:00
|
|
|
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
|
|
|
|
2022-01-30 21:51:32 +00:00
|
|
|
#[actix_web::test]
|
2019-12-07 23:59:24 +06:00
|
|
|
async fn test_add_product() {
|
2022-01-30 21:51:32 +00:00
|
|
|
let 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")
|
2022-01-30 21:51:32 +00:00
|
|
|
.insert_header((header::CONTENT_TYPE, "application/json"))
|
2019-04-14 10:34:41 -07:00
|
|
|
.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);
|
|
|
|
}
|
|
|
|
}
|