feat(event): refactor event retrieval to use slug instead of id

This commit is contained in:
2026-09-22 10:32:46 -03:00
parent 1f35a6d709
commit 8adbfecc35
5 changed files with 8 additions and 7 deletions

View File

@@ -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;

View File

@@ -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}`,
);
}
}

View File

@@ -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" />

View File

@@ -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) => {

View File

@@ -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: () =>