From 51fded7271f4d94412310c075634d3a8aafb35ef Mon Sep 17 00:00:00 2001 From: JakubWalkowiak Date: Sun, 3 Jan 2021 14:21:56 +0100 Subject: [PATCH] added accept and decline functions --- .../group-candidates.component.html | 2 +- .../group-candidates.component.ts | 8 +++++--- .../group-edit/group-edit.component.html | 16 +++++++++++----- .../group-edit/group-edit.component.ts | 17 +++++++++++++++-- .../group-users/group-users.component.html | 2 +- .../group-users/group-users.component.ts | 4 +++- .../group/services/group-candidate.service.ts | 8 ++++++-- src/environments/environment.ts | 3 ++- 8 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/app/group/components/group-candidates/group-candidates.component.html b/src/app/group/components/group-candidates/group-candidates.component.html index e6f2369..d83482e 100644 --- a/src/app/group/components/group-candidates/group-candidates.component.html +++ b/src/app/group/components/group-candidates/group-candidates.component.html @@ -11,7 +11,7 @@
- +
diff --git a/src/app/group/components/group-candidates/group-candidates.component.ts b/src/app/group/components/group-candidates/group-candidates.component.ts index a66570b..cde8f16 100644 --- a/src/app/group/components/group-candidates/group-candidates.component.ts +++ b/src/app/group/components/group-candidates/group-candidates.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnInit } from '@angular/core'; +import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core'; import { User } from 'src/app/user/interfaces/user.interface'; @Component({ @@ -9,6 +9,8 @@ import { User } from 'src/app/user/interfaces/user.interface'; export class GroupCandidatesComponent implements OnInit { @Input() candidates: User[]; + @Output() accept = new EventEmitter(); + @Output() decline = new EventEmitter(); constructor() { } @@ -17,11 +19,11 @@ export class GroupCandidatesComponent implements OnInit { } onAccept(id: string): void { - + this.accept.emit(id); } onDecline(id: string): void { - + this.decline.emit(id); } } diff --git a/src/app/group/components/group-edit/group-edit.component.html b/src/app/group/components/group-edit/group-edit.component.html index a2adfa4..591e0ef 100644 --- a/src/app/group/components/group-edit/group-edit.component.html +++ b/src/app/group/components/group-edit/group-edit.component.html @@ -1,8 +1,8 @@
- - + +

Group info:

@@ -21,11 +21,17 @@

Users:

- +
-
+

Group candidates:

- +
diff --git a/src/app/group/components/group-edit/group-edit.component.ts b/src/app/group/components/group-edit/group-edit.component.ts index 50b7c88..fed1cbd 100644 --- a/src/app/group/components/group-edit/group-edit.component.ts +++ b/src/app/group/components/group-edit/group-edit.component.ts @@ -15,7 +15,7 @@ export class GroupEditComponent implements OnInit { group$: Observable; groupCandidates$: Observable; - userId: string; + currentUserId: string; groupId: number; constructor(private groupService: GroupService, @@ -24,7 +24,7 @@ export class GroupEditComponent implements OnInit { private router: Router) { } ngOnInit(): void { - this.userId = localStorage.getItem('userId'); + this.currentUserId = localStorage.getItem('userId'); this.groupId = this.activatedRoute.snapshot.params['groupId']; this.group$ = this.groupService.getGroup(this.groupId); this.groupCandidates$ = this.groupCandidateService.getList(this.groupId); @@ -42,4 +42,17 @@ export class GroupEditComponent implements OnInit { }); } + onCandidateAccept(userId: string) { + this.groupCandidateService.accept(this.groupId, userId).subscribe(() => { + this.group$ = this.groupService.getGroup(this.groupId); + this.groupCandidates$ = this.groupCandidateService.getList(this.groupId); + }); + } + + onCandidateDecline(userId: string) { + this.groupCandidateService.decline(this.groupId, userId).subscribe(() => { + this.groupCandidates$ = this.groupCandidateService.getList(this.groupId); + }); + } + } diff --git a/src/app/group/components/group-users/group-users.component.html b/src/app/group/components/group-users/group-users.component.html index 1eba419..8dfbaa8 100644 --- a/src/app/group/components/group-users/group-users.component.html +++ b/src/app/group/components/group-users/group-users.component.html @@ -10,7 +10,7 @@
- +
diff --git a/src/app/group/components/group-users/group-users.component.ts b/src/app/group/components/group-users/group-users.component.ts index ab604d4..08fef5b 100644 --- a/src/app/group/components/group-users/group-users.component.ts +++ b/src/app/group/components/group-users/group-users.component.ts @@ -9,12 +9,14 @@ import { User } from 'src/app/user/interfaces/user.interface'; export class GroupUsersComponent implements OnInit { @Input() groupUsers: User[]; + @Input() adminId: string; @Output() deleteUser = new EventEmitter(); + currentUserId: string; constructor() { } ngOnInit(): void { - + this.currentUserId = localStorage.getItem('userId'); } onDeleteUser(id: string): void { diff --git a/src/app/group/services/group-candidate.service.ts b/src/app/group/services/group-candidate.service.ts index 319379d..8e421fa 100644 --- a/src/app/group/services/group-candidate.service.ts +++ b/src/app/group/services/group-candidate.service.ts @@ -24,7 +24,11 @@ export class GroupCandidateService { return this.http.post(environment.host + environment.apiEndpoints.groupCandidates.joinRequest, joinRequest); } - delete(): Observable { - return this.http.delete(`${environment.host}${environment.apiEndpoints.groupCandidates.delete}/${localStorage.getItem('userId')}`); + accept(groupId: number, userId: string): Observable { + return this.http.get(`${environment.host}${environment.apiEndpoints.groupCandidates.accept}/${groupId}/${userId}`); + } + + decline(groupId: number, userId: string): Observable { + return this.http.delete(`${environment.host}${environment.apiEndpoints.groupCandidates.decline}/${groupId}/${userId}`); } } diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 83bccd4..e071207 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -30,7 +30,8 @@ export const environment = { groupCandidates: { getList: 'api/groupCandidates/list', joinRequest: 'api/groupCandidates/join-request', - delete: 'api/groupCandidates/delete' + accept: 'api/groupCandidates/accept', + decline: 'api/groupCandidates/decline' } } };