Skip to content

Commit

Permalink
Merge pull request #1 from johanah29/jojo
Browse files Browse the repository at this point in the history
Adding capsules and lunches services
  • Loading branch information
johanah29 authored May 5, 2022
2 parents d42aa20 + ce447bf commit 22dcbac
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/app/services/capsules.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { CapsulesService } from './capsules.service';

describe('CapsulesService', () => {
let service: CapsulesService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(CapsulesService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
33 changes: 33 additions & 0 deletions src/app/services/capsules.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';

const CAPSULES_API='https://api.spacexdata.com/v3/capsules'

const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};

@Injectable({
providedIn: 'root'
})
export class CapsulesService {

constructor(private http: HttpClient) { }

public getCapsules():Observable<any> {
return this.http.get<any>(CAPSULES_API, httpOptions);
}

public getOneCapsule(capsule_serial:number):Observable<any> {
return this.http.get<any>(CAPSULES_API+'/'+capsule_serial, httpOptions);
}

public getPastCapsules():Observable<any>{
return this.http.get<any>(CAPSULES_API+'/past');
}

public getUpcomingCapsules():Observable<any>{
return this.http.get<any>(CAPSULES_API+'/upcoming');
}
}
16 changes: 16 additions & 0 deletions src/app/services/launches.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { LaunchesService } from './launches.service';

describe('LaunchesService', () => {
let service: LaunchesService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(LaunchesService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
45 changes: 45 additions & 0 deletions src/app/services/launches.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';


const LAUNCHES_API='https://api.spacexdata.com/v3/launches'

const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};



@Injectable({
providedIn: 'root'
})
export class LaunchesService {

constructor(private http: HttpClient) { }

public getLaunches():Observable<any> {
return this.http.get<any>(LAUNCHES_API, httpOptions);
}

public getOneLaunch(flight_number:number):Observable<any>{
return this.http.get<any>(LAUNCHES_API+'/'+flight_number);
}

public getPastLaunches():Observable<any>{
return this.http.get<any>(LAUNCHES_API+'/past');
}

public getUpcomingLaunches():Observable<any>{
return this.http.get<any>(LAUNCHES_API+'/upcoming');
}

public getLatestLaunch():Observable<any>{
return this.http.get<any>(LAUNCHES_API+'/latest');
}

public getNextLaunch():Observable<any>{
return this.http.get<any>(LAUNCHES_API+'/next');
}

}

0 comments on commit 22dcbac

Please sign in to comment.