Skip to content

Commit b4dc24c

Browse files
committed
Commercial with filtering of category
1 parent 0015b78 commit b4dc24c

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

angular/wallypop/.idea/workspace.xml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular/wallypop/src/app/app.routing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const appRoutes = [
1818
{ path: 'category', component: CategoryComponent},
1919
{ path: 'categoryList', component: CategoryListComponent},
2020
{ path: 'commercial', component: CommercialComponent },
21+
{ path: 'commercial/:id', component: CommercialComponent },
2122
{ path: 'post', component: PostComponent },
2223
{ path: 'post/:id', component: PostComponent },
2324
{ path: '**', component: NotFoundComponent}

angular/wallypop/src/app/components/articles/commercial.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ <h4 class="text-light">CATEGORÍA</h4>
3535
FILTROS</a>
3636
</p>
3737
<p>
38-
<small>Anuncios segunda mano . Las mejores ofertas en de segunda mano y de ocasión solo
39-
en </small>
38+
<small>Anuncios segunda mano. Las mejores ofertas en de segunda mano y de ocasión solo
39+
en Wallypop</small>
4040
</p>
4141
</form>
4242
</div>
@@ -64,7 +64,7 @@ <h4 class="text-light">CATEGORÍA</h4>
6464
<p class="full-width post-info-price">{{article.price}}€</p>
6565
<span class="post-info-zone">{{article.city}}</span>
6666
<span class="post-info-date">{{article.date}}</span>
67-
<a *ngIf="this.loginService.isLogged" href="/addFavorite/{{article.id_ARTICLE}}"><i class="fa fa-heart-o post-info-like"></i></a>
67+
<a *ngIf="this.loginService.isLogged()" href="/addFavorite/{{article.id_ARTICLE}}"><i class="fa fa-heart-o post-info-like"></i></a>
6868
</div>
6969
</ng-template>
7070
</div>

angular/wallypop/src/app/components/articles/commercial.component.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {Article} from '../../models/article.model';
55
import {Category} from '../../models/category.model';
66
import {CategoryService} from '../../services/category.service';
77
import {User} from '../../models/user.model';
8+
import {ActivatedRoute} from '@angular/router';
89

910
@Component({
1011
selector: 'commercial',
@@ -13,12 +14,21 @@ import {User} from '../../models/user.model';
1314
export class CommercialComponent implements OnInit {
1415
articles: Article[];
1516
categories: Category[];
16-
constructor(private articleService: ArticleService, private categoryService: CategoryService, private loginService: LoginService) {
17+
category: Category;
18+
idCategory: number;
19+
constructor(private articleService: ArticleService, private categoryService: CategoryService, private loginService: LoginService, private routing: ActivatedRoute) {
20+
this.idCategory = -1;
1721
}
1822

1923
ngOnInit(): void {
2024
this.getCategories();
21-
this.getArticles();
25+
26+
this.idCategory = this.routing.snapshot.params.id;
27+
if (this.idCategory !== undefined) {
28+
this.getArticlesFromCategory(this.idCategory);
29+
} else {
30+
this.getAllArticles();
31+
}
2232
}
2333

2434
getCategories(): void {
@@ -28,7 +38,14 @@ export class CommercialComponent implements OnInit {
2838
);
2939
}
3040

31-
getArticles(): void {
41+
getArticlesFromCategory(id: number | string): void {
42+
this.categoryService.getCategory(id).subscribe(
43+
articles => this.articles = articles,
44+
error => console.log(error)
45+
);
46+
}
47+
48+
getAllArticles(): void {
3249
this.articleService.getArticles().subscribe(
3350
article => this.articles = article,
3451
error => console.log(error)

angular/wallypop/src/app/services/category.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {catchError} from 'rxjs/operators';
55

66
import {Category} from '../models/category.model';
77
import {Router} from '@angular/router';
8+
import {Article} from '../models/article.model';
89

910
const BASE_URL = '/api/';
1011

@@ -26,10 +27,10 @@ export class CategoryService {
2627
) as Observable<Category[]>;
2728
}
2829

29-
getCategory(id: number | string): Observable<Category> {
30+
getCategory(id: number | string): Observable<Article[]> {
3031
return this.httpClient.get(BASE_URL + 'categories/' + id).pipe(
3132
catchError(error => CategoryService.handleError(error))
32-
) as Observable<Category>;
33+
) as Observable<Article[]>;
3334
}
3435

3536
addCategory(title: string, description: string, icon: string): void {

0 commit comments

Comments
 (0)