From 26582b08bf1fd93993f25374d6950ff50c4d723a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de>
Date: Thu, 5 Apr 2018 21:00:21 +0200
Subject: [PATCH] Fix comment listing

---
 .../comment-list/comment-list.component.ts    | 25 ++++---------------
 .../comment-create-page.component.ts          |  2 +-
 src/app/services/http/comment.service.ts      |  8 +++---
 3 files changed, 10 insertions(+), 25 deletions(-)

diff --git a/src/app/components/fragments/comment-list/comment-list.component.ts b/src/app/components/fragments/comment-list/comment-list.component.ts
index ff2e3707a..849302cff 100644
--- a/src/app/components/fragments/comment-list/comment-list.component.ts
+++ b/src/app/components/fragments/comment-list/comment-list.component.ts
@@ -20,6 +20,7 @@ export class CommentListComponent implements OnInit {
   user: User;
   comments: Comment[];
   isLoading = true;
+  roomId: string;
 
   constructor(protected authenticationService: AuthenticationService,
               private route: ActivatedRoute,
@@ -32,32 +33,16 @@ export class CommentListComponent implements OnInit {
   ngOnInit() {
     this.userRole = this.authenticationService.getRole();
     this.user = this.authenticationService.getUser();
-    this.route.params.subscribe(params => {
-      this.getRoom(params['roomId']);
-    });
-  }
-
-  getRoom(id: string): void {
-    this.roomService.getRoom(id).subscribe(
-      params => {
-        this.getComments(params['id']);
-      });
+    this.roomId = this.route.snapshot.paramMap.get('roomId');
+    this.getComments();
   }
 
-  getComments(roomId: string): void {
-    if (this.userRole === UserRole.CREATOR) {
-      this.commentService.getComments(roomId)
-        .subscribe(comments => {
-          this.comments = comments;
-          this.isLoading = false;
-        });
-    } else if (this.userRole === UserRole.PARTICIPANT) {
-      this.commentService.searchComments(roomId, this.user.id)
+  getComments(): void {
+      this.commentService.getComments(this.roomId)
         .subscribe(comments => {
           this.comments = comments;
           this.isLoading = false;
         });
-    }
   }
 
   setRead(comment: Comment): void {
diff --git a/src/app/components/pages/comment-create-page/comment-create-page.component.ts b/src/app/components/pages/comment-create-page/comment-create-page.component.ts
index 39a46689a..0d171e08b 100644
--- a/src/app/components/pages/comment-create-page/comment-create-page.component.ts
+++ b/src/app/components/pages/comment-create-page/comment-create-page.component.ts
@@ -50,7 +50,7 @@ export class CommentCreatePageComponent implements OnInit {
       read: false,
       revision: ''
     } as Comment).subscribe(() => {
-      this.child.getComments(this.roomId);
+      this.child.getComments();
       this.notification.show(`Comment '${subject}' successfully created.`);
     });
   }
diff --git a/src/app/services/http/comment.service.ts b/src/app/services/http/comment.service.ts
index 7a4ce7ba2..dc9ba3e65 100644
--- a/src/app/services/http/comment.service.ts
+++ b/src/app/services/http/comment.service.ts
@@ -47,10 +47,10 @@ export class CommentService extends BaseHttpService {
   }
 
   getComments(roomId: string): Observable<Comment[]> {
-    const url = `${this.apiUrl.base + this}/?roomId=${roomId}`;
+    const url = this.apiUrl.base + this.apiUrl.comment + this.apiUrl.find;
     return this.http.post<Comment[]>(url, {
-      properties: {},
-      externalFilters: { roomId: roomId }
+      properties: { roomId: roomId },
+      externalFilters: {}
     }, httpOptions).pipe(
       tap (_ => ''),
       catchError(this.handleError<Comment[]>('getComments', []))
@@ -66,7 +66,7 @@ export class CommentService extends BaseHttpService {
   }
 
   updateComment(comment: Comment): Observable<any> {
-    return this.http.put(this.apiUrl + this.apiUrl.comment + comment.id, comment, httpOptions).pipe(
+    return this.http.put(this.apiUrl + this.apiUrl.comment + '/' + comment.id, comment, httpOptions).pipe(
       tap(_ => ''),
       catchError(this.handleError<any>('updateComment'))
     );
-- 
GitLab