ajout de commentaire sur la page d'un post
This commit is contained in:
parent
0e61120aa7
commit
118b01294a
4
.vscode/extensions.json
vendored
4
.vscode/extensions.json
vendored
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
|
|
||||||
"recommendations": ["angular.ng-template"]
|
|
||||||
}
|
|
20
.vscode/launch.json
vendored
20
.vscode/launch.json
vendored
@ -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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
42
.vscode/tasks.json
vendored
42
.vscode/tasks.json
vendored
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
6
src/app/models/comment.ts
Normal file
6
src/app/models/comment.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export interface Comment {
|
||||||
|
id: bigint
|
||||||
|
content: string
|
||||||
|
commentDate: Date
|
||||||
|
isUpdated: boolean
|
||||||
|
}
|
@ -6,4 +6,5 @@ export interface Post {
|
|||||||
body: string
|
body: string
|
||||||
category: string
|
category: string
|
||||||
publicationDate: Date
|
publicationDate: Date
|
||||||
|
isUpdated: boolean
|
||||||
}
|
}
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
<h1>{{ concernedPost?.title }}</h1>
|
<h1>{{ concernedPost?.title }}</h1>
|
||||||
<em>Publié le {{ concernedPost?.publicationDate | date: "dd/MM/yyyy à HH:mm" }}</em>
|
<em>Publié le {{ concernedPost?.publicationDate | date: "dd/MM/yyyy à HH:mm" }}</em>
|
||||||
<div [innerHTML]="concernedPost?.body"></div>
|
<div [innerHTML]="concernedPost?.body"></div>
|
||||||
|
<div></div>
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import {Component} from '@angular/core';
|
import {Component} from '@angular/core';
|
||||||
import {ActivatedRoute} from '@angular/router';
|
import {ActivatedRoute} from '@angular/router';
|
||||||
import {Subscription} from 'rxjs';
|
import {mergeMap, Subscription} from 'rxjs';
|
||||||
import {Post} from '../../models/post';
|
import {Post} from '../../models/post';
|
||||||
import {PostService} from '../../services/post.service';
|
import {PostService} from '../../services/post.service';
|
||||||
import {HeaderComponent} from '../../components/header/header.component';
|
import {HeaderComponent} from '../../components/header/header.component';
|
||||||
import {DatePipe} from '@angular/common';
|
import {DatePipe} from '@angular/common';
|
||||||
|
import {CommentService} from '../../services/comment.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-post',
|
selector: 'app-post',
|
||||||
@ -21,12 +22,15 @@ export class PostComponent {
|
|||||||
concernedPost: Post | undefined;
|
concernedPost: Post | undefined;
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute,
|
constructor(private route: ActivatedRoute,
|
||||||
private postService: PostService) {
|
private postService: PostService,
|
||||||
|
private commentService: CommentService) {
|
||||||
this.route.paramMap.subscribe(params => {
|
this.route.paramMap.subscribe(params => {
|
||||||
const postId = params.get('postId');
|
const postId = params.get('postId');
|
||||||
if (postId) {
|
if (postId) {
|
||||||
this.subs.push(
|
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;
|
this.concernedPost = post;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
.content {
|
||||||
|
display: flex;
|
||||||
|
align-items: stretch;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 3em;
|
||||||
|
}
|
@ -1,14 +1,12 @@
|
|||||||
<app-header></app-header>
|
<app-header></app-header>
|
||||||
{{ concernedAuthor | json }}
|
{{ concernedAuthor | json }}
|
||||||
|
|
||||||
|
<div class="content">
|
||||||
<p-card header='Profil de {{ concernedAuthor?.name }}' subheader="role : {{ concernedAuthor?.role }}">
|
<p-avatar image="https://primefaces.org/cdn/primeng/images/demo/avatar/amyelsner.png" class="mr-2" size="xlarge"
|
||||||
<p class="m-0">
|
shape="circle"/>
|
||||||
<p-avatar image="https://primefaces.org/cdn/primeng/images/demo/avatar/amyelsner.png" class="mr-2" size="xlarge" shape="circle" />
|
|
||||||
<p-button label="Voir les posts de l'utilisateur"></p-button>
|
<p-button label="Voir les posts de l'utilisateur"></p-button>
|
||||||
@if (concernedAuthor?.id === actualAuthor?.id) {
|
@if (concernedAuthor?.id === actualAuthor?.id) {
|
||||||
<p-button label="Mettre à jour les données du profil"/>
|
<p-button label="Mettre à jour les données du profil"/>
|
||||||
<p-button label="Changer le mot de passe"/>
|
<p-button label="Changer le mot de passe"/>
|
||||||
}
|
}
|
||||||
</p>
|
</div>
|
||||||
</p-card>
|
|
||||||
|
29
src/app/services/comment.service.ts
Normal file
29
src/app/services/comment.service.ts
Normal file
@ -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<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"
|
||||||
|
// }
|
Loading…
Reference in New Issue
Block a user