From a4fa6f842cda091725c483cbfb06528d6b3d9b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Wed, 4 Apr 2018 15:32:21 +0200 Subject: [PATCH] Adjust content creation for api --- .../content-text-creator.component.html | 2 +- .../content-text-creator.component.ts | 14 ++++++-------- src/app/services/http/content.service.ts | 6 ++++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/app/components/fragments/content-text-creator/content-text-creator.component.html b/src/app/components/fragments/content-text-creator/content-text-creator.component.html index a841f3dd1..78e4f1c37 100644 --- a/src/app/components/fragments/content-text-creator/content-text-creator.component.html +++ b/src/app/components/fragments/content-text-creator/content-text-creator.component.html @@ -1,4 +1,4 @@ -<form (ngSubmit)="submitContent()"> +<form (ngSubmit)="submitContent(subject.value, body.value)"> <mat-form-field class="input-block"> <input matInput #subject [(ngModel)]="content.subject" placeholder="Subject" name="subject"> </mat-form-field> diff --git a/src/app/components/fragments/content-text-creator/content-text-creator.component.ts b/src/app/components/fragments/content-text-creator/content-text-creator.component.ts index 5608961eb..45a20bb9a 100644 --- a/src/app/components/fragments/content-text-creator/content-text-creator.component.ts +++ b/src/app/components/fragments/content-text-creator/content-text-creator.component.ts @@ -14,6 +14,7 @@ import { ContentDeleteComponent } from '../../dialogs/content-delete/content-del }) export class ContentTextCreatorComponent implements OnInit { + roomId: string; content: ContentText = new ContentText('1', '1', '0', @@ -32,9 +33,7 @@ export class ContentTextCreatorComponent implements OnInit { } ngOnInit() { - this.route.params.subscribe(params => { - this.content.roomId = params['roomId']; - }); + this.roomId = this.route.snapshot.paramMap.get('roomId'); } resetAfterSubmit() { @@ -43,16 +42,15 @@ export class ContentTextCreatorComponent implements OnInit { this.notificationService.show('Content submitted. Ready for creation of new content.'); } - submitContent() { + submitContent(subject: string, body: string) { if (this.content.body.valueOf() === '' || this.content.body.valueOf() === '') { this.notificationService.show('No empty fields allowed. Please check subject and body.'); return; } this.notificationService.show('Content submitted.'); - // ToDo: Check api call - // this.contentService.addContent(this.content); - // For Testing: - // console.log(this.content); + this.contentService.addContent(new ContentText( + '1', '1', this.roomId, subject, body, 1 + )).subscribe(); this.resetAfterSubmit(); } diff --git a/src/app/services/http/content.service.ts b/src/app/services/http/content.service.ts index 2e29b4985..16b94d3f9 100644 --- a/src/app/services/http/content.service.ts +++ b/src/app/services/http/content.service.ts @@ -11,7 +11,7 @@ const httpOptions = { @Injectable() export class ContentService extends BaseHttpService { - private contentUrl = 'api/contents'; + private contentUrl = 'api/content/'; constructor(private http: HttpClient) { super(); @@ -25,7 +25,9 @@ export class ContentService extends BaseHttpService { } addContent(content: Content): Observable<Content> { - return this.http.post<Content>(this.contentUrl, content, httpOptions).pipe( + return this.http.post<Content>(this.contentUrl, + { roomId: content.roomId, subject: content.subject, body: content.body, type: 'Content', format: content.format }, + httpOptions).pipe( catchError(this.handleError<Content>('addContent')) ); } -- GitLab