Added services in webapp.
This commit is contained in:
parent
c0bf2f6b2c
commit
e93d8a5ec7
7
src/main/webapp/src/app/service/basic-service.ts
Normal file
7
src/main/webapp/src/app/service/basic-service.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
export interface BasicService<T, ID> {
|
||||
findAll(): Observable<T[]>;
|
||||
|
||||
findById(id: ID): Observable<T>;
|
||||
}
|
14
src/main/webapp/src/app/service/crud-service.ts
Normal file
14
src/main/webapp/src/app/service/crud-service.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import {Observable} from 'rxjs';
|
||||
import {BasicService} from './basic-service';
|
||||
|
||||
export interface CrudService<T, ID> extends BasicService<T, ID> {
|
||||
findAll(): Observable<T[]>;
|
||||
|
||||
findById(id: ID): Observable<T>;
|
||||
|
||||
update(t: T): Observable<T>;
|
||||
|
||||
create(t: T): Observable<T>;
|
||||
|
||||
delete(id: number): Observable<void>;
|
||||
}
|
36
src/main/webapp/src/app/service/group.service.ts
Normal file
36
src/main/webapp/src/app/service/group.service.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {CrudService} from "./crud-service";
|
||||
import {Observable} from "rxjs";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {Group} from "../model/group";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class GroupService implements CrudService<Group, number>{
|
||||
|
||||
private apiUrl = 'api/group';
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
create(t: Group): Observable<Group> {
|
||||
return this.http.post<Group>(this.apiUrl, t)
|
||||
}
|
||||
|
||||
delete(id: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.apiUrl}/${id}`)
|
||||
}
|
||||
|
||||
findAll(): Observable<Group[]> {
|
||||
return this.http.get<Group[]>(this.apiUrl)
|
||||
}
|
||||
|
||||
findById(id: number): Observable<Group> {
|
||||
return this.http.get<Group>(`${this.apiUrl}/${id}`)
|
||||
}
|
||||
|
||||
update(t: Group): Observable<Group> {
|
||||
return this.http.put<Group>(this.apiUrl, t)
|
||||
}
|
||||
}
|
16
src/main/webapp/src/app/service/person.service.spec.ts
Normal file
16
src/main/webapp/src/app/service/person.service.spec.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { PersonService } from './person.service';
|
||||
|
||||
describe('PersonService', () => {
|
||||
let service: PersonService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(PersonService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
36
src/main/webapp/src/app/service/person.service.ts
Normal file
36
src/main/webapp/src/app/service/person.service.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {CrudService} from "./crud-service";
|
||||
import {Person} from "../model/person";
|
||||
import {Observable} from "rxjs";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class PersonService implements CrudService<Person, number>{
|
||||
|
||||
private apiUrl = 'api/person';
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
create(t: Person): Observable<Person> {
|
||||
return this.http.post<Person>(this.apiUrl, t)
|
||||
}
|
||||
|
||||
delete(id: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.apiUrl}/${id}`)
|
||||
}
|
||||
|
||||
findAll(): Observable<Person[]> {
|
||||
return this.http.get<Person[]>(this.apiUrl)
|
||||
}
|
||||
|
||||
findById(id: number): Observable<Person> {
|
||||
return this.http.get<Person>(`${this.apiUrl}/${id}`)
|
||||
}
|
||||
|
||||
update(t: Person): Observable<Person> {
|
||||
return this.http.put<Person>(this.apiUrl, t)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user