Ignore:
Timestamp:
12/28/21 08:56:55 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
b738035
Parents:
84d0fbb
Message:

pre final presentation

Location:
trip-planner-front/src/app/_services
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/src/app/_services/planner.service.ts

    r84d0fbb rbdd6491  
    1111
    1212    httpHeaders: HttpHeaders = new HttpHeaders({
    13         'Authorization': ''+sessionStorage.getItem("token"),
     13        'Authorization': '' + sessionStorage.getItem("token"),
    1414        'Accept': 'application/json',
    1515        'Content-Type': 'application/json'
    16       });
    17      
     16    });
    1817
    19     constructor(private httpClient: HttpClient){
     18
     19    constructor(private httpClient: HttpClient) {
    2020    }
    2121
    22    
    23     getAllPlanners():Observable<Planner[]>{
     22
     23    getAllPlanners(): Observable<Planner[]> {
    2424        let url = "http://localhost:8080/api/planners/user";
    2525        console.log("SERVID: " + sessionStorage.getItem("token"));
    26         console.log(this.httpHeaders.get('Authorization'))  ;
    27         return this.httpClient.get<Planner[]>(url, {headers: this.httpHeaders});     
     26        console.log(this.httpHeaders.get('Authorization'));
     27        return this.httpClient.get<Planner[]>(url, { headers: this.httpHeaders });
    2828    }
    2929
    30     postInitialPlanner(planner: Planner): Observable<Planner>{     
     30    postInitialPlanner(plannerDto: PlannerDto): Observable<Planner> {
    3131        let url = "http://localhost:8080/api/planner/new";
    32         return this.httpClient.post<Planner>(url, planner);
     32        return this.httpClient.post<Planner>(url, plannerDto);
    3333    }
    3434
    35     updatePlanner(id: number, plannerDto : PlannerDto):Observable<Planner>{   
    36     let url = "http://localhost:8080/api/edit/planner/" + id;
    37     return this.httpClient.put<Planner>(url, plannerDto, {headers: this.httpHeaders});
     35    updatePlanner(id: number, plannerDto: PlannerDto): Observable<Planner> {
     36        let url = "http://localhost:8080/api/edit/planner/" + id;
     37        return this.httpClient.put<Planner>(url, plannerDto, { headers: this.httpHeaders });
    3838    }
    3939
    40     getPlannerById(id:number):Observable<Planner>{
     40    getPlannerById(id: number): Observable<Planner> {
    4141        let url = "http://localhost:8080/api/planner/" + id;
    4242        return this.httpClient.get<Planner>(url);
    4343    }
    4444
    45 
     45    deletePlannerById(id: number): Observable<Planner> {
     46        let url = "http://localhost:8080/api/delete/" + id;
     47        return this.httpClient.delete<Planner>(url, { headers: this.httpHeaders });
     48    }
    4649}
  • trip-planner-front/src/app/_services/user.service.ts

    r84d0fbb rbdd6491  
    88
    99@Injectable({
    10     providedIn: 'root'
     10  providedIn: 'root'
    1111})
    12 export class UserService{
     12export class UserService {
    1313
    14      headers = new HttpHeaders({
    15         'Content-Type': 'application/json',
    16         'Access-Control-Allow-Headers': 'Content-Type',
     14  headers = new HttpHeaders({
     15    'Content-Type': 'application/json',
     16    'Access-Control-Allow-Headers': 'Content-Type',
    1717
    18       });
    19    
    20     constructor(private httpClient: HttpClient){
     18  });
    2119
    22     }
     20  constructor(private httpClient: HttpClient) {
    2321
    24     registerUser(user : UserDto) : Observable<User>{
    25         let url = "http://localhost:8080/api/users/register";
    26         var reqHeader = new HttpHeaders({'No-Auth' : 'True'});
    27         return this.httpClient.post<User>(url, user, { headers: reqHeader });
    28     }
    29    
    30     authenticateUser(loginResult : LoginRequest) {
    31         let url = "http://localhost:8080/api/users/login";
    32         var reqHeader = new HttpHeaders({'Content-Type': 'application/json'});
    33         return this.httpClient.post<any>(url, loginResult)
    34         .pipe(
    35             map(userData => {
    36                 sessionStorage.setItem("username", loginResult.username);
    37                 let tokenStr = userData.token;
    38                 sessionStorage.setItem("token", tokenStr);
    39                 return userData;
    40             })
    41         );
    42     }
    43  
    44       isUserLoggedIn() {
    45         let user = sessionStorage.getItem("username");
    46         let token = sessionStorage.getItem("token");
    47         console.log(user);
    48         console.log(token);
    49         console.log(!(user === null));
    50         return !(user === null);
    51       }
    52    
     22  }
     23
     24  registerUser(user: UserDto): Observable<User> {
     25    let url = "http://localhost:8080/api/users/register";
     26    return this.httpClient.post<User>(url, user, { headers: this.headers });
     27  }
     28
     29  authenticateUser(loginResult: LoginRequest) {
     30    let url = "http://localhost:8080/api/users/login";
     31    return this.httpClient.post<any>(url, loginResult)
     32      .pipe(
     33        map(userData => {
     34          sessionStorage.setItem("username", loginResult.username);
     35          let tokenStr = userData.token;
     36          sessionStorage.setItem("token", tokenStr);
     37          return userData;
     38        })
     39      );
     40  }
     41
     42  isUserLoggedIn() {
     43    let user = sessionStorage.getItem("username");
     44    let token = sessionStorage.getItem("token");
     45    console.log(user);
     46    console.log(token);
     47    console.log(!(user === null));
     48    return !(user === null);
     49  }
     50
    5351}
Note: See TracChangeset for help on using the changeset viewer.