import { Injectable } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class CommentService {
  url: string = 'http://localhost:8080/api/comments';
  constructor(private httpClient: HttpClient) {}

  list(postId: bigint) {
    return this.httpClient.get<Comment[]>(`${this.url}/posts/${postId}`);
  }

  create(content: string, postId: bigint, authorId: string): Observable<Comment> {
    return this.httpClient.post<Comment>(`${this.url}/posts/${postId}`, {postId: postId, authorId: authorId, content: content});
  }
}

// POST localhost:8080/api/comments/posts/1
// Content-Type: application/json
// Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ3cml0ZXIiLCJpYXQiOjE3MzY2OTYwNDgsImV4cCI6MTczNjczMjA0OH0.lHkOTGUzklZFJvm3poEhU5RhcG32y-ew-I2WpqDLVOs
//
// {
//   "postId": 1,
//   "content": "test",
//   "authorId": "2c8c4079-8649-4086-9a4e-3d7ddcb402d8"
// }