-
Notifications
You must be signed in to change notification settings - Fork 2
/
project.service.ts
92 lines (72 loc) · 2.34 KB
/
project.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, map } from 'rxjs';
import { DomSanitizer } from '@angular/platform-browser';
interface Project {
id: number;
name: string;
category: string;
image: string;
}
interface ApiResponse {
content: Project[];
pageNumber: number;
pageSize: number;
totalElements: number;
totalPages: number;
first: boolean;
last: boolean;
}
@Injectable({
providedIn: 'root'
})
export class ProjectService {
constructor(private http: HttpClient, private sanitizer: DomSanitizer) { }
getProjects(page: number): Observable<Project[]> {
return this.http.get<ApiResponse>(`/api/projects?page=${page}`).pipe(
map(response => response.content)
);
}
getProject(projectId: number): Observable<any[]> {
const url = `/api/projects/${projectId}/`;
return this.http.get<any[]>(url);
}
// Gets the first image of an specific project
getProjectFirstImage(projectId: number): Observable<any> {
const url = `/api/projects/${projectId}/images/1`;
return this.http.get(url, { responseType: 'blob' }).pipe(
map(blob => this.sanitizer.bypassSecurityTrustUrl(URL.createObjectURL(blob)))
);
}
getProjectGraphs(projectId: number): Observable<any> {
const url = `/api/projects/${projectId}/graphics`;
return this.http.get(url);
}
getMyProjects(page: number): Observable<Project[]> {
return this.http.get<Project[]>(`/api/users/projects`);
}
deleteProject(id: number): Observable<any> {
return this.http.delete(`/api/projects/${id}`);
}
donate(amount:number,projectId:number){
return this.http.post(`/api/projects/${projectId}/inversions`,{projectId, amount});
}
updateProject(projectId:number,project:any){
return this.http.put(`/api/projects/${projectId}`,project);
}
createProject(project:any){
return this.http.post(`/api/projects`,project);
}
deleteComment(projectId:number,commentId:number){
return this.http.delete(`/api/comments/${projectId}/${commentId}/`);
}
getCategories(){
return this.http.get(`/api/projects/categories`);
}
uploadImages(id: number, files: FormData){
return this.http.post(`/api/projects/${id}/images`, files);
}
newImages(id: number, files: FormData) {
return this.http.put(`/api/projects/${id}/images`, files);
}
}