From 5fb7ecd08e45efeaf1ee4bd301ef578487368a85 Mon Sep 17 00:00:00 2001 From: aoezdemir Date: Mon, 18 Mar 2024 00:35:00 +0100 Subject: [PATCH] Implement student registration DTO and student registration serivce --- .../student-register.component.ts | 65 +++++++++---------- .../src/app/models/student-registration.ts | 16 +++++ .../app/services/register/register.service.ts | 21 ++++++ 3 files changed, 67 insertions(+), 35 deletions(-) create mode 100644 frontend/src/app/models/student-registration.ts create mode 100644 frontend/src/app/services/register/register.service.ts diff --git a/frontend/src/app/components/students/student-register/student-register.component.ts b/frontend/src/app/components/students/student-register/student-register.component.ts index 81dbcef..574c234 100644 --- a/frontend/src/app/components/students/student-register/student-register.component.ts +++ b/frontend/src/app/components/students/student-register/student-register.component.ts @@ -1,6 +1,8 @@ import {Component, input, OnInit} from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import {ValidatorService} from "angular-iban"; +import {StudentRegistration} from "../../../models/student-registration"; +import {RegisterService} from "../../../services/register/register.service"; export const MY_DATE_FORMAT= { parse: { @@ -20,8 +22,6 @@ export const MY_DATE_FORMAT= { styleUrls: ['./student-register.component.scss'], }) export class StudentRegisterComponent implements OnInit { - inputText: string = ''; - masterFormGroup!: FormGroup; firstFormGroup!: FormGroup; secondFormGroup!: FormGroup; thirdFormGroup!: FormGroup; @@ -62,41 +62,9 @@ export class StudentRegisterComponent implements OnInit { 'Ein späterer rückwirkender Widerruf für aktuell stattfindende bzw. bereits stattgefundene\n' + 'Veranstaltungen ist ausgeschlossen.'; - constructor(private _formBuilder: FormBuilder) {} + constructor(private _formBuilder: FormBuilder, private registerService: RegisterService) {} ngOnInit() { - //TODO Test to group all forms into one master form - // this.masterFormGroup = this._formBuilder.group({ - // zeroFormGroup: this._formBuilder.group({ - // danceTraining: [''], - // karateTraining: [''], - // freeTraining: [''], - // }, { - // validators: [this.requireAtLeastOne] - // }), - // firstFormGroup: this._formBuilder.group({ - // firstName: ['', Validators.required], - // lastName: ['', Validators.required], - // birthdate: ['', Validators.required], - // postalCode: ['', [Validators.required, Validators.pattern(/^\d+$/)]], - // address: ['', Validators.required], - // phone: ['', [Validators.required, Validators.pattern(/^\d+$/)]], - // email: ['', [Validators.required, Validators.email]], - // }), - // secondFormGroup: this._formBuilder.group({ - // accountHolder: ['', Validators.required], - // iban: ['', [Validators.required, Validators.pattern(/^\d+$/)]], - // bic: ['', Validators.required], - // nameOfFinancialInstitute: ['', Validators.required], - // amount: ['', [Validators.required, Validators.pattern(/^\d+$/)]], - // einzugsermaechtigung: ['', Validators.required], - // }), - // thirdFormGroup: this._formBuilder.group({ - // einwilligung: ['', Validators.required], - // einverstaendniserklaerung: ['', Validators.required], - // }), - // }); - // } this.firstFormGroup = this._formBuilder.group({ firstName: ['', Validators.required], @@ -136,4 +104,31 @@ export class StudentRegisterComponent implements OnInit { },{emitEvent:false}) //Prevent circular change detection } } + + submit() { + const studentRegistration: StudentRegistration = { + // First Form Group + firstName: this.firstFormGroup.get('firstName')?.value, + lastName: this.firstFormGroup.get('lastName')?.value, + birthdate: this.firstFormGroup.get('birthdate')?.value, + postalCode: this.firstFormGroup.get('postalCode')?.value, + address: this.firstFormGroup.get('address')?.value, + phone: this.firstFormGroup.get('phone')?.value, + email: this.firstFormGroup.get('email')?.value, + + // Second Form Group + accountHolder: this.secondFormGroup.get('accountHolder')?.value, + iban: this.secondFormGroup.get('iban')?.value, + bic: this.secondFormGroup.get('bic')?.value, + nameOfFinancialInstitute: this.secondFormGroup.get('nameOfFinancialInstitute')?.value, + einzugsermaechtigung: this.secondFormGroup.get('einzugsermaechtigung')?.value, + + // Third Form Group + einwilligung: this.thirdFormGroup.get('einwilligung')?.value, + einverstaendniserklaerung: this.thirdFormGroup.get('einverstaendniserklaerung')?.value + }; + + this.registerService.set(studentRegistration); + + } } diff --git a/frontend/src/app/models/student-registration.ts b/frontend/src/app/models/student-registration.ts new file mode 100644 index 0000000..ddf801d --- /dev/null +++ b/frontend/src/app/models/student-registration.ts @@ -0,0 +1,16 @@ +export interface StudentRegistration { + firstName: string; + lastName: string; + birthdate: Date; + postalCode: string; + address: string; + phone: string; + email: string; + accountHolder: string; + iban: string; + bic: string; + nameOfFinancialInstitute: string; + einzugsermaechtigung: boolean; + einwilligung: boolean; + einverstaendniserklaerung: boolean; +} diff --git a/frontend/src/app/services/register/register.service.ts b/frontend/src/app/services/register/register.service.ts new file mode 100644 index 0000000..0a63508 --- /dev/null +++ b/frontend/src/app/services/register/register.service.ts @@ -0,0 +1,21 @@ +import { Injectable } from '@angular/core'; +import {HttpClient} from "@angular/common/http"; +import {StudentRegistration} from "../../models/student-registration"; +import {Observable} from "rxjs"; +import { environment } from 'src/environments/environment'; + +@Injectable({ + providedIn: 'root' +}) +export class RegisterService { + private readonly serviceName = 'register'; + constructor(private http: HttpClient) { } + + public set(registration: StudentRegistration): Observable { + const payload = JSON.stringify(registration); + + return this.http.post(`${environment.apiUrl}${this.serviceName}/set.php`, + payload + ); + } +}