diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 77b3745..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846 - "recommendations": ["angular.ng-template"] -} diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 925af83..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "ng serve", - "type": "chrome", - "request": "launch", - "preLaunchTask": "npm: start", - "url": "http://localhost:4200/" - }, - { - "name": "ng test", - "type": "chrome", - "request": "launch", - "preLaunchTask": "npm: test", - "url": "http://localhost:9876/debug.html" - } - ] -} diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index a298b5b..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - // For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558 - "version": "2.0.0", - "tasks": [ - { - "type": "npm", - "script": "start", - "isBackground": true, - "problemMatcher": { - "owner": "typescript", - "pattern": "$tsc", - "background": { - "activeOnStart": true, - "beginsPattern": { - "regexp": "(.*?)" - }, - "endsPattern": { - "regexp": "bundle generation complete" - } - } - } - }, - { - "type": "npm", - "script": "test", - "isBackground": true, - "problemMatcher": { - "owner": "typescript", - "pattern": "$tsc", - "background": { - "activeOnStart": true, - "beginsPattern": { - "regexp": "(.*?)" - }, - "endsPattern": { - "regexp": "bundle generation complete" - } - } - } - } - ] -} diff --git a/src/app/models/comment.ts b/src/app/models/comment.ts new file mode 100644 index 0000000..35098e7 --- /dev/null +++ b/src/app/models/comment.ts @@ -0,0 +1,6 @@ +export interface Comment { + id: bigint + content: string + commentDate: Date + isUpdated: boolean +} diff --git a/src/app/models/post.ts b/src/app/models/post.ts index d093e3f..8e7178f 100644 --- a/src/app/models/post.ts +++ b/src/app/models/post.ts @@ -6,4 +6,5 @@ export interface Post { body: string category: string publicationDate: Date + isUpdated: boolean } diff --git a/src/app/pages/post/post.component.html b/src/app/pages/post/post.component.html index 01af6e1..b64dce6 100644 --- a/src/app/pages/post/post.component.html +++ b/src/app/pages/post/post.component.html @@ -2,3 +2,4 @@

{{ concernedPost?.title }}

Publié le {{ concernedPost?.publicationDate | date: "dd/MM/yyyy à HH:mm" }}
+
diff --git a/src/app/pages/post/post.component.ts b/src/app/pages/post/post.component.ts index e8342cb..ce2b738 100644 --- a/src/app/pages/post/post.component.ts +++ b/src/app/pages/post/post.component.ts @@ -1,10 +1,11 @@ import {Component} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; -import {Subscription} from 'rxjs'; +import {mergeMap, Subscription} from 'rxjs'; import {Post} from '../../models/post'; import {PostService} from '../../services/post.service'; import {HeaderComponent} from '../../components/header/header.component'; import {DatePipe} from '@angular/common'; +import {CommentService} from '../../services/comment.service'; @Component({ selector: 'app-post', @@ -21,12 +22,15 @@ export class PostComponent { concernedPost: Post | undefined; constructor(private route: ActivatedRoute, - private postService: PostService) { + private postService: PostService, + private commentService: CommentService) { this.route.paramMap.subscribe(params => { const postId = params.get('postId'); if (postId) { this.subs.push( - this.postService.getPost(BigInt(postId)).subscribe(post => { + this.postService.getPost(BigInt(postId)).pipe( + mergeMap(post => this.commentService.list(post.id)) + ).subscribe(post => { this.concernedPost = post; }) ); diff --git a/src/app/pages/profile/profile.component.css b/src/app/pages/profile/profile.component.css index e69de29..ae0096b 100644 --- a/src/app/pages/profile/profile.component.css +++ b/src/app/pages/profile/profile.component.css @@ -0,0 +1,6 @@ +.content { + display: flex; + align-items: stretch; + flex-direction: column; + gap: 3em; +} diff --git a/src/app/pages/profile/profile.component.html b/src/app/pages/profile/profile.component.html index 97b986d..bae7a5d 100644 --- a/src/app/pages/profile/profile.component.html +++ b/src/app/pages/profile/profile.component.html @@ -1,14 +1,12 @@ {{ concernedAuthor | json }} - - -

- - - @if (concernedAuthor?.id === actualAuthor?.id) { - - - } -

-
+
+ + + @if (concernedAuthor?.id === actualAuthor?.id) { + + + } +
diff --git a/src/app/services/comment.service.ts b/src/app/services/comment.service.ts new file mode 100644 index 0000000..0c95f82 --- /dev/null +++ b/src/app/services/comment.service.ts @@ -0,0 +1,29 @@ +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(`${this.url}/posts/${postId}`); + } + + create(content: string, postId: bigint, authorId: string): Observable { + return this.httpClient.post(`${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" +// }