From daee45c90d9699d392f1b16df041fccf46a4de4f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 2 Feb 2021 18:36:22 +0200 Subject: Finished implementation of post updating in UI --- .../app/components/post-page/post-page.component.ts | 15 ++++++++------- src/DevHive.Angular/src/app/services/post.service.ts | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 15 deletions(-) (limited to 'src') 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 8796f20..21a5e50 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 @@ -101,14 +101,15 @@ export class PostPageComponent implements OnInit { } if (this.editingPost) { - const newMessage = this.editPostFormGroup.get('newPostMessage')?.value; - if (newMessage !== '') { - this._postService.putPostWithSessionStorageRequest(this.postId, newMessage).subscribe( - (result: object) => { - this.reloadPage(); - } - ); + let newMessage = this.editPostFormGroup.get('newPostMessage')?.value; + if (newMessage === '') { + newMessage = this.post.message; } + this._postService.putPostWithSessionStorageRequest(this.postId, newMessage, this.files).subscribe( + (result: object) => { + this.reloadPage(); + } + ); } this.editingPost = !this.editingPost; } diff --git a/src/DevHive.Angular/src/app/services/post.service.ts b/src/DevHive.Angular/src/app/services/post.service.ts index 466c0bb..7b2a539 100644 --- a/src/DevHive.Angular/src/app/services/post.service.ts +++ b/src/DevHive.Angular/src/app/services/post.service.ts @@ -27,11 +27,11 @@ export class PostService { return this.createPostRequest(userId, token, postMessage, files); } - putPostWithSessionStorageRequest(postId: Guid, newMessage: string): Observable { + putPostWithSessionStorageRequest(postId: Guid, newMessage: string, posts: File[]): Observable { const userId = this._tokenService.getUserIdFromSessionStorageToken(); const token = this._tokenService.getTokenFromSessionStorage(); - return this.putPostRequest(userId, token, postId, newMessage); + return this.putPostRequest(userId, token, postId, newMessage, posts); } deletePostWithSessionStorage(postId: Guid): Observable { @@ -62,16 +62,18 @@ export class PostService { return this._http.get(AppConstants.API_POST_URL, options); } - putPostRequest(userId: Guid, authToken: string, postId: Guid, newMessage: string): Observable { - const body = { - postId: postId.toString(), - newMessage: newMessage - }; + putPostRequest(userId: Guid, authToken: string, postId: Guid, newMessage: string, files: File[]): Observable { + const form = new FormData(); + form.append('postId', postId); + form.append('newMessage', newMessage); + for (const file of files) { + form.append('files', file, file.name); + } const options = { params: new HttpParams().set('UserId', userId.toString()), headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) }; - return this._http.put(AppConstants.API_POST_URL, body, options); + return this._http.put(AppConstants.API_POST_URL, form, options); } deletePostRequest(postId: Guid, authToken: string): Observable { -- cgit v1.2.3