more games information, games route (#756)

* more games information, games route

* adds banner url
This commit is contained in:
Wyatt Verchere
2023-11-14 10:01:31 -08:00
committed by GitHub
parent 375f992a0c
commit f4880d0519
19 changed files with 206 additions and 45 deletions

View File

@@ -796,7 +796,7 @@ async fn project_create_inner(
|(mut project_types, mut games), loader| {
if loaders.contains(&loader.id) {
project_types.extend(loader.supported_project_types);
games.extend(loader.supported_games.iter().map(|x| x.name().to_string()));
games.extend(loader.supported_games);
}
(project_types, games)
},

View File

@@ -3,7 +3,7 @@ use std::collections::HashMap;
use super::ApiError;
use crate::database::models::categories::{Category, DonationPlatform, ProjectType, ReportType};
use crate::database::models::loader_fields::{
Loader, LoaderField, LoaderFieldEnumValue, LoaderFieldType,
Game, Loader, LoaderField, LoaderFieldEnumValue, LoaderFieldType,
};
use crate::database::redis::RedisPool;
use actix_web::{web, HttpResponse};
@@ -16,6 +16,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
.route("category", web::get().to(category_list))
.route("loader", web::get().to(loader_list)),
)
.route("games", web::get().to(games_list))
.route("loader_fields", web::get().to(loader_fields_list))
.route("license", web::get().to(license_list))
.route("license/{id}", web::get().to(license_text))
@@ -24,6 +25,32 @@ pub fn config(cfg: &mut web::ServiceConfig) {
.route("project_type", web::get().to(project_type_list));
}
#[derive(serde::Serialize, serde::Deserialize)]
pub struct GameData {
pub slug: String,
pub name: String,
pub icon: Option<String>,
pub banner: Option<String>,
}
pub async fn games_list(
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
) -> Result<HttpResponse, ApiError> {
let results = Game::list(&**pool, &redis)
.await?
.into_iter()
.map(|x| GameData {
slug: x.slug,
name: x.name,
icon: x.icon_url,
banner: x.banner_url,
})
.collect::<Vec<_>>();
Ok(HttpResponse::Ok().json(results))
}
#[derive(serde::Serialize, serde::Deserialize)]
pub struct CategoryData {
pub icon: String,
@@ -69,11 +96,7 @@ pub async fn loader_list(
icon: x.icon,
name: x.loader,
supported_project_types: x.supported_project_types,
supported_games: x
.supported_games
.iter()
.map(|x| x.name().to_string())
.collect(),
supported_games: x.supported_games,
})
.collect::<Vec<_>>();

View File

@@ -423,8 +423,7 @@ async fn version_create_inner(
let (all_project_types, all_games): (Vec<String>, Vec<String>) =
loader_structs.iter().fold((vec![], vec![]), |mut acc, x| {
acc.0.extend_from_slice(&x.supported_project_types);
acc.1
.extend(x.supported_games.iter().map(|x| x.name().to_string()));
acc.1.extend(x.supported_games.clone());
acc
});