Commit e7b74065 authored by Simone Vuotto's avatar Simone Vuotto

Add requirement service and model + move services in "services" folder

parent 68089e4f
......@@ -9,7 +9,7 @@ import { ProjectDetailsComponent } from './project-details/project-details.compo
const routes: Routes = [
{ path: '', component: LoginComponent },
{ path: 'projects', component: ProjectsComponent, canActivate: [AuthGuard] },
{ path: 'projects/:id', component: ProjectDetailsComponent, canActivate: [AuthGuard]},
{ path: 'projects/:projectId', component: ProjectDetailsComponent, canActivate: [AuthGuard]},
// otherwise redirect to home
{ path: '**', redirectTo: '' }
......
......@@ -2,7 +2,7 @@
<nav class="navbar navbar-default navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#">ReqV</a>
<a class="navbar-brand" routerLink="/">ReqV</a>
<ul class="navbar-nav navbar-right" *ngIf="authenticationService.isAuthenticated()">
<li class="nav-item">
<a class="nav-link" (click)="logout()" routerLink="/" >Logout</a>
......
import { Component } from '@angular/core';
import { AuthenticationService } from './authentication.service';
import { AuthenticationService } from './services/authentication.service';
@Component({
selector: 'app-root',
......
......@@ -13,9 +13,10 @@ import { AlertComponent } from './alert/alert.component';
import { ProjectDialogComponent } from './project-dialog/project-dialog.component';
// Services
import { AuthenticationService } from './authentication.service';
import { AuthenticationService } from './services/authentication.service';
import { AlertService } from './alert/alert.service';
import { ProjectService } from './projects/project.service';
import { ProjectService } from './services/project.service';
import { RequirementService } from './services/requirement.service';
// Guards
import {AuthGuard} from './auth.guard';
......@@ -51,6 +52,7 @@ import { ProjectDetailsComponent } from './project-details/project-details.compo
multi: true
},
ProjectService,
RequirementService,
],
bootstrap: [ AppComponent ]
})
......
import { Injectable } from '@angular/core';
import {CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router} from '@angular/router';
import {AuthenticationService} from './authentication.service';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
import { AuthenticationService } from './services/authentication.service';
@Injectable()
export class AuthGuard implements CanActivate {
......
import { Component, OnInit } from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import {AuthenticationService} from '../authentication.service';
import {AlertService} from '../alert/alert.service';
import { AuthenticationService } from '../services/authentication.service';
import { AlertService } from '../alert/alert.service';
@Component({
......
export enum ReqState {
VALID = 'VALID',
INVALID = 'INVALID',
NOT_VALIDATED = 'NOT_VALIDATED',
}
export class Requirement {
id: number;
text: string;
project: number;
errorDescription: string;
state: ReqState;
}
import { Component, OnInit } from '@angular/core';
import { Project, ProjectType } from '../models/project';
import { ProjectService } from '../projects/project.service';
import { ProjectService } from '../services/project.service';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { AlertService } from '../alert/alert.service';
......
import { Component, OnInit } from '@angular/core';
import { ProjectService } from './project.service';
import { ProjectService } from '../services/project.service';
import { Project } from '../models/project';
@Component({
......
......@@ -34,6 +34,14 @@ export class ProjectService {
);
}
/** GET project */
getProject(id): Observable<Project> {
return this.http.get<Project>(this.projectsUrl + '/' + id, httpOptions)
.pipe(
catchError(this.handleError('getProjects', null))
);
}
/** POST new project */
createProject(project: Project): Observable<HttpResponse<Project>> {
return this.http.post<Project>(this.projectsUrl, project, {
......
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Requirement } from '../models/requirement';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class RequirementService {
private requirementsUrl = 'api/requirements';
private reqFileUrl = 'api/requirements/file';
constructor(private http: HttpClient) { }
getRequirements(projectId: number): Observable<Requirement[]> {
const params = new HttpParams().set('pId', projectId.toString());
return this.http.get<Requirement[]>(this.requirementsUrl, {params: params});
}
uploadFile(file: File, projectId: number) {
const formData = new FormData();
formData.append('file', file, file.name);
formData.append('pId', projectId.toString());
return this.http.post(this.reqFileUrl, formData, { observe: 'response' });
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment