diff --git a/.sqlx/query-04345d9c23430267f755b1420520df91bd403524fd60ba1a94e3a239ea70cae7.json b/.sqlx/query-04345d9c23430267f755b1420520df91bd403524fd60ba1a94e3a239ea70cae7.json deleted file mode 100644 index 1c31aaa7..00000000 --- a/.sqlx/query-04345d9c23430267f755b1420520df91bd403524fd60ba1a94e3a239ea70cae7.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE mods\n SET source_url = $1\n WHERE (id = $2)\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Varchar", - "Int8" - ] - }, - "nullable": [] - }, - "hash": "04345d9c23430267f755b1420520df91bd403524fd60ba1a94e3a239ea70cae7" -} diff --git a/.sqlx/query-268af672e8e475885c18da9edd81bac19f3a78a8a462bf9bb2dbe0a72c2f1ff7.json b/.sqlx/query-268af672e8e475885c18da9edd81bac19f3a78a8a462bf9bb2dbe0a72c2f1ff7.json new file mode 100644 index 00000000..aa5b4f46 --- /dev/null +++ b/.sqlx/query-268af672e8e475885c18da9edd81bac19f3a78a8a462bf9bb2dbe0a72c2f1ff7.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO mods_links (\n joining_mod_id, joining_platform_id, url\n )\n SELECT * FROM UNNEST($1::bigint[], $2::int[], $3::varchar[])\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8Array", + "Int4Array", + "VarcharArray" + ] + }, + "nullable": [] + }, + "hash": "268af672e8e475885c18da9edd81bac19f3a78a8a462bf9bb2dbe0a72c2f1ff7" +} diff --git a/.sqlx/query-2b8dafe9c3df9fd25235a13868e8e7607decfbe96a413cc576919a1fb510f269.json b/.sqlx/query-2b8dafe9c3df9fd25235a13868e8e7607decfbe96a413cc576919a1fb510f269.json deleted file mode 100644 index c011c5b0..00000000 --- a/.sqlx/query-2b8dafe9c3df9fd25235a13868e8e7607decfbe96a413cc576919a1fb510f269.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE mods\n SET discord_url = $1\n WHERE (id = $2)\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Varchar", - "Int8" - ] - }, - "nullable": [] - }, - "hash": "2b8dafe9c3df9fd25235a13868e8e7607decfbe96a413cc576919a1fb510f269" -} diff --git a/.sqlx/query-2efd0efe9ce16b2da01d9bcc1603e3a7ad0f9a1e5a457770608bc41dbb83f2dd.json b/.sqlx/query-2efd0efe9ce16b2da01d9bcc1603e3a7ad0f9a1e5a457770608bc41dbb83f2dd.json deleted file mode 100644 index e666764f..00000000 --- a/.sqlx/query-2efd0efe9ce16b2da01d9bcc1603e3a7ad0f9a1e5a457770608bc41dbb83f2dd.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n INSERT INTO payouts_values (user_id, mod_id, amount, created)\n SELECT * FROM UNNEST ($1::bigint[], $2::bigint[], $3::numeric[], $4::timestamptz[])\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8Array", - "Int8Array", - "NumericArray", - "TimestamptzArray" - ] - }, - "nullable": [] - }, - "hash": "2efd0efe9ce16b2da01d9bcc1603e3a7ad0f9a1e5a457770608bc41dbb83f2dd" -} diff --git a/.sqlx/query-4567790f0dc98ff20b596a33161d1f6ac8af73da67fe8c54192724626c6bf670.json b/.sqlx/query-4567790f0dc98ff20b596a33161d1f6ac8af73da67fe8c54192724626c6bf670.json deleted file mode 100644 index 7893cca8..00000000 --- a/.sqlx/query-4567790f0dc98ff20b596a33161d1f6ac8af73da67fe8c54192724626c6bf670.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n DELETE FROM mods_donations\n WHERE joining_mod_id = $1\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8" - ] - }, - "nullable": [] - }, - "hash": "4567790f0dc98ff20b596a33161d1f6ac8af73da67fe8c54192724626c6bf670" -} diff --git a/.sqlx/query-473db826b691ae1131990ef0927cfe5b63d48829dd41edb7def22248d5668ac7.json b/.sqlx/query-473db826b691ae1131990ef0927cfe5b63d48829dd41edb7def22248d5668ac7.json deleted file mode 100644 index de301423..00000000 --- a/.sqlx/query-473db826b691ae1131990ef0927cfe5b63d48829dd41edb7def22248d5668ac7.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n INSERT INTO mods_donations (\n joining_mod_id, joining_platform_id, url\n )\n SELECT * FROM UNNEST($1::bigint[], $2::int[], $3::varchar[])\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8Array", - "Int4Array", - "VarcharArray" - ] - }, - "nullable": [] - }, - "hash": "473db826b691ae1131990ef0927cfe5b63d48829dd41edb7def22248d5668ac7" -} diff --git a/.sqlx/query-4d0e2d4345aeab5ee7eed847c03c913073eeb43caaf299cddcac6e41351661fd.json b/.sqlx/query-4d0e2d4345aeab5ee7eed847c03c913073eeb43caaf299cddcac6e41351661fd.json new file mode 100644 index 00000000..801c4326 --- /dev/null +++ b/.sqlx/query-4d0e2d4345aeab5ee7eed847c03c913073eeb43caaf299cddcac6e41351661fd.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "\n DELETE FROM mods_links\n WHERE joining_mod_id = $1 AND joining_platform_id IN (\n SELECT id FROM link_platforms WHERE name = ANY($2)\n )\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8", + "TextArray" + ] + }, + "nullable": [] + }, + "hash": "4d0e2d4345aeab5ee7eed847c03c913073eeb43caaf299cddcac6e41351661fd" +} diff --git a/.sqlx/query-5db4b2678406a9977c1e37409920804e0225181befe8b784dea48e37e30fedcc.json b/.sqlx/query-5db4b2678406a9977c1e37409920804e0225181befe8b784dea48e37e30fedcc.json new file mode 100644 index 00000000..0dcd2037 --- /dev/null +++ b/.sqlx/query-5db4b2678406a9977c1e37409920804e0225181befe8b784dea48e37e30fedcc.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)\n VALUES ($1, $2, $3)\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8", + "Int4", + "Varchar" + ] + }, + "nullable": [] + }, + "hash": "5db4b2678406a9977c1e37409920804e0225181befe8b784dea48e37e30fedcc" +} diff --git a/.sqlx/query-07ebc9dc82cd012cd4f5880b1eb3d82602c195a3e3ddd557103ee037aa6dad1c.json b/.sqlx/query-5e7146bc9dc9145cf3d01875ee599ada89e28c63fd10b3f23680d6660d0e57a2.json similarity index 55% rename from .sqlx/query-07ebc9dc82cd012cd4f5880b1eb3d82602c195a3e3ddd557103ee037aa6dad1c.json rename to .sqlx/query-5e7146bc9dc9145cf3d01875ee599ada89e28c63fd10b3f23680d6660d0e57a2.json index 3f89936b..689e6395 100644 --- a/.sqlx/query-07ebc9dc82cd012cd4f5880b1eb3d82602c195a3e3ddd557103ee037aa6dad1c.json +++ b/.sqlx/query-5e7146bc9dc9145cf3d01875ee599ada89e28c63fd10b3f23680d6660d0e57a2.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n INSERT INTO mods_donations (joining_mod_id, joining_platform_id, url)\n VALUES ($1, $2, $3)\n ", + "query": "\n INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)\n VALUES ($1, $2, $3)\n ", "describe": { "columns": [], "parameters": { @@ -12,5 +12,5 @@ }, "nullable": [] }, - "hash": "07ebc9dc82cd012cd4f5880b1eb3d82602c195a3e3ddd557103ee037aa6dad1c" + "hash": "5e7146bc9dc9145cf3d01875ee599ada89e28c63fd10b3f23680d6660d0e57a2" } diff --git a/.sqlx/query-8b95bd5ed139be6545147217b2d83f6817ce05fd3212b900f0d437ca42decd47.json b/.sqlx/query-7b4b1ad13215473d1bfc5ba7f540b2360c15c193df1dd120722fda91a48ada24.json similarity index 55% rename from .sqlx/query-8b95bd5ed139be6545147217b2d83f6817ce05fd3212b900f0d437ca42decd47.json rename to .sqlx/query-7b4b1ad13215473d1bfc5ba7f540b2360c15c193df1dd120722fda91a48ada24.json index 2307d9fd..f068ba26 100644 --- a/.sqlx/query-8b95bd5ed139be6545147217b2d83f6817ce05fd3212b900f0d437ca42decd47.json +++ b/.sqlx/query-7b4b1ad13215473d1bfc5ba7f540b2360c15c193df1dd120722fda91a48ada24.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT m.id id, m.title title, m.description description, m.downloads downloads, m.follows follows,\n m.icon_url icon_url, m.body body, m.published published,\n m.updated updated, m.approved approved, m.queued, m.status status, m.requested_status requested_status,\n m.issues_url issues_url, m.source_url source_url, m.wiki_url wiki_url, m.discord_url discord_url, m.license_url license_url,\n m.team_id team_id, m.organization_id organization_id, m.license license, m.slug slug, m.moderation_message moderation_message, m.moderation_message_body moderation_message_body,\n m.webhook_sent, m.color,\n t.id thread_id, m.monetization_status monetization_status,\n ARRAY_AGG(DISTINCT l.loader) filter (where l.loader is not null) loaders,\n ARRAY_AGG(DISTINCT pt.name) filter (where pt.name is not null) project_types,\n ARRAY_AGG(DISTINCT g.slug) filter (where g.slug is not null) games,\n ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is false) categories,\n ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is true) additional_categories,\n JSONB_AGG(DISTINCT jsonb_build_object('id', v.id, 'date_published', v.date_published)) filter (where v.id is not null) versions,\n JSONB_AGG(DISTINCT jsonb_build_object('image_url', mg.image_url, 'featured', mg.featured, 'title', mg.title, 'description', mg.description, 'created', mg.created, 'ordering', mg.ordering)) filter (where mg.image_url is not null) gallery,\n JSONB_AGG(DISTINCT jsonb_build_object('platform_id', md.joining_platform_id, 'platform_short', dp.short, 'platform_name', dp.name,'url', md.url)) filter (where md.joining_platform_id is not null) donations\n FROM mods m \n INNER JOIN threads t ON t.mod_id = m.id\n LEFT JOIN mods_gallery mg ON mg.mod_id = m.id\n LEFT JOIN mods_donations md ON md.joining_mod_id = m.id\n LEFT JOIN donation_platforms dp ON md.joining_platform_id = dp.id\n LEFT JOIN mods_categories mc ON mc.joining_mod_id = m.id\n LEFT JOIN categories c ON mc.joining_category_id = c.id\n LEFT JOIN versions v ON v.mod_id = m.id AND v.status = ANY($3)\n LEFT JOIN loaders_versions lv ON lv.version_id = v.id\n LEFT JOIN loaders l on lv.loader_id = l.id\n LEFT JOIN loaders_project_types lpt ON lpt.joining_loader_id = l.id\n LEFT JOIN project_types pt ON pt.id = lpt.joining_project_type_id\n LEFT JOIN loaders_project_types_games lptg ON lptg.loader_id = l.id AND lptg.project_type_id = pt.id\n LEFT JOIN games g ON lptg.game_id = g.id\n WHERE m.id = ANY($1) OR m.slug = ANY($2)\n GROUP BY t.id, m.id;\n ", + "query": "\n SELECT m.id id, m.title title, m.description description, m.downloads downloads, m.follows follows,\n m.icon_url icon_url, m.body body, m.published published,\n m.updated updated, m.approved approved, m.queued, m.status status, m.requested_status requested_status,\n m.license_url license_url,\n m.team_id team_id, m.organization_id organization_id, m.license license, m.slug slug, m.moderation_message moderation_message, m.moderation_message_body moderation_message_body,\n m.webhook_sent, m.color,\n t.id thread_id, m.monetization_status monetization_status,\n ARRAY_AGG(DISTINCT l.loader) filter (where l.loader is not null) loaders,\n ARRAY_AGG(DISTINCT pt.name) filter (where pt.name is not null) project_types,\n ARRAY_AGG(DISTINCT g.slug) filter (where g.slug is not null) games,\n ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is false) categories,\n ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is true) additional_categories,\n JSONB_AGG(DISTINCT jsonb_build_object('id', v.id, 'date_published', v.date_published)) filter (where v.id is not null) versions,\n JSONB_AGG(DISTINCT jsonb_build_object('image_url', mg.image_url, 'featured', mg.featured, 'title', mg.title, 'description', mg.description, 'created', mg.created, 'ordering', mg.ordering)) filter (where mg.image_url is not null) gallery,\n JSONB_AGG(DISTINCT jsonb_build_object('platform_id', ml.joining_platform_id, 'platform_name', lp.name,'url', ml.url, 'donation', lp.donation)) filter (where ml.joining_platform_id is not null) links\n FROM mods m \n INNER JOIN threads t ON t.mod_id = m.id\n LEFT JOIN mods_gallery mg ON mg.mod_id = m.id\n LEFT JOIN mods_links ml ON ml.joining_mod_id = m.id\n LEFT JOIN link_platforms lp ON ml.joining_platform_id = lp.id\n LEFT JOIN mods_categories mc ON mc.joining_mod_id = m.id\n LEFT JOIN categories c ON mc.joining_category_id = c.id\n LEFT JOIN versions v ON v.mod_id = m.id AND v.status = ANY($3)\n LEFT JOIN loaders_versions lv ON lv.version_id = v.id\n LEFT JOIN loaders l on lv.loader_id = l.id\n LEFT JOIN loaders_project_types lpt ON lpt.joining_loader_id = l.id\n LEFT JOIN project_types pt ON pt.id = lpt.joining_project_type_id\n LEFT JOIN loaders_project_types_games lptg ON lptg.loader_id = l.id AND lptg.project_type_id = pt.id\n LEFT JOIN games g ON lptg.game_id = g.id\n WHERE m.id = ANY($1) OR m.slug = ANY($2)\n GROUP BY t.id, m.id;\n ", "describe": { "columns": [ { @@ -70,117 +70,97 @@ }, { "ordinal": 13, - "name": "issues_url", - "type_info": "Varchar" - }, - { - "ordinal": 14, - "name": "source_url", - "type_info": "Varchar" - }, - { - "ordinal": 15, - "name": "wiki_url", - "type_info": "Varchar" - }, - { - "ordinal": 16, - "name": "discord_url", - "type_info": "Varchar" - }, - { - "ordinal": 17, "name": "license_url", "type_info": "Varchar" }, { - "ordinal": 18, + "ordinal": 14, "name": "team_id", "type_info": "Int8" }, { - "ordinal": 19, + "ordinal": 15, "name": "organization_id", "type_info": "Int8" }, { - "ordinal": 20, + "ordinal": 16, "name": "license", "type_info": "Varchar" }, { - "ordinal": 21, + "ordinal": 17, "name": "slug", "type_info": "Varchar" }, { - "ordinal": 22, + "ordinal": 18, "name": "moderation_message", "type_info": "Varchar" }, { - "ordinal": 23, + "ordinal": 19, "name": "moderation_message_body", "type_info": "Varchar" }, { - "ordinal": 24, + "ordinal": 20, "name": "webhook_sent", "type_info": "Bool" }, { - "ordinal": 25, + "ordinal": 21, "name": "color", "type_info": "Int4" }, { - "ordinal": 26, + "ordinal": 22, "name": "thread_id", "type_info": "Int8" }, { - "ordinal": 27, + "ordinal": 23, "name": "monetization_status", "type_info": "Varchar" }, { - "ordinal": 28, + "ordinal": 24, "name": "loaders", "type_info": "VarcharArray" }, { - "ordinal": 29, + "ordinal": 25, "name": "project_types", "type_info": "VarcharArray" }, { - "ordinal": 30, + "ordinal": 26, "name": "games", "type_info": "VarcharArray" }, { - "ordinal": 31, + "ordinal": 27, "name": "categories", "type_info": "VarcharArray" }, { - "ordinal": 32, + "ordinal": 28, "name": "additional_categories", "type_info": "VarcharArray" }, { - "ordinal": 33, + "ordinal": 29, "name": "versions", "type_info": "Jsonb" }, { - "ordinal": 34, + "ordinal": 30, "name": "gallery", "type_info": "Jsonb" }, { - "ordinal": 35, - "name": "donations", + "ordinal": 31, + "name": "links", "type_info": "Jsonb" } ], @@ -206,10 +186,6 @@ false, true, true, - true, - true, - true, - true, false, true, false, @@ -230,5 +206,5 @@ null ] }, - "hash": "8b95bd5ed139be6545147217b2d83f6817ce05fd3212b900f0d437ca42decd47" + "hash": "7b4b1ad13215473d1bfc5ba7f540b2360c15c193df1dd120722fda91a48ada24" } diff --git a/.sqlx/query-83d428e1c07d16e356ef26bdf1d707940b1683b5f631ded1f6674a081453d67b.json b/.sqlx/query-83d428e1c07d16e356ef26bdf1d707940b1683b5f631ded1f6674a081453d67b.json deleted file mode 100644 index 41542fd8..00000000 --- a/.sqlx/query-83d428e1c07d16e356ef26bdf1d707940b1683b5f631ded1f6674a081453d67b.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE mods\n SET source_url = $1\n WHERE (id = $2)\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Varchar", - "Int8" - ] - }, - "nullable": [] - }, - "hash": "83d428e1c07d16e356ef26bdf1d707940b1683b5f631ded1f6674a081453d67b" -} diff --git a/.sqlx/query-fefb4f07a0f0c0cf74e554d120f8707d698fc8b4dbb66d2830f4ec0229bc1019.json b/.sqlx/query-83dc16cc7a0f4507e308a06f4924065e4ea25de0210be222ceae8eb645f888e3.json similarity index 58% rename from .sqlx/query-fefb4f07a0f0c0cf74e554d120f8707d698fc8b4dbb66d2830f4ec0229bc1019.json rename to .sqlx/query-83dc16cc7a0f4507e308a06f4924065e4ea25de0210be222ceae8eb645f888e3.json index e2b9c106..015a47d4 100644 --- a/.sqlx/query-fefb4f07a0f0c0cf74e554d120f8707d698fc8b4dbb66d2830f4ec0229bc1019.json +++ b/.sqlx/query-83dc16cc7a0f4507e308a06f4924065e4ea25de0210be222ceae8eb645f888e3.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n INSERT INTO mods (\n id, team_id, title, description, body,\n published, downloads, icon_url, issues_url,\n source_url, wiki_url, status, requested_status, discord_url,\n license_url, license,\n slug, color, monetization_status\n )\n VALUES (\n $1, $2, $3, $4, $5,\n $6, $7, $8, $9,\n $10, $11, $12, $13, $14,\n $15, $16, \n LOWER($17), $18, $19\n )\n ", + "query": "\n INSERT INTO mods (\n id, team_id, title, description, body,\n published, downloads, icon_url, status, requested_status,\n license_url, license,\n slug, color, monetization_status\n )\n VALUES (\n $1, $2, $3, $4, $5, $6, \n $7, $8, $9, $10, \n $11, $12, \n LOWER($13), $14, $15\n )\n ", "describe": { "columns": [], "parameters": { @@ -17,10 +17,6 @@ "Varchar", "Varchar", "Varchar", - "Varchar", - "Varchar", - "Varchar", - "Varchar", "Text", "Int4", "Varchar" @@ -28,5 +24,5 @@ }, "nullable": [] }, - "hash": "fefb4f07a0f0c0cf74e554d120f8707d698fc8b4dbb66d2830f4ec0229bc1019" + "hash": "83dc16cc7a0f4507e308a06f4924065e4ea25de0210be222ceae8eb645f888e3" } diff --git a/.sqlx/query-872374755deb5d68092dff9fcbc355da7c5c9cea4b471e79b17c4a9cfd6f9954.json b/.sqlx/query-872374755deb5d68092dff9fcbc355da7c5c9cea4b471e79b17c4a9cfd6f9954.json new file mode 100644 index 00000000..1dac397e --- /dev/null +++ b/.sqlx/query-872374755deb5d68092dff9fcbc355da7c5c9cea4b471e79b17c4a9cfd6f9954.json @@ -0,0 +1,14 @@ +{ + "db_name": "PostgreSQL", + "query": "\n DELETE FROM mods_links\n WHERE joining_mod_id = $1\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8" + ] + }, + "nullable": [] + }, + "hash": "872374755deb5d68092dff9fcbc355da7c5c9cea4b471e79b17c4a9cfd6f9954" +} diff --git a/.sqlx/query-88a085c2f2b1aa11eacdeedb68b490a695ebf2a9efb24bd5715b8d903f57e2c5.json b/.sqlx/query-88a085c2f2b1aa11eacdeedb68b490a695ebf2a9efb24bd5715b8d903f57e2c5.json new file mode 100644 index 00000000..fd7b63b9 --- /dev/null +++ b/.sqlx/query-88a085c2f2b1aa11eacdeedb68b490a695ebf2a9efb24bd5715b8d903f57e2c5.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "\n DELETE FROM mods_links\n WHERE joining_mod_id = $1 AND joining_platform_id IN (\n SELECT id FROM link_platforms WHERE name = ANY($2)\n )\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8", + "TextArray" + ] + }, + "nullable": [] + }, + "hash": "88a085c2f2b1aa11eacdeedb68b490a695ebf2a9efb24bd5715b8d903f57e2c5" +} diff --git a/.sqlx/query-8abb317c85f48c7dd9ccf4a7b8fbc0b58ac73f7ae87ff2dfe67009a51089f784.json b/.sqlx/query-8abb317c85f48c7dd9ccf4a7b8fbc0b58ac73f7ae87ff2dfe67009a51089f784.json deleted file mode 100644 index fc2c3450..00000000 --- a/.sqlx/query-8abb317c85f48c7dd9ccf4a7b8fbc0b58ac73f7ae87ff2dfe67009a51089f784.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE mods\n SET wiki_url = $1\n WHERE (id = $2)\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Varchar", - "Int8" - ] - }, - "nullable": [] - }, - "hash": "8abb317c85f48c7dd9ccf4a7b8fbc0b58ac73f7ae87ff2dfe67009a51089f784" -} diff --git a/.sqlx/query-99a1eac69d7f5a5139703df431e6a5c3012a90143a8c635f93632f04d0bc41d4.json b/.sqlx/query-99a1eac69d7f5a5139703df431e6a5c3012a90143a8c635f93632f04d0bc41d4.json deleted file mode 100644 index aba372c1..00000000 --- a/.sqlx/query-99a1eac69d7f5a5139703df431e6a5c3012a90143a8c635f93632f04d0bc41d4.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE mods\n SET wiki_url = $1\n WHERE (id = $2)\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Varchar", - "Int8" - ] - }, - "nullable": [] - }, - "hash": "99a1eac69d7f5a5139703df431e6a5c3012a90143a8c635f93632f04d0bc41d4" -} diff --git a/.sqlx/query-9aab2350d576fd934b0541d1f71f320ac939b44a179fee3d1638113cdb3ddfe7.json b/.sqlx/query-9aab2350d576fd934b0541d1f71f320ac939b44a179fee3d1638113cdb3ddfe7.json deleted file mode 100644 index 7683ee0c..00000000 --- a/.sqlx/query-9aab2350d576fd934b0541d1f71f320ac939b44a179fee3d1638113cdb3ddfe7.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n INSERT INTO mods_donations (joining_mod_id, joining_platform_id, url)\n VALUES ($1, $2, $3)\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8", - "Int4", - "Varchar" - ] - }, - "nullable": [] - }, - "hash": "9aab2350d576fd934b0541d1f71f320ac939b44a179fee3d1638113cdb3ddfe7" -} diff --git a/.sqlx/query-acbafe265c4b7a1c95b0494a0a03c8bd2cd778ae561ef5a662fa931ca26cf603.json b/.sqlx/query-acbafe265c4b7a1c95b0494a0a03c8bd2cd778ae561ef5a662fa931ca26cf603.json deleted file mode 100644 index 9cbd917c..00000000 --- a/.sqlx/query-acbafe265c4b7a1c95b0494a0a03c8bd2cd778ae561ef5a662fa931ca26cf603.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n DELETE FROM mods_donations\n WHERE joining_mod_id = $1\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8" - ] - }, - "nullable": [] - }, - "hash": "acbafe265c4b7a1c95b0494a0a03c8bd2cd778ae561ef5a662fa931ca26cf603" -} diff --git a/.sqlx/query-d8020ed838c032c2c287dc0f08989b3ab7156f2571bc75505e6f57b0caeef9c7.json b/.sqlx/query-b1bfb62f4a28ca0fae778738e8a8f325185a83c5d5a240c088a2397b35c55f2a.json similarity index 59% rename from .sqlx/query-d8020ed838c032c2c287dc0f08989b3ab7156f2571bc75505e6f57b0caeef9c7.json rename to .sqlx/query-b1bfb62f4a28ca0fae778738e8a8f325185a83c5d5a240c088a2397b35c55f2a.json index c8e8481e..5610c103 100644 --- a/.sqlx/query-d8020ed838c032c2c287dc0f08989b3ab7156f2571bc75505e6f57b0caeef9c7.json +++ b/.sqlx/query-b1bfb62f4a28ca0fae778738e8a8f325185a83c5d5a240c088a2397b35c55f2a.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT id FROM donation_platforms\n WHERE short = $1\n ", + "query": "\n SELECT id FROM link_platforms\n WHERE name = $1\n ", "describe": { "columns": [ { @@ -18,5 +18,5 @@ false ] }, - "hash": "d8020ed838c032c2c287dc0f08989b3ab7156f2571bc75505e6f57b0caeef9c7" + "hash": "b1bfb62f4a28ca0fae778738e8a8f325185a83c5d5a240c088a2397b35c55f2a" } diff --git a/.sqlx/query-bad7cae347771e801976c26f2afaf33bda371051923b8f74a2f32a0ef5c65e57.json b/.sqlx/query-bad7cae347771e801976c26f2afaf33bda371051923b8f74a2f32a0ef5c65e57.json deleted file mode 100644 index 1ab92b4c..00000000 --- a/.sqlx/query-bad7cae347771e801976c26f2afaf33bda371051923b8f74a2f32a0ef5c65e57.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE mods\n SET discord_url = $1\n WHERE (id = $2)\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Varchar", - "Int8" - ] - }, - "nullable": [] - }, - "hash": "bad7cae347771e801976c26f2afaf33bda371051923b8f74a2f32a0ef5c65e57" -} diff --git a/.sqlx/query-bc91841f9672608a28bd45a862919f2bd34fac0b3479e3b4b67a9f6bea2a562a.json b/.sqlx/query-bc91841f9672608a28bd45a862919f2bd34fac0b3479e3b4b67a9f6bea2a562a.json deleted file mode 100644 index fb1b14f1..00000000 --- a/.sqlx/query-bc91841f9672608a28bd45a862919f2bd34fac0b3479e3b4b67a9f6bea2a562a.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE mods\n SET issues_url = $1\n WHERE (id = $2)\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Varchar", - "Int8" - ] - }, - "nullable": [] - }, - "hash": "bc91841f9672608a28bd45a862919f2bd34fac0b3479e3b4b67a9f6bea2a562a" -} diff --git a/.sqlx/query-e3fb74a94a6a78b1007dd99ad11bdcfaa0957ed7d1683997aef7301e0f15baba.json b/.sqlx/query-e3fb74a94a6a78b1007dd99ad11bdcfaa0957ed7d1683997aef7301e0f15baba.json deleted file mode 100644 index ab0f3449..00000000 --- a/.sqlx/query-e3fb74a94a6a78b1007dd99ad11bdcfaa0957ed7d1683997aef7301e0f15baba.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE mods\n SET issues_url = $1\n WHERE (id = $2)\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Varchar", - "Int8" - ] - }, - "nullable": [] - }, - "hash": "e3fb74a94a6a78b1007dd99ad11bdcfaa0957ed7d1683997aef7301e0f15baba" -} diff --git a/.sqlx/query-76db1c204139e18002e5751c3dcefff79791a1dd852b62d34fcf008151e8945a.json b/.sqlx/query-fef7802edefa1a6957fa43ccf64b987c3547294f0c8581028ac6b83de42b3a00.json similarity index 64% rename from .sqlx/query-76db1c204139e18002e5751c3dcefff79791a1dd852b62d34fcf008151e8945a.json rename to .sqlx/query-fef7802edefa1a6957fa43ccf64b987c3547294f0c8581028ac6b83de42b3a00.json index a16f796c..bcca3ff2 100644 --- a/.sqlx/query-76db1c204139e18002e5751c3dcefff79791a1dd852b62d34fcf008151e8945a.json +++ b/.sqlx/query-fef7802edefa1a6957fa43ccf64b987c3547294f0c8581028ac6b83de42b3a00.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT id, short, name FROM donation_platforms\n ", + "query": "\n SELECT id, name, donation FROM link_platforms\n ", "describe": { "columns": [ { @@ -10,13 +10,13 @@ }, { "ordinal": 1, - "name": "short", + "name": "name", "type_info": "Varchar" }, { "ordinal": 2, - "name": "name", - "type_info": "Varchar" + "name": "donation", + "type_info": "Bool" } ], "parameters": { @@ -28,5 +28,5 @@ false ] }, - "hash": "76db1c204139e18002e5751c3dcefff79791a1dd852b62d34fcf008151e8945a" + "hash": "fef7802edefa1a6957fa43ccf64b987c3547294f0c8581028ac6b83de42b3a00" } diff --git a/src/database/models/categories.rs b/src/database/models/categories.rs index d34e0206..4e04dba5 100644 --- a/src/database/models/categories.rs +++ b/src/database/models/categories.rs @@ -130,10 +130,7 @@ impl Category { } impl LinkPlatform { - pub async fn get_id<'a, E>( - id: &str, - exec: E, - ) -> Result, DatabaseError> + pub async fn get_id<'a, E>(id: &str, exec: E) -> Result, DatabaseError> where E: sqlx::Executor<'a, Database = sqlx::Postgres>, { @@ -150,10 +147,7 @@ impl LinkPlatform { Ok(result.map(|r| LinkPlatformId(r.id))) } - pub async fn list<'a, E>( - exec: E, - redis: &RedisPool, - ) -> Result, DatabaseError> + pub async fn list<'a, E>(exec: E, redis: &RedisPool) -> Result, DatabaseError> where E: sqlx::Executor<'a, Database = sqlx::Postgres>, { diff --git a/src/database/models/project_item.rs b/src/database/models/project_item.rs index 189b50a0..3b666953 100644 --- a/src/database/models/project_item.rs +++ b/src/database/models/project_item.rs @@ -212,8 +212,7 @@ impl ProjectBuilder { version.insert(&mut *transaction).await?; } - LinkUrl::insert_many_projects(link_urls, self.project_id, &mut *transaction) - .await?; + LinkUrl::insert_many_projects(link_urls, self.project_id, &mut *transaction).await?; GalleryItem::insert_many(gallery_items, self.project_id, &mut *transaction).await?; diff --git a/src/models/v2/projects.rs b/src/models/v2/projects.rs index 0086409a..b89a11e1 100644 --- a/src/models/v2/projects.rs +++ b/src/models/v2/projects.rs @@ -8,8 +8,8 @@ use crate::database::models::{version_item, DatabaseError}; use crate::database::redis::RedisPool; use crate::models::ids::{ProjectId, VersionId}; use crate::models::projects::{ - Dependency, GalleryItem, License, Loader, ModeratorMessage, MonetizationStatus, - Project, ProjectStatus, Version, VersionFile, VersionStatus, VersionType, Link, + Dependency, GalleryItem, License, Link, Loader, ModeratorMessage, MonetizationStatus, Project, + ProjectStatus, Version, VersionFile, VersionStatus, VersionType, }; use crate::models::threads::ThreadId; use chrono::{DateTime, Utc}; @@ -125,25 +125,17 @@ impl LegacyProject { } } } - - let issues_url = data - .link_urls.get("issues") - .map(|l| l.url.clone()); - let source_url = data - .link_urls.get("source") - .map(|l| l.url.clone()); - let wiki_url = data - .link_urls.get("wiki") - .map(|l| l.url.clone()); - let discord_url = data - .link_urls.get("discord") - .map(|l| l.url.clone()); + + let issues_url = data.link_urls.get("issues").map(|l| l.url.clone()); + let source_url = data.link_urls.get("source").map(|l| l.url.clone()); + let wiki_url = data.link_urls.get("wiki").map(|l| l.url.clone()); + let discord_url = data.link_urls.get("discord").map(|l| l.url.clone()); let donation_urls = data .link_urls .iter() - .filter(|(_,l)| l.donation) - .map(|(_,l)| DonationLink::try_from(l.clone()).ok()) + .filter(|(_, l)| l.donation) + .map(|(_, l)| DonationLink::try_from(l.clone()).ok()) .collect::>>(); Self { diff --git a/src/models/v3/projects.rs b/src/models/v3/projects.rs index 2cb61c5f..5ded13ee 100644 --- a/src/models/v3/projects.rs +++ b/src/models/v3/projects.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use super::ids::{Base62Id, OrganizationId}; use super::teams::TeamId; use super::users::UserId; -use crate::database::models::project_item::{QueryProject, LinkUrl}; +use crate::database::models::project_item::{LinkUrl, QueryProject}; use crate::database::models::version_item::QueryVersion; use crate::models::threads::ThreadId; use chrono::{DateTime, Utc}; @@ -89,7 +89,7 @@ pub struct Project { pub icon_url: Option, /// A collection of links to the project's various pages. - pub link_urls : HashMap, + pub link_urls: HashMap, /// A string of URLs to visual content featuring the project pub gallery: Vec, @@ -160,11 +160,11 @@ impl From for Project { loaders: m.loaders, versions: data.versions.into_iter().map(|v| v.into()).collect(), icon_url: m.icon_url, - link_urls: - data.urls - .into_iter() - .map(|d| (d.platform_name.clone(), Link::from(d))) - .collect(), + link_urls: data + .urls + .into_iter() + .map(|d| (d.platform_name.clone(), Link::from(d))) + .collect(), gallery: data .gallery_items .into_iter() diff --git a/src/routes/v2/project_creation.rs b/src/routes/v2/project_creation.rs index 466fb830..faeeb69d 100644 --- a/src/routes/v2/project_creation.rs +++ b/src/routes/v2/project_creation.rs @@ -4,7 +4,7 @@ use crate::file_hosting::FileHost; use crate::models; use crate::models::ids::ImageId; use crate::models::projects::{Loader, Project, ProjectStatus, SideType}; -use crate::models::v2::projects::{LegacyProject, DonationLink}; +use crate::models::v2::projects::{DonationLink, LegacyProject}; use crate::queue::session::AuthQueue; use crate::routes::v3::project_creation::default_project_type; use crate::routes::v3::project_creation::{CreateError, NewGalleryItem}; @@ -212,7 +212,7 @@ pub async fn project_create( link_urls.insert(donation_url.platform, donation_url.url); } } - + Ok(v3::project_creation::ProjectCreateData { title: legacy_create.title, slug: legacy_create.slug, diff --git a/src/routes/v2/projects.rs b/src/routes/v2/projects.rs index 572a5baf..6e1244e1 100644 --- a/src/routes/v2/projects.rs +++ b/src/routes/v2/projects.rs @@ -4,9 +4,9 @@ use crate::database::redis::RedisPool; use crate::file_hosting::FileHost; use crate::models; use crate::models::projects::{ - MonetizationStatus, Project, ProjectStatus, SearchRequest, SideType, Link, + Link, MonetizationStatus, Project, ProjectStatus, SearchRequest, SideType, }; -use crate::models::v2::projects::{LegacyProject, DonationLink}; +use crate::models::v2::projects::{DonationLink, LegacyProject}; use crate::queue::session::AuthQueue; use crate::routes::v3::projects::ProjectIds; use crate::routes::{v2_reroute, v3, ApiError}; @@ -342,7 +342,7 @@ pub async fn project_edit( new_links.insert("issues".to_string(), None); } } - + if let Some(source_url) = v2_new_project.source_url { if let Some(source_url) = source_url { new_links.insert("source".to_string(), Some(source_url)); @@ -373,13 +373,20 @@ pub async fn project_edit( // Fetch current donation links from project so we know what to delete // Todo ensure secure let fetched_example_project = project_item::Project::get(&info.0, &**pool, &redis).await?; - let donation_links = fetched_example_project.map(|x| - x.urls.into_iter().filter_map(|l| - if l.donation { - Some(Link::from(l)) // TODO: tests - - } else { None }).collect::>() - ).unwrap_or_default(); + let donation_links = fetched_example_project + .map(|x| { + x.urls + .into_iter() + .filter_map(|l| { + if l.donation { + Some(Link::from(l)) // TODO: tests + } else { + None + } + }) + .collect::>() + }) + .unwrap_or_default(); // Set existing donation links to None for old_link in donation_links { @@ -391,7 +398,6 @@ pub async fn project_edit( new_links.insert(donation_url.id, Some(donation_url.url)); } } - let new_project = v3::projects::EditProject { title: v2_new_project.title, @@ -524,10 +530,10 @@ pub async fn projects_edit( session_queue: web::Data, ) -> Result { let bulk_edit_project = bulk_edit_project.into_inner(); - + let mut link_urls = HashMap::new(); - // If we are *setting* donation links, we will set every possible donation link to None, as + // If we are *setting* donation links, we will set every possible donation link to None, as // setting will delete all of them then 're-add' the ones we want to keep if let Some(donation_url) = bulk_edit_project.donation_urls { let link_platforms = LinkPlatform::list(&**pool, &redis).await?; @@ -586,7 +592,7 @@ pub async fn projects_edit( } else { link_urls.insert("discord".to_string(), None); } - } + } v3::projects::projects_edit( req, diff --git a/src/routes/v2/tags.rs b/src/routes/v2/tags.rs index 28903be4..535ec0bc 100644 --- a/src/routes/v2/tags.rs +++ b/src/routes/v2/tags.rs @@ -3,7 +3,9 @@ use std::collections::HashMap; use super::ApiError; use crate::database::models::loader_fields::LoaderFieldEnumValue; use crate::database::redis::RedisPool; -use crate::routes::v3::tags::{LoaderData as LoaderDataV3, LoaderFieldsEnumQuery, LinkPlatformQueryData}; +use crate::routes::v3::tags::{ + LinkPlatformQueryData, LoaderData as LoaderDataV3, LoaderFieldsEnumQuery, +}; use crate::routes::{v2_reroute, v3}; use actix_web::{get, web, HttpResponse}; use chrono::{DateTime, Utc}; @@ -174,16 +176,14 @@ pub async fn donation_platform_list( redis: web::Data, ) -> Result { let response = v3::tags::link_platform_list(pool, redis).await?; - + // Convert to V2 format Ok( match v2_reroute::extract_ok_json::>(response).await { Ok(platforms) => { let platforms = platforms .into_iter() - .map(|p| DonationPlatformQueryData { - name: p.name, - }) + .map(|p| DonationPlatformQueryData { name: p.name }) .collect::>(); HttpResponse::Ok().json(platforms) } diff --git a/src/routes/v3/project_creation.rs b/src/routes/v3/project_creation.rs index 9182a65b..535eb3d8 100644 --- a/src/routes/v3/project_creation.rs +++ b/src/routes/v3/project_creation.rs @@ -10,7 +10,7 @@ use crate::models::ids::{ImageId, OrganizationId}; use crate::models::images::{Image, ImageContext}; use crate::models::pats::Scopes; use crate::models::projects::{ - Link, License, MonetizationStatus, ProjectId, ProjectStatus, VersionId, VersionStatus, + License, Link, MonetizationStatus, ProjectId, ProjectStatus, VersionId, VersionStatus, }; use crate::models::teams::ProjectPermissions; use crate::models::threads::ThreadType; @@ -190,9 +190,7 @@ pub struct ProjectCreateData { /// An optional link to the project's license page pub license_url: Option, /// An optional list of all donation links the project has - #[validate( - custom(function = "crate::util::validate::validate_url_hashmap_values"), - )] + #[validate(custom(function = "crate::util::validate::validate_url_hashmap_values"))] #[serde(default)] pub link_urls: HashMap, @@ -648,10 +646,11 @@ async fn project_create_inner( let mut link_urls = vec![]; - let link_platforms = models::categories::LinkPlatform::list(&mut **transaction, redis).await?; + let link_platforms = + models::categories::LinkPlatform::list(&mut **transaction, redis).await?; for (platform, url) in &project_create_data.link_urls { let platform_id = - models::categories::LinkPlatform::get_id(&platform, &mut **transaction) + models::categories::LinkPlatform::get_id(platform, &mut **transaction) .await? .ok_or_else(|| { CreateError::InvalidInput(format!( @@ -813,12 +812,12 @@ async fn project_create_inner( .map(|v| v.version_id.into()) .collect::>(), icon_url: project_builder.icon_url.clone(), - link_urls: project_builder.link_urls.clone().into_iter().map(|x| { - ( - x.platform_name.clone(), - Link::from(x), - ) - }).collect(), + link_urls: project_builder + .link_urls + .clone() + .into_iter() + .map(|x| (x.platform_name.clone(), Link::from(x))) + .collect(), gallery: gallery_urls, color: project_builder.color, thread_id: thread_id.into(), diff --git a/src/routes/v3/projects.rs b/src/routes/v3/projects.rs index 9377b973..ae91fcaf 100644 --- a/src/routes/v3/projects.rs +++ b/src/routes/v3/projects.rs @@ -194,11 +194,9 @@ pub struct EditProject { length(max = 2048) )] pub license_url: Option>, - #[validate( - custom(function = "crate::util::validate::validate_url_hashmap_optional_values"), - )] + #[validate(custom(function = "crate::util::validate::validate_url_hashmap_optional_values"))] // (leave url empty to delete) - pub link_urls: Option>>, + pub link_urls: Option>>, pub license_id: Option, #[validate( length(min = 3, max = 64), @@ -687,12 +685,14 @@ pub async fn project_edit( ", id as db_ids::ProjectId, &ids_to_delete - ).execute(&mut *transaction).await?; + ) + .execute(&mut *transaction) + .await?; for (platform, url) in links { if let Some(url) = url { let platform_id = db_models::categories::LinkPlatform::get_id( - &platform, + platform, &mut *transaction, ) .await? @@ -712,7 +712,7 @@ pub async fn project_edit( url ) .execute(&mut *transaction) - .await?; + .await?; } } } @@ -1025,9 +1025,7 @@ pub struct BulkEditProject { pub add_additional_categories: Option>, pub remove_additional_categories: Option>, - #[validate( - custom(function = " crate::util::validate::validate_url_hashmap_optional_values") - )] + #[validate(custom(function = " crate::util::validate::validate_url_hashmap_optional_values"))] pub link_urls: Option>>, } @@ -1188,7 +1186,9 @@ pub async fn projects_edit( ", project.inner.id as db_ids::ProjectId, &ids_to_delete - ).execute(&mut *transaction).await?; + ) + .execute(&mut *transaction) + .await?; for (platform, url) in links { if let Some(url) = url { @@ -1213,7 +1213,6 @@ pub async fn projects_edit( ) .execute(&mut *transaction) .await?; - } } } diff --git a/src/routes/v3/tags.rs b/src/routes/v3/tags.rs index 9f8ca62a..859de079 100644 --- a/src/routes/v3/tags.rs +++ b/src/routes/v3/tags.rs @@ -214,9 +214,7 @@ pub async fn link_platform_list( let results: Vec = LinkPlatform::list(&**pool, &redis) .await? .into_iter() - .map(|x| LinkPlatformQueryData { - name: x.name, - }) + .map(|x| LinkPlatformQueryData { name: x.name }) .collect(); Ok(HttpResponse::Ok().json(results)) } diff --git a/src/util/validate.rs b/src/util/validate.rs index 70f171b7..93ae5087 100644 --- a/src/util/validate.rs +++ b/src/util/validate.rs @@ -96,10 +96,8 @@ pub fn validate_url(value: &str) -> Result<(), validator::ValidationError> { pub fn validate_url_hashmap_optional_values( values: &std::collections::HashMap>, ) -> Result<(), validator::ValidationError> { - for value in values.values() { - if let Some(value) = value { - validate_url(value)?; - } + for value in values.values().flatten() { + validate_url(value)?; } Ok(()) diff --git a/tests/common/api_common/models.rs b/tests/common/api_common/models.rs index 5fb6ae94..a186b76d 100644 --- a/tests/common/api_common/models.rs +++ b/tests/common/api_common/models.rs @@ -3,8 +3,8 @@ use labrinth::models::{ notifications::{NotificationAction, NotificationBody, NotificationId}, organizations::OrganizationId, projects::{ - Dependency, GalleryItem, License, ModeratorMessage, MonetizationStatus, - ProjectId, ProjectStatus, VersionFile, VersionId, VersionStatus, VersionType, + Dependency, GalleryItem, License, ModeratorMessage, MonetizationStatus, ProjectId, + ProjectStatus, VersionFile, VersionId, VersionStatus, VersionType, }, teams::{OrganizationPermissions, ProjectPermissions, TeamId}, threads::ThreadId, diff --git a/tests/common/api_v3/project.rs b/tests/common/api_v3/project.rs index 89fcf9f4..c031efcd 100644 --- a/tests/common/api_v3/project.rs +++ b/tests/common/api_v3/project.rs @@ -8,7 +8,7 @@ use actix_web::{ use async_trait::async_trait; use bytes::Bytes; use chrono::{DateTime, Utc}; -use labrinth::{search::SearchResults, util::actix::AppendsMultipart, models::projects::Project}; +use labrinth::{models::projects::Project, search::SearchResults, util::actix::AppendsMultipart}; use rust_decimal::Decimal; use serde_json::json; diff --git a/tests/project.rs b/tests/project.rs index 7556575d..c83da7e8 100644 --- a/tests/project.rs +++ b/tests/project.rs @@ -6,7 +6,7 @@ use common::api_v3::ApiV3; use common::database::*; use common::dummy_data::DUMMY_CATEGORIES; -use common::environment::{with_test_environment_all, TestEnvironment, with_test_environment}; +use common::environment::{with_test_environment, with_test_environment_all, TestEnvironment}; use common::permissions::{PermissionsTest, PermissionsTestContext}; use futures::StreamExt; use labrinth::database::models::project_item::{PROJECTS_NAMESPACE, PROJECTS_SLUGS_NAMESPACE}; @@ -288,7 +288,7 @@ async fn test_add_remove_project() { #[actix_rt::test] pub async fn test_patch_project() { - with_test_environment(None, |test_env : TestEnvironment| async move { + with_test_environment(None, |test_env: TestEnvironment| async move { let api = &test_env.api; let alpha_project_slug = &test_env.dummy.as_ref().unwrap().project_alpha.project_slug; @@ -410,7 +410,7 @@ pub async fn test_patch_project() { "body": "New successful body", "categories": [DUMMY_CATEGORIES[0]], "license_id": "MIT", - "link_urls": + "link_urls": { "patreon": "https://patreon.com", "issues": "https://github.com", @@ -429,9 +429,7 @@ pub async fn test_patch_project() { assert_eq!(resp.status(), 404); // New slug does work - let project = api - .get_project_deserialized("newslug", USER_USER_PAT) - .await; + let project = api.get_project_deserialized("newslug", USER_USER_PAT).await; assert_eq!(project.slug.unwrap(), "newslug"); assert_eq!(project.title, "New successful title"); @@ -444,23 +442,23 @@ pub async fn test_patch_project() { assert_eq!(link_urls.len(), 4); assert_eq!(link_urls["patreon"].platform, "patreon"); assert_eq!(link_urls["patreon"].url, "https://patreon.com"); - assert_eq!(link_urls["patreon"].donation, true); + assert!(link_urls["patreon"].donation); assert_eq!(link_urls["issues"].platform, "issues"); assert_eq!(link_urls["issues"].url, "https://github.com"); - assert_eq!(link_urls["issues"].donation, false); + assert!(!link_urls["issues"].donation); assert_eq!(link_urls["discord"].platform, "discord"); assert_eq!(link_urls["discord"].url, "https://discord.gg"); - assert_eq!(link_urls["discord"].donation, false); + assert!(!link_urls["discord"].donation); assert_eq!(link_urls["wiki"].platform, "wiki"); assert_eq!(link_urls["wiki"].url, "https://wiki.com"); - assert_eq!(link_urls["wiki"].donation, false); + assert!(!link_urls["wiki"].donation); // Unset the set link_urls let resp = api .edit_project( "newslug", json!({ - "link_urls": + "link_urls": { "issues": null, } @@ -470,11 +468,9 @@ pub async fn test_patch_project() { .await; println!("{:?}", resp.response().body()); assert_eq!(resp.status(), 204); - let project = api - .get_project_deserialized("newslug", USER_USER_PAT) - .await; + let project = api.get_project_deserialized("newslug", USER_USER_PAT).await; assert_eq!(project.link_urls.len(), 3); - assert_eq!(project.link_urls.contains_key("issues"), false); + assert!(!project.link_urls.contains_key("issues")); }) .await; } @@ -531,18 +527,18 @@ pub async fn test_bulk_edit_links() { // The first loop, sets issue, the second, clears it for all projects. for issues in [Some("https://www.issues.com"), None] { let resp = api - .edit_project_bulk( - &[alpha_project_id, beta_project_id], - json!({ - "link_urls": { - "issues": issues, - "wiki": "https://wiki.com", - "patreon": "https://patreon.com", - }, - }), - ADMIN_USER_PAT, - ) - .await; + .edit_project_bulk( + &[alpha_project_id, beta_project_id], + json!({ + "link_urls": { + "issues": issues, + "wiki": "https://wiki.com", + "patreon": "https://patreon.com", + }, + }), + ADMIN_USER_PAT, + ) + .await; assert_eq!(resp.status(), StatusCode::NO_CONTENT); let alpha_body = api @@ -553,7 +549,7 @@ pub async fn test_bulk_edit_links() { assert_eq!(alpha_body.link_urls["issues"].url, issues); } else { assert_eq!(alpha_body.link_urls.len(), 2); - assert_eq!(alpha_body.link_urls.contains_key("issues"), false); + assert!(!alpha_body.link_urls.contains_key("issues")); } assert_eq!(alpha_body.link_urls["wiki"].url, "https://wiki.com"); assert_eq!(alpha_body.link_urls["patreon"].url, "https://patreon.com"); @@ -566,7 +562,6 @@ pub async fn test_bulk_edit_links() { beta_body.additional_categories, alpha_body.additional_categories, ); - } }) .await; diff --git a/tests/v2/project.rs b/tests/v2/project.rs index 35f9bce3..dbac112f 100644 --- a/tests/v2/project.rs +++ b/tests/v2/project.rs @@ -1,7 +1,10 @@ use crate::common::{ api_common::ApiProject, api_v2::ApiV2, - database::{ENEMY_USER_PAT, FRIEND_USER_ID, FRIEND_USER_PAT, MOD_USER_PAT, USER_USER_PAT, ADMIN_USER_PAT}, + database::{ + ADMIN_USER_PAT, ENEMY_USER_PAT, FRIEND_USER_ID, FRIEND_USER_PAT, MOD_USER_PAT, + USER_USER_PAT, + }, dummy_data::{TestFile, DUMMY_CATEGORIES}, environment::{with_test_environment, TestEnvironment}, permissions::{PermissionsTest, PermissionsTestContext}, @@ -550,7 +553,7 @@ pub async fn test_bulk_edit_links() { ADMIN_USER_PAT, ) .await; - assert_eq!(resp.status(), StatusCode::NO_CONTENT); + assert_eq!(resp.status(), StatusCode::NO_CONTENT); let alpha_body = api .get_project_deserialized(alpha_project_id, ADMIN_USER_PAT) @@ -558,7 +561,10 @@ pub async fn test_bulk_edit_links() { let donation_urls = alpha_body.donation_urls.unwrap(); assert_eq!(donation_urls.len(), 1); assert_eq!(donation_urls[0].url, "https://www.patreon.com/my_user"); - assert_eq!(alpha_body.issues_url, Some("https://github.com".to_string())); + assert_eq!( + alpha_body.issues_url, + Some("https://github.com".to_string()) + ); assert_eq!(alpha_body.discord_url, None); let beta_body = api @@ -571,92 +577,118 @@ pub async fn test_bulk_edit_links() { assert_eq!(beta_body.discord_url, None); let resp = api - .edit_project_bulk( - &[alpha_project_id, beta_project_id], - json!({ - "discord_url": "https://discord.gg", - "issues_url": null, - "add_donation_urls": [ - { - "id": "bmac", - "platform": "Buy Me a Coffee", - "url": "https://www.buymeacoffee.com/my_user" - } - ], - }), - ADMIN_USER_PAT, - ) - .await; + .edit_project_bulk( + &[alpha_project_id, beta_project_id], + json!({ + "discord_url": "https://discord.gg", + "issues_url": null, + "add_donation_urls": [ + { + "id": "bmac", + "platform": "Buy Me a Coffee", + "url": "https://www.buymeacoffee.com/my_user" + } + ], + }), + ADMIN_USER_PAT, + ) + .await; assert_eq!(resp.status(), StatusCode::NO_CONTENT); let alpha_body = api .get_project_deserialized(alpha_project_id, ADMIN_USER_PAT) .await; - let donation_urls = alpha_body.donation_urls.unwrap().into_iter().sorted_by_key(|x| x.id.clone()).collect_vec(); + let donation_urls = alpha_body + .donation_urls + .unwrap() + .into_iter() + .sorted_by_key(|x| x.id.clone()) + .collect_vec(); assert_eq!(donation_urls.len(), 2); assert_eq!(donation_urls[0].url, "https://www.buymeacoffee.com/my_user"); assert_eq!(donation_urls[1].url, "https://www.patreon.com/my_user"); assert_eq!(alpha_body.issues_url, None); - assert_eq!(alpha_body.discord_url, Some("https://discord.gg".to_string())); + assert_eq!( + alpha_body.discord_url, + Some("https://discord.gg".to_string()) + ); let beta_body = api .get_project_deserialized(beta_project_id, ADMIN_USER_PAT) .await; - let donation_urls = beta_body.donation_urls.unwrap().into_iter().sorted_by_key(|x| x.id.clone()).collect_vec(); + let donation_urls = beta_body + .donation_urls + .unwrap() + .into_iter() + .sorted_by_key(|x| x.id.clone()) + .collect_vec(); assert_eq!(donation_urls.len(), 2); assert_eq!(donation_urls[0].url, "https://www.buymeacoffee.com/my_user"); assert_eq!(donation_urls[1].url, "https://www.patreon.com/my_user"); assert_eq!(alpha_body.issues_url, None); - assert_eq!(alpha_body.discord_url, Some("https://discord.gg".to_string())); + assert_eq!( + alpha_body.discord_url, + Some("https://discord.gg".to_string()) + ); let resp = api - .edit_project_bulk( - &[alpha_project_id, beta_project_id], - json!({ - "donation_urls": [ - { - "id": "patreon", - "platform": "Patreon", - "url": "https://www.patreon.com/my_user" - }, - { - "id": "ko-fi", - "platform": "Ko-fi", - "url": "https://www.ko-fi.com/my_user" - } - ], - "add_donation_urls": [ - { - "id": "paypal", - "platform": "PayPal", - "url": "https://www.paypal.com/my_user" - } - ], - "remove_donation_urls": [ - { - "id": "ko-fi", - "platform": "Ko-fi", - "url": "https://www.ko-fi.com/my_user" - } - ], - }), - ADMIN_USER_PAT, - ) - .await; + .edit_project_bulk( + &[alpha_project_id, beta_project_id], + json!({ + "donation_urls": [ + { + "id": "patreon", + "platform": "Patreon", + "url": "https://www.patreon.com/my_user" + }, + { + "id": "ko-fi", + "platform": "Ko-fi", + "url": "https://www.ko-fi.com/my_user" + } + ], + "add_donation_urls": [ + { + "id": "paypal", + "platform": "PayPal", + "url": "https://www.paypal.com/my_user" + } + ], + "remove_donation_urls": [ + { + "id": "ko-fi", + "platform": "Ko-fi", + "url": "https://www.ko-fi.com/my_user" + } + ], + }), + ADMIN_USER_PAT, + ) + .await; assert_eq!(resp.status(), StatusCode::NO_CONTENT); let alpha_body = api .get_project_deserialized(alpha_project_id, ADMIN_USER_PAT) .await; - let donation_urls = alpha_body.donation_urls.unwrap().into_iter().sorted_by_key(|x| x.id.clone()).collect_vec(); + let donation_urls = alpha_body + .donation_urls + .unwrap() + .into_iter() + .sorted_by_key(|x| x.id.clone()) + .collect_vec(); assert_eq!(donation_urls.len(), 2); assert_eq!(donation_urls[0].url, "https://www.patreon.com/my_user"); assert_eq!(donation_urls[1].url, "https://www.paypal.com/my_user"); - + let beta_body = api .get_project_deserialized(beta_project_id, ADMIN_USER_PAT) .await; - let donation_urls = beta_body.donation_urls.unwrap().into_iter().sorted_by_key(|x| x.id.clone()).collect_vec(); + let donation_urls = beta_body + .donation_urls + .unwrap() + .into_iter() + .sorted_by_key(|x| x.id.clone()) + .collect_vec(); assert_eq!(donation_urls.len(), 2); assert_eq!(donation_urls[0].url, "https://www.patreon.com/my_user"); assert_eq!(donation_urls[1].url, "https://www.paypal.com/my_user");