aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-02-02 18:36:22 +0200
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-02-02 18:36:22 +0200
commitdaee45c90d9699d392f1b16df041fccf46a4de4f (patch)
treedfe26b1fd1b01a5cdcdc61542a4c8af602e456ea
parenta7709358f6a6575e9dd42ec1eabf74d8b552cf3a (diff)
downloadDevHive-daee45c90d9699d392f1b16df041fccf46a4de4f.tar
DevHive-daee45c90d9699d392f1b16df041fccf46a4de4f.tar.gz
DevHive-daee45c90d9699d392f1b16df041fccf46a4de4f.zip
Finished implementation of post updating in UI
-rw-r--r--src/DevHive.Angular/src/app/components/post-page/post-page.component.ts15
-rw-r--r--src/DevHive.Angular/src/app/services/post.service.ts18
2 files changed, 18 insertions, 15 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 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<object> {
+ putPostWithSessionStorageRequest(postId: Guid, newMessage: string, posts: File[]): Observable<object> {
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<object> {
@@ -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<object> {
- const body = {
- postId: postId.toString(),
- newMessage: newMessage
- };
+ putPostRequest(userId: Guid, authToken: string, postId: Guid, newMessage: string, files: File[]): Observable<object> {
+ 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<object> {