| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import { Injectable } from '@angular/core';
- import { HttpClient } from '@angular/common/http';
- import { Observable, BehaviorSubject } from 'rxjs';
- import { User } from '../../models/user.model';
- @Injectable({
- providedIn: 'root'
- })
- export class UserService {
- private baseUrl = 'http://localhost:8085/api/users';
- // Reactive session stream holding the active parsed user object or null if guest
- private currentSessionSubject = new BehaviorSubject<any>(null);
- public currentSession$ = this.currentSessionSubject.asObservable();
- constructor(private http: HttpClient) {
- // Automatically initialize stream status from storage on application startup boot phase
- this.loadInitialSession();
- }
- private loadInitialSession(): void {
- const activeSessionStr = localStorage.getItem('nexus_mock_session');
- if (activeSessionStr) {
- try {
- this.currentSessionSubject.next(JSON.parse(activeSessionStr));
- } catch (e) {
- console.error('Initial session recovery failed:', e);
- }
- }
- }
- // Notifies all reactive stream observers across the system that a new identity is confirmed
- updateSessionState(sessionData: any): void {
- localStorage.setItem('nexus_mock_session', JSON.stringify(sessionData));
- this.currentSessionSubject.next(sessionData);
- }
- // Clear tracking tokens and broadcast the null context downstream to trigger logout transitions
- clearSessionState(): void {
- localStorage.removeItem('nexus_mock_session');
- this.currentSessionSubject.next(null);
- }
- register(userData: User): Observable<User> {
- return this.http.post<User>(`${this.baseUrl}/register`, userData);
- }
- login(credentials: { email: any; password: any }): Observable<User> {
- return this.http.post<User>(`${this.baseUrl}/login`, {
- email: credentials.email,
- password: credentials.password
- });
- }
- getUserById(userId: number): Observable<User> {
- return this.http.get<User>(`${this.baseUrl}/${userId}`);
- }
- // Initiates Stripe Checkout compiler sequences by fetching the dynamic mapping redirect URL
- createStripeSession(userId: number, amount: number): Observable<{ url: string }> {
- return this.http.post<{ url: string }>('http://localhost:8085/api/payment/create-checkout-session', {
- userId: userId,
- amount: amount
- });
- }
- // Requests the operational simulation pipeline wrapper to instantly verify balance records
- simulateWebhookPayment(userId: number, amount: number): Observable<any> {
- return this.http.post('http://localhost:8085/api/payment/simulate-success-webhook', {
- userId: userId,
- amount: amount
- });
- }
- }
|