added feeds

This commit is contained in:
2023-09-17 11:54:37 +02:00
parent 018bbf3918
commit 43e5d473b7
21 changed files with 76 additions and 25 deletions
+6 -2
View File
@@ -10,8 +10,9 @@ pub async fn add(new_feed: web::Json<NewFeedSchema>) -> HttpResponse {
let mut connection = establish_connection();
let title: String = new_feed.title.clone();
let url: String = new_feed.url.clone();
let user_id: i32 = new_feed.user_id;
let new_feed = NewFeed::new(title, url);
let new_feed = NewFeed::new(title, url, user_id);
let insert_result = diesel::insert_into(feed::table)
.values(&new_feed)
@@ -19,6 +20,9 @@ pub async fn add(new_feed: web::Json<NewFeedSchema>) -> HttpResponse {
match insert_result {
Ok(_) => HttpResponse::Created().await.unwrap(),
Err(_) => HttpResponse::Conflict().await.unwrap(),
Err(e) => {
log::error!("{e}");
HttpResponse::Conflict().await.unwrap()
}
}
}
+5
View File
@@ -5,6 +5,7 @@ mod add;
pub mod feeds;
mod get;
pub mod structs;
mod sync;
pub fn feed_factory(app: &mut web::ServiceConfig) {
let base_path: Path = Path {
@@ -19,4 +20,8 @@ pub fn feed_factory(app: &mut web::ServiceConfig) {
&base_path.define(String::from("/add")),
web::post().to(add::add),
);
app.route(
&base_path.define(String::from("/sync")),
web::post().to(sync::sync),
);
}
+6
View File
@@ -7,3 +7,9 @@ pub struct Feed {
pub title: String,
pub items: Vec<Article>,
}
impl Feed {
pub fn new(title: String, items: Vec<Article>) -> Feed {
Feed { title, items }
}
}
+12
View File
@@ -0,0 +1,12 @@
use actix_web::{HttpRequest, Responder};
use diesel::prelude::*;
use crate::{database::establish_connection, schema::feed};
use super::structs::feed::Feed;
pub async fn sync(req: HttpRequest) -> impl Responder {
let mut connection: diesel::PgConnection = establish_connection();
let users = feed::table.load::<Feed>(&mut connection).unwrap();
}