Newer
Older
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, BehaviorSubject, Subject } from 'rxjs';
import { Comment } from '../../models/comment';
import { catchError, tap } from 'rxjs/operators';
import { BaseHttpService } from './base-http.service';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
export class CommentService extends BaseHttpService {

Lukas Mauß
committed
getComment(commentId: string): Observable<Comment> {
const connectionUrl = `${this.apiUrl.base}${this.apiUrl.comment}/~${commentId}`;
return this.http.get<Comment>(connectionUrl, httpOptions).pipe(
catchError(this.handleError<Comment>('addComment'))
);
}
addComment(comment: Comment): Observable<Comment> {
const connectionUrl = this.apiUrl.base + this.apiUrl.comment + '/';
return this.http.post<Comment>(connectionUrl,
read: comment.read, creationTimestamp: comment.creationTimestamp
}, httpOptions).pipe(
tap(_ => ''),
catchError(this.handleError<Comment>('addComment'))
);

Lukas Mauß
committed
deleteComment(commentId: string): Observable<Comment> {
const connectionUrl = `${this.apiUrl.base + this.apiUrl.comment}/${commentId}`;
return this.http.delete<Comment>(connectionUrl, httpOptions).pipe(
catchError(this.handleError<Comment>('deleteComment'))
);
getComments(roomId: string): Observable<Comment[]> {
const connectionUrl = this.apiUrl.base + this.apiUrl.comment + this.apiUrl.find;
return this.http.post<Comment[]>(connectionUrl, {
catchError(this.handleError<Comment[]>('getComments', []))
);
updateComment(comment: Comment): Observable<any> {
const connectionUrl = this.apiUrl.base + this.apiUrl.comment + '/' + comment.id;
return this.http.put(connectionUrl, comment, httpOptions).pipe(
setState(state: boolean) {
this.exportButton.next(state);
}