Added Services Page, ToS & Imprint
This commit is contained in:
1 parent
3b8fd5752e
commit
0b9596b534
29 files changed
+1038
-23
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
|
||||
interface Username {
|
||||
id: number;
|
||||
username: string;
|
||||
password: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserService {
|
||||
private apiUrl = '/api/users';
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
getAllUsers(token: string | null): Observable<any[]> {
|
||||
const headers = new HttpHeaders().set('Authorization', `Bearer ${token}`);
|
||||
return this.http.get<any[]>(`${this.apiUrl}/?timestamp=${new Date().getTime()}`, { headers });
|
||||
}
|
||||
|
||||
createUser(token: string, username: string, password: string): Observable<any> {
|
||||
const headers = new HttpHeaders().set('Authorization', `Bearer ${token}`);
|
||||
return this.http.post<any>(this.apiUrl, {
|
||||
username,
|
||||
password
|
||||
}, { headers });
|
||||
}
|
||||
|
||||
editUser(id: number, token: string | null, username: string, password: string): Observable<any> {
|
||||
const headers = new HttpHeaders().set('Authorization', `Bearer ${token}`);
|
||||
|
||||
const body: any = {};
|
||||
if (username) {
|
||||
body.username = username
|
||||
}
|
||||
if (password) {
|
||||
body.password = password;
|
||||
}
|
||||
|
||||
return this.http.put<any>(`${this.apiUrl}/${id}`, body, { headers });
|
||||
}
|
||||
|
||||
deleteUser(id: number, token: string): Observable<boolean> {
|
||||
const headers = new HttpHeaders().set('Authorization', `Bearer ${token}`);
|
||||
return this.http.delete<any>(`${this.apiUrl}/${id}`, { headers }).pipe(
|
||||
map((response) => {
|
||||
// If the backend responds successfully, return true
|
||||
return !!(response && response.message === 'User deleted');
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
getUserById(id: number, token: string): Observable<Username | undefined> {
|
||||
const headers = new HttpHeaders().set('Authorization', `Bearer ${token}`);
|
||||
return this.http.get<Username>(`${this.apiUrl}/${id}`, { headers }).pipe(
|
||||
map(user => user)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user