aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/services
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-ui/src/app/services')
-rw-r--r--ufund-ui/src/app/services/cupboard.service.spec.ts16
-rw-r--r--ufund-ui/src/app/services/cupboard.service.ts44
-rw-r--r--ufund-ui/src/app/services/users.service.spec.ts16
-rw-r--r--ufund-ui/src/app/services/users.service.ts35
4 files changed, 111 insertions, 0 deletions
diff --git a/ufund-ui/src/app/services/cupboard.service.spec.ts b/ufund-ui/src/app/services/cupboard.service.spec.ts
new file mode 100644
index 0000000..56da56d
--- /dev/null
+++ b/ufund-ui/src/app/services/cupboard.service.spec.ts
@@ -0,0 +1,16 @@
+import { TestBed } from '@angular/core/testing';
+
+import { CupboardService } from './cupboard.service';
+
+describe('CupboardService', () => {
+ let service: CupboardService;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({});
+ service = TestBed.inject(CupboardService);
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+});
diff --git a/ufund-ui/src/app/services/cupboard.service.ts b/ufund-ui/src/app/services/cupboard.service.ts
new file mode 100644
index 0000000..6e2671a
--- /dev/null
+++ b/ufund-ui/src/app/services/cupboard.service.ts
@@ -0,0 +1,44 @@
+import {Injectable} from '@angular/core';
+import {HttpClient, HttpHeaders} from '@angular/common/http';
+import {Need} from '../models/Need';
+import {Observable} from 'rxjs';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class CupboardService {
+
+ private url = "localhost:8080/cupboard"
+ private httpOptions = {
+ headers: new HttpHeaders({'Content-Type': 'application/json'})
+ };
+
+ constructor(
+ private http: HttpClient
+ ) {}
+
+ createNeed(need: Need): Observable<boolean> {
+ return this.http.post<boolean>(
+ this.url, need, this.httpOptions)
+ }
+
+ getNeeds(): Observable<Need[]> {
+ return this.http.get<Need[]>(this.url, this.httpOptions)
+ }
+
+ searchNeeds(name: String): Observable<Need[]> {
+ return this.http.get<Need[]>(`${this.url}/?name=${name}`, this.httpOptions)
+ }
+
+ getNeed(id: number): Observable<Need> {
+ return this.http.get<Need>(`${this.url}/${id}`, this.httpOptions)
+ }
+
+ updateNeed(id: number, data: Need): Observable<boolean> {
+ return this.http.put<boolean>(`${this.url}/${id}`, data, this.httpOptions)
+ }
+
+ deleteNeed(id: number): Observable<boolean> {
+ return this.http.put<boolean>(`${this.url}/${id}`, this.httpOptions)
+ }
+}
diff --git a/ufund-ui/src/app/services/users.service.spec.ts b/ufund-ui/src/app/services/users.service.spec.ts
new file mode 100644
index 0000000..f81244a
--- /dev/null
+++ b/ufund-ui/src/app/services/users.service.spec.ts
@@ -0,0 +1,16 @@
+import { TestBed } from '@angular/core/testing';
+
+import { UsersService } from './users.service';
+
+describe('UsersService', () => {
+ let service: UsersService;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({});
+ service = TestBed.inject(UsersService);
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+});
diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts
new file mode 100644
index 0000000..65a9e61
--- /dev/null
+++ b/ufund-ui/src/app/services/users.service.ts
@@ -0,0 +1,35 @@
+import { Injectable } from '@angular/core';
+import {HttpClient, HttpHeaders} from '@angular/common/http';
+import {Observable} from 'rxjs';
+import {User} from '../models/User';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class UsersService {
+
+ private url = "localhost:8080/cupboard"
+ private httpOptions = {
+ headers: new HttpHeaders({'Content-Type': 'application/json'})
+ };
+
+ constructor(
+ private http: HttpClient
+ ) {}
+
+ createUser(data: User): Observable<User> {
+ return this.http.post<User>(this.url, data, this.httpOptions)
+ }
+
+ getUser(id: number): Observable<User> {
+ return this.http.get<User>(`${this.url}/${id}`, this.httpOptions)
+ }
+
+ updateUser(id: number): Observable<User> {
+ return this.http.put<User>(`${this.url}/${id}`, this.httpOptions)
+ }
+
+ deleteUser(id: number): Observable<boolean> {
+ return this.http.delete<boolean>(`${this.url}/${id}`, this.httpOptions)
+ }
+}