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
+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;