aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vs/DevHive-Angular/v16/.suobin32256 -> 52736 bytes
-rw-r--r--.vs/VSWorkspaceState.json5
-rw-r--r--.vs/slnx.sqlitebin167936 -> 167936 bytes
-rw-r--r--src/app/components/post/post.component.html2
-rw-r--r--src/app/components/post/post.component.ts35
-rw-r--r--src/app/services/rating.service.ts27
6 files changed, 61 insertions, 8 deletions
diff --git a/.vs/DevHive-Angular/v16/.suo b/.vs/DevHive-Angular/v16/.suo
index eb32805..ceaae10 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 6e9e1ba..c78c053 100644
--- a/.vs/VSWorkspaceState.json
+++ b/.vs/VSWorkspaceState.json
@@ -1,12 +1,11 @@
{
"ExpandedNodes": [
"",
- "\\e2e\\src",
"\\src",
"\\src\\app",
"\\src\\app\\components",
- "\\src\\app\\components\\post",
- "\\src\\app\\services"
+ "\\src\\app\\services",
+ "\\src\\models"
],
"SelectedNode": "\\src\\app\\services\\rating.service.ts",
"PreviewInSolutionExplorer": false
diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite
index a563275..5dcda80 100644
--- a/.vs/slnx.sqlite
+++ b/.vs/slnx.sqlite
Binary files differ
diff --git a/src/app/components/post/post.component.html b/src/app/components/post/post.component.html
index 4584591..830fa75 100644
--- a/src/app/components/post/post.component.html
+++ b/src/app/components/post/post.component.html
@@ -36,7 +36,7 @@
<summary class="score">
{{ votesNumber }}
</summary>
- <button class="vote">
+ <button class="vote" (click)="downVotePost()">
</button>
</section>
diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts
index 0f48337..168b6a3 100644
--- a/src/app/components/post/post.component.ts
+++ b/src/app/components/post/post.component.ts
@@ -66,10 +66,45 @@ export class PostComponent implements OnInit {
return;
}
+ this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe(
+ () => {
+ this.votesNumber += 2;
+ },
+ () => {
+ 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;
+ }
+
+ 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 5a86b67..9403575 100644
--- a/src/app/services/rating.service.ts
+++ b/src/app/services/rating.service.ts
@@ -22,16 +22,35 @@ export class RatingService {
return this.createRatingRequest(userId, token, postId, isLike);
}
+ putRatingWithSessionStorageRequest(postId: Guid, isLike: boolean): Observable<object> {
+ const userId = this._tokenService.getUserIdFromSessionStorageToken();
+ const token = this._tokenService.getTokenFromSessionStorage();
+
+ return this.putRatingRequest(userId, token, postId, isLike);
+ }
+
createRatingRequest(userId: Guid, authToken: string, postId: Guid, isLike: boolean): Observable<object> {
+ const options = {
+ params: new HttpParams().set('UserId', userId.toString()),
+ headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken)
+ };
const body = {
postId: postId.toString(),
isLike: isLike
- };
+ };
+
+ return this._http.post(AppConstants.API_RATING_URL, body, options);
+ }
+
+ putRatingRequest(userId: Guid, authToken: string, postId: Guid, isLike: boolean): Observable<object> {
const options = {
- params: new HttpParams().set('UserId', userId.toString()),
- headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken)
+ params: new HttpParams().set('UserId', userId.toString()).set('PostId', postId.toString()),
+ headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken)
+ };
+ const body = {
+ isLike: isLike
};
- return this._http.post(AppConstants.API_RATING_URL, body, options);
+ return this._http.put(AppConstants.API_RATING_URL, body, options);
}
}