running so far

master
Mathias Rothenhaeusler 2022-12-27 18:17:24 +01:00
parent 31b47e892d
commit 8b121c9e6e
16 changed files with 134 additions and 18 deletions

19
README.md 100644
View File

@ -0,0 +1,19 @@
## RSS-Reader
# Diesel Setup
setup, first step, or when docker been and DB not found.
`diesel setup`
generate table
`diesel migration generate create_to_do_items`
fill up and down
`diesel migration run`
# docker
`docker exec -it 59ff8bad10c0 psql -d rss -U admin`

View File

@ -1,12 +1,12 @@
version: "3.7"
services:
postgres:
container_name: 'rss-postgres'
image: 'postgres:latest'
container_name: "rss-postgres"
image: "postgres:latest"
restart: always
ports:
- '5432:5432'
- "5432:5432"
environment:
- 'POSTGRES_USER=admin'
- 'POSTGRES_DB=to_do'
- 'POSTGRES_PASSWORD=secret+123'
- "POSTGRES_USER=admin"
- "POSTGRES_DB=rss"
- "POSTGRES_PASSWORD=secret+123"

View File

@ -25,8 +25,32 @@ function apiCall(url, method) {
return xhr;
}
function runRenderProcess(params) {
document.getElementById("mainContainer").innerHtml = params;
function runRenderProcess(data) {
params = renderArticle(data["feeds"]);
// document.getElementById("mainContainer").innerHtml = params;
}
function renderArticle(feeds) {
let placeholder = "<div>";
for (i = 0; i < feeds.length; i++) {
let title = feeds[i]["title"];
placeholder += '<div class="itemContainer">' + "<p>" + title + "</p>";
let items = feeds[i]["items"];
for (t = 0; t < items.length; t++) {
placeholder +=
'<div class="article">' +
"<p>" +
items[t].title +
"</p>" +
"<p>" +
items[t].content +
"</p>";
}
placeholder += "</div>" + "</div>";
}
placeholder += "</div>";
document.getElementById("mainContainer").innerHTML = placeholder;
}
function getArticles() {

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)
}
}

View File

@ -1,2 +1,3 @@
pub mod articles;
pub mod login;
pub mod new_user;

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)]

View File

@ -1,2 +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)

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())
}

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 {

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(),
}
}
}

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>,
}

View File

@ -0,0 +1,2 @@
pub mod article;
pub mod feed;

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 {

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"),

View File

@ -18,7 +18,7 @@
</style>
<body>
<div class="mainContainer"></div>
<div id="mainContainer" class="mainContainer"></div>
</body>
<script>
JAVASCRIPT;