Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Renamed default project type to unknown. (#774)
Browse files Browse the repository at this point in the history
* small change

* plugins and datapacks now correctly return to project

* Adds to search
  • Loading branch information
thesuzerain authored Dec 1, 2023
1 parent 58093a9 commit b3b5521
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
5 changes: 5 additions & 0 deletions migrations/20231130153100_loader_fields_loaders.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Adds missing loader_fields_loaders entries for mrpack loader
INSERT INTO loader_fields_loaders
SELECT l.id, lf.id FROM loaders l CROSS JOIN loader_fields lf
WHERE l.loader='mrpack' AND lf.field=ANY(ARRAY['game_versions','client_and_server','server_only','client_only','singleplayer'])
ON CONFLICT DO NOTHING;
22 changes: 18 additions & 4 deletions src/models/v2/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,26 @@ impl LegacyProject {
let mut game_versions = Vec::new();

// V2 versions only have one project type- v3 versions can rarely have multiple.
// We'll just use the first one.
let mut project_type = data
.project_types
// We'll prioritize 'modpack' first, then 'mod', and if neither are found, use the first one.
// If there are no project types, default to 'project'
let mut project_types = data.project_types;
if project_types.contains(&"modpack".to_string()) {
project_types = vec!["modpack".to_string()];
} else if project_types.contains(&"mod".to_string()) {
project_types = vec!["mod".to_string()];
}
let project_type = project_types
.first()
.cloned()
.unwrap_or("unknown".to_string());
.unwrap_or("project".to_string()); // Default to 'project' if none are found

let mut project_type = if project_type == "datapack" || project_type == "plugin" {
// These are not supported in V2, so we'll just use 'mod' instead
"mod".to_string()
} else {
project_type
};

let mut loaders = data.loaders;

if let Some(versions_item) = versions_item {
Expand Down
27 changes: 22 additions & 5 deletions src/models/v2/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,29 @@ impl LegacyResultSearchProject {
display_categories.sort();
display_categories.dedup();

// V2 versions only have one project type- v3 versions can rarely have multiple.
// We'll prioritize 'modpack' first, then 'mod', and if neither are found, use the first one.
// If there are no project types, default to 'project'
let mut project_types = result_search_project.project_types;
if project_types.contains(&"modpack".to_string()) {
project_types = vec!["modpack".to_string()];
} else if project_types.contains(&"mod".to_string()) {
project_types = vec!["mod".to_string()];
}
let project_type = project_types
.first()
.cloned()
.unwrap_or("project".to_string()); // Default to 'project' if none are found

let project_type = if project_type == "datapack" || project_type == "plugin" {
// These are not supported in V2, so we'll just use 'mod' instead
"mod".to_string()
} else {
project_type
};

Self {
project_type: result_search_project
.project_types
.first()
.cloned()
.unwrap_or_default(),
project_type,
client_side: result_search_project
.loader_fields
.get("client_side")
Expand Down
4 changes: 2 additions & 2 deletions tests/files/dummy_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ INSERT INTO loader_fields (
true
);
INSERT INTO loader_fields_loaders(loader_id, loader_field_id)
SELECT l.id, lf.id FROM loaders l CROSS JOIN loader_fields lf WHERE lf.field = 'test_fabric_optional' AND l.loader = 'fabric';
SELECT l.id, lf.id FROM loaders l CROSS JOIN loader_fields lf WHERE lf.field = 'test_fabric_optional' AND l.loader = 'fabric' ON CONFLICT DO NOTHING;

-- Sample game versions, loaders, categories
-- Game versions is '2'
Expand All @@ -68,7 +68,7 @@ INSERT INTO loader_field_enum_values(enum_id, value, metadata, ordering)
VALUES (2, 'Ordering_Positive100', '{"type":"release","major":false}', 100);

INSERT INTO loader_fields_loaders(loader_id, loader_field_id)
SELECT l.id, lf.id FROM loaders l CROSS JOIN loader_fields lf WHERE lf.field IN ('game_versions','singleplayer', 'client_and_server', 'client_only', 'server_only');
SELECT l.id, lf.id FROM loaders l CROSS JOIN loader_fields lf WHERE lf.field IN ('game_versions','singleplayer', 'client_and_server', 'client_only', 'server_only') ON CONFLICT DO NOTHING;

INSERT INTO categories (id, category, project_type) VALUES
(51, 'combat', 1),
Expand Down
3 changes: 2 additions & 1 deletion tests/v2/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ async fn add_version_project_types_v2() {
let test_project = api
.get_project_deserialized(&test_project.slug.unwrap(), USER_USER_PAT)
.await;
assert_eq!(test_project.project_type, "unknown"); // No project_type set, as no versions are set
assert_eq!(test_project.project_type, "project"); // No project_type set, as no versions are set
// Default to 'project' if none are found
// This is a known difference between older v2 ,but is acceptable.
// This would be the appropriate test on older v2:
// assert_eq!(test_project.project_type, "modpack");
Expand Down

0 comments on commit b3b5521

Please sign in to comment.