import { Injectable } from '@angular/core' ; import { Observable } from 'rxjs' ; import { HttpClient , HttpHeaders , HttpParams } from '@angular/common/http' ; import { Order } from '../models/order' ; const headers = new HttpHeaders ( ) . set ( 'Content-Type' , 'application/json' ) ; const apiUrl = "/shop/api/orders" ; @ Injectable ( { providedIn : 'root' } ) export class OrderService { constructor ( private http ) { } getOrdersByCustomer ( customerId ) { const params = new HttpParams ( ) . set ( 'customerId' , customerId ) ; return this . http . get < Order [ ] > ( apiUrl , { headers , params } ) ; } getOrders ( ) { return this . http . get < Order [ ] > ( apiUrl , { headers } ) ; } createOrder ( customerId , order ) { const params = new HttpParams ( ) . set ( 'customerId' , customerId ) ; return this . http . post < Order > ( apiUrl , order , { headers , params } ) ; } updateOrder ( id , order ) { return this . http . put < Order > ( `${ apiUrl }/${ id }` , order , { headers } ) ; } }