Skip to content

Commit

Permalink
feat:
Browse files Browse the repository at this point in the history
- api service conected
- method post in login component
- login and response interfaces
  • Loading branch information
GonzalesRav committed Apr 21, 2023
1 parent ff7eb4b commit c49acfc
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 10 deletions.
2 changes: 2 additions & 0 deletions burguer-queen/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';
import { MenuComponent } from './menu/menu.component';
import { ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http'

@NgModule({
declarations: [
Expand All @@ -16,6 +17,7 @@ import { ReactiveFormsModule } from '@angular/forms';
BrowserModule,
AppRoutingModule,
ReactiveFormsModule,
HttpClientModule
],
providers: [],
bootstrap: [AppComponent]
Expand Down
4 changes: 4 additions & 0 deletions burguer-queen/src/app/interfaces/login.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface LoginI {
email: string;
password: string;
}
4 changes: 4 additions & 0 deletions burguer-queen/src/app/interfaces/response.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface ResponseI {
status: string;
response: string;
}
9 changes: 5 additions & 4 deletions burguer-queen/src/app/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
</div>

<div class="col-md-6 col-lg-6" style="margin-top: 80px;">
<form [formGroup]="formLogin"
<!-- Cómo colocarlo sin necesidad de definir parámetro -->
<form [formGroup]="formLogin" (ngSubmit)="onClickLogin(formLogin.value)"
style="background-color: #EA8D6F; border-radius: 10px; box-shadow: 0px 0px 10px rgba(0,0,0,0.3);" class="p-3">
<img src="../assets/images/bienvenido.png" alt="Welcome Image" class="img-fluid mx-auto d-block">
<div class="form-group mt-3">
<label for="exampleInputEmail1">Email</label>
<input type="email" class="form-control" formControlName="email" id="exampleInputEmail1"
<input type="email" class="form-control" formControlName="email" id="email" name="email"
aria-describedby="emailHelp" placeholder="[email protected]" style="width: 100%; margin-left: 5px;">

<div class="alert alert-danger mt-3 p-1" [hidden]="email.valid">
Expand All @@ -19,14 +20,14 @@
</div>
<div class="form-group mt-3">
<label for="exampleInputPassword1">Contraseña</label>
<input type="password" class="form-control" formControlName="password" id="exampleInputPassword1"
<input type="password" class="form-control" formControlName="password" id="password" name="password"
placeholder="********" style="width: 100%; margin-left: 5px;">

<div class="alert alert-danger mt-3 p-1"
[hidden]="password.valid || password.pristine"> El campo debe estar
lleno. </div>
</div>
<button type="submit" class="btn btn-warning mx-auto d-block mt-3" [disabled]="formLogin.invalid" style="background-color: #FDE293;" (click)="onClickLogin()">INICIAR
<button type="submit" class="btn btn-warning mx-auto d-block mt-3" [disabled]="formLogin.invalid" style="background-color: #FDE293;">INICIAR
SESIÓN</button>
</form>
</div>
Expand Down
22 changes: 16 additions & 6 deletions burguer-queen/src/app/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import { Component } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { LoginI } from '../interfaces/login.interface';
import { ApiBQService } from '../services/api-bq.service';

@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class LoginComponent {
onClickLogin(){
console.log("onClickLogin")

formLogin = new FormGroup({
email : new FormControl('', Validators.email),
password : new FormControl('',Validators.required)
})

constructor( private api:ApiBQService) {}

onClickLogin(form:any){ // Cómo colocarlo sin necesidad de definir parámetro
this.api.loginByEmail(form).subscribe(data =>{
console.log(data);

})
}

get email(){
Expand All @@ -18,10 +31,7 @@ export class LoginComponent {
get password(){
return this.formLogin.get('password') as FormControl;
}
formLogin = new FormGroup({
'email' : new FormControl('', Validators.email),
'password' : new FormControl('',Validators.required)
})



}
Expand Down
16 changes: 16 additions & 0 deletions burguer-queen/src/app/services/api-bq.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { ApiBQService } from '../services/api-bq.service';

describe('ApiBQService', () => {
let service: ApiBQService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ApiBQService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
20 changes: 20 additions & 0 deletions burguer-queen/src/app/services/api-bq.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Injectable } from '@angular/core';
import { LoginI } from '../interfaces/login.interface';
import { ResponseI } from '../interfaces/response.interface';
import { HttpClient, HttpHeaders } from '@angular/common/http'
import { Observable } from 'rxjs';

@Injectable({
providedIn: 'root'
})
export class ApiBQService {

url:string = "http://localhost:8080/";

constructor(private http:HttpClient) { }

loginByEmail(form: LoginI):Observable<ResponseI>{
let authUrl = this.url + 'login'
return this.http.post<ResponseI>(authUrl, form)
}
}

0 comments on commit c49acfc

Please sign in to comment.