This commit is contained in:
2025-08-07 16:57:51 -05:00
parent 4efa6c9d77
commit 4dcff1d883
12 changed files with 158 additions and 161 deletions

View File

@@ -2,8 +2,9 @@ import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, lastValueFrom } from 'rxjs';
import { BusinessListing, CommercialPropertyListing } from '../../../../bizmatch-server/src/models/db.model';
import { BusinessListingCriteria, CommercialPropertyListingCriteria, ListingType, ResponseBusinessListingArray, ResponseCommercialPropertyListingArray } from '../../../../bizmatch-server/src/models/main.model';
import { ListingType, ResponseBusinessListingArray, ResponseCommercialPropertyListingArray } from '../../../../bizmatch-server/src/models/main.model';
import { environment } from '../../environments/environment';
import { getCriteriaByListingCategory, getSortByListingCategory } from '../utils/utils';
@Injectable({
providedIn: 'root',
@@ -12,20 +13,21 @@ export class ListingsService {
private apiBaseUrl = environment.apiBaseUrl;
constructor(private http: HttpClient) {}
async getListings(
criteria: BusinessListingCriteria | CommercialPropertyListingCriteria,
listingsCategory: 'business' | 'professionals_brokers' | 'commercialProperty',
): Promise<ResponseBusinessListingArray | ResponseCommercialPropertyListingArray> {
const result = await lastValueFrom(this.http.post<ResponseBusinessListingArray | ResponseCommercialPropertyListingArray>(`${this.apiBaseUrl}/bizmatch/listings/${listingsCategory}/find`, criteria));
async getListings(listingsCategory: 'business' | 'professionals_brokers' | 'commercialProperty'): Promise<ResponseBusinessListingArray | ResponseCommercialPropertyListingArray> {
const criteria = getCriteriaByListingCategory(listingsCategory);
const sortBy = getSortByListingCategory(listingsCategory);
const body = { ...criteria, sortBy }; // Merge sortBy in Body
const result = await lastValueFrom(this.http.post<ResponseBusinessListingArray | ResponseCommercialPropertyListingArray>(`${this.apiBaseUrl}/bizmatch/listings/${listingsCategory}/find`, body));
return result;
}
getNumberOfListings(criteria: BusinessListingCriteria | CommercialPropertyListingCriteria, listingsCategory: 'business' | 'commercialProperty'): Observable<number> {
return this.http.post<number>(`${this.apiBaseUrl}/bizmatch/listings/${listingsCategory}/findTotal`, criteria);
}
async getListingsByPrompt(criteria: BusinessListingCriteria | CommercialPropertyListingCriteria): Promise<BusinessListing[]> {
const result = await lastValueFrom(this.http.post<BusinessListing[]>(`${this.apiBaseUrl}/bizmatch/listings/business/search`, criteria));
return result;
getNumberOfListings(listingsCategory: 'business' | 'commercialProperty'): Observable<number> {
const criteria = getCriteriaByListingCategory(listingsCategory);
const sortBy = getSortByListingCategory(listingsCategory);
const body = { ...criteria, sortBy }; // Merge, falls relevant (wenn Backend sortBy für Count braucht; sonst ignorieren)
return this.http.post<number>(`${this.apiBaseUrl}/bizmatch/listings/${listingsCategory}/findTotal`, body);
}
getListingById(id: string, listingsCategory?: 'business' | 'commercialProperty'): Observable<ListingType> {
const result = this.http.get<ListingType>(`${this.apiBaseUrl}/bizmatch/listings/${listingsCategory}/${id}`);
return result;

View File

@@ -1,17 +1,30 @@
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
import { SortByOptions } from '../../../../bizmatch-server/src/models/db.model';
import { BusinessListingCriteria, CommercialPropertyListingCriteria, UserListingCriteria } from '../../../../bizmatch-server/src/models/main.model';
import { getCriteriaProxy } from '../utils/utils';
@Injectable({
providedIn: 'root',
})
export class SearchService {
private criteriaSource = new Subject<BusinessListingCriteria | CommercialPropertyListingCriteria | UserListingCriteria>();
private criteriaSource = new Subject<{
criteria: BusinessListingCriteria | CommercialPropertyListingCriteria | UserListingCriteria;
sortBy?: SortByOptions;
}>();
currentCriteria = this.criteriaSource.asObservable();
constructor() {}
search(criteria: BusinessListingCriteria | CommercialPropertyListingCriteria | UserListingCriteria): void {
this.criteriaSource.next(criteria);
search(criteriaType: 'businessListings' | 'commercialPropertyListings' | 'brokerListings'): void {
const criteria = getCriteriaProxy(criteriaType, this);
const storedSortBy =
criteriaType === 'businessListings'
? sessionStorage.getItem('businessSortBy')
: criteriaType === 'commercialPropertyListings'
? sessionStorage.getItem('commercialSortBy')
: sessionStorage.getItem('professionalsSortBy');
const sortBy = storedSortBy && storedSortBy !== 'null' ? (storedSortBy as SortByOptions) : null;
this.criteriaSource.next({ criteria, sortBy });
}
}