Skip to content

Conversation

@mschwrdtnr
Copy link
Contributor

@mschwrdtnr mschwrdtnr commented Sep 3, 2019

We build a small login page with this tutorial

We've already implemented:

  • basic components based on a fake backend
  • Login
  • register
  • ValidatorFunction for matching password check

Do not merge. This pr is just for the progress.

mschwrdtnr and others added 7 commits September 2, 2019 20:51
+ remove firstname, name
+ add passwordconfirm
+ implement ValidatorFn for matching password

Co-Authored-By: NemareLethiere <nemarelethiere@users.noreply.github.com>
@artifactdev
Copy link
Collaborator

artifactdev commented Sep 4, 2019

For the api requests we should implement a basicservice which can be used across different servises.:

import { environment } from '../../environments/environment';
import { Injectable, isDevMode } from '@angular/core';
import { Observable, of } from 'rxjs';
import { tap, map } from 'rxjs/operators';
import { Router } from '@angular/router';
import { BasicAppData } from '../classes/basic-app-data';
import { Events } from './../classes/enum/events.enum';
import { EventsService } from 'angular4-events';

@Injectable({
  providedIn: 'root'
})

export class BaseRestService {
  public basicAppData : BasicAppData = null;

  constructor(
    private httpClient: HttpClient,
    private router: Router,
    private events: EventsService
  ) { }

  public get<T>(path: string): Observable<T> {
    return this.httpClient.get<T>(this.basicAppData.sspAPI + path).pipe(
      tap(
        success => {
          if (isDevMode()) {
            //console.log('GET success' + path);
          }

        },
        error => this.handleError(error)
      )
    );
  }

  public post<T>(path: string, data: any): Observable<T> {
    return this.httpClient.post<T>(this.basicAppData.sspAPI + path, data).pipe(
      tap(
        success => {
          if (isDevMode()) {
            console.log('POST success' + path);
          }
        },
        error => this.handleError(error)
      )
    );
  }

  public put<T>(path: string, data: any): Observable<T> {
    return this.httpClient.put<T>(this.basicAppData.sspAPI + path, data).pipe(
      tap(
        success => {
          if (isDevMode()) {
            console.log('Put success' + path);
          }
        },
        error => this.handleError(error)
      )
    );
  }

  public delete<T>(path: string): Observable<T> {
    return this.httpClient.delete<T>(this.basicAppData.sspAPI + path).pipe(
      tap(
        success => {
          if (isDevMode()) {
            console.log('DELETE success' + path);
          }
        },
        error => this.handleError(error)
      )
    );
  }

  public handleError(error: Error): Observable<string> {
    if (error instanceof HttpErrorResponse) {
      switch (error.status) {
        case 500:
          console.log('Laden Sie bitte die Seite neu');
          break;
        case 404:
          //this.router.navigate(['/not-found']);
          break;
        case 403:
          return Observable.throw(error.error.text);
          //this.router.navigate(['/api-error']);
          break;
        default:
          //this.errorMessageService.errors.emit(new Error(`Fehler ${error.status} ${error.message}`));
          break;
      }
    } else {
      // other types of errors

    }
  }
}

constructor(private http: HttpClient) { }

getAll() {
return this.http.get<User[]>(`${environment.apiUrl}/users`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API Endpoints should be moved into an enum

</div>
<div class="form-group">
<label for="password">Password</label>
<label for="password">Passwort</label>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should generate components for inputs where label is only shown when a label is given by input. Input type, state (readonly ...) should be configurable too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants