markdown.rs
2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::models::markdown;
use crate::Pool;
use actix_web::{Error, HttpResponse, web};
use anyhow::Result;
use artshop_common::types::MarkdownJson;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct Patchset {
patch: Option<i32>,
}
pub async fn get_markdowns(pool: web::Data<Pool>)
-> Result<HttpResponse, Error>
{
Ok( web::block(move || markdown::get_markdowns(pool.into_inner()))
. await
. map(|markdowns| HttpResponse::Ok().json(markdowns))
. map_err(|_| HttpResponse::InternalServerError())?
)
}
pub async fn get_markdown( pool: web::Data<Pool>
, name: web::Path<String>
, patch: web::Query<Patchset>
) -> Result<HttpResponse, Error>
{
let pool = pool.into_inner();
let name = name.into_inner();
let patch = patch.into_inner();
Ok( web::block(move || markdown::get_markdown(pool, name.as_str(), patch.patch))
. await
. map(|markdowns| HttpResponse::Ok().json(markdowns))
. map_err(|_| HttpResponse::InternalServerError())?
)
}
pub async fn get_patches( pool: web::Data<Pool>
, name: web::Path<String>
) -> Result<HttpResponse, Error> {
let pool = pool.into_inner();
let name = name.into_inner();
Ok( web::block(move || markdown::get_patches(pool, name.as_str()))
. await
. map(|patches| HttpResponse::Ok().json(patches))
. map_err(|_| HttpResponse::InternalServerError())?
)
}
pub async fn update_markdown( pool: web::Data<Pool>
, name: web::Path<String>
, item: web::Json<MarkdownJson> )
-> Result<HttpResponse, Error>
{
let pool = pool.into_inner();
let name = name.into_inner();
let item = item.into_inner();
Ok(web::block(move || markdown::update_markdown(pool, name, item))
. await
. map(|markdown| HttpResponse::Ok().json(markdown))
. map_err(|_| HttpResponse::InternalServerError())?)
}