aboutsummaryrefslogtreecommitdiff
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
parentfe4c9eaeac345c63e0c08c43b9dc3185d07716e8 (diff)
downloadDevHive-Angular-051da12e0edd5408c902695fbc45ddd15d7972b1.tar
DevHive-Angular-051da12e0edd5408c902695fbc45ddd15d7972b1.tar.gz
DevHive-Angular-051da12e0edd5408c902695fbc45ddd15d7972b1.zip
added upvote post functionality
-rw-r--r--.vs/DevHive-Angular/v16/.suobin32256 -> 32256 bytes
-rw-r--r--.vs/slnx.sqlitebin167936 -> 167936 bytes
-rw-r--r--src/app/app-constants.module.ts1
-rw-r--r--src/app/components/post/post.component.ts17
-rw-r--r--src/app/services/post.service.ts2
-rw-r--r--src/app/services/rating.service.ts20
6 files changed, 37 insertions, 3 deletions
diff --git a/.vs/DevHive-Angular/v16/.suo b/.vs/DevHive-Angular/v16/.suo
index c5248df..eb32805 100644
--- a/.vs/DevHive-Angular/v16/.suo
+++ b/.vs/DevHive-Angular/v16/.suo
Binary files differ
diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite
index d413bfa..a563275 100644
--- a/.vs/slnx.sqlite
+++ b/.vs/slnx.sqlite
Binary files differ
diff --git a/src/app/app-constants.module.ts b/src/app/app-constants.module.ts
index d72af53..f8722f7 100644
--- a/src/app/app-constants.module.ts
+++ b/src/app/app-constants.module.ts
@@ -9,6 +9,7 @@ export class AppConstants {
public static API_TECHNOLOGY_URL = AppConstants.BASE_API_URL + '/Technology';
public static API_POST_URL = AppConstants.BASE_API_URL + '/Post';
+ public static API_RATING_URL = AppConstants.BASE_API_URL + '/Rating';
public static API_FEED_URL = AppConstants.BASE_API_URL + '/Feed';
public static API_COMMENT_URL = AppConstants.BASE_API_URL + '/Comment';
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++;
+ }
+ );
}
}
diff --git a/src/app/services/post.service.ts b/src/app/services/post.service.ts
index 7b2a539..d582085 100644
--- a/src/app/services/post.service.ts
+++ b/src/app/services/post.service.ts
@@ -15,7 +15,7 @@ export class PostService {
{ }
getDefaultPost(): Post {
- return new Post(Guid.createEmpty(), 'Gosho', 'Trapov', 'gosho_trapov', 'Your opinion on my idea?', new Date(), [], []);
+ return new Post(Guid.createEmpty(), 'Gosho', 'Trapov', 'gosho_trapov', 'Your opinion on my idea?', new Date(), [], [], 0);
}
/* Requests from session storage */
diff --git a/src/app/services/rating.service.ts b/src/app/services/rating.service.ts
index 630a43c..5a86b67 100644
--- a/src/app/services/rating.service.ts
+++ b/src/app/services/rating.service.ts
@@ -14,4 +14,24 @@ import { TokenService } from './token.service';
export class RatingService {
constructor(private _http: HttpClient, private _tokenService: TokenService)
{ }
+
+ createRatingWithSessionStorageRequest(postId: Guid, isLike: boolean): Observable<object> {
+ const userId = this._tokenService.getUserIdFromSessionStorageToken();
+ const token = this._tokenService.getTokenFromSessionStorage();
+
+ return this.createRatingRequest(userId, token, postId, isLike);
+ }
+
+ createRatingRequest(userId: Guid, authToken: string, postId: Guid, isLike: boolean): Observable<object> {
+ const body = {
+ postId: postId.toString(),
+ isLike: isLike
+ };
+ const options = {
+ params: new HttpParams().set('UserId', userId.toString()),
+ headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken)
+ };
+
+ return this._http.post(AppConstants.API_RATING_URL, body, options);
+ }
}