1234567891011121314151617181920212223242526272829303132333435363738 |
- import { Injectable } from '@angular/core';
- import {User} from '../dtcservice/user';
- import { Observable, of } from 'rxjs';
- import { HttpClient, HttpHeaders } from '@angular/common/http';
- const httpOptions = {
- headers: new HttpHeaders({ 'Content-Type': 'application/json' })
- };
- @Injectable({
- providedIn: 'root'
- })
- export class UserService {
- constructor(private http: HttpClient) { }
- private apihost = 'http://localhost:8080';
- getUsers(): Observable<User[]> {
- return this.http.get<User[]>(this.apihost+'/user');
- }
- addUser(user:User):Observable<User>{
- return this.http.post<User>(this.apihost+"/user",user,httpOptions);
- }
- updateUser (user: User, id:number): Observable<any> {
- return this.http.put(`${this.apihost}/user/${id}`, user, httpOptions);
- }
- getUser(id: number): Observable<User> {
- const url = `${this.apihost}/user/${id}`;
- return this.http.get<User>(url);
- }
- deleteUser(id:number):Observable<any>{
- return this.http.delete(`${this.apihost}/user/${id}`);
- }
- }
|