diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts
index 7125145..f1de12c 100644
--- a/src/app/app.routes.ts
+++ b/src/app/app.routes.ts
@@ -8,6 +8,7 @@ import {authGuard} from './guards/auth.guard';
import {ProfileComponent} from './profile/profile.component';
import {NewPostComponent} from './new-post/new-post.component';
import {writerGuard} from './guards/writer.guard';
+import {PostComponent} from './post/post.component';
export const routes: Routes = [
{path: '', component: HomeComponent},
@@ -15,6 +16,7 @@ export const routes: Routes = [
{path: 'register', component: RegisterComponent, canActivate: [authGuard]},
{path: 'logout', component: LogoutComponent},
{path: 'profile/:authorId', component: ProfileComponent},
+ {path: 'post/:postId', component: PostComponent},
{path: 'new-post', component: NewPostComponent, canActivate: [writerGuard]},
{path: '**', component: NotFoundComponent}
];
diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html
index 9d61f57..a682e04 100644
--- a/src/app/home/home.component.html
+++ b/src/app/home/home.component.html
@@ -2,7 +2,8 @@
@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({