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

Adjust comment service to api

parent 79684a75
No related merge requests found
...@@ -11,21 +11,27 @@ const httpOptions = { ...@@ -11,21 +11,27 @@ const httpOptions = {
@Injectable() @Injectable()
export class CommentService extends BaseHttpService { export class CommentService extends BaseHttpService {
private commentsUrl = 'api/comments'; private apiUrl = {
base: 'https://arsnova-staging.mni.thm.de/api',
comment: '/comment',
find: '/find'
};
constructor( private http: HttpClient ) { constructor( private http: HttpClient ) {
super(); super();
} }
/** TODO: getComment().. **/
addComment(comment: Comment): Observable<Comment> { addComment(comment: Comment): Observable<Comment> {
return this.http.post<Comment>(this.commentsUrl, comment, httpOptions).pipe( return this.http.post<Comment>(this.apiUrl.base + this.apiUrl.comment + '/', comment, httpOptions).pipe(
tap (_ => ''), tap (_ => ''),
catchError(this.handleError<Comment>('addComment')) catchError(this.handleError<Comment>('addComment'))
); );
} }
deleteComment(comment: Comment): Observable<Comment> { deleteComment(comment: Comment): Observable<Comment> {
const url = `${this.commentsUrl}/${comment.id}`; const url = `${this.apiUrl.base + this.apiUrl.comment }/${comment.id}`;
return this.http.delete<Comment>(url, httpOptions).pipe( return this.http.delete<Comment>(url, httpOptions).pipe(
tap (_ => ''), tap (_ => ''),
catchError(this.handleError<Comment>('deleteComment')) catchError(this.handleError<Comment>('deleteComment'))
...@@ -33,15 +39,18 @@ export class CommentService extends BaseHttpService { ...@@ -33,15 +39,18 @@ export class CommentService extends BaseHttpService {
} }
getComments(roomId: string): Observable<Comment[]> { getComments(roomId: string): Observable<Comment[]> {
const url = `${this.commentsUrl}/?roomId=${roomId}`; const url = `${this.apiUrl.base + this}/?roomId=${roomId}`;
return this.http.get<Comment[]>(url).pipe( return this.http.post<Comment[]>(url, {
properties: {},
externalFilters: { roomId: roomId }
}, httpOptions).pipe(
tap (_ => ''), tap (_ => ''),
catchError(this.handleError<Comment[]>('getComments', [])) catchError(this.handleError<Comment[]>('getComments', []))
); );
} }
searchComments(roomId: string, userId: string): Observable<Comment[]> { searchComments(roomId: string, userId: string): Observable<Comment[]> {
const url = `${this.commentsUrl}/?roomId=${roomId}&userId=${userId}`; const url = `${this.apiUrl.base}/?roomId=${roomId}&userId=${userId}`;
return this.http.get<Comment[]>(url).pipe( return this.http.get<Comment[]>(url).pipe(
tap (_ => ''), tap (_ => ''),
catchError(this.handleError<Comment[]>('getComments', [])) catchError(this.handleError<Comment[]>('getComments', []))
...@@ -49,7 +58,7 @@ export class CommentService extends BaseHttpService { ...@@ -49,7 +58,7 @@ export class CommentService extends BaseHttpService {
} }
updateComment(comment: Comment): Observable<any> { updateComment(comment: Comment): Observable<any> {
return this.http.put(this.commentsUrl, comment, httpOptions).pipe( return this.http.put(this.apiUrl + this.apiUrl.comment + comment.id, comment, httpOptions).pipe(
tap(_ => ''), tap(_ => ''),
catchError(this.handleError<any>('updateComment')) catchError(this.handleError<any>('updateComment'))
); );
......
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