recipes/api/src/rest/ctrl/recipe.rs

23 lines
636 B
Rust
Raw Normal View History

2022-05-14 00:45:31 +03:00
use std::io::Cursor;
use std::str::FromStr;
use tiny_http::{Header, Response};
use crate::repo::recipe::StaticRecipeRepo;
use crate::rest::types::Url;
use crate::{domain, rest};
2022-05-14 00:45:31 +03:00
pub fn fetch_list(rest_ctx: &rest::Context, _url: &Url) -> Response<Cursor<Vec<u8>>> {
use domain::recipe::fetch_list;
2022-05-14 00:45:31 +03:00
let repo = StaticRecipeRepo;
let ctx = rest_ctx.clone().into();
2022-05-14 00:45:31 +03:00
// TODO: catch notfound error
let recipe = fetch_list::execute(&repo, &ctx);
2022-05-14 00:45:31 +03:00
let data = serde_json::to_string(&recipe).unwrap();
Response::from_string(data)
.with_header(Header::from_str("content-type: application/json").unwrap())
}