geo coding, user service, listing for business

This commit is contained in:
2024-03-10 20:59:23 +01:00
parent 06f349d1c3
commit 6ad40b6dca
59 changed files with 120466 additions and 687 deletions

View File

@@ -0,0 +1,18 @@
import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
export interface GeoResult { city: string; state: string; state_code: string }
@Injectable({
providedIn: 'root'
})
export class GeoService {
private apiBaseUrl = environment.apiBaseUrl;
constructor(private http: HttpClient) { }
findCitiesStartingWith(prefix:string, state?:string):Observable<GeoResult[]>{
const stateString = state?`/${state}`:''
return this.http.get<GeoResult[]>(`${this.apiBaseUrl}/bizmatch/geo/${prefix}${stateString}`);
}
}

View File

@@ -20,7 +20,7 @@ export class SelectOptionsService {
this.prices = allSelectOptions.prices;
this.listingCategories = allSelectOptions.listingCategories;
this.categories = allSelectOptions.categories;
this.locations = allSelectOptions.locations;
this.states = allSelectOptions.locations;
}
public typesOfBusiness: Array<KeyValueStyle>;
@@ -30,10 +30,10 @@ export class SelectOptionsService {
public categories: Array<KeyValueStyle>;
public locations: Array<any>;
public states: Array<any>;
getLocation(value:string):string{
return this.locations.find(l=>l.value===value)?.name
getState(value:string):string{
return this.states.find(l=>l.value===value)?.name
}
getBusiness(value:string):string{

View File

@@ -1,20 +1,25 @@
import { Injectable, Signal, WritableSignal, computed, effect, signal } from '@angular/core';
import { Component } from '@angular/core';
import { jwtDecode } from 'jwt-decode';
import { Observable, distinctUntilChanged, filter, from, map } from 'rxjs';
import { Observable, distinctUntilChanged, filter, from, lastValueFrom, map } from 'rxjs';
import { CommonModule } from '@angular/common';
import { KeycloakService } from './keycloak.service';
import { JwtToken, User } from '../../../../common-models/src/main.model';
import { environment } from '../../environments/environment';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class UserService {
private apiBaseUrl = environment.apiBaseUrl;
// -----------------------------
// Keycloak services
// -----------------------------
private user$ = new Observable<User>();
private user:User
public $isLoggedIn : Signal<boolean>;
constructor(public keycloak:KeycloakService){
constructor(public keycloak:KeycloakService,private http: HttpClient){
this.user$ = from(this.keycloak.getToken()).pipe(
filter(t => !!t),
distinctUntilChanged(),
@@ -50,15 +55,12 @@ export class UserService {
const token = await this.keycloak.getToken();
this.user = this.map2User(token);
}
getUserName(){
return this.user?.username
}
private map2User(jwt:string):User{
const token = jwtDecode<JwtToken>(jwt);
return {
id:token.user_id,
username:token.preferred_username,
firstname:token.given_name,
lastname:token.family_name,
email:token.email
@@ -91,4 +93,14 @@ export class UserService {
register(url:string){
this.keycloak.register({redirectUri:url});
}
// -----------------------------
// Redis services
// -----------------------------
async save(user:User):Promise<User>{
return await lastValueFrom(this.http.post<User>(`${this.apiBaseUrl}/bizmatch/user`,user));
}
async getById(id:string):Promise<User>{
return await lastValueFrom(this.http.get<User>(`${this.apiBaseUrl}/bizmatch/user/${id}`));
}
}