-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trigger a profile (e.g., tag, photo, etc.) update on visit. #114
Changes from all commits
a2813e6
ebeee9d
1a204df
83af928
e33ce6c
83a517c
5759ef5
258056f
0171abd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -18,7 +18,9 @@ | |||
insert_into, | ||||
prelude::*, | ||||
result::{DatabaseErrorKind, Error as DieselError}, | ||||
sql_query, update, | ||||
sql_query, | ||||
sql_types::Text, | ||||
update, | ||||
}; | ||||
use smithe_database::{ | ||||
db_models::empty_player_ids::EmptyPlayerId, schema::empty_player_ids::dsl::*, | ||||
|
@@ -62,12 +64,24 @@ | |||
pub async fn get_all_like(tag: &str) -> Result<Vec<Player>> { | ||||
let processed_tag = tag.replace(' ', "%"); | ||||
// ^^^ transform spaces into wildcards to make search more inclusive | ||||
|
||||
let mut db_connection = smithe_database::connect().await?; | ||||
let matching_players: Vec<Player> = players | ||||
.filter(gamer_tag.ilike(format!("%{}%", processed_tag))) // case-insensitive like | ||||
.get_results::<Player>(&mut db_connection) | ||||
.await?; | ||||
|
||||
let query = diesel::sql_query("SELECT * FROM players WHERE gamer_tag ILIKE $1 ORDER BY LENGTH(gamer_tag) ASC, player_id ASC") | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idk why GitHub is showing this as a change considering you only changed this in your old PR and Line 69 in 6d3ada3
|
||||
.bind::<Text, _>(format!("%{}%", processed_tag)); | ||||
let mut matching_players: Vec<Player> = query.get_results::<Player>(&mut db_connection).await?; | ||||
|
||||
match tag.parse::<i32>() { | ||||
Ok(pid) => { | ||||
if let Ok(exact_id_match) = get_player(pid).await { | ||||
matching_players.insert(0, exact_id_match); | ||||
} | ||||
} | ||||
Err(_) => { | ||||
if let Ok(exact_slug_match) = get_player_from_slug(&processed_tag).await { | ||||
matching_players.insert(0, exact_slug_match); | ||||
} | ||||
} | ||||
} | ||||
|
||||
Ok(matching_players) | ||||
} | ||||
|
@@ -708,6 +722,25 @@ | |||
assert_eq!(res.unwrap().len(), 1); | ||||
} | ||||
|
||||
#[tokio::test] | ||||
#[cfg(feature = "skip_db_tests")] | ||||
async fn test_get_all_like_id() { | ||||
let res = get_all_like("1178271").await; | ||||
assert!(res.is_ok()); | ||||
assert_eq!( | ||||
res.unwrap()[0].user_slug, | ||||
format!("user/{}", DANTOTTO_PLAYER_SLUG) | ||||
); | ||||
} | ||||
|
||||
#[tokio::test] | ||||
#[cfg(feature = "skip_db_tests")] | ||||
async fn test_get_all_like_slug() { | ||||
let res = get_all_like(DANTOTTO_PLAYER_SLUG).await; | ||||
assert!(res.is_ok()); | ||||
assert_eq!(res.unwrap()[0].player_id, DANTOTTO_PLAYER_ID); | ||||
} | ||||
|
||||
#[tokio::test] | ||||
#[cfg(feature = "skip_db_tests")] | ||||
async fn test_get_player() { | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the name of this function is a bit confusing at this point 😅