Skip to content

Commit 7fddf58

Browse files
committed
add refactoring
1 parent 541edb5 commit 7fddf58

4 files changed

Lines changed: 9 additions & 77 deletions

File tree

backend/src/db/db.rs

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,3 @@
1-
// // src/db/db.rs
2-
// use anyhow::Result;
3-
// use dotenv::dotenv;
4-
// use sqlx::{sqlite::SqlitePool, Pool, Sqlite};
5-
// use std::env;
6-
7-
// #[derive(Clone)]
8-
// pub struct Databases {
9-
// pub mcu_pool: Pool<Sqlite>,
10-
// pub devices_pool: Pool<Sqlite>,
11-
// }
12-
13-
// pub async fn init_dbs() -> Databases {
14-
// dotenv().ok();
15-
16-
// let database_url = env::var("DATABASE_URL")
17-
// .expect("DATABASE_URL must be set in .env (e.g. sqlite://./db.sqlite)");
18-
19-
// let pool = SqlitePool::connect(&database_url)
20-
// .await
21-
// .expect("Failed to create database pool.");
22-
23-
// // Применяем миграции (папка ./migrations)
24-
// sqlx::migrate!("./migrations")
25-
// .run(&pool)
26-
// .await
27-
// .expect("Failed to run database migrations.");
28-
29-
// Databases {
30-
// mcu_pool: pool.clone(),
31-
// devices_pool: pool,
32-
// }
33-
// }
34-
35-
// /// Вставка предсказания в БД (создаёт устройство, если ещё не существует).
36-
// /// person / not_person — вероятности (0.0..1.0).
37-
// pub async fn insert_prediction(
38-
// pool: &Pool<Sqlite>,
39-
// device_id: &str,
40-
// person: f64,
41-
// not_person: f64,
42-
// ) -> Result<()> {
43-
// // Ensure device exists (INSERT OR IGNORE)
44-
// sqlx::query(
45-
// r#"
46-
// INSERT OR IGNORE INTO devices(device_id, created_at) VALUES (?1, CURRENT_TIMESTAMP)
47-
// "#,
48-
// )
49-
// .bind(device_id)
50-
// .execute(pool)
51-
// .await?;
52-
53-
// // insert into mcu_data; timestamp uses CURRENT_TIMESTAMP
54-
// sqlx::query(
55-
// r#"
56-
// INSERT INTO mcu_data(device_id, person, not_person, timestamp)
57-
// VALUES (?1, ?2, ?3, CURRENT_TIMESTAMP)
58-
// "#,
59-
// )
60-
// .bind(device_id)
61-
// .bind(person)
62-
// .bind(not_person)
63-
// .execute(pool)
64-
// .await?;
65-
66-
// Ok(())
67-
// }
68-
691
use anyhow::Result;
702
use dotenv::dotenv;
713
use sqlx::{postgres::PgPoolOptions, Pool, Postgres};

backend/src/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use actix_web::{middleware::Logger, web, App, HttpResponse, HttpServer};
55
use dotenv::dotenv;
66
use env_logger::Env;
77
use std::env;
8-
use tokio::task;
98

109
mod db;
1110
mod handlers;
@@ -37,7 +36,7 @@ async fn main() -> std::io::Result<()> {
3736
});
3837
let frontend_index = format!("{}/index.html", frontend_dist);
3938

40-
// подключаемся к PostgreSQL
39+
// подключаемся к PostgreSQL
4140
let dbs: Databases = init_dbs().await;
4241

4342
// MQTT listener
@@ -70,7 +69,12 @@ async fn main() -> std::io::Result<()> {
7069
.wrap(cors)
7170
.app_data(Data::new(dbs.clone()))
7271
// Auth routes
73-
.service(web::scope("/api/auth").service(handlers::auth::login).service(handlers::auth::me).service(handlers::auth::update_profile))
72+
.service(
73+
web::scope("/api/auth")
74+
.service(handlers::auth::login)
75+
.service(handlers::auth::me)
76+
.service(handlers::auth::update_profile),
77+
)
7478
// Predictions routes
7579
.service(
7680
web::scope("/api/predictions")

backend/src/routes/server_routes.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,5 @@ use crate::handlers;
22
use actix_web::web;
33

44
pub fn init_predictions(cfg: &mut web::ServiceConfig) {
5-
cfg.service(handlers::get_data::get_predictions) // GET /api/predictions
6-
.service(handlers::get_data_by_device::get_prediction_by_device) // GET /api/predictions/device/{device_id}
7-
.service(handlers::add_data_by_id::add_prediction);
8-
// .service(handlers::delete_data_by_id::delete_prediction_by_id)
9-
// .service(handlers::update_data_by_id::update_prediction_by_id);
5+
cfg.service(handlers::get_data::get_predictions); // GET /api/predictions
106
}

backend/src/services/mqtt_listener.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use chrono::{Datelike, NaiveDate, NaiveDateTime, NaiveTime, Utc};
1+
use chrono::{Datelike, NaiveDate, Utc};
22
use log::{error, info, warn};
33
use regex::Regex;
44
use rumqttc::{AsyncClient, Event, Incoming, MqttOptions, QoS};

0 commit comments

Comments
 (0)