2323import io .papermc .fill .database .ProjectRepository ;
2424import io .papermc .fill .database .VersionEntity ;
2525import io .papermc .fill .database .VersionRepository ;
26+ import io .papermc .fill .exception .BuildNotFoundException ;
2627import io .papermc .fill .exception .FamilyNotFoundException ;
2728import io .papermc .fill .exception .ProjectNotFoundException ;
2829import io .papermc .fill .graphql .BuildFilters ;
5455import java .util .Comparator ;
5556import java .util .List ;
5657import java .util .Optional ;
58+ import java .util .function .Function ;
5759import java .util .stream .Stream ;
5860import org .jspecify .annotations .NullMarked ;
5961import org .jspecify .annotations .Nullable ;
@@ -266,10 +268,7 @@ public Connection<BuildWithDownloads<DownloadWithUrl>> mapVersionBuilds(
266268 builds = this .builds .findAllByVersion (version , pageable );
267269 }
268270 return BUILD_PAGINATOR .paginate (
269- builds .map (build -> new BuildWithDownloadsImpl <>(build , Downloads .map (build .downloads (), download -> {
270- final URI url = this .storage .getDownloadUrl (project , version , build , download );
271- return download .withUrl (url );
272- }))),
271+ builds .map (this .mapBuild (project , version )),
273272 orderBy != null ? orderBy .direction () : null ,
274273 after ,
275274 before ,
@@ -278,6 +277,18 @@ public Connection<BuildWithDownloads<DownloadWithUrl>> mapVersionBuilds(
278277 );
279278 }
280279
280+ @ SchemaMapping (typeName = "Version" , field = "build" )
281+ public @ Nullable BuildWithDownloads <DownloadWithUrl > mapProjectVersion (
282+ final VersionEntity version ,
283+ @ Argument
284+ final int number
285+ ) {
286+ final ProjectEntity project = this .projects .findById (version .project ()).orElseThrow (ProjectNotFoundException ::new );
287+ return this .builds .findByVersionAndNumber (version ._id (), number )
288+ .map (this .mapBuild (project , version ))
289+ .orElseThrow (BuildNotFoundException ::new );
290+ }
291+
281292 @ SchemaMapping (typeName = "Build" , field = "id" )
282293 public String mapBuildId (final BuildWithDownloads <DownloadWithUrl > build ) {
283294 return build .id ();
@@ -316,4 +327,11 @@ public Collection<DownloadWithUrl> mapBuildDownloads(final BuildWithDownloads<Do
316327 ) {
317328 return build .getDownloadByKey (key );
318329 }
330+
331+ private Function <BuildEntity , BuildWithDownloads <DownloadWithUrl >> mapBuild (final Project project , final Version version ) {
332+ return build -> new BuildWithDownloadsImpl <>(build , Downloads .map (build .downloads (), download -> {
333+ final URI url = this .storage .getDownloadUrl (project , version , build , download );
334+ return download .withUrl (url );
335+ }));
336+ }
319337}
0 commit comments