@@ -73,7 +73,8 @@ pub fn config(cfg: &mut web::ServiceConfig) {
7373 "version/{slug}" ,
7474 web:: get ( ) . to ( super :: versions:: version_project_get) ,
7575 )
76- . route ( "dependencies" , web:: get ( ) . to ( dependency_list) ) ,
76+ . route ( "dependencies" , web:: get ( ) . to ( dependency_list) )
77+ . route ( "dependents" , web:: get ( ) . to ( dependents_list) ) ,
7778 ) ,
7879 ) ;
7980}
@@ -895,6 +896,7 @@ pub async fn project_edit(
895896 project_item. inner . id ,
896897 project_item. inner . slug ,
897898 None ,
899+ None ,
898900 & redis,
899901 )
900902 . await ?;
@@ -1094,6 +1096,82 @@ pub async fn dependency_list(
10941096 }
10951097}
10961098
1099+ pub async fn dependents_list (
1100+ req : HttpRequest ,
1101+ info : web:: Path < ( String , ) > ,
1102+ pool : web:: Data < PgPool > ,
1103+ redis : web:: Data < RedisPool > ,
1104+ session_queue : web:: Data < AuthQueue > ,
1105+ ) -> Result < HttpResponse , ApiError > {
1106+ let string = info. into_inner ( ) . 0 ;
1107+
1108+ let result = db_models:: DBProject :: get ( & string, & * * pool, & redis) . await ?;
1109+
1110+ let user_option = get_user_from_headers (
1111+ & req,
1112+ & * * pool,
1113+ & redis,
1114+ & session_queue,
1115+ Scopes :: PROJECT_READ ,
1116+ )
1117+ . await
1118+ . map ( |x| x. 1 )
1119+ . ok ( ) ;
1120+
1121+ if let Some ( project) = result {
1122+ if !is_visible_project ( & project. inner , & user_option, & pool, false )
1123+ . await ?
1124+ {
1125+ return Err ( ApiError :: NotFound ) ;
1126+ }
1127+
1128+ let dependents = database:: DBProject :: get_dependents (
1129+ project. inner . id ,
1130+ & * * pool,
1131+ & redis,
1132+ )
1133+ . await ?;
1134+ let project_ids =
1135+ dependents. iter ( ) . map ( |x| x. 1 ) . unique ( ) . collect :: < Vec < _ > > ( ) ;
1136+
1137+ let dep_version_ids = dependents
1138+ . iter ( )
1139+ . map ( |x| x. 0 )
1140+ . unique ( )
1141+ . collect :: < Vec < db_models:: DBVersionId > > ( ) ;
1142+ let ( projects_result, versions_result) = futures:: future:: try_join (
1143+ database:: DBProject :: get_many_ids ( & project_ids, & * * pool, & redis) ,
1144+ database:: DBVersion :: get_many ( & dep_version_ids, & * * pool, & redis) ,
1145+ )
1146+ . await ?;
1147+
1148+ let mut projects = filter_visible_projects (
1149+ projects_result,
1150+ & user_option,
1151+ & pool,
1152+ false ,
1153+ )
1154+ . await ?;
1155+ let mut versions = filter_visible_versions (
1156+ versions_result,
1157+ & user_option,
1158+ & pool,
1159+ & redis,
1160+ )
1161+ . await ?;
1162+
1163+ projects. sort_by ( |a, b| b. published . cmp ( & a. published ) ) ;
1164+ projects. dedup_by ( |a, b| a. id == b. id ) ;
1165+
1166+ versions. sort_by ( |a, b| b. date_published . cmp ( & a. date_published ) ) ;
1167+ versions. dedup_by ( |a, b| a. id == b. id ) ;
1168+
1169+ Ok ( HttpResponse :: Ok ( ) . json ( DependencyInfo { projects, versions } ) )
1170+ } else {
1171+ Err ( ApiError :: NotFound )
1172+ }
1173+ }
1174+
10971175pub struct CategoryChanges < ' a > {
10981176 pub categories : & ' a Option < Vec < String > > ,
10991177 pub add_categories : & ' a Option < Vec < String > > ,
@@ -1328,6 +1406,7 @@ pub async fn projects_edit(
13281406 project. inner . id ,
13291407 project. inner . slug ,
13301408 None ,
1409+ None ,
13311410 & redis,
13321411 )
13331412 . await ?;
@@ -1521,6 +1600,7 @@ pub async fn project_icon_edit(
15211600 project_item. inner . id ,
15221601 project_item. inner . slug ,
15231602 None ,
1603+ None ,
15241604 & redis,
15251605 )
15261606 . await ?;
@@ -1610,6 +1690,7 @@ pub async fn delete_project_icon(
16101690 project_item. inner . id ,
16111691 project_item. inner . slug ,
16121692 None ,
1693+ None ,
16131694 & redis,
16141695 )
16151696 . await ?;
@@ -1765,6 +1846,7 @@ pub async fn add_gallery_item(
17651846 project_item. inner . id ,
17661847 project_item. inner . slug ,
17671848 None ,
1849+ None ,
17681850 & redis,
17691851 )
17701852 . await ?;
@@ -1948,6 +2030,7 @@ pub async fn edit_gallery_item(
19482030 project_item. inner . id ,
19492031 project_item. inner . slug ,
19502032 None ,
2033+ None ,
19512034 & redis,
19522035 )
19532036 . await ?;
@@ -2062,6 +2145,7 @@ pub async fn delete_gallery_item(
20622145 project_item. inner . id ,
20632146 project_item. inner . slug ,
20642147 None ,
2148+ None ,
20652149 & redis,
20662150 )
20672151 . await ?;
0 commit comments