parent
6822b5eab5
commit
ec35f66a88
|
@ -1,4 +1,4 @@
|
||||||
## RSS-Reader
|
## RSS-Reader [WIP]
|
||||||
|
|
||||||
# Diesel Setup
|
# Diesel Setup
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ version: "3.7"
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
container_name: "rss-postgres"
|
container_name: "rss-postgres"
|
||||||
image: "postgres:latest"
|
image: "postgres:15"
|
||||||
ports:
|
ports:
|
||||||
- "5432:5432"
|
- "5432:5432"
|
||||||
environment:
|
environment:
|
||||||
|
|
|
@ -20,7 +20,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
let app = App::new()
|
let app = App::new()
|
||||||
.wrap_fn(|req, srv| {
|
.wrap_fn(|req, srv| {
|
||||||
let mut passed: bool;
|
let mut passed: bool;
|
||||||
let request_url: String = String::from(req.uri().path().clone());
|
let request_url: String = String::from(req.uri().path());
|
||||||
|
|
||||||
log::info!("Request Url: {}", request_url);
|
log::info!("Request Url: {}", request_url);
|
||||||
if req.path().contains("/article/") {
|
if req.path().contains("/article/") {
|
||||||
|
|
|
@ -22,6 +22,6 @@ pub fn feed_factory(app: &mut web::ServiceConfig) {
|
||||||
);
|
);
|
||||||
app.route(
|
app.route(
|
||||||
&base_path.define(String::from("/sync")),
|
&base_path.define(String::from("/sync")),
|
||||||
web::post().to(sync::sync),
|
actix_web::Route::to(web::post(), sync::sync),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,35 @@
|
||||||
use super::feeds;
|
use super::feeds;
|
||||||
use crate::{database::establish_connection, models::feed::rss_feed::Feed, schema::feed};
|
use crate::{
|
||||||
use actix_web::{HttpRequest, HttpResponse, Responder};
|
database::establish_connection,
|
||||||
|
models::feed::rss_feed::Feed,
|
||||||
|
schema::feed::{self, user_id},
|
||||||
|
};
|
||||||
|
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
pub async fn sync(req: HttpRequest) -> impl Responder {
|
#[derive(Deserialize)]
|
||||||
|
pub struct JsonUser {
|
||||||
|
user_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn sync(_req: HttpRequest, data: web::Json<JsonUser>) -> impl Responder {
|
||||||
let mut connection: diesel::PgConnection = establish_connection();
|
let mut connection: diesel::PgConnection = establish_connection();
|
||||||
|
|
||||||
let feed: Vec<Feed> = feed::table.load::<Feed>(&mut connection).unwrap();
|
let req_user_id = data.user_id.parse::<i32>().unwrap();
|
||||||
|
log::info!("{:?}", req_user_id);
|
||||||
|
|
||||||
|
let feed: Vec<Feed> = feed::table
|
||||||
|
.filter(user_id.eq(req_user_id))
|
||||||
|
.load::<Feed>(&mut connection)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// Create an asynchronous stream of Feed items
|
// Create an asynchronous stream of Feed items
|
||||||
let feed_stream = futures::stream::iter(feed.clone().into_iter()).map(|feed| {
|
let feed_stream = futures::stream::iter(feed.clone().into_iter()).map(|feed| {
|
||||||
// Asynchronously fetch the feed_list for each feed
|
// Asynchronously fetch the feed_list for each feed
|
||||||
async move {
|
async move {
|
||||||
let feed_list = feeds::get_feed(&feed.url).await.unwrap();
|
let _feed_list = feeds::get_feed(&feed.url).await.unwrap();
|
||||||
// Process feed_list here
|
// Process feed_list here
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,10 +3,11 @@ import { ref, onMounted } from 'vue';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
const feeds = ref([]);
|
const feeds = ref([]);
|
||||||
|
const buttonText = 'Sync'
|
||||||
|
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get('feeds', {
|
const response = await axios.get('feeds/get', {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'user-token': localStorage.getItem("user-token")
|
'user-token': localStorage.getItem("user-token")
|
||||||
|
@ -18,6 +19,23 @@ const fetchData = async () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function sync() {
|
||||||
|
try {
|
||||||
|
const repsponse = await axios.post('feeds/sync', {
|
||||||
|
user_id: localStorage.getItem("user-id")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'user-token': localStorage.getItem("user-token")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error sync', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchData();
|
fetchData();
|
||||||
});
|
});
|
||||||
|
@ -26,7 +44,7 @@ onMounted(() => {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<h1>Feeds</h1>
|
<h1>Feeds</h1> <button @click="sync">{{ buttonText }}</button>
|
||||||
<div id='aricle'>
|
<div id='aricle'>
|
||||||
<template v-for="feed in feeds">
|
<template v-for="feed in feeds">
|
||||||
<h2>{{ feed.title }}</h2>
|
<h2>{{ feed.title }}</h2>
|
||||||
|
|
|
@ -28,6 +28,12 @@ export default defineConfig({
|
||||||
secure: false,
|
secure: false,
|
||||||
rewrite: (path) => path.replace(/^\/feeds\/get/, ''),
|
rewrite: (path) => path.replace(/^\/feeds\/get/, ''),
|
||||||
},
|
},
|
||||||
|
'/feeds/sync': {
|
||||||
|
target: 'http://localhost:8001/api/v1/article/sync',
|
||||||
|
changeOrigin: true,
|
||||||
|
secure: false,
|
||||||
|
rewrite: (path) => path.replace(/^\/feeds\/sync/, ''),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
cors: false
|
cors: false
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue