initial release
This commit is contained in:
33
bizmatch/src/app/services/listings.service.ts
Normal file
33
bizmatch/src/app/services/listings.service.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, lastValueFrom } from 'rxjs';
|
||||
import { BusinessListing, ListingCriteria } from '../models/main.model';
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ListingsService {
|
||||
private apiBaseUrl = environment.apiBaseUrl;
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
getAllListings():Observable<BusinessListing[]>{
|
||||
return this.http.get<BusinessListing[]>(`${this.apiBaseUrl}/bizmatch/listings`);
|
||||
}
|
||||
async getListings(criteria:ListingCriteria):Promise<BusinessListing[]>{
|
||||
const result = await lastValueFrom(this.http.post<BusinessListing[]>(`${this.apiBaseUrl}/bizmatch/listings/search`,criteria));
|
||||
return result;
|
||||
}
|
||||
getListingById(id:string):Observable<BusinessListing>{
|
||||
return this.http.get<BusinessListing>(`${this.apiBaseUrl}/bizmatch/listings/${id}`);
|
||||
}
|
||||
async update(listing:any,id:string){
|
||||
await lastValueFrom(this.http.put<BusinessListing>(`${this.apiBaseUrl}/bizmatch/listings/${id}`,listing));
|
||||
}
|
||||
async create(listing:any){
|
||||
await lastValueFrom(this.http.post<BusinessListing>(`${this.apiBaseUrl}/bizmatch/listings`,listing));
|
||||
}
|
||||
async deleteListing(id:string){
|
||||
await lastValueFrom(this.http.delete<BusinessListing>(`${this.apiBaseUrl}/bizmatch/listings/${id}`));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user