From fa5c69952cc380f540b6583385cab60feb5f3607 Mon Sep 17 00:00:00 2001 From: Art Date: Sun, 12 Sep 2021 11:33:40 +0300 Subject: [PATCH] 98. Login service call (#12) --- .../src/app/dto/user-login.spec.ts | 7 +++++++ support-portal-frontend/src/app/dto/user-login.ts | 4 ++++ .../src/app/service/authentication.service.ts | 15 ++++++++++++++- support-portal-frontend/tsconfig.json | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 support-portal-frontend/src/app/dto/user-login.spec.ts create mode 100644 support-portal-frontend/src/app/dto/user-login.ts diff --git a/support-portal-frontend/src/app/dto/user-login.spec.ts b/support-portal-frontend/src/app/dto/user-login.spec.ts new file mode 100644 index 0000000..d18d057 --- /dev/null +++ b/support-portal-frontend/src/app/dto/user-login.spec.ts @@ -0,0 +1,7 @@ +import {UserLogin} from './user-login'; + +describe('UserLogin', () => { + it('should create an instance', () => { + expect(new UserLogin()).toBeTruthy(); + }); +}); diff --git a/support-portal-frontend/src/app/dto/user-login.ts b/support-portal-frontend/src/app/dto/user-login.ts new file mode 100644 index 0000000..29fa7bf --- /dev/null +++ b/support-portal-frontend/src/app/dto/user-login.ts @@ -0,0 +1,4 @@ +export class UserLogin { + username: string; + password: string; +} diff --git a/support-portal-frontend/src/app/service/authentication.service.ts b/support-portal-frontend/src/app/service/authentication.service.ts index 41f8aa9..aa9afd5 100644 --- a/support-portal-frontend/src/app/service/authentication.service.ts +++ b/support-portal-frontend/src/app/service/authentication.service.ts @@ -1,9 +1,22 @@ import {Injectable} from '@angular/core'; +import {environment} from "../../environments/environment"; +import {HttpClient, HttpErrorResponse, HttpResponse} from "@angular/common/http"; +import {UserLogin} from "../dto/user-login"; +import {Observable} from "rxjs"; @Injectable({ providedIn: 'root' }) export class AuthenticationService { - constructor() { } + private host: string = environment.apiUrl; + + constructor(private httpClient: HttpClient) { + } + + public login(userDto: UserLogin): Observable | HttpErrorResponse> { + return this.httpClient.post | HttpErrorResponse>(`${this.host}/user/login`, userDto, {observe: 'response'}); + } + + } diff --git a/support-portal-frontend/tsconfig.json b/support-portal-frontend/tsconfig.json index 6df8283..82954b2 100644 --- a/support-portal-frontend/tsconfig.json +++ b/support-portal-frontend/tsconfig.json @@ -6,6 +6,7 @@ "outDir": "./dist/out-tsc", "forceConsistentCasingInFileNames": true, "strict": true, + "strictPropertyInitialization": false, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, "sourceMap": true,