From d88fe4a5391ae21f08cb525b12582898f9f369f8 Mon Sep 17 00:00:00 2001 From: ki8vi Date: Sun, 18 Aug 2024 23:32:03 +0600 Subject: [PATCH] feat: add carriage serice --- .../carriagesService/carriage.service.spec.ts | 19 +++++++++++ .../api/carriagesService/carriage.service.ts | 34 +++++++++++++++++++ src/app/api/models/carriage.ts | 11 ++++++ 3 files changed, 64 insertions(+) create mode 100644 src/app/api/carriagesService/carriage.service.spec.ts create mode 100644 src/app/api/carriagesService/carriage.service.ts create mode 100644 src/app/api/models/carriage.ts diff --git a/src/app/api/carriagesService/carriage.service.spec.ts b/src/app/api/carriagesService/carriage.service.spec.ts new file mode 100644 index 0000000..91fc29a --- /dev/null +++ b/src/app/api/carriagesService/carriage.service.spec.ts @@ -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(); + }); +}); diff --git a/src/app/api/carriagesService/carriage.service.ts b/src/app/api/carriagesService/carriage.service.ts new file mode 100644 index 0000000..19b9ecb --- /dev/null +++ b/src/app/api/carriagesService/carriage.service.ts @@ -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 { + return this.httpClient.get(this.CARRIAGE_ENDPOINT); + } + + public createCarriage(name: string, rows: number, leftSeats: number, rightSeats: number): Observable { + const body = { name, rows, leftSeats, rightSeats }; + return this.httpClient.post(this.CARRIAGE_ENDPOINT, body); + } + + public updateCarriage( + code: string, + name: string, + rows: number, + leftSeats: number, + rightSeats: number, + ): Observable { + const body = { name, rows, leftSeats, rightSeats }; + return this.httpClient.put(`${this.CARRIAGE_ENDPOINT}/${code}`, body); + } +} diff --git a/src/app/api/models/carriage.ts b/src/app/api/models/carriage.ts new file mode 100644 index 0000000..4fd04bc --- /dev/null +++ b/src/app/api/models/carriage.ts @@ -0,0 +1,11 @@ +export interface Carriage { + code: string; + name: string; + rows: number; + leftSeats: number; + rightSeats: number; +} + +export interface Code { + code: string; +}