user search (i think)

This commit is contained in:
Reid 2023-08-29 02:54:30 -07:00
parent 80c884f489
commit 82aae16766
Signed by: reidlab
GPG key ID: 6C9EAA3364F962C8
7 changed files with 81 additions and 5 deletions

View file

@ -28,7 +28,6 @@ CREATE TABLE users (
wave INTEGER NOT NULL DEFAULT 0, wave INTEGER NOT NULL DEFAULT 0,
robot INTEGER NOT NULL DEFAULT 0, robot INTEGER NOT NULL DEFAULT 0,
spider INTEGER NOT NULL DEFAULT 0, spider INTEGER NOT NULL DEFAULT 0,
swing_copter INTEGER NOT NULL DEFAULT 0,
explosion INTEGER NOT NULL DEFAULT 0, explosion INTEGER NOT NULL DEFAULT 0,
special INTEGER NOT NULL DEFAULT 0, special INTEGER NOT NULL DEFAULT 0,
glow INTEGER NOT NULL DEFAULT 0, glow INTEGER NOT NULL DEFAULT 0,

View file

@ -62,7 +62,6 @@ pub struct User {
pub wave: i32, pub wave: i32,
pub robot: i32, pub robot: i32,
pub spider: i32, pub spider: i32,
pub swing_copter: i32,
pub explosion: i32, pub explosion: i32,
pub special: i32, pub special: i32,
pub glow: i32, pub glow: i32,

View file

@ -47,7 +47,6 @@ diesel::table! {
wave -> Int4, wave -> Int4,
robot -> Int4, robot -> Int4,
spider -> Int4, spider -> Int4,
swing_copter -> Int4,
explosion -> Int4, explosion -> Int4,
special -> Int4, special -> Int4,
glow -> Int4, glow -> Int4,

View file

@ -1 +1,2 @@
pub mod accounts; pub mod accounts;
pub mod users;

1
src/endpoints/users.rs Normal file
View file

@ -0,0 +1 @@
pub mod get_users;

View file

@ -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 = "<input>")]
pub fn get_users(input: Form<FormGetUsers>) -> 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::<i32>() {
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::<User, >(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")
}

View file

@ -1,6 +1,7 @@
#![feature(decl_macro)] #![feature(decl_macro)]
#![feature(lazy_cell)] #![feature(lazy_cell)]
#[macro_use] extern crate maplit;
#[macro_use] extern crate rocket; #[macro_use] extern crate rocket;
mod db; mod db;
@ -29,6 +30,8 @@ fn rocket() -> _ {
]) ])
.mount(CONFIG.general.append_path.as_str(), routes![ .mount(CONFIG.general.append_path.as_str(), routes![
endpoints::accounts::login_account::login_account, endpoints::accounts::login_account::login_account,
endpoints::accounts::register_account::register_account endpoints::accounts::register_account::register_account,
endpoints::users::get_users::get_users
]) ])
} }