From 06d8bc2b863fdf16526d1560bd6aa45d5fdadeeb Mon Sep 17 00:00:00 2001 From: Guams Date: Sat, 28 Dec 2024 01:31:19 +0100 Subject: [PATCH] =?UTF-8?q?visiualistation=20des=20posts=20et=20crud=20par?= =?UTF-8?q?tiellement=20commenc=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/app.routes.ts | 18 ++-- .../header/header.component.css | 0 .../components/header/header.component.html | 2 + .../header/header.component.ts | 6 +- .../post-form/post-form.component.css} | 0 .../post-form/post-form.component.html | 1 + .../post-form/post-form.component.ts | 13 +++ .../post-home/post-home.component.css | 0 .../post-home/post-home.component.html | 2 +- .../post-home/post-home.component.ts | 0 src/app/header/header.component.html | 2 - src/app/{ => pages}/home/home.component.css | 0 src/app/{ => pages}/home/home.component.html | 0 src/app/{ => pages}/home/home.component.ts | 25 ++--- .../{ => pages}/login/login.component.html | 0 src/app/{ => pages}/login/login.component.ts | 6 +- .../{ => pages}/logout/logout.component.html | 0 .../{ => pages}/logout/logout.component.ts | 2 +- .../my-posts/my-posts.component.css} | 0 .../pages/my-posts/my-posts.component.html | 59 ++++++++++ src/app/pages/my-posts/my-posts.component.ts | 101 ++++++++++++++++++ .../new-post/new-post.component.html | 0 .../new-post/new-post.component.ts | 10 +- .../not-found/not-found.component.html | 0 .../not-found/not-found.component.ts | 0 src/app/{ => pages}/post/post.component.html | 2 +- src/app/{ => pages}/post/post.component.ts | 13 +-- .../profile/profile.component.html | 0 .../{ => pages}/profile/profile.component.ts | 6 +- .../register/register.component.html | 0 .../register/register.component.ts | 2 +- src/app/services/author.service.ts | 21 +++- src/app/services/post.service.ts | 9 ++ src/index.html | 2 +- 34 files changed, 241 insertions(+), 61 deletions(-) rename src/app/{ => components}/header/header.component.css (100%) create mode 100644 src/app/components/header/header.component.html rename src/app/{ => components}/header/header.component.ts (97%) rename src/app/{login/login.component.css => components/post-form/post-form.component.css} (100%) create mode 100644 src/app/components/post-form/post-form.component.html create mode 100644 src/app/components/post-form/post-form.component.ts rename src/app/{ => components}/post-home/post-home.component.css (100%) rename src/app/{ => components}/post-home/post-home.component.html (77%) rename src/app/{ => components}/post-home/post-home.component.ts (100%) delete mode 100644 src/app/header/header.component.html rename src/app/{ => pages}/home/home.component.css (100%) rename src/app/{ => pages}/home/home.component.html (100%) rename src/app/{ => pages}/home/home.component.ts (66%) rename src/app/{ => pages}/login/login.component.html (100%) rename src/app/{ => pages}/login/login.component.ts (93%) rename src/app/{ => pages}/logout/logout.component.html (100%) rename src/app/{ => pages}/logout/logout.component.ts (92%) rename src/app/{not-found/not-found.component.css => pages/my-posts/my-posts.component.css} (100%) create mode 100644 src/app/pages/my-posts/my-posts.component.html create mode 100644 src/app/pages/my-posts/my-posts.component.ts rename src/app/{ => pages}/new-post/new-post.component.html (100%) rename src/app/{ => pages}/new-post/new-post.component.ts (92%) rename src/app/{ => pages}/not-found/not-found.component.html (100%) rename src/app/{ => pages}/not-found/not-found.component.ts (100%) rename src/app/{ => pages}/post/post.component.html (55%) rename src/app/{ => pages}/post/post.component.ts (67%) rename src/app/{ => pages}/profile/profile.component.html (100%) rename src/app/{ => pages}/profile/profile.component.ts (88%) rename src/app/{ => pages}/register/register.component.html (100%) rename src/app/{ => pages}/register/register.component.ts (78%) diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index f1de12c..d525b5a 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -1,14 +1,15 @@ import {Routes} from '@angular/router'; -import {LoginComponent} from './login/login.component'; -import {HomeComponent} from './home/home.component'; -import {RegisterComponent} from './register/register.component'; -import {LogoutComponent} from './logout/logout.component'; -import {NotFoundComponent} from './not-found/not-found.component'; +import {LoginComponent} from './pages/login/login.component'; +import {HomeComponent} from './pages/home/home.component'; +import {RegisterComponent} from './pages/register/register.component'; +import {LogoutComponent} from './pages/logout/logout.component'; +import {NotFoundComponent} from './pages/not-found/not-found.component'; import {authGuard} from './guards/auth.guard'; -import {ProfileComponent} from './profile/profile.component'; -import {NewPostComponent} from './new-post/new-post.component'; +import {ProfileComponent} from './pages/profile/profile.component'; +import {NewPostComponent} from './pages/new-post/new-post.component'; import {writerGuard} from './guards/writer.guard'; -import {PostComponent} from './post/post.component'; +import {PostComponent} from './pages/post/post.component'; +import {MyPostsComponent} from './pages/my-posts/my-posts.component'; export const routes: Routes = [ {path: '', component: HomeComponent}, @@ -17,6 +18,7 @@ export const routes: Routes = [ {path: 'logout', component: LogoutComponent}, {path: 'profile/:authorId', component: ProfileComponent}, {path: 'post/:postId', component: PostComponent}, + {path: 'my-posts', component: MyPostsComponent, canActivate: [writerGuard]}, {path: 'new-post', component: NewPostComponent, canActivate: [writerGuard]}, {path: '**', component: NotFoundComponent} ]; diff --git a/src/app/header/header.component.css b/src/app/components/header/header.component.css similarity index 100% rename from src/app/header/header.component.css rename to src/app/components/header/header.component.css diff --git a/src/app/components/header/header.component.html b/src/app/components/header/header.component.html new file mode 100644 index 0000000..2eaa21b --- /dev/null +++ b/src/app/components/header/header.component.html @@ -0,0 +1,2 @@ + + diff --git a/src/app/header/header.component.ts b/src/app/components/header/header.component.ts similarity index 97% rename from src/app/header/header.component.ts rename to src/app/components/header/header.component.ts index 2d4d4a4..4ed7b30 100644 --- a/src/app/header/header.component.ts +++ b/src/app/components/header/header.component.ts @@ -3,7 +3,7 @@ import { CookieService } from 'ngx-cookie-service'; import { MenuItem } from 'primeng/api'; import { MenubarModule } from 'primeng/menubar'; import { ToastModule } from 'primeng/toast'; -import { Author } from '../models/author'; +import { Author } from '../../models/author'; @Component({ selector: 'app-header', @@ -70,8 +70,8 @@ export class HeaderComponent { label: 'Mes posts', icon: 'pi pi-file-edit', items: [ - { label: 'Ajouter un post', icon: 'pi pi-plus', routerLink: 'new-post' }, - { label: 'Voir mes posts', icon: 'pi pi-eye', routerLink: ['posts', `${author.id}`] } + { label: 'Ajouter un post', icon: 'pi pi-plus', routerLink: '/new-post' }, + { label: 'Voir mes posts', icon: 'pi pi-eye', routerLink: '/my-posts' } ] }; } diff --git a/src/app/login/login.component.css b/src/app/components/post-form/post-form.component.css similarity index 100% rename from src/app/login/login.component.css rename to src/app/components/post-form/post-form.component.css diff --git a/src/app/components/post-form/post-form.component.html b/src/app/components/post-form/post-form.component.html new file mode 100644 index 0000000..397f182 --- /dev/null +++ b/src/app/components/post-form/post-form.component.html @@ -0,0 +1 @@ +

post-form works!

diff --git a/src/app/components/post-form/post-form.component.ts b/src/app/components/post-form/post-form.component.ts new file mode 100644 index 0000000..d029999 --- /dev/null +++ b/src/app/components/post-form/post-form.component.ts @@ -0,0 +1,13 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-post-form', + standalone: true, + imports: [], + templateUrl: './post-form.component.html', + styleUrl: './post-form.component.css' +}) +export class PostFormComponent { + + +} diff --git a/src/app/post-home/post-home.component.css b/src/app/components/post-home/post-home.component.css similarity index 100% rename from src/app/post-home/post-home.component.css rename to src/app/components/post-home/post-home.component.css diff --git a/src/app/post-home/post-home.component.html b/src/app/components/post-home/post-home.component.html similarity index 77% rename from src/app/post-home/post-home.component.html rename to src/app/components/post-home/post-home.component.html index 79e1bfa..84ad00e 100644 --- a/src/app/post-home/post-home.component.html +++ b/src/app/components/post-home/post-home.component.html @@ -2,7 +2,7 @@

{{ title }}

{{ category }}

-

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

+ Publié le {{ date | date : "dd/MM/yyyy à HH:mm" }}

{{ description }}

diff --git a/src/app/post-home/post-home.component.ts b/src/app/components/post-home/post-home.component.ts similarity index 100% rename from src/app/post-home/post-home.component.ts rename to src/app/components/post-home/post-home.component.ts diff --git a/src/app/header/header.component.html b/src/app/header/header.component.html deleted file mode 100644 index 1976851..0000000 --- a/src/app/header/header.component.html +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/src/app/home/home.component.css b/src/app/pages/home/home.component.css similarity index 100% rename from src/app/home/home.component.css rename to src/app/pages/home/home.component.css diff --git a/src/app/home/home.component.html b/src/app/pages/home/home.component.html similarity index 100% rename from src/app/home/home.component.html rename to src/app/pages/home/home.component.html diff --git a/src/app/home/home.component.ts b/src/app/pages/home/home.component.ts similarity index 66% rename from src/app/home/home.component.ts rename to src/app/pages/home/home.component.ts index c27fd71..bc2885d 100644 --- a/src/app/home/home.component.ts +++ b/src/app/pages/home/home.component.ts @@ -1,27 +1,25 @@ import {Component, OnDestroy} from '@angular/core'; import {AvatarModule} from 'primeng/avatar'; import {Button} from 'primeng/button'; -import {AuthorService} from '../services/author.service'; -import {Author} from '../models/author'; +import {AuthorService} from '../../services/author.service'; +import {Author} from '../../models/author'; import {JsonPipe} from '@angular/common'; import {Subscription} from 'rxjs'; import {MessageService} from 'primeng/api'; -import {HeaderComponent} from '../header/header.component'; +import {HeaderComponent} from '../../components/header/header.component'; import {ToastModule} from 'primeng/toast'; import {CookieService} from 'ngx-cookie-service'; -import {PostService} from '../services/post.service'; -import {Post} from '../models/post'; -import {PostHomeComponent} from '../post-home/post-home.component'; +import {PostService} from '../../services/post.service'; +import {Post} from '../../models/post'; +import {PostHomeComponent} from '../../components/post-home/post-home.component'; @Component({ selector: 'app-home', standalone: true, imports: [ AvatarModule, - Button, HeaderComponent, ToastModule, - JsonPipe, PostHomeComponent ], templateUrl: './home.component.html', @@ -33,7 +31,6 @@ export class HomeComponent implements OnDestroy { subs: Subscription[] = [] constructor( - private messageService: MessageService, private postService: PostService, private cookieService: CookieService) { @@ -47,16 +44,6 @@ export class HomeComponent implements OnDestroy { })); } - successMessage(summary: string, detail: string): void { - this.messageService.add({ - severity: 'success', - summary: summary, - detail: detail, - life: 3000, - closable: false - }); - } - ngOnDestroy(): void { this.subs.forEach(sub => sub.unsubscribe()); } diff --git a/src/app/login/login.component.html b/src/app/pages/login/login.component.html similarity index 100% rename from src/app/login/login.component.html rename to src/app/pages/login/login.component.html diff --git a/src/app/login/login.component.ts b/src/app/pages/login/login.component.ts similarity index 93% rename from src/app/login/login.component.ts rename to src/app/pages/login/login.component.ts index 4a20a32..e2beec4 100644 --- a/src/app/login/login.component.ts +++ b/src/app/pages/login/login.component.ts @@ -2,14 +2,14 @@ import {ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA, OnDestroy} from '@ import {FormsModule} from '@angular/forms'; import {InputTextModule} from 'primeng/inputtext'; import {Button} from 'primeng/button'; -import {AuthorService} from '../services/author.service'; +import {AuthorService} from '../../services/author.service'; import {ToastModule} from 'primeng/toast'; import {MessageService} from 'primeng/api'; -import {Author} from '../models/author'; +import {Author} from '../../models/author'; import {Subscription, switchMap} from 'rxjs'; import {JsonPipe} from '@angular/common'; import { CookieService } from 'ngx-cookie-service'; -import {HeaderComponent} from '../header/header.component'; +import {HeaderComponent} from '../../components/header/header.component'; import {Router} from '@angular/router'; @Component({ diff --git a/src/app/logout/logout.component.html b/src/app/pages/logout/logout.component.html similarity index 100% rename from src/app/logout/logout.component.html rename to src/app/pages/logout/logout.component.html diff --git a/src/app/logout/logout.component.ts b/src/app/pages/logout/logout.component.ts similarity index 92% rename from src/app/logout/logout.component.ts rename to src/app/pages/logout/logout.component.ts index ed0cfaf..0a9a8ba 100644 --- a/src/app/logout/logout.component.ts +++ b/src/app/pages/logout/logout.component.ts @@ -1,6 +1,6 @@ import {Component, OnInit} from '@angular/core'; import {CookieService} from 'ngx-cookie-service'; -import {HeaderComponent} from '../header/header.component'; +import {HeaderComponent} from '../../components/header/header.component'; import {Router} from '@angular/router'; import {MessageService} from 'primeng/api'; diff --git a/src/app/not-found/not-found.component.css b/src/app/pages/my-posts/my-posts.component.css similarity index 100% rename from src/app/not-found/not-found.component.css rename to src/app/pages/my-posts/my-posts.component.css diff --git a/src/app/pages/my-posts/my-posts.component.html b/src/app/pages/my-posts/my-posts.component.html new file mode 100644 index 0000000..918f98e --- /dev/null +++ b/src/app/pages/my-posts/my-posts.component.html @@ -0,0 +1,59 @@ + + + + + + ID + Titre + Catégorie + Date de publication + Description + + + + + + + + {{ post.id }} + {{ post.title }} + {{ post.category }} + {{ post.publicationDate | date: "dd/MM/yyyy à HH:mm" }} + {{ post.description }} + + + + + + + + + + + + + + + + + + + + + diff --git a/src/app/pages/my-posts/my-posts.component.ts b/src/app/pages/my-posts/my-posts.component.ts new file mode 100644 index 0000000..cd44b80 --- /dev/null +++ b/src/app/pages/my-posts/my-posts.component.ts @@ -0,0 +1,101 @@ +import {Component, OnDestroy} from '@angular/core'; +import {HeaderComponent} from '../../components/header/header.component'; +import {TableModule} from 'primeng/table'; +import {CookieService} from 'ngx-cookie-service'; +import {AuthorService} from '../../services/author.service'; +import {ReplaySubject, Subscription} from 'rxjs'; +import {Post} from '../../models/post'; +import {Author} from '../../models/author'; +import {MessageService} from 'primeng/api'; +import {DatePipe} from '@angular/common'; +import {Button} from 'primeng/button'; +import {DialogModule} from 'primeng/dialog'; +import {InputTextModule} from 'primeng/inputtext'; +import {PostHomeComponent} from '../../components/post-home/post-home.component'; +import {PostService} from '../../services/post.service'; + +@Component({ + selector: 'app-my-posts', + standalone: true, + imports: [ + HeaderComponent, + TableModule, + Button, + DatePipe, + DialogModule, + InputTextModule, + PostHomeComponent + ], + templateUrl: './my-posts.component.html', + styleUrl: './my-posts.component.css' +}) +export class MyPostsComponent implements OnDestroy { + subs: Subscription[] = []; + previewDialogVisibility: boolean[] = []; + updateDialogVisibility: boolean[] = []; + deleteDialogVisibility: boolean[] = []; + posts: Post[] = []; + concernedAuthor: Author | undefined; + + + constructor(private cookieService: CookieService, + private postService: PostService, + private authorService: AuthorService, + private messageService: MessageService) { + this.concernedAuthor = this.cookieService.get('author') ? JSON.parse(this.cookieService.get('author')) : undefined; + this.updatePosts(); + } + + failureMessage(summary: string, detail: string): void { + this.messageService.add({ + severity: 'error', + summary: summary, + detail: detail, + life: 3000, + closable: false + }); + } + + updatePosts(): void { + if (this.cookieService.get('token')) { + this.authorService.getAuthorsPosts(this.concernedAuthor?.id, this.cookieService.get('token')).subscribe({ + next: posts => this.posts = posts, + error: error => this.failureMessage("Erreur", error.message), + } + ) + } + } + + deletePost(id: bigint, rowIndex: number) { + this.postService.deletePost(id, this.cookieService.get('token')).subscribe({ + next: (_) => { + this.updatePosts() + this.successMessage("Post supprimé", "Ce post a été supprimé avec succès") + }, + error: error => this.failureMessage("Erreur", error.message), + }); + this.closeDialog(this.deleteDialogVisibility, rowIndex) + } + + successMessage(summary: string, detail: string): void { + this.messageService.add({ + severity: 'success', + summary: summary, + detail: detail, + life: 3000, + closable: false + }); + } + + openDialog(dialogBooleanTab: boolean[], index: number) { + dialogBooleanTab[index] = true; + } + + closeDialog(dialogBooleanTab: boolean[], index: number) { + dialogBooleanTab[index] = false; + } + + ngOnDestroy(): void { + this.subs.forEach(sub => sub.unsubscribe()); + } +} diff --git a/src/app/new-post/new-post.component.html b/src/app/pages/new-post/new-post.component.html similarity index 100% rename from src/app/new-post/new-post.component.html rename to src/app/pages/new-post/new-post.component.html diff --git a/src/app/new-post/new-post.component.ts b/src/app/pages/new-post/new-post.component.ts similarity index 92% rename from src/app/new-post/new-post.component.ts rename to src/app/pages/new-post/new-post.component.ts index 038a063..646b5d1 100644 --- a/src/app/new-post/new-post.component.ts +++ b/src/app/pages/new-post/new-post.component.ts @@ -1,17 +1,17 @@ import {Component, OnDestroy} from '@angular/core'; -import {HeaderComponent} from '../header/header.component'; +import {HeaderComponent} from '../../components/header/header.component'; import {FormBuilder, FormControl, FormGroup, ReactiveFormsModule, ValidationErrors, Validators} from '@angular/forms'; import {InputTextModule} from 'primeng/inputtext'; import {InputTextareaModule} from 'primeng/inputtextarea'; import {FileSelectEvent, FileUploadModule} from 'primeng/fileupload'; import {mergeMap, Subscription, switchMap} from 'rxjs'; -import {Post} from '../models/post'; -import {PostService} from '../services/post.service'; +import {Post} from '../../models/post'; +import {PostService} from '../../services/post.service'; import {CookieService} from 'ngx-cookie-service'; import {MessageService} from 'primeng/api'; import {EditorModule} from 'primeng/editor'; -import {AuthorService} from '../services/author.service'; -import {Author} from '../models/author'; +import {AuthorService} from '../../services/author.service'; +import {Author} from '../../models/author'; import {Router} from '@angular/router'; @Component({ diff --git a/src/app/not-found/not-found.component.html b/src/app/pages/not-found/not-found.component.html similarity index 100% rename from src/app/not-found/not-found.component.html rename to src/app/pages/not-found/not-found.component.html diff --git a/src/app/not-found/not-found.component.ts b/src/app/pages/not-found/not-found.component.ts similarity index 100% rename from src/app/not-found/not-found.component.ts rename to src/app/pages/not-found/not-found.component.ts diff --git a/src/app/post/post.component.html b/src/app/pages/post/post.component.html similarity index 55% rename from src/app/post/post.component.html rename to src/app/pages/post/post.component.html index 1f0e574..01af6e1 100644 --- a/src/app/post/post.component.html +++ b/src/app/pages/post/post.component.html @@ -1,4 +1,4 @@

{{ concernedPost?.title }}

-{{ concernedPost?.publicationDate | date: "dd/MM/yyyy" }} +Publié le {{ concernedPost?.publicationDate | date: "dd/MM/yyyy à HH:mm" }}
diff --git a/src/app/post/post.component.ts b/src/app/pages/post/post.component.ts similarity index 67% rename from src/app/post/post.component.ts rename to src/app/pages/post/post.component.ts index 5758f5c..e8342cb 100644 --- a/src/app/post/post.component.ts +++ b/src/app/pages/post/post.component.ts @@ -1,19 +1,16 @@ -import { Component } from '@angular/core'; +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'; +import {Post} from '../../models/post'; +import {PostService} from '../../services/post.service'; +import {HeaderComponent} from '../../components/header/header.component'; +import {DatePipe} from '@angular/common'; @Component({ selector: 'app-post', standalone: true, imports: [ HeaderComponent, - JsonPipe, DatePipe ], templateUrl: './post.component.html', diff --git a/src/app/profile/profile.component.html b/src/app/pages/profile/profile.component.html similarity index 100% rename from src/app/profile/profile.component.html rename to src/app/pages/profile/profile.component.html diff --git a/src/app/profile/profile.component.ts b/src/app/pages/profile/profile.component.ts similarity index 88% rename from src/app/profile/profile.component.ts rename to src/app/pages/profile/profile.component.ts index 38913e0..aee4333 100644 --- a/src/app/profile/profile.component.ts +++ b/src/app/pages/profile/profile.component.ts @@ -1,10 +1,10 @@ import {Component, OnDestroy} from '@angular/core'; -import {HeaderComponent} from '../header/header.component'; +import {HeaderComponent} from '../../components/header/header.component'; import {ActivatedRoute, Router} from '@angular/router'; import {CookieService} from 'ngx-cookie-service'; -import {Author} from '../models/author'; +import {Author} from '../../models/author'; import {Subscription} from 'rxjs'; -import {AuthorService} from '../services/author.service'; +import {AuthorService} from '../../services/author.service'; import {JsonPipe} from '@angular/common'; import {AvatarModule} from 'primeng/avatar'; import {CardModule} from 'primeng/card'; diff --git a/src/app/register/register.component.html b/src/app/pages/register/register.component.html similarity index 100% rename from src/app/register/register.component.html rename to src/app/pages/register/register.component.html diff --git a/src/app/register/register.component.ts b/src/app/pages/register/register.component.ts similarity index 78% rename from src/app/register/register.component.ts rename to src/app/pages/register/register.component.ts index f87ae57..e0d4800 100644 --- a/src/app/register/register.component.ts +++ b/src/app/pages/register/register.component.ts @@ -1,5 +1,5 @@ import { Component } from '@angular/core'; -import {HeaderComponent} from '../header/header.component'; +import {HeaderComponent} from '../../components/header/header.component'; @Component({ selector: 'app-register', diff --git a/src/app/services/author.service.ts b/src/app/services/author.service.ts index 4f341a3..4be9556 100644 --- a/src/app/services/author.service.ts +++ b/src/app/services/author.service.ts @@ -2,25 +2,27 @@ import {Injectable} from '@angular/core'; import {HttpClient, HttpHeaders} from '@angular/common/http'; import {Observable} from 'rxjs'; import {Author} from '../models/author'; +import {Post} from '../models/post'; @Injectable({ providedIn: 'root' }) export class AuthorService { + url: string = "http://localhost:8080/api/authors"; constructor(private httpClient: HttpClient) {} list(): Observable { - return this.httpClient.get("http://localhost:8080/api/authors"); + return this.httpClient.get(this.url); } login(name: string, password: string) { - return this.httpClient.post("http://localhost:8080/api/authors/login", {name: name, password: password}) + return this.httpClient.post(`${this.url}/login`, {name: name, password: password}) } me(token: string): Observable { const headers = new HttpHeaders().set("Authorization", "Bearer " + token); - return this.httpClient.get("http://localhost:8080/api/authors/me", {'headers': headers}); + return this.httpClient.get(`${this.url}/me`, {'headers': headers}); } attributePost(authorId: string | undefined, postId: bigint, token: string) { @@ -29,14 +31,23 @@ export class AuthorService { 'Authorization': `Bearer ${token}` }) }; - return this.httpClient.put(`http://localhost:8080/api/authors/${authorId}/posts`, postId, httpOptions); + return this.httpClient.put(`${this.url}/${authorId}/posts`, postId, httpOptions); } getAuthor(id: string | null): Observable { if (id) { - return this.httpClient.get("http://localhost:8080/api/authors/" + id); + return this.httpClient.get(`${this.url}/${id}`); } else { throw new Error("Not Found"); } } + + getAuthorsPosts(id: string | undefined, token: string): Observable { + const httpOptions = { + headers: new HttpHeaders({ + 'Authorization': `Bearer ${token}` + }) + }; + return this.httpClient.get(`${this.url}/${id}/posts`, httpOptions); + } } diff --git a/src/app/services/post.service.ts b/src/app/services/post.service.ts index 35d6a86..3bd54c8 100644 --- a/src/app/services/post.service.ts +++ b/src/app/services/post.service.ts @@ -18,6 +18,15 @@ export class PostService { return this.httpClient.get(`${this.url}/${id}`); } + deletePost(id: bigint, token: string) { + const httpOptions = { + headers: new HttpHeaders({ + 'Authorization': `Bearer ${token}` + }) + }; + return this.httpClient.delete(`${this.url}/${id}`, httpOptions); + } + createPost(post: any, token: string | undefined): Observable { const httpOptions = { headers: new HttpHeaders({ diff --git a/src/index.html b/src/index.html index 2f8af21..f216df2 100644 --- a/src/index.html +++ b/src/index.html @@ -2,7 +2,7 @@ - ReviewFront + A BON ENTENDEUR