From 1f008dfc777022582e5e0cf0823175e66c2790cf Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sat, 6 Mar 2021 14:43:32 +0200 Subject: starting development of rating system --- src/app/services/rating.service.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/app/services/rating.service.ts (limited to 'src/app/services') diff --git a/src/app/services/rating.service.ts b/src/app/services/rating.service.ts new file mode 100644 index 0000000..630a43c --- /dev/null +++ b/src/app/services/rating.service.ts @@ -0,0 +1,17 @@ +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import * as FormData from 'form-data'; +import { Guid } from 'guid-typescript'; +import { Observable } from 'rxjs'; +import { Post } from 'src/models/post'; +import { AppConstants } from '../app-constants.module'; +import { TokenService } from './token.service'; + + +@Injectable({ + providedIn: 'root' +}) +export class RatingService { + constructor(private _http: HttpClient, private _tokenService: TokenService) + { } +} -- cgit v1.2.3 From 051da12e0edd5408c902695fbc45ddd15d7972b1 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Thu, 11 Mar 2021 21:57:16 +0200 Subject: added upvote post functionality --- .vs/DevHive-Angular/v16/.suo | Bin 32256 -> 32256 bytes .vs/slnx.sqlite | Bin 167936 -> 167936 bytes src/app/app-constants.module.ts | 1 + src/app/components/post/post.component.ts | 17 +++++++++++++++-- src/app/services/post.service.ts | 2 +- src/app/services/rating.service.ts | 20 ++++++++++++++++++++ 6 files changed, 37 insertions(+), 3 deletions(-) (limited to 'src/app/services') diff --git a/.vs/DevHive-Angular/v16/.suo b/.vs/DevHive-Angular/v16/.suo index c5248df..eb32805 100644 Binary files a/.vs/DevHive-Angular/v16/.suo and b/.vs/DevHive-Angular/v16/.suo differ diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index d413bfa..a563275 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite 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 { + 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 { + 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); + } } -- cgit v1.2.3 From afeba5e832d87bc659d72e7d945a78821bd7e7b8 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Fri, 12 Mar 2021 21:16:34 +0200 Subject: adding downVote functionality --- .vs/DevHive-Angular/v16/.suo | Bin 32256 -> 52736 bytes .vs/VSWorkspaceState.json | 5 ++-- .vs/slnx.sqlite | Bin 167936 -> 167936 bytes src/app/components/post/post.component.html | 2 +- src/app/components/post/post.component.ts | 35 ++++++++++++++++++++++++++++ src/app/services/rating.service.ts | 27 +++++++++++++++++---- 6 files changed, 61 insertions(+), 8 deletions(-) (limited to 'src/app/services') diff --git a/.vs/DevHive-Angular/v16/.suo b/.vs/DevHive-Angular/v16/.suo index eb32805..ceaae10 100644 Binary files a/.vs/DevHive-Angular/v16/.suo and b/.vs/DevHive-Angular/v16/.suo 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 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite 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 @@ {{ votesNumber }} - 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 { + 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 { + 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 { 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); } } -- cgit v1.2.3 From 531ce1bbda5f3909a0701b14377ae08b5c1993cb Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Fri, 12 Mar 2021 21:30:18 +0200 Subject: adding functionality to get rating by userid and postId in rating service --- .vs/slnx.sqlite | Bin 167936 -> 167936 bytes src/app/services/rating.service.ts | 16 ++++++++++++++++ 2 files changed, 16 insertions(+) (limited to 'src/app/services') diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 5dcda80..9e7e654 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/src/app/services/rating.service.ts b/src/app/services/rating.service.ts index 9403575..f3e3265 100644 --- a/src/app/services/rating.service.ts +++ b/src/app/services/rating.service.ts @@ -29,6 +29,13 @@ export class RatingService { return this.putRatingRequest(userId, token, postId, isLike); } + getRatingByUserAndPostWithSessionStorageRequest(postId: Guid): Observable { + const userId = this._tokenService.getUserIdFromSessionStorageToken(); + const token = this._tokenService.getTokenFromSessionStorage(); + + return this.getRatingByUserAndPostRequest(userId, token, postId); + } + createRatingRequest(userId: Guid, authToken: string, postId: Guid, isLike: boolean): Observable { const options = { params: new HttpParams().set('UserId', userId.toString()), @@ -53,4 +60,13 @@ export class RatingService { return this._http.put(AppConstants.API_RATING_URL, body, options); } + + getRatingByUserAndPostRequest(userId: Guid, authToken: string, postId: Guid): Observable { + const options = { + params: new HttpParams().set('UserId', userId.toString()).set('PostId', postId.toString()), + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + + return this._http.get(AppConstants.API_RATING_URL + 'GetByUserAndPost', options); + } } -- cgit v1.2.3 From 2ea7a39c3f8eaf90ec28f8fd6fc465f215a0d99b Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sat, 13 Mar 2021 11:46:57 +0200 Subject: upVote functionality is finished --- .vs/DevHive-Angular/v16/.suo | Bin 52736 -> 62976 bytes .vs/VSWorkspaceState.json | 3 +- .vs/slnx.sqlite | Bin 167936 -> 167936 bytes src/app/components/post/post.component.ts | 71 ++++++++++++++++++++---------- src/app/services/rating.service.ts | 18 +++++++- 5 files changed, 66 insertions(+), 26 deletions(-) (limited to 'src/app/services') diff --git a/.vs/DevHive-Angular/v16/.suo b/.vs/DevHive-Angular/v16/.suo index ceaae10..6b50c82 100644 Binary files a/.vs/DevHive-Angular/v16/.suo and b/.vs/DevHive-Angular/v16/.suo 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 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite 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 { + 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 { 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 { + 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); } } -- cgit v1.2.3 From e8fef550d576aa3eba9d51ea70a3beeac6157ba5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 14 Mar 2021 09:03:03 +0200 Subject: Renamed all models to have proper naming (from model-name.ts to model-name.model.ts), updated includes of services --- src/app/services/comment.service.ts | 2 +- src/app/services/language.service.ts | 2 +- src/app/services/post.service.ts | 2 +- src/app/services/technology.service.ts | 2 +- src/app/services/user.service.ts | 6 +- src/models/comment.model.ts | 70 +++++++++++++++++++++++ src/models/comment.ts | 70 ----------------------- src/models/identity/friend.model.ts | 3 + src/models/identity/friend.ts | 3 - src/models/identity/role.model.ts | 3 + src/models/identity/role.ts | 3 - src/models/identity/user.model.ts | 100 +++++++++++++++++++++++++++++++++ src/models/identity/user.ts | 100 --------------------------------- src/models/language.model.ts | 6 ++ src/models/language.ts | 6 -- src/models/post-comment.model.ts | 5 ++ src/models/post-comment.ts | 5 -- src/models/post.model.ts | 81 ++++++++++++++++++++++++++ src/models/post.ts | 81 -------------------------- src/models/technology.model.ts | 6 ++ src/models/technology.ts | 6 -- 21 files changed, 281 insertions(+), 281 deletions(-) create mode 100644 src/models/comment.model.ts delete mode 100644 src/models/comment.ts create mode 100644 src/models/identity/friend.model.ts delete mode 100644 src/models/identity/friend.ts create mode 100644 src/models/identity/role.model.ts delete mode 100644 src/models/identity/role.ts create mode 100644 src/models/identity/user.model.ts delete mode 100644 src/models/identity/user.ts create mode 100644 src/models/language.model.ts delete mode 100644 src/models/language.ts create mode 100644 src/models/post-comment.model.ts delete mode 100644 src/models/post-comment.ts create mode 100644 src/models/post.model.ts delete mode 100644 src/models/post.ts create mode 100644 src/models/technology.model.ts delete mode 100644 src/models/technology.ts (limited to 'src/app/services') diff --git a/src/app/services/comment.service.ts b/src/app/services/comment.service.ts index c9dbf35..29707ab 100644 --- a/src/app/services/comment.service.ts +++ b/src/app/services/comment.service.ts @@ -2,7 +2,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Guid } from 'guid-typescript'; import { Observable } from 'rxjs'; -import { Comment } from 'src/models/comment'; +import { Comment } from 'src/models/comment.model'; import { AppConstants } from '../app-constants.module'; import { TokenService } from './token.service'; diff --git a/src/app/services/language.service.ts b/src/app/services/language.service.ts index 15e241f..5846dd6 100644 --- a/src/app/services/language.service.ts +++ b/src/app/services/language.service.ts @@ -2,7 +2,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Guid } from 'guid-typescript'; import { Observable } from 'rxjs'; -import { Language } from 'src/models/language'; +import { Language } from 'src/models/language.model'; import { AppConstants } from '../app-constants.module'; import { TokenService } from './token.service'; diff --git a/src/app/services/post.service.ts b/src/app/services/post.service.ts index 7b2a539..eb613a6 100644 --- a/src/app/services/post.service.ts +++ b/src/app/services/post.service.ts @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core'; import * as FormData from 'form-data'; import { Guid } from 'guid-typescript'; import { Observable } from 'rxjs'; -import { Post } from 'src/models/post'; +import { Post } from 'src/models/post.model'; import { AppConstants } from '../app-constants.module'; import { TokenService } from './token.service'; diff --git a/src/app/services/technology.service.ts b/src/app/services/technology.service.ts index dbdc039..fcc3d4c 100644 --- a/src/app/services/technology.service.ts +++ b/src/app/services/technology.service.ts @@ -2,7 +2,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Guid } from 'guid-typescript'; import { Observable } from 'rxjs'; -import { Technology } from 'src/models/technology'; +import { Technology } from 'src/models/technology.model'; import { AppConstants } from '../app-constants.module'; import { TokenService } from './token.service'; diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts index 31862c4..f22952e 100644 --- a/src/app/services/user.service.ts +++ b/src/app/services/user.service.ts @@ -1,12 +1,12 @@ import { Injectable } from '@angular/core'; import { Guid } from 'guid-typescript'; -import { User } from '../../models/identity/user'; +import { User } from '../../models/identity/user.model'; import { FormGroup } from '@angular/forms'; import { AppConstants } from 'src/app/app-constants.module'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; -import { Role } from 'src/models/identity/role'; -import { Friend } from 'src/models/identity/friend'; +import { Role } from 'src/models/identity/role.model'; +import { Friend } from 'src/models/identity/friend.model'; import { TokenService } from './token.service'; @Injectable({ diff --git a/src/models/comment.model.ts b/src/models/comment.model.ts new file mode 100644 index 0000000..0d1755f --- /dev/null +++ b/src/models/comment.model.ts @@ -0,0 +1,70 @@ +import { Guid } from 'guid-typescript'; + +export class Comment { + private _commentId: Guid; + private _postId: Guid; + private _issuerFirstName: string; + private _issuerLastName: string; + private _issuerUsername: string; + private _message: string; + private _timeCreated: Date; + + constructor(commentId: Guid, postId: Guid, issuerFirstName: string, issuerLastName: string, issuerUsername: string, message: string, timeCreated: Date) { + this.commentId = commentId; + this.postId = postId; + this.issuerFirstName = issuerFirstName; + this.issuerLastName = issuerLastName; + this.issuerUsername = issuerUsername; + this.message = message; + this.timeCreated = timeCreated; + } + + public get commentId(): Guid { + return this._commentId; + } + public set commentId(v: Guid) { + this._commentId = v; + } + + public get postId(): Guid { + return this._postId; + } + public set postId(v: Guid) { + this._postId = v; + } + + public get issuerFirstName(): string { + return this._issuerFirstName; + } + public set issuerFirstName(v: string) { + this._issuerFirstName = v; + } + + public get issuerLastName(): string { + return this._issuerLastName; + } + public set issuerLastName(v: string) { + this._issuerLastName = v; + } + + public get issuerUsername(): string { + return this._issuerUsername; + } + public set issuerUsername(v: string) { + this._issuerUsername = v; + } + + public get message(): string { + return this._message; + } + public set message(v: string) { + this._message = v; + } + + public get timeCreated(): Date { + return this._timeCreated; + } + public set timeCreated(v: Date) { + this._timeCreated = v; + } +} diff --git a/src/models/comment.ts b/src/models/comment.ts deleted file mode 100644 index 0d1755f..0000000 --- a/src/models/comment.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { Guid } from 'guid-typescript'; - -export class Comment { - private _commentId: Guid; - private _postId: Guid; - private _issuerFirstName: string; - private _issuerLastName: string; - private _issuerUsername: string; - private _message: string; - private _timeCreated: Date; - - constructor(commentId: Guid, postId: Guid, issuerFirstName: string, issuerLastName: string, issuerUsername: string, message: string, timeCreated: Date) { - this.commentId = commentId; - this.postId = postId; - this.issuerFirstName = issuerFirstName; - this.issuerLastName = issuerLastName; - this.issuerUsername = issuerUsername; - this.message = message; - this.timeCreated = timeCreated; - } - - public get commentId(): Guid { - return this._commentId; - } - public set commentId(v: Guid) { - this._commentId = v; - } - - public get postId(): Guid { - return this._postId; - } - public set postId(v: Guid) { - this._postId = v; - } - - public get issuerFirstName(): string { - return this._issuerFirstName; - } - public set issuerFirstName(v: string) { - this._issuerFirstName = v; - } - - public get issuerLastName(): string { - return this._issuerLastName; - } - public set issuerLastName(v: string) { - this._issuerLastName = v; - } - - public get issuerUsername(): string { - return this._issuerUsername; - } - public set issuerUsername(v: string) { - this._issuerUsername = v; - } - - public get message(): string { - return this._message; - } - public set message(v: string) { - this._message = v; - } - - public get timeCreated(): Date { - return this._timeCreated; - } - public set timeCreated(v: Date) { - this._timeCreated = v; - } -} diff --git a/src/models/identity/friend.model.ts b/src/models/identity/friend.model.ts new file mode 100644 index 0000000..22290cd --- /dev/null +++ b/src/models/identity/friend.model.ts @@ -0,0 +1,3 @@ +export class Friend { + public userName: string; +} diff --git a/src/models/identity/friend.ts b/src/models/identity/friend.ts deleted file mode 100644 index 22290cd..0000000 --- a/src/models/identity/friend.ts +++ /dev/null @@ -1,3 +0,0 @@ -export class Friend { - public userName: string; -} diff --git a/src/models/identity/role.model.ts b/src/models/identity/role.model.ts new file mode 100644 index 0000000..132b0b0 --- /dev/null +++ b/src/models/identity/role.model.ts @@ -0,0 +1,3 @@ +export class Role { + public name: string; +} diff --git a/src/models/identity/role.ts b/src/models/identity/role.ts deleted file mode 100644 index 132b0b0..0000000 --- a/src/models/identity/role.ts +++ /dev/null @@ -1,3 +0,0 @@ -export class Role { - public name: string; -} diff --git a/src/models/identity/user.model.ts b/src/models/identity/user.model.ts new file mode 100644 index 0000000..e0038e0 --- /dev/null +++ b/src/models/identity/user.model.ts @@ -0,0 +1,100 @@ +import { Guid } from 'guid-typescript'; +import { Language } from '../language'; +import { Technology } from '../technology'; +import { Friend } from './friend'; +import { Role } from './role'; + +export class User { + private _id : Guid; + private _lastName : string; + private _firstName : string; + private _userName : string; + private _email: string; + private _profilePictureURL : string; + private _languages: Language[]; + private _technologies: Technology[]; + private _roles: Role[]; + private _friends: Friend[]; + + constructor(id: Guid, userName: string, firstName: string, lastName: string, email: string, profilePictureURL: string, languages: Language[], technologies: Technology[], roles: Role[], friends: Friend[]) { + this.id = id; + this.userName = userName; + this.firstName = firstName; + this.lastName = lastName; + this.email = email; + this._profilePictureURL = profilePictureURL; + this.languages = languages; + this.technologies = technologies; + this.roles = roles; + } + + public get id(): Guid { + return this._id; + } + public set id(v: Guid) { + this._id = v; + } + + public get userName(): string { + return this._userName; + } + public set userName(v: string) { + this._userName = v; + } + + public get firstName(): string { + return this._firstName; + } + public set firstName(v: string) { + this._firstName = v; + } + + public get lastName(): string { + return this._lastName; + } + public set lastName(v: string) { + this._lastName = v; + } + + public get email(): string { + return this._email; + } + public set email(v: string) { + this._email = v; + } + + public get profilePictureURL(): string { + return this._profilePictureURL; + } + public set profilePictureURL(v: string) { + this._profilePictureURL = v; + } + + public get languages(): Language[] { + return this._languages; + } + public set languages(v: Language[]) { + this._languages = v; + } + + public get technologies(): Technology[] { + return this._technologies; + } + public set technologies(v: Technology[]) { + this._technologies = v; + } + + public get roles(): Role[] { + return this._roles; + } + public set roles(v: Role[]) { + this._roles = v; + } + + public get friends(): Friend[] { + return this._friends; + } + public set friends(v: Friend[]) { + this._friends = v; + } +} diff --git a/src/models/identity/user.ts b/src/models/identity/user.ts deleted file mode 100644 index e0038e0..0000000 --- a/src/models/identity/user.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { Guid } from 'guid-typescript'; -import { Language } from '../language'; -import { Technology } from '../technology'; -import { Friend } from './friend'; -import { Role } from './role'; - -export class User { - private _id : Guid; - private _lastName : string; - private _firstName : string; - private _userName : string; - private _email: string; - private _profilePictureURL : string; - private _languages: Language[]; - private _technologies: Technology[]; - private _roles: Role[]; - private _friends: Friend[]; - - constructor(id: Guid, userName: string, firstName: string, lastName: string, email: string, profilePictureURL: string, languages: Language[], technologies: Technology[], roles: Role[], friends: Friend[]) { - this.id = id; - this.userName = userName; - this.firstName = firstName; - this.lastName = lastName; - this.email = email; - this._profilePictureURL = profilePictureURL; - this.languages = languages; - this.technologies = technologies; - this.roles = roles; - } - - public get id(): Guid { - return this._id; - } - public set id(v: Guid) { - this._id = v; - } - - public get userName(): string { - return this._userName; - } - public set userName(v: string) { - this._userName = v; - } - - public get firstName(): string { - return this._firstName; - } - public set firstName(v: string) { - this._firstName = v; - } - - public get lastName(): string { - return this._lastName; - } - public set lastName(v: string) { - this._lastName = v; - } - - public get email(): string { - return this._email; - } - public set email(v: string) { - this._email = v; - } - - public get profilePictureURL(): string { - return this._profilePictureURL; - } - public set profilePictureURL(v: string) { - this._profilePictureURL = v; - } - - public get languages(): Language[] { - return this._languages; - } - public set languages(v: Language[]) { - this._languages = v; - } - - public get technologies(): Technology[] { - return this._technologies; - } - public set technologies(v: Technology[]) { - this._technologies = v; - } - - public get roles(): Role[] { - return this._roles; - } - public set roles(v: Role[]) { - this._roles = v; - } - - public get friends(): Friend[] { - return this._friends; - } - public set friends(v: Friend[]) { - this._friends = v; - } -} diff --git a/src/models/language.model.ts b/src/models/language.model.ts new file mode 100644 index 0000000..e3aa61e --- /dev/null +++ b/src/models/language.model.ts @@ -0,0 +1,6 @@ +import { Guid } from 'guid-typescript'; + +export class Language { + public id: Guid; + public name: string; +} diff --git a/src/models/language.ts b/src/models/language.ts deleted file mode 100644 index e3aa61e..0000000 --- a/src/models/language.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Guid } from 'guid-typescript'; - -export class Language { - public id: Guid; - public name: string; -} diff --git a/src/models/post-comment.model.ts b/src/models/post-comment.model.ts new file mode 100644 index 0000000..5d1e346 --- /dev/null +++ b/src/models/post-comment.model.ts @@ -0,0 +1,5 @@ +import { Guid } from 'guid-typescript'; + +export class PostComment { + public id: Guid; +} diff --git a/src/models/post-comment.ts b/src/models/post-comment.ts deleted file mode 100644 index 5d1e346..0000000 --- a/src/models/post-comment.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Guid } from 'guid-typescript'; - -export class PostComment { - public id: Guid; -} diff --git a/src/models/post.model.ts b/src/models/post.model.ts new file mode 100644 index 0000000..8e58bea --- /dev/null +++ b/src/models/post.model.ts @@ -0,0 +1,81 @@ +import { Guid } from 'guid-typescript'; +import { Comment } from './comment'; +import { PostComment } from './post-comment'; + +export class Post { + private _postId: Guid; + private _creatorFirstName: string; + private _creatorLastName: string; + private _creatorUsername: string; + private _message: string; + private _timeCreated: Date; + private _comments: PostComment[]; + private _fileURLs: string[]; + + constructor(postId: Guid, creatorFirstName: string, creatorLastName: string, creatorUsername: string, message: string, timeCreated: Date, comments: PostComment[], fileURLs: string[]) { + this.postId = postId; + this.creatorFirstName = creatorFirstName; + this.creatorLastName = creatorLastName; + this.creatorUsername = creatorUsername; + this.message = message; + this.timeCreated = timeCreated; + this.comments = comments; + this.fileURLs = fileURLs; + } + + public get postId(): Guid { + return this._postId; + } + public set postId(v: Guid) { + this._postId = v; + } + + public get creatorFirstName(): string { + return this._creatorFirstName; + } + public set creatorFirstName(v: string) { + this._creatorFirstName = v; + } + + public get creatorLastName(): string { + return this._creatorLastName; + } + public set creatorLastName(v: string) { + this._creatorLastName = v; + } + + public get creatorUsername(): string { + return this._creatorUsername; + } + public set creatorUsername(v: string) { + this._creatorUsername = v; + } + + public get message(): string { + return this._message; + } + public set message(v: string) { + this._message = v; + } + + public get timeCreated(): Date { + return this._timeCreated; + } + public set timeCreated(v: Date) { + this._timeCreated = v; + } + + public get comments(): PostComment[] { + return this._comments; + } + public set comments(v: PostComment[]) { + this._comments = v; + } + + public get fileURLs(): string[] { + return this._fileURLs; + } + public set fileURLs(v: string[]) { + this._fileURLs = v; + } +} diff --git a/src/models/post.ts b/src/models/post.ts deleted file mode 100644 index 8e58bea..0000000 --- a/src/models/post.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { Guid } from 'guid-typescript'; -import { Comment } from './comment'; -import { PostComment } from './post-comment'; - -export class Post { - private _postId: Guid; - private _creatorFirstName: string; - private _creatorLastName: string; - private _creatorUsername: string; - private _message: string; - private _timeCreated: Date; - private _comments: PostComment[]; - private _fileURLs: string[]; - - constructor(postId: Guid, creatorFirstName: string, creatorLastName: string, creatorUsername: string, message: string, timeCreated: Date, comments: PostComment[], fileURLs: string[]) { - this.postId = postId; - this.creatorFirstName = creatorFirstName; - this.creatorLastName = creatorLastName; - this.creatorUsername = creatorUsername; - this.message = message; - this.timeCreated = timeCreated; - this.comments = comments; - this.fileURLs = fileURLs; - } - - public get postId(): Guid { - return this._postId; - } - public set postId(v: Guid) { - this._postId = v; - } - - public get creatorFirstName(): string { - return this._creatorFirstName; - } - public set creatorFirstName(v: string) { - this._creatorFirstName = v; - } - - public get creatorLastName(): string { - return this._creatorLastName; - } - public set creatorLastName(v: string) { - this._creatorLastName = v; - } - - public get creatorUsername(): string { - return this._creatorUsername; - } - public set creatorUsername(v: string) { - this._creatorUsername = v; - } - - public get message(): string { - return this._message; - } - public set message(v: string) { - this._message = v; - } - - public get timeCreated(): Date { - return this._timeCreated; - } - public set timeCreated(v: Date) { - this._timeCreated = v; - } - - public get comments(): PostComment[] { - return this._comments; - } - public set comments(v: PostComment[]) { - this._comments = v; - } - - public get fileURLs(): string[] { - return this._fileURLs; - } - public set fileURLs(v: string[]) { - this._fileURLs = v; - } -} diff --git a/src/models/technology.model.ts b/src/models/technology.model.ts new file mode 100644 index 0000000..1869d14 --- /dev/null +++ b/src/models/technology.model.ts @@ -0,0 +1,6 @@ +import { Guid } from 'guid-typescript'; + +export class Technology { + public id: Guid; + public name: string; +} diff --git a/src/models/technology.ts b/src/models/technology.ts deleted file mode 100644 index 1869d14..0000000 --- a/src/models/technology.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Guid } from 'guid-typescript'; - -export class Technology { - public id: Guid; - public name: string; -} -- cgit v1.2.3 From 904b618fbd00d5e21328a0e709bce3cf9f45cae1 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 14 Mar 2021 21:59:04 +0200 Subject: Fixed outdated imports in post component and rating service --- src/app/components/post/post.component.ts | 18 +++++++++--------- src/app/services/rating.service.ts | 6 ++---- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'src/app/services') diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index 4bb41a7..319e9cd 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -4,8 +4,8 @@ import { Guid } from 'guid-typescript'; import { PostService } from 'src/app/services/post.service'; 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 { User } from 'src/models/identity/user.model'; +import { Post } from 'src/models/post.model'; import { TokenService } from '../../services/token.service'; @Component({ @@ -41,9 +41,9 @@ export class PostComponent implements OnInit { this.voteBtns = document.getElementsByClassName('vote') as HTMLCollectionOf; - this.timeCreated = new Date(this.post.timeCreated).toLocaleString('en-GB'); + this.timeCreated = new Date(this.post.timeCreated).toLocaleString('en-GB'); - this.loadUser(); + this.loadUser(); } }); } @@ -75,7 +75,7 @@ export class PostComponent implements OnInit { } this._ratingServe.getRatingByUserAndPostWithSessionStorageRequest(Guid.parse(this.paramId)).subscribe( - (x: object) => { + (x: object) => { if (Object.values(x)[3] === isLike) { this.deleteRating(Object.values(x)[0], isLike); @@ -99,14 +99,14 @@ export class PostComponent implements OnInit { this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), isLike).subscribe( () => { this.votesNumber += -1 + Number(isLike) * 2; - } - ); -} + } + ); + } private putRating(isLike: boolean): void { this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), isLike).subscribe( () => { - // when false -2 + 0 wjen true -2 + 4 + // when false -2 + 0 wjen true -2 + 4 this.votesNumber += -2 + Number(isLike) * 4; } ); diff --git a/src/app/services/rating.service.ts b/src/app/services/rating.service.ts index 58ff1f4..be35a81 100644 --- a/src/app/services/rating.service.ts +++ b/src/app/services/rating.service.ts @@ -1,9 +1,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import * as FormData from 'form-data'; import { Guid } from 'guid-typescript'; import { Observable } from 'rxjs'; -import { Post } from 'src/models/post'; import { AppConstants } from '../app-constants.module'; import { TokenService } from './token.service'; @@ -51,7 +49,7 @@ export class RatingService { const body = { postId: postId.toString(), isLike: isLike - }; + }; return this._http.post(AppConstants.API_RATING_URL, body, options); } @@ -61,7 +59,7 @@ export class RatingService { params: new HttpParams().set('UserId', userId.toString()).set('PostId', postId.toString()), headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) }; - const body = { + const body = { isLike: isLike }; -- cgit v1.2.3 From 084238dfa39f31b3661362cbe8cdea44e8f05992 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 19 Mar 2021 19:52:26 +0200 Subject: Fixed requests, following API updates --- src/app/services/comment.service.ts | 4 ++-- src/app/services/language.service.ts | 2 +- src/app/services/post.service.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/app/services') diff --git a/src/app/services/comment.service.ts b/src/app/services/comment.service.ts index 29707ab..70ab005 100644 --- a/src/app/services/comment.service.ts +++ b/src/app/services/comment.service.ts @@ -55,7 +55,7 @@ export class CommentService { getCommentRequest(id: Guid): Observable { const options = { - params: new HttpParams().set('Id', id.toString()) + params: new HttpParams().set('CommentId', id.toString()) }; return this._http.get(AppConstants.API_COMMENT_URL, options); } @@ -75,7 +75,7 @@ export class CommentService { deleteCommentRequest(commentId: Guid, authToken: string): Observable { const options = { - params: new HttpParams().set('Id', commentId.toString()), + params: new HttpParams().set('CommentId', commentId.toString()), headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) }; return this._http.delete(AppConstants.API_COMMENT_URL, options); diff --git a/src/app/services/language.service.ts b/src/app/services/language.service.ts index 5846dd6..ec368da 100644 --- a/src/app/services/language.service.ts +++ b/src/app/services/language.service.ts @@ -105,7 +105,7 @@ export class LanguageService { deleteLanguageRequest(authToken: string, langId: Guid): Observable { const options = { - params: new HttpParams().set('Id', langId.toString()), + params: new HttpParams().set('LanguageId', langId.toString()), headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) }; return this._http.delete(AppConstants.API_LANGUAGE_URL, options); diff --git a/src/app/services/post.service.ts b/src/app/services/post.service.ts index c8bd892..b49ffea 100644 --- a/src/app/services/post.service.ts +++ b/src/app/services/post.service.ts @@ -78,7 +78,7 @@ export class PostService { deletePostRequest(postId: Guid, authToken: string): Observable { const options = { - params: new HttpParams().set('Id', postId.toString()), + params: new HttpParams().set('PostId', postId.toString()), headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) }; return this._http.delete(AppConstants.API_POST_URL, options); -- cgit v1.2.3 From b78b0d1509ba1f7eae276734254933374544827e Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 22 Mar 2021 16:36:15 +0200 Subject: Service methods that return default object values now return empty string values --- src/app/services/comment.service.ts | 2 +- src/app/services/post.service.ts | 2 +- src/app/services/user.service.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/app/services') diff --git a/src/app/services/comment.service.ts b/src/app/services/comment.service.ts index 70ab005..9839b01 100644 --- a/src/app/services/comment.service.ts +++ b/src/app/services/comment.service.ts @@ -14,7 +14,7 @@ export class CommentService { { } getDefaultComment(): Comment { - return new Comment(Guid.createEmpty(), Guid.createEmpty(), 'Gosho', 'Trapov', 'gosho_trapov', 'Your opinion on my idea?', new Date()); + return new Comment(Guid.createEmpty(), Guid.createEmpty(), '', '', '', '', new Date()); } /* Requests from session storage */ diff --git a/src/app/services/post.service.ts b/src/app/services/post.service.ts index b49ffea..1a6e021 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(), [], [], 0); + return new Post(Guid.createEmpty(), '', '', '', '', new Date(), [], [], 0); } /* Requests from session storage */ diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts index f22952e..29058b4 100644 --- a/src/app/services/user.service.ts +++ b/src/app/services/user.service.ts @@ -17,7 +17,7 @@ export class UserService { { } getDefaultUser(): User { - return new User(Guid.createEmpty(), 'gosho_trapov', 'Gosho', 'Trapov', 'gotra@bg.com', AppConstants.FALLBACK_PROFILE_ICON, [], [], [], []); + return new User(Guid.createEmpty(), '', '', '', '', AppConstants.FALLBACK_PROFILE_ICON, [], [], [], []); } /* Requests from session storage */ -- cgit v1.2.3 From ab8122e2cbeefe55b7dca1aeeb1cbaf830ed25b5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 29 Mar 2021 15:46:25 +0300 Subject: Fixed update user request in service and in profile settings --- .../profile-settings/profile-settings.component.ts | 2 +- src/app/services/user.service.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/app/services') diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index 4724f02..78a57ec 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -201,7 +201,7 @@ export class ProfileSettingsComponent implements OnInit { this.patchLanguagesControl(); this.patchTechnologiesControl(); - this._userService.putUserFromSessionStorageRequest(this.updateUserFormGroup, this.user.roles, this.user.friends).subscribe({ + this._userService.putUserFromSessionStorageRequest(this.updateUserFormGroup, this.chosenLanguages, this.chosenTechnologies, this.user.roles, this.user.friends).subscribe({ next: () => { this._successBar.showMsg('Profile updated successfully!'); diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts index 29058b4..10c8c59 100644 --- a/src/app/services/user.service.ts +++ b/src/app/services/user.service.ts @@ -8,6 +8,8 @@ import { Observable } from 'rxjs'; import { Role } from 'src/models/identity/role.model'; import { Friend } from 'src/models/identity/friend.model'; import { TokenService } from './token.service'; +import { Language } from 'src/models/language.model'; +import { Technology } from 'src/models/technology.model'; @Injectable({ providedIn: 'root' @@ -36,11 +38,11 @@ export class UserService { return this.addFriendToUserRequest(userUserName, token, newFriendUserName); } - putUserFromSessionStorageRequest(updateUserFormGroup: FormGroup, userRoles: Role[], userFriends: Friend[]): Observable { + putUserFromSessionStorageRequest(updateUserFormGroup: FormGroup, languages: Language[], technologies: Technology[], userRoles: Role[], userFriends: Friend[]): Observable { const userId = this._tokenService.getUserIdFromSessionStorageToken(); const token = this._tokenService.getTokenFromSessionStorage(); - return this.putUserRequest(userId, token, updateUserFormGroup, userRoles, userFriends); + return this.putUserRequest(userId, token, updateUserFormGroup, languages, technologies, userRoles, userFriends); } putProfilePictureFromSessionStorageRequest(newPicture: File): Observable { @@ -119,7 +121,7 @@ export class UserService { return this._http.get(AppConstants.API_USER_URL + '/GetUser', options); } - putUserRequest(userId: Guid, authToken: string, updateUserFormGroup: FormGroup, userRoles: Role[], userFriends: Friend[]): Observable { + putUserRequest(userId: Guid, authToken: string, updateUserFormGroup: FormGroup, languages: Language[], technologies: Technology[], userRoles: Role[], userFriends: Friend[]): Observable { const body = { UserName: updateUserFormGroup.get('username')?.value, Email: updateUserFormGroup.get('email')?.value, @@ -128,8 +130,8 @@ export class UserService { Password: updateUserFormGroup.get('password')?.value, Roles: userRoles, Friends: userFriends, - Languages: updateUserFormGroup.get('languages')?.value, - Technologies: updateUserFormGroup.get('technologies')?.value + Languages: languages, + Technologies: technologies }; const options = { params: new HttpParams().set('Id', userId.toString()), -- cgit v1.2.3 From 386b25c583c1a1632282beab91537ff54e1bce83 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 7 Apr 2021 21:13:28 +0300 Subject: Added profile picture service and removed put profile picture from user service --- src/app/app-constants.module.ts | 1 + src/app/services/profile-picture.service.ts | 32 +++++++++++++++++++++++++++++ src/app/services/user.service.ts | 17 --------------- 3 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 src/app/services/profile-picture.service.ts (limited to 'src/app/services') diff --git a/src/app/app-constants.module.ts b/src/app/app-constants.module.ts index 39538e0..d1bd9f5 100644 --- a/src/app/app-constants.module.ts +++ b/src/app/app-constants.module.ts @@ -2,6 +2,7 @@ export class AppConstants { public static BASE_API_URL = 'http://localhost:5000/api'; public static API_USER_URL = AppConstants.BASE_API_URL + '/User'; + public static API_PROFILE_PICTURE_URL = AppConstants.BASE_API_URL + '/ProfilePicture'; public static API_USER_LOGIN_URL = AppConstants.API_USER_URL + '/login'; public static API_USER_REGISTER_URL = AppConstants.API_USER_URL + '/register'; diff --git a/src/app/services/profile-picture.service.ts b/src/app/services/profile-picture.service.ts new file mode 100644 index 0000000..8b9d0a3 --- /dev/null +++ b/src/app/services/profile-picture.service.ts @@ -0,0 +1,32 @@ +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Guid } from 'guid-typescript'; +import { Observable } from 'rxjs'; +import { AppConstants } from '../app-constants.module'; +import { TokenService } from './token.service'; + +@Injectable({ + providedIn: 'root' +}) +export class ProfilePictureService { + constructor(private _http: HttpClient, private _tokenService: TokenService) + { } + + putPictureWithSessionStorageRequest(newPicture: File): Observable { + const userId = this._tokenService.getUserIdFromSessionStorageToken(); + const token = this._tokenService.getTokenFromSessionStorage(); + + return this.putRatingRequest(userId, token, newPicture); + } + + putRatingRequest(userId: Guid, authToken: string, newPicture: File): Observable { + const options = { + params: new HttpParams().set('UserId', userId.toString()), + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + const form = new FormData(); + form.append('picture', newPicture); + + return this._http.put(AppConstants.API_PROFILE_PICTURE_URL, form, options); + } +} diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts index 10c8c59..e910ada 100644 --- a/src/app/services/user.service.ts +++ b/src/app/services/user.service.ts @@ -45,13 +45,6 @@ export class UserService { return this.putUserRequest(userId, token, updateUserFormGroup, languages, technologies, userRoles, userFriends); } - putProfilePictureFromSessionStorageRequest(newPicture: File): Observable { - const userId = this._tokenService.getUserIdFromSessionStorageToken(); - const token = this._tokenService.getTokenFromSessionStorage(); - - return this.putProfilePictureRequest(userId, token, newPicture); - } - putBareUserFromSessionStorageRequest(user: User, password: string): Observable { const userId = this._tokenService.getUserIdFromSessionStorageToken(); const token = this._tokenService.getTokenFromSessionStorage(); @@ -150,16 +143,6 @@ export class UserService { return this._http.put(AppConstants.API_USER_URL, body, options); } - putProfilePictureRequest(userId: Guid, authToken: string, newPicture: File): Observable { - const form = new FormData(); - form.append('picture', newPicture); - const options = { - params: new HttpParams().set('UserId', userId.toString()), - headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) - }; - return this._http.put(AppConstants.API_USER_URL + '/ProfilePicture', form, options); - } - deleteUserRequest(userId: Guid, authToken: string): Observable { const options = { params: new HttpParams().set('Id', userId.toString()), -- cgit v1.2.3 From ed7f805d265e3162639d329785de0edb8cfc22ff Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 8 Apr 2021 09:19:39 +0300 Subject: Added friends service, from which you could add and remove friends --- src/app/app-constants.module.ts | 1 + src/app/services/friend.service.ts | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/app/services/friend.service.ts (limited to 'src/app/services') diff --git a/src/app/app-constants.module.ts b/src/app/app-constants.module.ts index d1bd9f5..67091d9 100644 --- a/src/app/app-constants.module.ts +++ b/src/app/app-constants.module.ts @@ -3,6 +3,7 @@ export class AppConstants { public static API_USER_URL = AppConstants.BASE_API_URL + '/User'; public static API_PROFILE_PICTURE_URL = AppConstants.BASE_API_URL + '/ProfilePicture'; + public static API_FRIENDS_URL = AppConstants.BASE_API_URL + '/Friends'; public static API_USER_LOGIN_URL = AppConstants.API_USER_URL + '/login'; public static API_USER_REGISTER_URL = AppConstants.API_USER_URL + '/register'; diff --git a/src/app/services/friend.service.ts b/src/app/services/friend.service.ts new file mode 100644 index 0000000..6821606 --- /dev/null +++ b/src/app/services/friend.service.ts @@ -0,0 +1,44 @@ +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Guid } from 'guid-typescript'; +import { Observable } from 'rxjs'; +import { AppConstants } from '../app-constants.module'; +import { TokenService } from './token.service'; + +@Injectable({ + providedIn: 'root' +}) +export class FriendService { + constructor(private _http: HttpClient, private _tokenService: TokenService) + { } + + postFriendWithSessionStorageRequest(friendUsername: string): Observable { + const userId = this._tokenService.getUserIdFromSessionStorageToken(); + const token = this._tokenService.getTokenFromSessionStorage(); + + return this.postFriendRequest(userId, token, friendUsername); + } + + deleteFriendWithSessionStorageRequest(friendUsername: string): Observable { + const userId = this._tokenService.getUserIdFromSessionStorageToken(); + const token = this._tokenService.getTokenFromSessionStorage(); + + return this.deleteFriendRequest(userId, token, friendUsername); + } + + postFriendRequest(userId: Guid, authToken: string, friendUsername: string): Observable { + const options = { + params: new HttpParams().set('UserId', userId.toString()).set('FriendUsername', friendUsername), + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + return this._http.post(AppConstants.API_FRIENDS_URL, {}, options); + } + + deleteFriendRequest(userId: Guid, authToken: string, friendUsername: string): Observable { + const options = { + params: new HttpParams().set('UserId', userId.toString()).set('FriendUsername', friendUsername), + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + return this._http.delete(AppConstants.API_FRIENDS_URL, options); + } +} -- cgit v1.2.3 From 3b778aef651fe9383a281c4c2999f21312ea28ba Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 8 Apr 2021 09:24:10 +0300 Subject: Removed unused bare user requests from user service --- src/app/services/user.service.ts | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'src/app/services') diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts index e910ada..690fff5 100644 --- a/src/app/services/user.service.ts +++ b/src/app/services/user.service.ts @@ -45,13 +45,6 @@ export class UserService { return this.putUserRequest(userId, token, updateUserFormGroup, languages, technologies, userRoles, userFriends); } - putBareUserFromSessionStorageRequest(user: User, password: string): Observable { - const userId = this._tokenService.getUserIdFromSessionStorageToken(); - const token = this._tokenService.getTokenFromSessionStorage(); - - return this.putBareUserRequest(userId, token, user, password); - } - deleteUserFromSessionStorageRequest(): Observable { const userId = this._tokenService.getUserIdFromSessionStorageToken(); const token = this._tokenService.getTokenFromSessionStorage(); @@ -133,16 +126,6 @@ export class UserService { return this._http.put(AppConstants.API_USER_URL, body, options); } - putBareUserRequest(userId: Guid, authToken: string, user: User, password: string): Observable { - const body: object = user; - Object.assign(body, { password: password }); - const options = { - params: new HttpParams().set('Id', userId.toString()), - headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) - }; - return this._http.put(AppConstants.API_USER_URL, body, options); - } - deleteUserRequest(userId: Guid, authToken: string): Observable { const options = { params: new HttpParams().set('Id', userId.toString()), -- cgit v1.2.3