68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import {forkJoin, Observable} from 'rxjs';
|
|
import {Tutorial} from '../../models/tutorial.model';
|
|
import {HttpClient, HttpEvent, HttpHeaders, HttpRequest} from '@angular/common/http';
|
|
import {GlobalConstants} from '../../global-constants';
|
|
import {FileInfo} from '../../models/file-info';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class UserApiService {
|
|
baseUrl = `${GlobalConstants.API_URL}/user`;
|
|
|
|
constructor(private http: HttpClient) {
|
|
|
|
}
|
|
|
|
upload(file: File): Observable<HttpEvent<any>> {
|
|
const formData: FormData = new FormData();
|
|
formData.append('file', file);
|
|
|
|
const req = new HttpRequest('POST', `${this.baseUrl}/upload`, formData, {
|
|
reportProgress: true,
|
|
responseType: 'json'
|
|
});
|
|
|
|
return this.http.request(req);
|
|
}
|
|
|
|
|
|
saveZhipuaiImage(url: string): Observable<any> {
|
|
return this.http.post(`${this.baseUrl}/saveZhipuAiImage`, {imageUrl:url});
|
|
}
|
|
|
|
getImages(): Observable<FileInfo[]> {
|
|
return this.http.get<FileInfo[]>(`${this.baseUrl}/getImages`);
|
|
}
|
|
|
|
getUserAllTutorials(): Observable<Tutorial[]> {
|
|
return this.http.get<Tutorial[]>(`${this.baseUrl}/tutorials`);
|
|
}
|
|
|
|
getTutorial(id: string | null | undefined): Observable<Tutorial> {
|
|
return this.http.get<Tutorial>(`${this.baseUrl}/tutorial-get/${id}`);
|
|
}
|
|
|
|
create(data: any): Observable<any> {
|
|
return this.http.post(`${this.baseUrl}/tutorial-add`, data);
|
|
}
|
|
|
|
update(id: any,data: any): Observable<any> {
|
|
return this.http.put(`${this.baseUrl}/tutorial-update/${id}`, data);
|
|
}
|
|
|
|
deleteTutorials(tutorials: Tutorial[]): Observable<Tutorial[]> {
|
|
return forkJoin(
|
|
tutorials.map((tutorial) =>
|
|
this.http.delete<Tutorial>(`${this.baseUrl}/tutorials/${tutorial.id}`)
|
|
)
|
|
);
|
|
}
|
|
|
|
deleteTutorial(id: number): Observable<Tutorial> {
|
|
return this.http.delete<Tutorial>(`${this.baseUrl}/tutorials/${id}`);
|
|
}
|
|
|
|
}
|