This commit is contained in:
Fbase965
2026-03-11 12:46:53 +00:00
parent 7ad9b36249
commit 1ceffa0dea
87 changed files with 8133 additions and 353 deletions

View File

@@ -0,0 +1,90 @@
import { HttpClient } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { Observable, map } from 'rxjs';
type QueryResult<T> = { docs: T[] };
@Injectable({ providedIn: 'root' })
export class SpacexApiService {
private readonly http = inject(HttpClient);
private readonly baseUrl = 'https://api.spacexdata.com/v4';
getLaunches(): Observable<any[]> {
return this.http
.post<QueryResult<any>>(`${this.baseUrl}/launches/query`, {
query: {},
options: {
sort: { date_utc: -1 },
pagination: false,
populate: [
{ path: 'rocket', select: { name: 1 } },
{ path: 'launchpad', select: { name: 1 } }
]
}
})
.pipe(map((result) => result.docs ?? []));
}
getRockets(): Observable<any[]> {
return this.http
.post<QueryResult<any>>(`${this.baseUrl}/rockets/query`, {
query: {},
options: { sort: { first_flight: -1 }, pagination: false }
})
.pipe(map((result) => result.docs ?? []));
}
getCapsules(): Observable<any[]> {
return this.http
.post<QueryResult<any>>(`${this.baseUrl}/capsules/query`, {
query: {},
options: { sort: { serial: 1 }, pagination: false }
})
.pipe(map((result) => result.docs ?? []));
}
getStarlink(): Observable<any[]> {
return this.http
.post<QueryResult<any>>(`${this.baseUrl}/starlink/query`, {
query: {},
options: {
select: {
version: 1,
longitude: 1,
latitude: 1,
height_km: 1,
velocity_kms: 1,
spaceTrack: 1
},
limit: 120,
sort: { launch: -1 }
}
})
.pipe(
map((result) =>
(result.docs ?? []).filter((item) => item.latitude !== null && item.longitude !== null)
)
);
}
getLaunchpads(): Observable<any[]> {
return this.http
.post<QueryResult<any>>(`${this.baseUrl}/launchpads/query`, {
query: {},
options: {
pagination: false,
populate: [{ path: 'rockets', select: { name: 1 } }]
}
})
.pipe(map((result) => result.docs ?? []));
}
getLandpads(): Observable<any[]> {
return this.http
.post<QueryResult<any>>(`${this.baseUrl}/landpads/query`, {
query: {},
options: { pagination: false }
})
.pipe(map((result) => result.docs ?? []));
}
}