running so far

This commit is contained in:
2022-12-27 18:17:24 +01:00
parent 31b47e892d
commit 8b121c9e6e
16 changed files with 134 additions and 18 deletions
+19
View File
@@ -0,0 +1,19 @@
use actix_web::{HttpResponse, Responder};
use reqwest::StatusCode;
use serde::Serialize;
use crate::reader::structs::feed::Feed;
#[derive(Serialize)]
pub struct Articles {
pub feeds: Vec<Feed>,
}
impl Responder for Articles {
type Body = String;
fn respond_to(self, _req: &actix_web::HttpRequest) -> actix_web::HttpResponse<Self::Body> {
let body = serde_json::to_string(&self).unwrap();
HttpResponse::with_body(StatusCode::OK, body)
}
}
+1
View File
@@ -1,2 +1,3 @@
pub mod articles;
pub mod login;
pub mod new_user;
+1 -1
View File
@@ -1,5 +1,5 @@
use super::super::feed;
use super::super::user::user::User;
use crate::schema::feed;
use diesel::{Associations, Identifiable, Queryable};
#[derive(Queryable, Identifiable, Associations)]
-1
View File
@@ -1,2 +1 @@
+1 -1
View File
@@ -2,7 +2,7 @@ use std::error::Error;
use rss::Channel;
pub async fn get_feed(feed: &String) -> Result<Channel, Box<dyn Error>> {
pub async fn get_feed(feed: &str) -> Result<Channel, Box<dyn Error>> {
let content = reqwest::get(feed).await?.bytes().await?;
let channel = Channel::read_from(&content[..])?;
Ok(channel)
+27 -5
View File
@@ -1,9 +1,31 @@
use actix_web::{HttpRequest, HttpResponse};
use crate::auth::jwt::JwtToken;
use crate::{auth::jwt::JwtToken, reader::feeds, json_serialization::articles::Articles};
use actix_web::{HttpRequest, Responder};
use super::structs::{article::{Article, self}, feed::Feed};
pub async fn get(req: HttpRequest) -> HttpResponse {
let token: JwtToken = JwtToken::decode_from_request(req).unwrap();
pub async fn get(req: HttpRequest) -> impl Responder {
// let _token: JwtToken = JwtToken::decode_from_request(req).unwrap();
todo!();
let feed = feeds::get_feed("https://www.heise.de/rss/heise-Rubrik-Wissen.rdf").await.unwrap();
let feed_title: String = feed.title.clone();
let feed_items: Vec<Article> = feed.into_items().into_iter().map(|item| {
let title = item.title.unwrap();
let content = item.content.unwrap();
Article {
title,
content,
}
} ).collect();
let feeds = vec![(Feed {title: feed_title, items: feed_items})];
let articles: Articles = Articles { feeds };
articles.respond_to(&req)
//
//
// HttpResponse::Ok()
// .content_type("text/html; charset=utf-8")
// .body(feed.to_string())
}
+1
View File
@@ -3,6 +3,7 @@ use actix_web::web;
use crate::views::path::Path;
pub mod feeds;
mod get;
pub mod structs;
pub fn feed_factory(app: &mut web::ServiceConfig) {
let base_path: Path = Path {
+16
View File
@@ -0,0 +1,16 @@
use serde::Serialize;
#[derive(Serialize)]
pub struct Article {
pub title: String,
pub content: String,
}
impl Article {
pub fn new(title: &str, content: &str) -> Article {
Article {
title: title.to_string(),
content: content.to_string(),
}
}
}
+9
View File
@@ -0,0 +1,9 @@
use serde::Serialize;
use super::article::Article;
#[derive(Serialize)]
pub struct Feed {
pub title: String,
pub items: Vec<Article>,
}
+2
View File
@@ -0,0 +1,2 @@
pub mod article;
pub mod feed;
+1 -1
View File
@@ -1,4 +1,4 @@
use super::content_loader::{add_component, read_file};
use super::content_loader::read_file;
use actix_web::HttpResponse;
pub async fn reader() -> HttpResponse {
+4
View File
@@ -2,6 +2,10 @@ use super::path::Path;
use actix_web::web;
mod create;
/// curl --header "Content-Type: application/json" \
/// --data '{"name":"Mike","email": "email@local.local", "password":"secret"}' \
/// http://localhost:8001/api/v1/user/create -v
///
pub fn user_factory(app: &mut web::ServiceConfig) {
let base_path: Path = Path {
prefix: String::from("/user"),