feat(event): refactor event retrieval to use slug instead of id
This commit is contained in:
@@ -2,6 +2,7 @@ import { ApiPaginatedResponse } from '../api-paginated-response.interface';
|
||||
|
||||
export interface StoreEvent {
|
||||
id: number;
|
||||
slug: string;
|
||||
event_category_id: number | null;
|
||||
title: string;
|
||||
subtitle: string | null;
|
||||
|
||||
@@ -16,9 +16,9 @@ export class EventService extends BaseApiService {
|
||||
});
|
||||
}
|
||||
|
||||
get(id: number): Observable<ApiResponse<StoreEvent>> {
|
||||
get(slug: string): Observable<ApiResponse<StoreEvent>> {
|
||||
return this.http.get<ApiResponse<StoreEvent>>(
|
||||
`${this.tenantService.getTenantApiUrl()}/events/${id}`,
|
||||
`${this.tenantService.getTenantApiUrl()}/events/${slug}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<a class="event-card" [routerLink]="['/evento', event().id]">
|
||||
<a class="event-card" [routerLink]="['/evento', event().slug]">
|
||||
<div class="event-card__image">
|
||||
@if (event().image) {
|
||||
<img [src]="event().image" [alt]="event().title" />
|
||||
|
||||
@@ -62,9 +62,9 @@ export class EventDetailPageComponent {
|
||||
|
||||
constructor() {
|
||||
this.route.paramMap.pipe(
|
||||
map((params) => Number(params.get('id'))),
|
||||
switchMap((id) => Number.isInteger(id) && id > 0
|
||||
? this.events.get(id).pipe(map((response) => response.data), catchError(() => of(null)))
|
||||
map((params) => params.get('slug')?.trim() ?? ''),
|
||||
switchMap((slug) => slug
|
||||
? this.events.get(slug).pipe(map((response) => response.data), catchError(() => of(null)))
|
||||
: of(null)),
|
||||
takeUntilDestroyed(this.destroyRef),
|
||||
).subscribe((event) => {
|
||||
|
||||
@@ -98,7 +98,7 @@ export const routes: Routes = [
|
||||
import('./pages/search-page/search-page.component').then((m) => m.SearchPageComponent),
|
||||
},
|
||||
{
|
||||
path: 'evento/:id',
|
||||
path: 'evento/:slug',
|
||||
canMatch: [isMultiEventStorefront],
|
||||
canActivate: [hasMenuGuard('event.detail')],
|
||||
loadComponent: () =>
|
||||
|
||||
Reference in New Issue
Block a user