aboutsummaryrefslogtreecommitdiff
path: root/src/app/components/post/post.component.ts
diff options
context:
space:
mode:
authorDanail Dimitrov <danaildimitrov321@gmail.com>2021-03-11 21:57:16 +0200
committerDanail Dimitrov <danaildimitrov321@gmail.com>2021-03-11 21:57:16 +0200
commit051da12e0edd5408c902695fbc45ddd15d7972b1 (patch)
tree8b626c44f135f166e9833aa9fbb5d92adb455193 /src/app/components/post/post.component.ts
parentfe4c9eaeac345c63e0c08c43b9dc3185d07716e8 (diff)
downloadDevHive-Angular-051da12e0edd5408c902695fbc45ddd15d7972b1.tar
DevHive-Angular-051da12e0edd5408c902695fbc45ddd15d7972b1.tar.gz
DevHive-Angular-051da12e0edd5408c902695fbc45ddd15d7972b1.zip
added upvote post functionality
Diffstat (limited to 'src/app/components/post/post.component.ts')
-rw-r--r--src/app/components/post/post.component.ts17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts
index f813d8c..0f48337 100644
--- a/src/app/components/post/post.component.ts
+++ b/src/app/components/post/post.component.ts
@@ -6,6 +6,7 @@ import { RatingService } from 'src/app/services/rating.service';
import { UserService } from 'src/app/services/user.service';
import { User } from 'src/models/identity/user';
import { Post } from 'src/models/post';
+import { TokenService } from '../../services/token.service';
@Component({
selector: 'app-post',
@@ -19,11 +20,14 @@ export class PostComponent implements OnInit {
public votesNumber: number;
public timeCreated: string;
@Input() paramId: string;
+ public loggedIn = false;
- constructor(private _postService: PostService, private _ratingServe: RatingService, private _userService: UserService, private _router: Router)
+ constructor(private _postService: PostService, private _ratingServe: RatingService, private _userService: UserService, private _router: Router, private _tokenService: TokenService)
{ }
ngOnInit(): void {
+ this.loggedIn = this._tokenService.getTokenFromSessionStorage() !== '';
+
this.post = this._postService.getDefaultPost();
this.user = this._userService.getDefaultUser();
@@ -57,6 +61,15 @@ export class PostComponent implements OnInit {
}
upVotePost(): void {
-
+ if (!this.loggedIn) {
+ this._router.navigate(['/login']);
+ return;
+ }
+
+ this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe(
+ () => {
+ this.votesNumber++;
+ }
+ );
}
}