fix ordering in list_matches
This commit is contained in:
parent
55c76db7b6
commit
095ad981db
2 changed files with 8 additions and 4 deletions
|
@ -40,6 +40,7 @@ impl QueryFragment<Pg> for ListBotMatches {
|
||||||
|
|
||||||
out.push_sql(") main_player ON matches.id = main_player.match_id");
|
out.push_sql(") main_player ON matches.id = main_player.match_id");
|
||||||
|
|
||||||
|
// TODO: this won't work properly for matches with > 2 players
|
||||||
if let Some(opponent_id) = self.opponent_id.as_ref() {
|
if let Some(opponent_id) = self.opponent_id.as_ref() {
|
||||||
out.push_sql(" JOIN (");
|
out.push_sql(" JOIN (");
|
||||||
out.push_sql(concat!(
|
out.push_sql(concat!(
|
||||||
|
@ -70,11 +71,14 @@ impl QueryFragment<Pg> for ListBotMatches {
|
||||||
if let Some(before) = self.before.as_ref() {
|
if let Some(before) = self.before.as_ref() {
|
||||||
out.push_sql(" AND matches.created_at < ");
|
out.push_sql(" AND matches.created_at < ");
|
||||||
out.push_bind_param::<Timestamp, _>(before)?;
|
out.push_bind_param::<Timestamp, _>(before)?;
|
||||||
out.push_sql(" ORDER BY matches.created_at DESC");
|
|
||||||
} else if let Some(after) = self.after.as_ref() {
|
} else if let Some(after) = self.after.as_ref() {
|
||||||
out.push_sql(" AND matches.created_at > ");
|
out.push_sql(" AND matches.created_at > ");
|
||||||
out.push_bind_param::<Timestamp, _>(after)?;
|
out.push_bind_param::<Timestamp, _>(after)?;
|
||||||
out.push_sql(" ORDER BY matches.created_at ASC");
|
}
|
||||||
|
if self.after.is_some() {
|
||||||
|
out.push_sql(" ORDER BY matches.created_at ASC")
|
||||||
|
} else {
|
||||||
|
out.push_sql(" ORDER BY matches.created_at DESC")
|
||||||
}
|
}
|
||||||
out.push_sql(" LIMIT ");
|
out.push_sql(" LIMIT ");
|
||||||
out.push_bind_param::<BigInt, _>(&self.amount)?;
|
out.push_bind_param::<BigInt, _>(&self.amount)?;
|
||||||
|
|
|
@ -75,8 +75,8 @@ pub async fn list_recent_matches(
|
||||||
let bot = db::bots::find_bot_by_name(&bot_name, &mut conn)
|
let bot = db::bots::find_bot_by_name(&bot_name, &mut conn)
|
||||||
.map_err(|_| StatusCode::BAD_REQUEST)?;
|
.map_err(|_| StatusCode::BAD_REQUEST)?;
|
||||||
|
|
||||||
let opponent_id = if let Some(opponent_name) = params.opponent {
|
let opponent_id = if let Some(ref opponent_name) = params.opponent {
|
||||||
let opponent = db::bots::find_bot_by_name(&opponent_name, &mut conn)
|
let opponent = db::bots::find_bot_by_name(opponent_name, &mut conn)
|
||||||
.map_err(|_| StatusCode::BAD_REQUEST)?;
|
.map_err(|_| StatusCode::BAD_REQUEST)?;
|
||||||
Some(opponent.id)
|
Some(opponent.id)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue