diff --git a/migrations/2023-08-27-090522_users/up.sql b/migrations/2023-08-27-090522_users/up.sql
index 026bb93..3230564 100644
--- a/migrations/2023-08-27-090522_users/up.sql
+++ b/migrations/2023-08-27-090522_users/up.sql
@@ -28,7 +28,6 @@ CREATE TABLE users (
wave INTEGER NOT NULL DEFAULT 0,
robot INTEGER NOT NULL DEFAULT 0,
spider INTEGER NOT NULL DEFAULT 0,
- swing_copter INTEGER NOT NULL DEFAULT 0,
explosion INTEGER NOT NULL DEFAULT 0,
special INTEGER NOT NULL DEFAULT 0,
glow INTEGER NOT NULL DEFAULT 0,
diff --git a/src/db/models.rs b/src/db/models.rs
index 239270a..304e140 100644
--- a/src/db/models.rs
+++ b/src/db/models.rs
@@ -62,7 +62,6 @@ pub struct User {
pub wave: i32,
pub robot: i32,
pub spider: i32,
- pub swing_copter: i32,
pub explosion: i32,
pub special: i32,
pub glow: i32,
diff --git a/src/db/schema.rs b/src/db/schema.rs
index 232b06a..a56613f 100644
--- a/src/db/schema.rs
+++ b/src/db/schema.rs
@@ -47,7 +47,6 @@ diesel::table! {
wave -> Int4,
robot -> Int4,
spider -> Int4,
- swing_copter -> Int4,
explosion -> Int4,
special -> Int4,
glow -> Int4,
diff --git a/src/endpoints.rs b/src/endpoints.rs
index 5184f86..5667352 100644
--- a/src/endpoints.rs
+++ b/src/endpoints.rs
@@ -1 +1,2 @@
-pub mod accounts;
\ No newline at end of file
+pub mod accounts;
+pub mod users;
\ No newline at end of file
diff --git a/src/endpoints/users.rs b/src/endpoints/users.rs
new file mode 100644
index 0000000..b244c93
--- /dev/null
+++ b/src/endpoints/users.rs
@@ -0,0 +1 @@
+pub mod get_users;
\ No newline at end of file
diff --git a/src/endpoints/users/get_users.rs b/src/endpoints/users/get_users.rs
new file mode 100644
index 0000000..fe8530e
--- /dev/null
+++ b/src/endpoints/users/get_users.rs
@@ -0,0 +1,74 @@
+use rocket::form::Form;
+use rocket::http::Status;
+use rocket::response::status;
+
+use diesel::prelude::*;
+use diesel::result::Error;
+
+use crate::helpers;
+use crate::db;
+
+#[derive(FromForm)]
+pub struct FormGetUsers {
+ page: i64,
+ str: String
+}
+
+#[post("/accounts/getGJUsers20.php", data = "")]
+pub fn get_users(input: Form) -> status::Custom<&'static str> {
+ let connection = &mut db::establish_connection_pg();
+
+ // query users
+ use crate::schema::users::dsl::*;
+ use crate::models::User;
+
+ let mut query = users.into_boxed();
+
+ match input.str.parse::() {
+ Ok(id_value) => query = query.filter(id.eq(id_value)),
+ Err(_) => query = query.filter(username.like(input.str.to_owned() + "%"))
+ };
+
+ let results = query
+ .order(stars.desc())
+ .limit(10)
+ .offset(input.page * 10)
+ .get_result::(connection)
+ .expect("Fatal error loading users");
+
+ let response = helpers::format::format(hashmap! {
+ 1 => results.username,
+ 2 => results.id.to_string(),
+ 3 => results.stars.to_string(),
+ 4 => results.demons.to_string(),
+ 8 => results.creator_points.to_string(),
+ 9 => {
+ vec![
+ results.cube,
+ results.ship,
+ results.ball,
+ results.ufo,
+ results.wave,
+ results.robot
+ ][results.icon_type as usize].to_string()
+ },
+ 10 => results.color1.to_string(),
+ 11 => results.color2.to_string(),
+ 13 => results.coins.to_string(),
+ 14 => results.icon_type.to_string(),
+ 15 => results.special.to_string(),
+ 16 => {
+ match results.account_id {
+ Some(account_id_value) => account_id_value.to_string(),
+ None => match results.udid {
+ Some(udid_value) => udid_value.to_string(),
+ None => panic!("user has no account_id or udid?!?!?")
+ }
+ }
+ }
+ });
+
+ println!("{}", response);
+
+ return status::Custom(Status::Ok, "1")
+}
\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index adcd126..bc0551e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,7 @@
#![feature(decl_macro)]
#![feature(lazy_cell)]
+#[macro_use] extern crate maplit;
#[macro_use] extern crate rocket;
mod db;
@@ -29,6 +30,8 @@ fn rocket() -> _ {
])
.mount(CONFIG.general.append_path.as_str(), routes![
endpoints::accounts::login_account::login_account,
- endpoints::accounts::register_account::register_account
+ endpoints::accounts::register_account::register_account,
+
+ endpoints::users::get_users::get_users
])
}
\ No newline at end of file