FarmMapsLib/projects/common/src/fm/services/folder.service.ts

50 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-06-25 07:47:53 +00:00
import { Injectable } from '@angular/core';
import { Observable , Observer } from 'rxjs';
import {map} from 'rxjs/operators';
import { IListItem } from '../models/list.item';
import { IItem } from '../models/item';
import { HttpClient } from "@angular/common/http";
import { AppConfig } from "../shared/app.config";
@Injectable({
providedIn: 'root',
})
export class FolderService {
constructor(public httpClient: HttpClient, public appConfig: AppConfig) {
}
ApiEndpoint() {
return this.appConfig.getConfig("apiEndPoint");
}
2020-07-07 07:24:45 +00:00
getFolder(code: string): Observable<IListItem> {
return this.httpClient.get<IListItem>(`${this.ApiEndpoint()}/api/v1/folders/${code}`);
2020-06-25 07:47:53 +00:00
}
getMyRoots(): Observable<IListItem[]> {
2020-07-07 07:24:45 +00:00
return this.httpClient.get<IListItem[]>(`${this.ApiEndpoint()}/api/v1/folders/my_roots`);
2020-06-25 07:47:53 +00:00
}
getFolderParents(code: string): Observable<IListItem[]> {
2020-07-07 07:24:45 +00:00
return this.httpClient.get<IListItem[]>(`${this.ApiEndpoint()}/api/v1/folders/${code}/parents`);
2020-06-25 07:47:53 +00:00
}
getChildFolders(code: string): Observable<IListItem[]> {
2020-07-07 07:24:45 +00:00
return this.httpClient.get<IListItem[]>(`${this.ApiEndpoint()}/api/v1/folders/${code}/listfolders`);
2020-06-25 07:47:53 +00:00
}
getItems(code: string,skip:number, take:number): Observable<IListItem[]> {
2020-07-07 07:24:45 +00:00
return this.httpClient.get<IListItem[]>(`${this.ApiEndpoint()}/api/v1/folders/${code}/list?skip=${skip}&take=${take}`);
2020-06-25 07:47:53 +00:00
}
moveItem(itemCode: string, newParentCode: string): Observable<IListItem> {
const body = { itemCode: itemCode,newParentCode: newParentCode };
2020-07-07 07:24:45 +00:00
return this.httpClient.post<IListItem>(`${this.ApiEndpoint()}/api/v1/items/move`, body);
2020-06-25 07:47:53 +00:00
}
createFolder(folder: IItem): Observable<IListItem> {
2020-07-07 07:24:45 +00:00
return this.httpClient.post<IListItem>(`${this.ApiEndpoint()}/api/v1/folders/`, folder);
2020-06-25 07:47:53 +00:00
}
}