mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Add API service
This commit is contained in:
12
ui/src/app/api.service.spec.ts
Normal file
12
ui/src/app/api.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { APIService } from './api.service';
|
||||
|
||||
describe('APIService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: APIService = TestBed.get(APIService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
39
ui/src/app/api.service.ts
Normal file
39
ui/src/app/api.service.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {retry} from 'rxjs/operators';
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
export interface CreateRequest {
|
||||
url: string;
|
||||
format: string;
|
||||
quality: string;
|
||||
page_size: number;
|
||||
}
|
||||
|
||||
export interface CreateResponse {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface UserResponse {
|
||||
user_id: string;
|
||||
feature_level: number;
|
||||
full_name: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class APIService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
createFeed(request: CreateRequest): Observable<CreateResponse> {
|
||||
return this.http.post<CreateResponse>('/api/create', request);
|
||||
}
|
||||
|
||||
getUser(): Observable<UserResponse> {
|
||||
return this.http.get<UserResponse>('/api/user')
|
||||
.pipe(
|
||||
retry(3)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { AppComponent } from './app.component';
|
||||
import { IndexComponent } from './index/index.component';
|
||||
import { InputComponent } from './input/input.component';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {HttpClientModule} from '@angular/common/http';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
@@ -15,6 +16,7 @@ import {FormsModule} from '@angular/forms';
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
HttpClientModule,
|
||||
FormsModule,
|
||||
AppRoutingModule
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user