From 95aa7e2883a9fafcc3c729d37c039e60616b3d4c Mon Sep 17 00:00:00 2001 From: Jakub Walkowiak Date: Wed, 23 Dec 2020 23:37:16 +0100 Subject: [PATCH] changed services and views --- src/app/app-routing.module.ts | 2 ++ .../group-edit/group-edit.component.html | 5 +++-- .../group-edit/group-edit.component.ts | 4 ++-- .../group-main/group-main.component.html | 2 -- src/app/group/group.module.ts | 2 ++ .../subject-main/subject-main.component.ts | 17 +++++++++-------- .../subject-delete-request.service.ts | 10 +++++----- src/app/subject/services/subject.service.ts | 12 ++++++------ src/app/subject/subject.module.ts | 3 +++ .../user/components/login/login.component.ts | 2 +- src/environments/environment.ts | 19 +++++++++++++------ 11 files changed, 46 insertions(+), 32 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index d5cd793..8b10b1f 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -1,3 +1,4 @@ +import { GroupModule } from './group/group.module'; import { AuthGuard } from './auth/auth.guard'; import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; @@ -5,6 +6,7 @@ import { Routes, RouterModule } from '@angular/router'; const routes: Routes = [ { path: '', redirectTo: 'user', pathMatch: 'full' }, + { path: 'group', loadChildren: () => import('./group/group.module').then(m => m.GroupModule), canActivate: [AuthGuard] }, { path: 'subject', loadChildren: () => import('./subject/subject.module').then(m => m.SubjectModule), canActivate: [AuthGuard] }, { path: 'user', loadChildren: () => import('./user/user.module').then(m => m.UserModule) } ]; 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 235e195..b7b3cdb 100644 --- a/src/app/group/components/group-edit/group-edit.component.html +++ b/src/app/group/components/group-edit/group-edit.component.html @@ -1,7 +1,7 @@
- - + +
@@ -14,6 +14,7 @@ Admin: {{ group.admin.fullName }} ({{group.admin.userName}})
+
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 c8bf319..97da66b 100644 --- a/src/app/group/components/group-edit/group-edit.component.ts +++ b/src/app/group/components/group-edit/group-edit.component.ts @@ -27,13 +27,13 @@ export class GroupEditComponent implements OnInit { onDelete(): void { this.groupService.delete(this.groupId).subscribe(() => { - this.router.navigateByUrl('/groups'); + this.router.navigateByUrl('/group'); }); } onLeaveGroup(): void { this.groupService.leaveGroup(this.groupId).subscribe(() => { - this.router.navigateByUrl('/groups'); + this.router.navigateByUrl('/group'); }); } diff --git a/src/app/group/components/group-main/group-main.component.html b/src/app/group/components/group-main/group-main.component.html index 5eadb09..3733df4 100644 --- a/src/app/group/components/group-main/group-main.component.html +++ b/src/app/group/components/group-main/group-main.component.html @@ -16,5 +16,3 @@ - - diff --git a/src/app/group/group.module.ts b/src/app/group/group.module.ts index 20ebfcb..2d1bbc0 100644 --- a/src/app/group/group.module.ts +++ b/src/app/group/group.module.ts @@ -1,3 +1,4 @@ +import { SubjectModule } from './../subject/subject.module'; import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { GroupMainComponent } from './components/group-main/group-main.component'; @@ -29,6 +30,7 @@ import { MatButtonModule } from '@angular/material/button'; ReactiveFormsModule, MatCheckboxModule, MatButtonModule, + SubjectModule ] }) export class GroupModule { } diff --git a/src/app/subject/components/subject-main/subject-main.component.ts b/src/app/subject/components/subject-main/subject-main.component.ts index b188773..e03d8fd 100644 --- a/src/app/subject/components/subject-main/subject-main.component.ts +++ b/src/app/subject/components/subject-main/subject-main.component.ts @@ -1,5 +1,5 @@ import { SubjectDeleteRequestService } from './../../services/subject-delete-request.service'; -import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { Component, Input, OnInit, ViewEncapsulation } from '@angular/core'; import { Observable } from 'rxjs'; import { Subject } from '../../interfaces/subject.interface'; import { SubjectService } from '../../services/subject.service'; @@ -13,6 +13,7 @@ import { Router } from '@angular/router'; }) export class SubjectMainComponent implements OnInit { + @Input() groupId: number; subjects$: Observable; subjectDeleteRequests$: Observable; @@ -21,8 +22,8 @@ export class SubjectMainComponent implements OnInit { private subjectDeleteRequestService: SubjectDeleteRequestService) { } ngOnInit(): void { - this.subjects$ = this.subjectService.getList(); - this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getList(); + this.subjects$ = this.subjectService.getListByGroupId(Number(localStorage.getItem('userId'))); + this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getListByGroupId(this.groupId); } onAddNewSubject(): void { @@ -31,29 +32,29 @@ export class SubjectMainComponent implements OnInit { onApproveDeletion(deletionRequestId: number): void { this.subjectDeleteRequestService.approveDeletion(deletionRequestId).subscribe(() => { - this.subjects$ = this.subjectService.getList(); - this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getList(); + this.subjects$ = this.subjectService.getListByGroupId(this.groupId); + this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getListByGroupId(this.groupId); alert('Deletion approved'); }); } onAddDeleteRequest(id: number): void { this.subjectDeleteRequestService.add(id).subscribe(() => { - this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getList(); + this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getListByGroupId(this.groupId); alert('Delete request sent'); }); } onCancelDeletion(deletionRequestId: number): void { this.subjectDeleteRequestService.cancelDeletion(deletionRequestId).subscribe(() => { - this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getList(); + this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getListByGroupId(this.groupId); alert('Deletion canceled'); }); } onDeleteSubject(id: number): void { this.subjectService.delete(id).subscribe(() => { - this.subjects$ = this.subjectService.getList(); + this.subjects$ = this.subjectService.getListByGroupId(this.groupId); alert('success'); }); } diff --git a/src/app/subject/services/subject-delete-request.service.ts b/src/app/subject/services/subject-delete-request.service.ts index 3e1e263..5172b6e 100644 --- a/src/app/subject/services/subject-delete-request.service.ts +++ b/src/app/subject/services/subject-delete-request.service.ts @@ -12,18 +12,18 @@ export class SubjectDeleteRequestService { constructor(private http: HttpClient) { } add(subjectId: number): Observable { - return this.http.post(`${environment.host + environment.apiEndpoints.deleteRequests.addDeletionRequest}`, {subjectId}); + return this.http.post(`${environment.host + environment.apiEndpoints.deleteRequests.add}`, {subjectId}); } approveDeletion(id: number): Observable { - return this.http.post(`${environment.host + environment.apiEndpoints.deleteRequests.approveDeletion}`, {id}); + return this.http.post(`${environment.host + environment.apiEndpoints.deleteRequests.approve}`, {id}); } cancelDeletion(id: number): Observable { - return this.http.delete(`${environment.host + environment.apiEndpoints.deleteRequests.cancelDeletion}/${id}`); + return this.http.delete(`${environment.host + environment.apiEndpoints.deleteRequests.cancel}/${id}`); } - getList(): Observable { - return this.http.get(environment.host + environment.apiEndpoints.deleteRequests.getList); + getListByGroupId(groupId: number): Observable { + return this.http.get(`${environment.host + environment.apiEndpoints.deleteRequests.getListByGroupId}/${groupId}`); } } diff --git a/src/app/subject/services/subject.service.ts b/src/app/subject/services/subject.service.ts index 6c38c73..aaee05b 100644 --- a/src/app/subject/services/subject.service.ts +++ b/src/app/subject/services/subject.service.ts @@ -12,22 +12,22 @@ export class SubjectService { constructor(private http: HttpClient) { } add(subject: Subject): Observable { - return this.http.post(environment.host + environment.apiEndpoints.subjects, subject); + return this.http.post(environment.host + environment.apiEndpoints.subjects.add, subject); } delete(id: number): Observable { - return this.http.delete(`${environment.host + environment.apiEndpoints.subjects}/${id}`); + return this.http.delete(`${environment.host + environment.apiEndpoints.subjects.delete}/${id}`); } getById(id: number): Observable { - return this.http.get(`${environment.host + environment.apiEndpoints.subjects}/${id}`); + return this.http.get(`${environment.host + environment.apiEndpoints.subjects.getById}/${id}`); } - getList(): Observable { - return this.http.get(environment.host + environment.apiEndpoints.subjects); + getListByGroupId(groupId: number): Observable { + return this.http.get(`${environment.host + environment.apiEndpoints.subjects.getListByGroupId}/${groupId}`); } update(subject: Subject): Observable { - return this.http.put(`${environment.host + environment.apiEndpoints.subjects}/${subject.id}`, subject); + return this.http.put(`${environment.host + environment.apiEndpoints.subjects.update}/${subject.id}`, subject); } } diff --git a/src/app/subject/subject.module.ts b/src/app/subject/subject.module.ts index 5bc83ad..3ae9efa 100644 --- a/src/app/subject/subject.module.ts +++ b/src/app/subject/subject.module.ts @@ -27,6 +27,9 @@ import { SubjectDeleteRequestListComponent } from './components/subject-delete-r MatCheckboxModule, MatButtonModule, MatDatepickerModule + ], + exports: [ + SubjectMainComponent, SubjectListComponent, SubjectEditComponent, SubjectDeleteRequestListComponent ] }) export class SubjectModule { } diff --git a/src/app/user/components/login/login.component.ts b/src/app/user/components/login/login.component.ts index b476d65..baee077 100644 --- a/src/app/user/components/login/login.component.ts +++ b/src/app/user/components/login/login.component.ts @@ -36,7 +36,7 @@ export class LoginComponent implements OnInit { localStorage.setItem('userId', auth.user.id); localStorage.setItem('userName', auth.user.userName); localStorage.setItem('fullName', auth.user.fullName); - this.router.navigateByUrl('/subjects'); + this.router.navigateByUrl('/group'); }); } diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 877514f..fb6177b 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -2,12 +2,18 @@ export const environment = { production: false, host: 'http://localhost:56764/', apiEndpoints: { - subjects: 'api/subjects', + subjects: { + getListByGroupId: 'api/subjects/list-by-group-id', + getById: 'api/subjects/get-by-id', + delete: 'api/subjects/delete', + add: 'api/subjects/add', + update: 'api/subjects/update' + }, deleteRequests: { - getList: 'api/subjectDeleteRequests/list', - addDeletionRequest: 'api/subjectDeleteRequests/addDeletionRequest', - approveDeletion: 'api/subjectDeleteRequests/approveDeletion', - cancelDeletion: 'api/subjectDeleteRequests/cancelDeletion', + getListByGroupId: 'api/subjectDeleteRequests/list-by-group-id', + add: 'api/subjectDeleteRequests/add', + approve: 'api/subjectDeleteRequests/approve', + cancel: 'api/subjectDeleteRequests/cancel', }, users: { register: 'api/users/register', @@ -18,7 +24,8 @@ export const environment = { getById: 'api/groups/get-by-id', getCurrentUserGroups: 'api/groups/current-user-groups', create: 'api/groups/create', - delete: 'api/groups/delete' + delete: 'api/groups/delete', + leave: 'api/groups/leave' }, groupCandidates: { getList: 'api/group-candidates/list',