From c73a29a3d10ba9bc3ce940d75d2514a228928c5e Mon Sep 17 00:00:00 2001
From: Lukas Kimpel <lukas.kimpel@mni.thm.de>
Date: Wed, 14 Mar 2018 22:15:25 +0100
Subject: [PATCH] Refactor id to contentId Select first content (due to array
 as return paramter)

---
 .../content-answers-list.component.ts              | 12 +++---------
 src/app/content-detail/content-detail.component.ts |  2 +-
 src/app/content.service.ts                         |  6 +++---
 src/app/in-memory-data.service.ts                  | 14 +++++++-------
 4 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/src/app/content-answers-list/content-answers-list.component.ts b/src/app/content-answers-list/content-answers-list.component.ts
index ef2df1a52..e621957ab 100644
--- a/src/app/content-answers-list/content-answers-list.component.ts
+++ b/src/app/content-answers-list/content-answers-list.component.ts
@@ -20,18 +20,12 @@ export class ContentAnswersListComponent implements OnInit {
 
   ngOnInit() {
     this.route.params.subscribe(params => {
-      this.getContent(params['id']);
+      this.getAnswerTexts(params['contentId']);
     });
   }
 
-  getContent(id: string): void {
-    this.contentService.getContent(id).subscribe(params => {
-      this.getAnswerTexts(params['id']);
-    })
-  }
-
-  getAnswerTexts(id: string): void {
-    this.contentAnswerService.getAnswerTexts(id)
+  getAnswerTexts(contentId: string): void {
+    this.contentAnswerService.getAnswerTexts(contentId)
       .subscribe(textAnswers => {
         this.textAnswers = textAnswers;
       });
diff --git a/src/app/content-detail/content-detail.component.ts b/src/app/content-detail/content-detail.component.ts
index 8abd123cf..288ec68f4 100644
--- a/src/app/content-detail/content-detail.component.ts
+++ b/src/app/content-detail/content-detail.component.ts
@@ -24,6 +24,6 @@ export class ContentDetailComponent implements OnInit {
 
   getContent(contentId: string): void {
     this.contentService.getContent(contentId)
-      .subscribe(content => this.content = content);
+      .subscribe(content => this.content = content[0]);
   }
 }
diff --git a/src/app/content.service.ts b/src/app/content.service.ts
index 75e59adcb..07e9f2262 100644
--- a/src/app/content.service.ts
+++ b/src/app/content.service.ts
@@ -29,10 +29,10 @@ export class ContentService extends ErrorHandlingService {
     );
   }
 
-  getContent(id: string): Observable<Content> {
-    const url = `${this.contentUrl}/${id}`;
+  getContent(contentId: string): Observable<Content> {
+    const url = `${this.contentUrl}/?contentId=${contentId}`;
     return this.http.get<Content>(url).pipe(
-      catchError(this.handleError<Content>(`getContent id=${id}`))
+      catchError(this.handleError<Content>(`getContent id=${contentId}`))
     );
   }
 }
diff --git a/src/app/in-memory-data.service.ts b/src/app/in-memory-data.service.ts
index 6919f5f75..30b63b24b 100644
--- a/src/app/in-memory-data.service.ts
+++ b/src/app/in-memory-data.service.ts
@@ -87,21 +87,21 @@ export class InMemoryDataService implements InMemoryDbService {
 
     const contents = [
       {
-        id: '1',
+        contentId: '1',
         revision: '1',
         roomId: '1',
-        subject: 'Textaufgabe 1',
-        body: 'testcontent alpha beta',
+        subject: 'Text Content 1',
+        body: 'This is a body of a text content.',
         round: 1,
         format: ContentType.TEXT
       },
       {
-        id: '2',
+        contentId: '2',
         revision: '2',
         roomId: '3',
-        subject: 'Textaufgabe 2',
-        body: 'Ein Mann kauft 20 Melonen. Eine Melone wiegt jeweils 5kg. Berechnen Sie das Gesamtgewicht.',
-        round: 5,
+        subject: 'Text Content 2',
+        body: 'This is yet another body of a text content.',
+        round: 2,
         format: ContentType.TEXT
       }
     ];
-- 
GitLab