running so far
parent
31b47e892d
commit
8b121c9e6e
|
@ -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`
|
|
@ -1,12 +1,12 @@
|
||||||
version: "3.7"
|
version: "3.7"
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
container_name: 'rss-postgres'
|
container_name: "rss-postgres"
|
||||||
image: 'postgres:latest'
|
image: "postgres:latest"
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- '5432:5432'
|
- "5432:5432"
|
||||||
environment:
|
environment:
|
||||||
- 'POSTGRES_USER=admin'
|
- "POSTGRES_USER=admin"
|
||||||
- 'POSTGRES_DB=to_do'
|
- "POSTGRES_DB=rss"
|
||||||
- 'POSTGRES_PASSWORD=secret+123'
|
- "POSTGRES_PASSWORD=secret+123"
|
||||||
|
|
|
@ -25,8 +25,32 @@ function apiCall(url, method) {
|
||||||
return xhr;
|
return xhr;
|
||||||
}
|
}
|
||||||
|
|
||||||
function runRenderProcess(params) {
|
function runRenderProcess(data) {
|
||||||
document.getElementById("mainContainer").innerHtml = params;
|
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() {
|
function getArticles() {
|
||||||
|
|
|
@ -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,2 +1,3 @@
|
||||||
|
pub mod articles;
|
||||||
pub mod login;
|
pub mod login;
|
||||||
pub mod new_user;
|
pub mod new_user;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use super::super::feed;
|
|
||||||
use super::super::user::user::User;
|
use super::super::user::user::User;
|
||||||
|
use crate::schema::feed;
|
||||||
use diesel::{Associations, Identifiable, Queryable};
|
use diesel::{Associations, Identifiable, Queryable};
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable, Associations)]
|
#[derive(Queryable, Identifiable, Associations)]
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::error::Error;
|
||||||
|
|
||||||
use rss::Channel;
|
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 content = reqwest::get(feed).await?.bytes().await?;
|
||||||
let channel = Channel::read_from(&content[..])?;
|
let channel = Channel::read_from(&content[..])?;
|
||||||
Ok(channel)
|
Ok(channel)
|
||||||
|
|
|
@ -1,9 +1,31 @@
|
||||||
use actix_web::{HttpRequest, HttpResponse};
|
use crate::{auth::jwt::JwtToken, reader::feeds, json_serialization::articles::Articles};
|
||||||
use crate::auth::jwt::JwtToken;
|
use actix_web::{HttpRequest, Responder};
|
||||||
|
|
||||||
|
use super::structs::{article::{Article, self}, feed::Feed};
|
||||||
|
|
||||||
pub async fn get(req: HttpRequest) -> HttpResponse {
|
pub async fn get(req: HttpRequest) -> impl Responder {
|
||||||
let token: JwtToken = JwtToken::decode_from_request(req).unwrap();
|
// 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())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use actix_web::web;
|
||||||
use crate::views::path::Path;
|
use crate::views::path::Path;
|
||||||
pub mod feeds;
|
pub mod feeds;
|
||||||
mod get;
|
mod get;
|
||||||
|
pub mod structs;
|
||||||
|
|
||||||
pub fn feed_factory(app: &mut web::ServiceConfig) {
|
pub fn feed_factory(app: &mut web::ServiceConfig) {
|
||||||
let base_path: Path = Path {
|
let base_path: Path = Path {
|
||||||
|
|
|
@ -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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use super::article::Article;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct Feed {
|
||||||
|
pub title: String,
|
||||||
|
pub items: Vec<Article>,
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod article;
|
||||||
|
pub mod feed;
|
|
@ -1,4 +1,4 @@
|
||||||
use super::content_loader::{add_component, read_file};
|
use super::content_loader::read_file;
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
|
|
||||||
pub async fn reader() -> HttpResponse {
|
pub async fn reader() -> HttpResponse {
|
||||||
|
|
|
@ -2,6 +2,10 @@ use super::path::Path;
|
||||||
use actix_web::web;
|
use actix_web::web;
|
||||||
mod create;
|
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) {
|
pub fn user_factory(app: &mut web::ServiceConfig) {
|
||||||
let base_path: Path = Path {
|
let base_path: Path = Path {
|
||||||
prefix: String::from("/user"),
|
prefix: String::from("/user"),
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="mainContainer"></div>
|
<div id="mainContainer" class="mainContainer"></div>
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
JAVASCRIPT;
|
JAVASCRIPT;
|
||||||
|
|
Loading…
Reference in New Issue