Skip to content

Commit 99172c6

Browse files
committed
Fixed filtering the job opportunities
1 parent 168f15c commit 99172c6

File tree

4 files changed

+81
-56
lines changed

4 files changed

+81
-56
lines changed

front-end/src/app/model/vaga.model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export class Vaga {
33
number: number;
44
title: String;
55
body: string;
6-
labels: string[];
6+
labels: { name: string }[];
77
username: string;
88
password: string;
9-
}
9+
}

front-end/src/app/pages/cadastro-vaga/cadastro-vaga.page.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@
1313

1414
<ion-content>
1515
<ion-list>
16+
1617
<ion-item>
17-
<ion-label position="floating">Titulo</ion-label>
18-
<ion-input [ngModel]="vaga?.title"></ion-input>
18+
<!-- <ion-input [ngModel]="vaga?.title"></ion-input> -->
19+
<h2 [innerHTML]="vaga?.title"></h2>
1920
</ion-item>
2021
<ion-item>
2122
<ion-label position="stacked">Descrição</ion-label>
2223
<div [innerHTML]="getContent(vaga?.body)"></div>
2324

2425
</ion-item>
2526
<ion-item>
26-
<ion-label position="floating">Labels</ion-label>
27-
<ion-input [ngModel]="getLabels(vaga?.labels)"></ion-input>
27+
<!-- <ion-label position="floating">Labels</ion-label>
28+
<ion-input [ngModel]="getLabels(vaga?.labels)" [disabled]="true"></ion-input> -->
29+
<div [innerHTML]="getLabels(vaga?.labels)"></div>
2830
</ion-item>
2931
</ion-list>
3032
</ion-content>

front-end/src/app/pages/cadastro-vaga/cadastro-vaga.page.ts

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,51 +23,49 @@ export class CadastroVagaPage implements OnInit {
2323

2424
private renderer = new marked.Renderer();
2525
private defaultOptions: marked.MarkedOptions = {};
26-
2726

2827
vaga: Vaga;
2928
async ngOnInit() {
30-
31-
const loading = await this.loadingController.create({
32-
message: 'Please wait...',
33-
spinner:'bubbles'
29+
const loading = await this.loadingController.create({
30+
message: "Please wait...",
31+
spinner: "bubbles",
3432
});
3533
loading.present();
3634

3735
this.applyDefaultOptions();
38-
this.vagaService
39-
.getVagaById(this.route.snapshot.params["id"])
40-
.subscribe(
41-
{
42-
next:async(result:Vaga)=>{
43-
this.vaga = result;
44-
await loading.dismiss();
45-
},
46-
error: async (response: any) => {
47-
await loading.dismiss();
48-
console.error(response);
49-
const { error, statusText } = response;
50-
let { message } = error ? error : { message: statusText };
51-
52-
const alert = await this.alertController.create({
53-
cssClass: "my-custom-class",
54-
header: "Ops!!!",
55-
message,
56-
buttons: [
57-
{
58-
text: "OK",
59-
id: "confirm-button",
60-
handler: () => {
61-
this.router.navigate(["home"]);
62-
alert.dismiss();
63-
},
64-
},
65-
],
66-
});
67-
await alert.present();
68-
},
36+
this.vagaService.getVagaById(this.route.snapshot.params["id"]).subscribe({
37+
next: async (result: Vaga) => {
38+
this.vaga = result;
39+
await loading.dismiss();
40+
},
41+
error: async (response: any) => {
42+
await loading.dismiss();
43+
console.error(response);
44+
const { error, statusText } = response;
45+
let { message } = error ? error : { message: statusText };
46+
47+
if (!message && response.message) {
48+
message = response.message;
6949
}
70-
);
50+
51+
const alert = await this.alertController.create({
52+
cssClass: "my-custom-class",
53+
header: "Ops!!!",
54+
message,
55+
buttons: [
56+
{
57+
text: "OK",
58+
id: "confirm-button",
59+
handler: () => {
60+
this.router.navigate(["home"]);
61+
alert.dismiss();
62+
},
63+
},
64+
],
65+
});
66+
await alert.present();
67+
},
68+
});
7169
}
7270

7371
getContent(content: string) {
Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,59 @@
11
import { Vaga } from "./../model/vaga.model";
22
import { HttpClient } from "@angular/common/http";
33
import { Injectable } from "@angular/core";
4-
import { Observable } from "rxjs";
4+
import { Observable, of, throwError } from "rxjs";
5+
import { filter, switchMap } from "rxjs/operators";
56
import { environment } from "src/environments/environment";
67

78
const BASE_URL_REPOS = environment.BASE_URL_REPOS;
9+
10+
const ehVaga = (vaga: Vaga) => {
11+
if (vaga?.labels) {
12+
return (
13+
vaga.labels.map((label) => label.name).indexOf("dependencies") == -1
14+
);
15+
}
16+
return true;
17+
};
18+
819
@Injectable({
920
providedIn: "root",
1021
})
1122
export class VagaService {
1223
constructor(private http: HttpClient) {}
1324

14-
getAllVagas(): Observable<Vaga[]> {
15-
return this.http.get<Vaga[]>(
16-
`${BASE_URL_REPOS}/soujava/vagas-java/issues?state=open&page=1&per_page=100`
17-
);
18-
}
25+
// getAllVagas(): Observable<Vaga[]> {
26+
// return this.http.get<Vaga[]>(
27+
// `${BASE_URL_REPOS}/soujava/vagas-java/issues?state=open&page=1&per_page=100`
28+
// );
29+
// }
1930

2031
getAllVagasPaginacao(
2132
page: number,
2233
itensPorPagina: number
2334
): Observable<Vaga[]> {
24-
return this.http.get<Vaga[]>(
25-
`${BASE_URL_REPOS}/soujava/vagas-java/issues?state=open&page=${page}&per_page=${itensPorPagina}`
26-
);
35+
return this.http
36+
.get<Vaga[]>(
37+
`${BASE_URL_REPOS}/soujava/vagas-java/issues?state=open&page=${page}&per_page=${itensPorPagina}`
38+
)
39+
.pipe(
40+
switchMap((vagas) => {
41+
return of(vagas.filter(ehVaga));
42+
})
43+
);
2744
}
2845

29-
getVagaById(id: number): Observable<Vaga> {
30-
return this.http.get<Vaga>(
31-
`${BASE_URL_REPOS}/soujava/vagas-java/issues/${id}`
32-
);
46+
47+
getVagaById(id: number): Observable<Vaga | null> {
48+
return this.http
49+
.get<Vaga>(`${BASE_URL_REPOS}/soujava/vagas-java/issues/${id}`)
50+
.pipe(
51+
switchMap((vaga) => {
52+
if(!ehVaga(vaga)){
53+
return throwError(new Error("Not found"));
54+
}
55+
return of(vaga);
56+
})
57+
);
3358
}
3459
}

0 commit comments

Comments
 (0)