aboutsummaryrefslogtreecommitdiff
path: root/src/app/components/post/post.component.ts
diff options
context:
space:
mode:
authorDanail Dimitrov <danaildimitrov321@gmail.com>2021-03-13 11:46:57 +0200
committerDanail Dimitrov <danaildimitrov321@gmail.com>2021-03-13 11:46:57 +0200
commit2ea7a39c3f8eaf90ec28f8fd6fc465f215a0d99b (patch)
tree12e948c76ad9ff1ad4fd8d365ea80290515aa942 /src/app/components/post/post.component.ts
parent531ce1bbda5f3909a0701b14377ae08b5c1993cb (diff)
downloadDevHive-Angular-2ea7a39c3f8eaf90ec28f8fd6fc465f215a0d99b.tar
DevHive-Angular-2ea7a39c3f8eaf90ec28f8fd6fc465f215a0d99b.tar.gz
DevHive-Angular-2ea7a39c3f8eaf90ec28f8fd6fc465f215a0d99b.zip
upVote functionality is finished
Diffstat (limited to 'src/app/components/post/post.component.ts')
-rw-r--r--src/app/components/post/post.component.ts71
1 files changed, 47 insertions, 24 deletions
diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts
index 168b6a3..68bf161 100644
--- a/src/app/components/post/post.component.ts
+++ b/src/app/components/post/post.component.ts
@@ -22,8 +22,7 @@ export class PostComponent implements OnInit {
@Input() paramId: string;
public loggedIn = false;
- constructor(private _postService: PostService, private _ratingServe: RatingService, private _userService: UserService, private _router: Router, private _tokenService: TokenService)
- { }
+ constructor(private _postService: PostService, private _ratingServe: RatingService, private _userService: UserService, private _router: Router, private _tokenService: TokenService) { }
ngOnInit(): void {
this.loggedIn = this._tokenService.getTokenFromSessionStorage() !== '';
@@ -66,45 +65,69 @@ export class PostComponent implements OnInit {
return;
}
- this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe(
- () => {
- this.votesNumber += 2;
+ this._ratingServe.getRatingByUserAndPostWithSessionStorageRequest(Guid.parse(this.paramId)).subscribe(
+ (x: object) => {
+ if (Object.values(x)[3]) {
+ this.deleteUpVoteRating(Object.values(x)[0]);
+ }
+ else {
+ this.putUpVoteRating();
+ }
},
() => {
this.crateUpVoteRating();
}
- );
- }
-
- crateUpVoteRating(): void {
- this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe(
- () => {
- this.votesNumber++;
- }
);
}
-
- downVotePost(): void {
- if (!this.loggedIn) {
- this._router.navigate(['/login']);
- return;
+
+ crateUpVoteRating(): void {
+ this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe(
+ () => {
+ this.votesNumber++;
}
+ );
+}
- this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), false).subscribe(
+ putUpVoteRating(): void {
+ this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe(
() => {
- this.votesNumber -= 2;
+ this.votesNumber += 2;
},
() => {
- this.crateDownVoteRating();
+ this.crateUpVoteRating();
}
- );
+ );
}
- crateDownVoteRating(): void {
- this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), false).subscribe(
+ deleteUpVoteRating(ratingId: string): void {
+ this._ratingServe.deleteRatingFromSessionStorageRequest(Guid.parse(ratingId)).subscribe(
() => {
this.votesNumber--;
}
);
}
+
+ downVotePost(): void {
+ if(!this.loggedIn) {
+ this._router.navigate(['/login']);
+ return;
+}
+
+this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), false).subscribe(
+ () => {
+ this.votesNumber -= 2;
+ },
+ () => {
+ this.crateDownVoteRating();
+ }
+);
+ }
+
+ crateDownVoteRating(): void {
+ this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), false).subscribe(
+ () => {
+ this.votesNumber--;
+ }
+ );
+}
}