diff options
Diffstat (limited to 'planetwars-server/src/db')
-rw-r--r-- | planetwars-server/src/db/maps.rs | 7 | ||||
-rw-r--r-- | planetwars-server/src/db/matches.rs | 5 |
2 files changed, 11 insertions, 1 deletions
diff --git a/planetwars-server/src/db/maps.rs b/planetwars-server/src/db/maps.rs index 8972461..4f0e026 100644 --- a/planetwars-server/src/db/maps.rs +++ b/planetwars-server/src/db/maps.rs @@ -14,6 +14,7 @@ pub struct Map { pub id: i32, pub name: String, pub file_path: String, + pub is_ranked: bool, } pub fn create_map(new_map: NewMap, conn: &mut PgConnection) -> QueryResult<Map> { @@ -33,3 +34,9 @@ pub fn find_map_by_name(name: &str, conn: &mut PgConnection) -> QueryResult<Map> pub fn list_maps(conn: &mut PgConnection) -> QueryResult<Vec<Map>> { maps::table.get_results(conn) } + +pub fn get_ranked_maps(conn: &mut PgConnection) -> QueryResult<Vec<Map>> { + maps::table + .filter(maps::is_ranked.eq(true)) + .get_results(conn) +} diff --git a/planetwars-server/src/db/matches.rs b/planetwars-server/src/db/matches.rs index 2aff44b..7af5b4d 100644 --- a/planetwars-server/src/db/matches.rs +++ b/planetwars-server/src/db/matches.rs @@ -140,12 +140,15 @@ fn fetch_full_match_data( } // TODO: this method should disappear -pub fn list_matches(amount: i64, conn: &mut PgConnection) -> QueryResult<Vec<FullMatchData>> { +pub fn fetch_ranked_maps(amount: i64, conn: &mut PgConnection) -> QueryResult<Vec<FullMatchData>> { conn.transaction(|conn| { let matches = matches::table + .inner_join(maps::table) .filter(matches::state.eq(MatchState::Finished)) + .filter(maps::is_ranked.eq(true)) .order_by(matches::created_at.desc()) .limit(amount) + .select(matches::all_columns) .get_results::<MatchBase>(conn)?; fetch_full_match_data(matches, conn) |