From 6f419c7b3dad3a4b005105530a7bee27893d3359 Mon Sep 17 00:00:00 2001
From: SinTan1729 <sayantan.santra689@gmail.com>
Date: Mon, 3 Mar 2025 12:27:59 -0600
Subject: [PATCH] new: Enforce ordering of data Closes #46 Data is returned in
 order of id, which should match the order it was inserted in. In the WebUI,
 the entries are shown in reverse, so the latest link is at the top.

---
 actix/src/database.rs      | 2 +-
 resources/static/script.js | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/actix/src/database.rs b/actix/src/database.rs
index 7dbebca..110bcc4 100644
--- a/actix/src/database.rs
+++ b/actix/src/database.rs
@@ -33,7 +33,7 @@ pub fn find_url(shortlink: &str, db: &Connection, needhits: bool) -> (Option<Str
 // Get all URLs in DB
 pub fn getall(db: &Connection) -> Vec<DBRow> {
     let mut statement = db
-        .prepare_cached("SELECT * FROM urls")
+        .prepare_cached("SELECT * FROM urls ORDER BY id ASC")
         .expect("Error preparing SQL statement for getall.");
 
     let mut data = statement
diff --git a/resources/static/script.js b/resources/static/script.js
index d798276..339112d 100644
--- a/resources/static/script.js
+++ b/resources/static/script.js
@@ -56,7 +56,7 @@ const refreshData = async () => {
         }
     } else {
         let data = await res.json();
-        displayData(data);
+        displayData(data.reverse());
     }
 }