summaryrefslogtreecommitdiff
path: root/src/locations.rs
diff options
context:
space:
mode:
authorDawid Rycerz <dawid@rycerz.xyz>2025-07-14 20:35:00 +0300
committerDawid Rycerz <dawid@rycerz.xyz>2025-07-14 20:35:00 +0300
commit1c2873b3059f3e4d6bd02307ec5b22f761ce1c80 (patch)
treede196a57b76fcacbbc842bbb5bf2641c8f82be91 /src/locations.rs
parent50ce8cb96b2b218751c2fc2a6b19372f51846acc (diff)
feat: Update routes and fix issues
Diffstat (limited to 'src/locations.rs')
-rw-r--r--src/locations.rs40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/locations.rs b/src/locations.rs
index e5f881d..2f8c3f8 100644
--- a/src/locations.rs
+++ b/src/locations.rs
@@ -21,13 +21,20 @@ impl<'a> LocationRepository<'a> {
}
pub async fn get_location(&self, id: i64) -> Result<Option<Location>, sqlx::Error> {
- sqlx::query_as::<_, Location>("SELECT id, latitude, longitude, user_id FROM locations WHERE id = ?")
- .bind(id)
- .fetch_optional(self.db)
- .await
+ sqlx::query_as::<_, Location>(
+ "SELECT id, latitude, longitude, user_id FROM locations WHERE id = ?",
+ )
+ .bind(id)
+ .fetch_optional(self.db)
+ .await
}
- pub async fn create_location(&self, latitude: f64, longitude: f64, user_id: i64) -> Result<Location, sqlx::Error> {
+ pub async fn create_location(
+ &self,
+ latitude: f64,
+ longitude: f64,
+ user_id: i64,
+ ) -> Result<Location, sqlx::Error> {
sqlx::query_as::<_, Location>(
"INSERT INTO locations (latitude, longitude, user_id) VALUES (?, ?, ?) RETURNING id, latitude, longitude, user_id"
)
@@ -38,7 +45,12 @@ impl<'a> LocationRepository<'a> {
.await
}
- pub async fn update_location(&self, id: i64, latitude: f64, longitude: f64) -> Result<Location, sqlx::Error> {
+ pub async fn update_location(
+ &self,
+ id: i64,
+ latitude: f64,
+ longitude: f64,
+ ) -> Result<Location, sqlx::Error> {
sqlx::query_as::<_, Location>(
"UPDATE locations SET latitude = ?, longitude = ? WHERE id = ? RETURNING id, latitude, longitude, user_id"
)
@@ -62,7 +74,7 @@ impl<'a> LocationRepository<'a> {
mod tests {
use super::*;
use crate::users::{UserRepository, UserRole};
- use sqlx::{SqlitePool, Executor};
+ use sqlx::{Executor, SqlitePool};
use tokio;
async fn setup_db() -> SqlitePool {
@@ -72,8 +84,10 @@ mod tests {
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id TEXT NOT NULL UNIQUE,
role TEXT NOT NULL DEFAULT 'user'
- );"
- ).await.unwrap();
+ );",
+ )
+ .await
+ .unwrap();
pool.execute(
"CREATE TABLE locations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -81,8 +95,10 @@ mod tests {
longitude REAL NOT NULL,
user_id INTEGER NOT NULL,
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE NO ACTION
- );"
- ).await.unwrap();
+ );",
+ )
+ .await
+ .unwrap();
pool
}
@@ -136,4 +152,4 @@ mod tests {
let locations = repo.list_locations().await.unwrap();
assert_eq!(locations.len(), 2);
}
-} \ No newline at end of file
+}