Skip to content

Commit

Permalink
feat: add carriage serice
Browse files Browse the repository at this point in the history
  • Loading branch information
ki8vi committed Aug 18, 2024
1 parent b6c0e6a commit d88fe4a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/app/api/carriagesService/carriage.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { provideHttpClient } from '@angular/common/http';
import { TestBed } from '@angular/core/testing';

import { CarriageService } from './carriage.service';

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

beforeEach(() => {
TestBed.configureTestingModule({
providers: [provideHttpClient()],
});
service = TestBed.inject(CarriageService);
});

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

import { Observable } from 'rxjs';

import { Carriage, Code } from '../models/carriage';

@Injectable({
providedIn: 'root',
})
export class CarriageService {
private httpClient = inject(HttpClient);
private CARRIAGE_ENDPOINT = 'carriage';

public getCarriages(): Observable<Carriage[]> {
return this.httpClient.get<Carriage[]>(this.CARRIAGE_ENDPOINT);
}

public createCarriage(name: string, rows: number, leftSeats: number, rightSeats: number): Observable<Code> {
const body = { name, rows, leftSeats, rightSeats };
return this.httpClient.post<Code>(this.CARRIAGE_ENDPOINT, body);
}

public updateCarriage(
code: string,
name: string,
rows: number,
leftSeats: number,
rightSeats: number,
): Observable<Code> {
const body = { name, rows, leftSeats, rightSeats };
return this.httpClient.put<Code>(`${this.CARRIAGE_ENDPOINT}/${code}`, body);
}
}
11 changes: 11 additions & 0 deletions src/app/api/models/carriage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface Carriage {
code: string;
name: string;
rows: number;
leftSeats: number;
rightSeats: number;
}

export interface Code {
code: string;
}

0 comments on commit d88fe4a

Please sign in to comment.