[refactor] removed unused api.rs
module to streamline code structure
This commit is contained in:
7
backend-rust/crates/api/Cargo.lock
generated
Normal file
7
backend-rust/crates/api/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "api"
|
||||
version = "0.1.0"
|
28
backend-rust/crates/api/Cargo.toml
Normal file
28
backend-rust/crates/api/Cargo.toml
Normal file
@@ -0,0 +1,28 @@
|
||||
[package]
|
||||
name = "owly-news-api"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
tokio = { workspace = true, features = ["full"] }
|
||||
axum = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde_json = { workspace = true }
|
||||
sqlx = { workspace = true, features = ["runtime-tokio", "tls-native-tls", "sqlite", "macros", "migrate", "chrono", "json"] }
|
||||
dotenv = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
tracing-subscriber = { workspace = true, features = ["env-filter", "json"] }
|
||||
toml = { workspace = true }
|
||||
unicode-segmentation = { workspace = true }
|
||||
sha2 = { workspace = true }
|
||||
hex = { workspace = true }
|
||||
readability = { workspace = true }
|
||||
scraper = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
tokio-test = { workspace = true }
|
||||
axum-test = { workspace = true }
|
3
backend-rust/crates/api/src/api.rs
Normal file
3
backend-rust/crates/api/src/api.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod handlers;
|
||||
pub mod middleware;
|
||||
pub mod routes;
|
41
backend-rust/crates/api/src/api/handlers.rs
Normal file
41
backend-rust/crates/api/src/api/handlers.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use axum::Json;
|
||||
use axum::extract::State;
|
||||
use serde_json::Value;
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
pub async fn get_articles(State(pool): State<SqlitePool>) -> Result<Json<Value>, AppError> {
|
||||
// TODO: Article logic
|
||||
Ok(Json(serde_json::json!({"articles": []})))
|
||||
}
|
||||
|
||||
pub async fn get_summaries(State(pool): State<SqlitePool>) -> Result<Json<Value>, AppError> {
|
||||
// TODO: Summaries logic
|
||||
Ok(Json(serde_json::json!({"summaries": []})))
|
||||
}
|
||||
|
||||
use axum::{
|
||||
http::StatusCode,
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
|
||||
pub struct AppError(anyhow::Error);
|
||||
|
||||
impl IntoResponse for AppError {
|
||||
fn into_response(self) -> Response {
|
||||
let (status, message) = match self.0.downcast_ref::<sqlx::Error>() {
|
||||
Some(_) => (StatusCode::INTERNAL_SERVER_ERROR, "Database error occurred"),
|
||||
None => (StatusCode::INTERNAL_SERVER_ERROR, "An error occurred"),
|
||||
};
|
||||
|
||||
tracing::error!("API Error: {:?}", self.0);
|
||||
(status, message).into_response()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> From<E> for AppError
|
||||
where
|
||||
E: Into<anyhow::Error>, {
|
||||
fn from(err: E) -> Self {
|
||||
Self(err.into())
|
||||
}
|
||||
}
|
0
backend-rust/crates/api/src/api/middleware.rs
Normal file
0
backend-rust/crates/api/src/api/middleware.rs
Normal file
11
backend-rust/crates/api/src/api/routes.rs
Normal file
11
backend-rust/crates/api/src/api/routes.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use axum::Router;
|
||||
use axum::routing::get;
|
||||
use sqlx::SqlitePool;
|
||||
use crate::api::handlers;
|
||||
|
||||
pub fn routes() -> Router<SqlitePool> {
|
||||
Router::new()
|
||||
.route("/articles", get(handlers::get_articles))
|
||||
.route("/summaries", get(handlers::get_summaries))
|
||||
// Add more routes as needed
|
||||
}
|
2
backend-rust/crates/api/src/lib.rs
Normal file
2
backend-rust/crates/api/src/lib.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod api;
|
||||
pub use api::*;
|
Reference in New Issue
Block a user