Skip to content
Snippets Groups Projects
Commit a4fa6f84 authored by Lukas Mauß's avatar Lukas Mauß
Browse files

Adjust content creation for api

parent 9ec12aef
No related merge requests found
<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>
......
......@@ -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();
}
......
......@@ -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'))
);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment