@for (post of posts; track post.id) { - + - + - +

{{ title }}

{{ category }}

- {{ date }} +

{{ date | date : "dd/MM/yyyy" }}

{{ description }}

- + diff --git a/src/app/post-home/post-home.component.ts b/src/app/post-home/post-home.component.ts index 725c380..2a1caab 100644 --- a/src/app/post-home/post-home.component.ts +++ b/src/app/post-home/post-home.component.ts @@ -1,24 +1,30 @@ import {Component, Input} from '@angular/core'; import {Button} from 'primeng/button'; import {CardModule} from 'primeng/card'; +import {DatePipe} from '@angular/common'; +import {RouterLink} from '@angular/router'; @Component({ selector: 'app-post-home', standalone: true, imports: [ Button, - CardModule + CardModule, + DatePipe, + RouterLink ], templateUrl: './post-home.component.html', styleUrl: './post-home.component.css' }) export class PostHomeComponent { + @Input() postId: bigint = BigInt(0); @Input() title: string = ''; @Input() illustration: string = ''; @Input() category: string = ''; - @Input() date: Date = new Date(); + @Input() date: Date | undefined; @Input() description: string = ''; @Input() username: string = ''; @Input() avatar: string = ''; + constructor() {} } diff --git a/src/app/post/post.component.css b/src/app/post/post.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/post/post.component.html b/src/app/post/post.component.html new file mode 100644 index 0000000..1f0e574 --- /dev/null +++ b/src/app/post/post.component.html @@ -0,0 +1,4 @@ + +

{{ concernedPost?.title }}

+{{ concernedPost?.publicationDate | date: "dd/MM/yyyy" }} +
diff --git a/src/app/post/post.component.ts b/src/app/post/post.component.ts new file mode 100644 index 0000000..5758f5c --- /dev/null +++ b/src/app/post/post.component.ts @@ -0,0 +1,41 @@ +import { Component } from '@angular/core'; +import {ActivatedRoute} from '@angular/router'; +import {AuthorService} from '../services/author.service'; +import {CookieService} from 'ngx-cookie-service'; +import {Subscription} from 'rxjs'; +import {Post} from '../models/post'; +import {PostService} from '../services/post.service'; +import {HeaderComponent} from '../header/header.component'; +import {DatePipe, JsonPipe} from '@angular/common'; + +@Component({ + selector: 'app-post', + standalone: true, + imports: [ + HeaderComponent, + JsonPipe, + DatePipe + ], + templateUrl: './post.component.html', + styleUrl: './post.component.css' +}) +export class PostComponent { + subs: Subscription[] = []; + concernedPost: Post | undefined; + + constructor(private route: ActivatedRoute, + private postService: PostService) { + this.route.paramMap.subscribe(params => { + const postId = params.get('postId'); + if (postId) { + this.subs.push( + this.postService.getPost(BigInt(postId)).subscribe(post => { + this.concernedPost = post; + }) + ); + } + }); + + } + +} diff --git a/src/app/services/post.service.ts b/src/app/services/post.service.ts index cdb7876..35d6a86 100644 --- a/src/app/services/post.service.ts +++ b/src/app/services/post.service.ts @@ -14,6 +14,10 @@ export class PostService { return this.httpClient.get(this.url); } + getPost(id: bigint) { + return this.httpClient.get(`${this.url}/${id}`); + } + createPost(post: any, token: string | undefined): Observable { const httpOptions = { headers: new HttpHeaders({