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

23 lines
636 B
Rust

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};
pub fn fetch_list(rest_ctx: &rest::Context, _url: &Url) -> Response<Cursor<Vec<u8>>> {
use domain::recipe::fetch_list;
let repo = StaticRecipeRepo;
let ctx = rest_ctx.clone().into();
// TODO: catch notfound error
let recipe = fetch_list::execute(&repo, &ctx);
let data = serde_json::to_string(&recipe).unwrap();
Response::from_string(data)
.with_header(Header::from_str("content-type: application/json").unwrap())
}