(&self, request: Request<PostPerPage>)
| 37 | #[tonic::async_trait] |
| 38 | impl Blogpost for MyServer { |
| 39 | async fn get_posts(&self, request: Request<PostPerPage>) -> Result<Response<PostList>, Status> { |
| 40 | let conn = &self.connection; |
| 41 | let posts_per_page = request.into_inner().per_page; |
| 42 | |
| 43 | let mut response = PostList { post: Vec::new() }; |
| 44 | |
| 45 | let (posts, _) = Query::find_posts_in_page(conn, 1, posts_per_page) |
| 46 | .await |
| 47 | .expect("Cannot find posts in page"); |
| 48 | |
| 49 | for post in posts { |
| 50 | response.post.push(Post { |
| 51 | id: post.id, |
| 52 | title: post.title, |
| 53 | content: post.text, |
| 54 | }); |
| 55 | } |
| 56 | |
| 57 | Ok(Response::new(response)) |
| 58 | } |
| 59 | |
| 60 | async fn add_post(&self, request: Request<Post>) -> Result<Response<PostId>, Status> { |
| 61 | let conn = &self.connection; |
no test coverage detected