feat: HTTP-Anforderungsdienste mit HttpClient im Frontend implementieren
This commit is contained in:
parent
66a8471f05
commit
320e81719b
@ -5,6 +5,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
|
|||||||
import { MatStepperModule } from '@angular/material/stepper';
|
import { MatStepperModule } from '@angular/material/stepper';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
import { MatSelectModule } from '@angular/material/select';
|
import { MatSelectModule } from '@angular/material/select';
|
||||||
|
import { ReceiverService } from '../../services/receiver.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-envelope-creation',
|
selector: 'app-envelope-creation',
|
||||||
@ -23,6 +24,9 @@ import { MatSelectModule } from '@angular/material/select';
|
|||||||
})
|
})
|
||||||
export class EnvelopeCreationComponent {
|
export class EnvelopeCreationComponent {
|
||||||
|
|
||||||
|
constructor(private receiverService: ReceiverService) {
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.selectedType = this.types[0].value;
|
this.selectedType = this.types[0].value;
|
||||||
}
|
}
|
||||||
@ -39,8 +43,8 @@ export class EnvelopeCreationComponent {
|
|||||||
|
|
||||||
selectedType: string = "Mietvertrag"
|
selectedType: string = "Mietvertrag"
|
||||||
types: any[] = [
|
types: any[] = [
|
||||||
{value: 0, viewValue: 'Mietvertrag'},
|
{ value: 0, viewValue: 'Mietvertrag' },
|
||||||
{value: 1, viewValue: 'Kaufvertrag'}
|
{ value: 1, viewValue: 'Kaufvertrag' }
|
||||||
];
|
];
|
||||||
typeControl = new FormControl('Mietvertrag', [Validators.required]);
|
typeControl = new FormControl('Mietvertrag', [Validators.required]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { API_URL } from '../tokens/index';
|
|||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class EnvelopeReceiverService {
|
export class EnvelopeReceiverService {
|
||||||
private url: string;
|
protected url: string;
|
||||||
|
|
||||||
constructor(private http: HttpClient) {
|
constructor(private http: HttpClient) {
|
||||||
const api_url = inject(API_URL);
|
const api_url = inject(API_URL);
|
||||||
@ -16,12 +16,14 @@ export class EnvelopeReceiverService {
|
|||||||
|
|
||||||
getEnvelopeReceiver(options?: { min_status?: number; max_status?: number; ignore_status?: number[] }): Observable<any> {
|
getEnvelopeReceiver(options?: { min_status?: number; max_status?: number; ignore_status?: number[] }): Observable<any> {
|
||||||
let params = new HttpParams();
|
let params = new HttpParams();
|
||||||
if (options?.min_status !== undefined)
|
if (options) {
|
||||||
params = params.set('min_status', options?.min_status.toString());
|
if (options.min_status)
|
||||||
if (options?.max_status !== undefined)
|
params = params.set('min_status', options.min_status.toString());
|
||||||
params = params.set('max_status', options?.max_status.toString());
|
if (options.max_status)
|
||||||
if (options?.ignore_status !== undefined)
|
params = params.set('max_status', options.max_status.toString());
|
||||||
params = params.set('ignore_status', options?.ignore_status.join(','));
|
if (options.ignore_status)
|
||||||
|
params = params.set('ignore_status', options.ignore_status.join(','));
|
||||||
|
}
|
||||||
return this.http.get<any>(this.url, { params });
|
return this.http.get<any>(this.url, { params });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ReceiverService } from './receiver.service';
|
||||||
|
|
||||||
|
describe('ReceiverService', () => {
|
||||||
|
let service: ReceiverService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(ReceiverService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||||
|
import { Injectable, inject } from '@angular/core';
|
||||||
|
import { API_URL } from '../tokens';
|
||||||
|
import { Observable, firstValueFrom } from 'rxjs';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class ReceiverService {
|
||||||
|
protected url: string;
|
||||||
|
|
||||||
|
constructor(private http: HttpClient) {
|
||||||
|
const api_url = inject(API_URL);
|
||||||
|
this.url = `${api_url}/receiver`;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getReceiver(options?: { emailAdress?: string; signature?: string; }): Observable<any> {
|
||||||
|
let params = new HttpParams();
|
||||||
|
|
||||||
|
if (options) {
|
||||||
|
if (options.emailAdress)
|
||||||
|
params = params.set('emailAdress', options?.emailAdress.toString());
|
||||||
|
if (options?.signature)
|
||||||
|
params = params.set('signature', options?.signature.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.http.get<any>(this.url, { params });
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getReceiverAsync(options?: { emailAdress?: string; signature?: string; }): Promise<any> {
|
||||||
|
return await firstValueFrom(this.getReceiver(options));
|
||||||
|
}
|
||||||
|
|
||||||
|
public createReceiver(emailAddress: string): Observable<any> {
|
||||||
|
return this.http.post<any>(this.url, { emailAddress: emailAddress });
|
||||||
|
}
|
||||||
|
|
||||||
|
public async createReceiverAsync(emailAddress: string): Promise<any> {
|
||||||
|
return await firstValueFrom(this.createReceiver(emailAddress));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user