You've already forked AstralRinth
forked from didirus/AstralRinth
Cleans up and removes TODOs, adds tests (#844)
* removes version ordering from v2; simplifies now-unecessary three-level faceting * resolved some todos * test for game version updating * merge fixes; display_categories fix
This commit is contained in:
@@ -12,7 +12,6 @@ use crate::routes::v3::projects::ProjectIds;
|
||||
use crate::routes::{v2_reroute, v3, ApiError};
|
||||
use crate::search::{search_for_project, SearchConfig, SearchError};
|
||||
use actix_web::{delete, get, patch, post, web, HttpRequest, HttpResponse};
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use std::collections::HashMap;
|
||||
@@ -53,35 +52,16 @@ pub async fn project_search(
|
||||
web::Query(info): web::Query<SearchRequest>,
|
||||
config: web::Data<SearchConfig>,
|
||||
) -> Result<HttpResponse, SearchError> {
|
||||
// TODO: make this nicer
|
||||
// Search now uses loader_fields instead of explicit 'client_side' and 'server_side' fields
|
||||
// While the backend for this has changed, it doesnt affect much
|
||||
// in the API calls except that 'versions:x' is now 'game_versions:x'
|
||||
let facets: Option<Vec<Vec<Vec<String>>>> = if let Some(facets) = info.facets {
|
||||
let facets = serde_json::from_str::<Vec<Vec<serde_json::Value>>>(&facets)?;
|
||||
// Search can now *optionally* have a third inner array: So Vec(AND)<Vec(OR)<Vec(AND)< _ >>>
|
||||
// For every inner facet, we will check if it can be deserialized into a Vec<&str>, and do so.
|
||||
// If not, we will assume it is a single facet and wrap it in a Vec.
|
||||
let facets: Vec<Vec<Vec<String>>> = facets
|
||||
.into_iter()
|
||||
.map(|facets| {
|
||||
facets
|
||||
.into_iter()
|
||||
.map(|facet| {
|
||||
if facet.is_array() {
|
||||
serde_json::from_value::<Vec<String>>(facet).unwrap_or_default()
|
||||
} else {
|
||||
vec![serde_json::from_value::<String>(facet).unwrap_or_default()]
|
||||
}
|
||||
})
|
||||
.collect_vec()
|
||||
})
|
||||
.collect_vec();
|
||||
let facets: Option<Vec<Vec<String>>> = if let Some(facets) = info.facets {
|
||||
let facets = serde_json::from_str::<Vec<Vec<String>>>(&facets)?;
|
||||
|
||||
// These loaders specifically used to be combined with 'mod' to be a plugin, but now
|
||||
// they are their own loader type. We will convert 'mod' to 'mod' OR 'plugin'
|
||||
// as it essentially was before.
|
||||
let facets = v2_reroute::convert_plugin_loaders_v3(facets);
|
||||
let facets = v2_reroute::convert_plugin_loader_facets_v3(facets);
|
||||
|
||||
Some(
|
||||
facets
|
||||
@@ -89,27 +69,22 @@ pub async fn project_search(
|
||||
.map(|facet| {
|
||||
facet
|
||||
.into_iter()
|
||||
.map(|facets| {
|
||||
facets
|
||||
.into_iter()
|
||||
.map(|facet| {
|
||||
if let Some((key, operator, val)) = parse_facet(&facet) {
|
||||
format!(
|
||||
"{}{}{}",
|
||||
match key.as_str() {
|
||||
"versions" => "game_versions",
|
||||
"project_type" => "project_types",
|
||||
"title" => "name",
|
||||
x => x,
|
||||
},
|
||||
operator,
|
||||
val
|
||||
)
|
||||
} else {
|
||||
facet.to_string()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.map(|facet| {
|
||||
if let Some((key, operator, val)) = parse_facet(&facet) {
|
||||
format!(
|
||||
"{}{}{}",
|
||||
match key.as_str() {
|
||||
"versions" => "game_versions",
|
||||
"project_type" => "project_types",
|
||||
"title" => "name",
|
||||
x => x,
|
||||
},
|
||||
operator,
|
||||
val
|
||||
)
|
||||
} else {
|
||||
facet.to_string()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
|
||||
@@ -215,7 +215,6 @@ pub struct EditVersion {
|
||||
pub downloads: Option<u32>,
|
||||
pub status: Option<VersionStatus>,
|
||||
pub file_types: Option<Vec<EditVersionFileType>>,
|
||||
pub ordering: Option<Option<i32>>, //TODO: How do you actually pass this in json?
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@@ -291,7 +290,7 @@ pub async fn version_edit(
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}),
|
||||
ordering: new_version.ordering,
|
||||
ordering: None,
|
||||
fields,
|
||||
};
|
||||
|
||||
|
||||
@@ -178,18 +178,18 @@ pub fn convert_side_types_v3(
|
||||
fields
|
||||
}
|
||||
|
||||
// Converts plugin loaders from v2 to v3
|
||||
// Converts plugin loaders from v2 to v3, for search facets
|
||||
// Within every 1st and 2nd level (the ones allowed in v2), we convert every instance of:
|
||||
// "project_type:mod" to "project_type:plugin" OR "project_type:mod"
|
||||
pub fn convert_plugin_loaders_v3(facets: Vec<Vec<Vec<String>>>) -> Vec<Vec<Vec<String>>> {
|
||||
pub fn convert_plugin_loader_facets_v3(facets: Vec<Vec<String>>) -> Vec<Vec<String>> {
|
||||
facets
|
||||
.into_iter()
|
||||
.map(|inner_facets| {
|
||||
if inner_facets == [["project_type:mod"]] {
|
||||
if inner_facets == ["project_type:mod"] {
|
||||
vec![
|
||||
vec!["project_type:plugin".to_string()],
|
||||
vec!["project_type:datapack".to_string()],
|
||||
vec!["project_type:mod".to_string()],
|
||||
"project_type:plugin".to_string(),
|
||||
"project_type:datapack".to_string(),
|
||||
"project_type:mod".to_string(),
|
||||
]
|
||||
} else {
|
||||
inner_facets
|
||||
|
||||
@@ -583,8 +583,6 @@ async fn upload_file_to_version_inner(
|
||||
};
|
||||
|
||||
let all_loaders = models::loader_fields::Loader::list(&mut **transaction, &redis).await?;
|
||||
|
||||
// TODO: this coded is reused a lot, it should be refactored into a function
|
||||
let selected_loaders = version
|
||||
.loaders
|
||||
.iter()
|
||||
|
||||
@@ -132,7 +132,6 @@ pub async fn get_update_from_hash(
|
||||
.map(|x| x.1)
|
||||
.ok();
|
||||
let hash = info.into_inner().0.to_lowercase();
|
||||
|
||||
if let Some(file) = database::models::Version::get_file_from_hash(
|
||||
hash_query
|
||||
.algorithm
|
||||
@@ -185,7 +184,6 @@ pub async fn get_update_from_hash(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Err(ApiError::NotFound)
|
||||
}
|
||||
|
||||
|
||||
@@ -202,8 +202,12 @@ pub struct EditVersion {
|
||||
pub downloads: Option<u32>,
|
||||
pub status: Option<VersionStatus>,
|
||||
pub file_types: Option<Vec<EditVersionFileType>>,
|
||||
|
||||
pub ordering: Option<Option<i32>>, //TODO: How do you actually pass this in json?
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
with = "::serde_with::rust::double_option"
|
||||
)]
|
||||
pub ordering: Option<Option<i32>>,
|
||||
|
||||
// Flattened loader fields
|
||||
// All other fields are loader-specific VersionFields
|
||||
@@ -220,8 +224,6 @@ pub struct EditVersionFileType {
|
||||
pub file_type: Option<FileType>,
|
||||
}
|
||||
|
||||
// TODO: Avoid this 'helper' pattern here and similar fnunctoins- a macro might be the best bet here to ensure it's callable from both v2 and v3
|
||||
// (web::Path can't be recreated naturally)
|
||||
pub async fn version_edit(
|
||||
req: HttpRequest,
|
||||
info: web::Path<(VersionId,)>,
|
||||
|
||||
Reference in New Issue
Block a user