aboutsummaryrefslogtreecommitdiff
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
parent531ce1bbda5f3909a0701b14377ae08b5c1993cb (diff)
downloadDevHive-Angular-2ea7a39c3f8eaf90ec28f8fd6fc465f215a0d99b.tar
DevHive-Angular-2ea7a39c3f8eaf90ec28f8fd6fc465f215a0d99b.tar.gz
DevHive-Angular-2ea7a39c3f8eaf90ec28f8fd6fc465f215a0d99b.zip
upVote functionality is finished
-rw-r--r--.vs/DevHive-Angular/v16/.suobin52736 -> 62976 bytes
-rw-r--r--.vs/VSWorkspaceState.json3
-rw-r--r--.vs/slnx.sqlitebin167936 -> 167936 bytes
-rw-r--r--src/app/components/post/post.component.ts71
-rw-r--r--src/app/services/rating.service.ts18
5 files changed, 66 insertions, 26 deletions
diff --git a/.vs/DevHive-Angular/v16/.suo b/.vs/DevHive-Angular/v16/.suo
index ceaae10..6b50c82 100644
--- a/.vs/DevHive-Angular/v16/.suo
+++ b/.vs/DevHive-Angular/v16/.suo
Binary files differ
diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json
index c78c053..9d81b57 100644
--- a/.vs/VSWorkspaceState.json
+++ b/.vs/VSWorkspaceState.json
@@ -4,9 +4,10 @@
"\\src",
"\\src\\app",
"\\src\\app\\components",
+ "\\src\\app\\components\\post",
"\\src\\app\\services",
"\\src\\models"
],
- "SelectedNode": "\\src\\app\\services\\rating.service.ts",
+ "SelectedNode": "\\src\\app\\components\\post\\post.component.ts",
"PreviewInSolutionExplorer": false
} \ No newline at end of file
diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite
index 9e7e654..e79a43d 100644
--- a/.vs/slnx.sqlite
+++ b/.vs/slnx.sqlite
Binary files differ
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--;
+ }
+ );
+}
}
diff --git a/src/app/services/rating.service.ts b/src/app/services/rating.service.ts
index f3e3265..58ff1f4 100644
--- a/src/app/services/rating.service.ts
+++ b/src/app/services/rating.service.ts
@@ -36,6 +36,13 @@ export class RatingService {
return this.getRatingByUserAndPostRequest(userId, token, postId);
}
+ deleteRatingFromSessionStorageRequest(ratingId: Guid): Observable<object> {
+ const userId = this._tokenService.getUserIdFromSessionStorageToken();
+ const token = this._tokenService.getTokenFromSessionStorage();
+
+ return this.deleteRatingRequest(userId, token, ratingId);
+ }
+
createRatingRequest(userId: Guid, authToken: string, postId: Guid, isLike: boolean): Observable<object> {
const options = {
params: new HttpParams().set('UserId', userId.toString()),
@@ -67,6 +74,15 @@ export class RatingService {
headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken)
};
- return this._http.get(AppConstants.API_RATING_URL + 'GetByUserAndPost', options);
+ return this._http.get(AppConstants.API_RATING_URL + '/GetByUserAndPost', options);
+ }
+
+ deleteRatingRequest(userId: Guid, authToken: string, ratingId: Guid): Observable<object> {
+ const options = {
+ params: new HttpParams().set('UserId', userId.toString()).set('RatingId', ratingId.toString()),
+ headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken)
+ };
+
+ return this._http.delete(AppConstants.API_RATING_URL, options);
}
}