diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-02-01 12:47:48 +0200 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-02-01 12:47:48 +0200 |
| commit | d92db08645c6efefa329f2ca0e244951f46596c9 (patch) | |
| tree | 741a2b8d56fe8a2af885af8c72621d78b20b9ddd /src/DevHive.Angular | |
| parent | e6521851635da41a4334ccead73659b5a864b4a3 (diff) | |
| download | DevHive-d92db08645c6efefa329f2ca0e244951f46596c9.tar DevHive-d92db08645c6efefa329f2ca0e244951f46596c9.tar.gz DevHive-d92db08645c6efefa329f2ca0e244951f46596c9.zip | |
Implemented deleting post in post-page
Diffstat (limited to 'src/DevHive.Angular')
| -rw-r--r-- | src/DevHive.Angular/src/app/components/post-page/post-page.component.ts | 7 | ||||
| -rw-r--r-- | src/DevHive.Angular/src/app/services/post.service.ts | 18 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/DevHive.Angular/src/app/components/post-page/post-page.component.ts b/src/DevHive.Angular/src/app/components/post-page/post-page.component.ts index 3705ae6..de8aa94 100644 --- a/src/DevHive.Angular/src/app/components/post-page/post-page.component.ts +++ b/src/DevHive.Angular/src/app/components/post-page/post-page.component.ts @@ -49,7 +49,7 @@ export class PostPageComponent implements OnInit { if (this.editingPost) { const newMessage = this.editPostFormGroup.get('newPostMessage')?.value; if (newMessage !== '') { - this._postService.putPostFromSessionStorageRequest(this.postId, newMessage).subscribe( + this._postService.putPostWithSessionStorageRequest(this.postId, newMessage).subscribe( (result: object) => { // Reload the page this._router.routeReuseStrategy.shouldReuseRoute = () => false; @@ -63,5 +63,10 @@ export class PostPageComponent implements OnInit { } deletePost(): void { + this._postService.deletePostWithSessionStorage(this.postId).subscribe( + (result: object) => { + this._router.navigate(['/profile/' + this._tokenService.getUsernameFromSessionStorageToken()]); + } + ); } } diff --git a/src/DevHive.Angular/src/app/services/post.service.ts b/src/DevHive.Angular/src/app/services/post.service.ts index c8f9a61..2cca9be 100644 --- a/src/DevHive.Angular/src/app/services/post.service.ts +++ b/src/DevHive.Angular/src/app/services/post.service.ts @@ -20,20 +20,26 @@ export class PostService { /* Requests from session storage */ - createPostFromSessionStorageRequest(postMessage: string): Observable<object> { + createPostWithSessionStorageRequest(postMessage: string): Observable<object> { const userId = this._tokenService.getUserIdFromSessionStorageToken(); const token = this._tokenService.getTokenFromSessionStorage(); return this.createPostRequest(userId, token, postMessage); } - putPostFromSessionStorageRequest(postId: Guid, newMessage: string): Observable<object> { + putPostWithSessionStorageRequest(postId: Guid, newMessage: string): Observable<object> { const userId = this._tokenService.getUserIdFromSessionStorageToken(); const token = this._tokenService.getTokenFromSessionStorage(); return this.putPostRequest(userId, token, postId, newMessage); } + deletePostWithSessionStorage(postId: Guid): Observable<object> { + const token = this._tokenService.getTokenFromSessionStorage(); + + return this.deletePostRequest(postId, token); + } + /* Post requests */ createPostRequest(userId: Guid, authToken: string, postMessage: string): Observable<object> { @@ -64,4 +70,12 @@ export class PostService { }; return this._http.put(AppConstants.API_POST_URL, body, options); } + + deletePostRequest(postId: Guid, authToken: string): Observable<object> { + const options = { + params: new HttpParams().set('Id', postId.toString()), + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + return this._http.delete(AppConstants.API_POST_URL, options); + } } |
