refactor: move auth service to core
This commit is contained in:
parent
6d1cb81e6b
commit
3059a923b4
@ -1,6 +1,6 @@
|
||||
import { CanActivateFn, Router } from "@angular/router";
|
||||
import { inject } from "@angular/core";
|
||||
import { AuthService } from "../../features/auth/services/auth-service";
|
||||
import { AuthService } from "@core/services/auth-service";
|
||||
|
||||
export const authGuard: CanActivateFn = (route, state) => {
|
||||
const authService = inject(AuthService);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { CanActivateFn } from "@angular/router";
|
||||
import { inject } from "@angular/core";
|
||||
import { AuthService } from "../../features/auth/services/auth-service";
|
||||
import { AuthService } from "@core/services/auth-service";
|
||||
|
||||
export const roleGuard: CanActivateFn = (route, state) => {
|
||||
const authService = inject(AuthService);
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { Component, inject } from "@angular/core";
|
||||
import { LucideAngularModule, Search, ShoppingCart, User } from "lucide-angular";
|
||||
import { RouterLink } from "@angular/router";
|
||||
import { AuthService, AuthState } from "../../../features/auth/services/auth-service";
|
||||
import { AuthService, AuthState } from "@core/services/auth-service";
|
||||
import { CartService } from "@app/core/services/cart-service";
|
||||
import { Cart } from "@app/shared/components/cart/cart";
|
||||
import { CartModel } from "@app/core/models/cart.model";
|
||||
@ -10,7 +9,7 @@ import { AsyncPipe } from "@angular/common";
|
||||
|
||||
@Component({
|
||||
selector: "app-header",
|
||||
imports: [LucideAngularModule, RouterLink, Cart, AsyncPipe],
|
||||
imports: [LucideAngularModule, Cart, AsyncPipe],
|
||||
templateUrl: "./header.html",
|
||||
styleUrl: "./header.css",
|
||||
})
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { computed, inject, Injectable, Signal, signal, WritableSignal } from "@angular/core";
|
||||
import { RegisterUserRequest, User } from "../../../core/models/user.model";
|
||||
import { RegisterUserRequest, User } from "../models/user.model";
|
||||
import { HttpClient, HttpErrorResponse } from "@angular/common/http";
|
||||
import { API_URL, BACKEND_URL } from "../../../core/tokens/api-url-tokens";
|
||||
import { API_URL, BACKEND_URL } from "../tokens/api-url-tokens";
|
||||
import { switchMap, tap } from "rxjs";
|
||||
import { LocalStorageService } from "../../../core/services/local-storage.service";
|
||||
import { LocalStorageService } from "../services/local-storage.service";
|
||||
|
||||
export enum AuthState {
|
||||
Loading = "loading",
|
||||
@ -2,7 +2,7 @@ import { HttpClient, HttpErrorResponse } from "@angular/common/http";
|
||||
import { effect, inject, Injectable, signal } from "@angular/core";
|
||||
import { API_URL } from "../tokens/api-url-tokens";
|
||||
import { CartItemModel, CartItemRequest, CartModel } from "../models/cart.model";
|
||||
import { AuthService, AuthState } from "@app/features/auth/services/auth-service";
|
||||
import { AuthService, AuthState } from "@core/services/auth-service";
|
||||
import { Cart } from "@app/shared/components/cart/cart";
|
||||
import { BehaviorSubject, tap } from "rxjs";
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import { Router, Routes } from "@angular/router";
|
||||
import { Login } from "./components/login/login";
|
||||
import { Register } from "./components/register/register";
|
||||
import { inject } from "@angular/core";
|
||||
import { AuthService } from "./services/auth-service";
|
||||
import { AuthService } from "@core/services/auth-service";
|
||||
|
||||
export const AuthRoutes: Routes = [
|
||||
{
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { Component, inject } from "@angular/core";
|
||||
import { Router, RouterLink } from "@angular/router";
|
||||
import { Router } from "@angular/router";
|
||||
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from "@angular/forms";
|
||||
import { AuthService } from "../../services/auth-service";
|
||||
import { Error } from "../../../../shared/components/error/error";
|
||||
import { AuthService } from "@core/services/auth-service";
|
||||
import { Error } from "@app/shared/components/error/error";
|
||||
|
||||
@Component({
|
||||
selector: "app-login",
|
||||
imports: [RouterLink, ReactiveFormsModule, Error],
|
||||
imports: [ReactiveFormsModule, Error],
|
||||
templateUrl: "./login.html",
|
||||
styleUrl: "./login.css",
|
||||
})
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { Component, inject, signal } from "@angular/core";
|
||||
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from "@angular/forms";
|
||||
import { AuthService } from "../../services/auth-service";
|
||||
import { RegisterUserRequest } from "../../../../core/models/user.model";
|
||||
import { Error } from "../../../../shared/components/error/error";
|
||||
import { AuthService } from "@core/services/auth-service";
|
||||
import { RegisterUserRequest } from "@core/models/user.model";
|
||||
import { Error } from "@shared/components/error/error";
|
||||
import { Router, RouterLink } from "@angular/router";
|
||||
|
||||
@Component({
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import { Component } from "@angular/core";
|
||||
import { Component, inject, OnInit } from "@angular/core";
|
||||
import { AddressForm } from "../components/address-form/address-form";
|
||||
import { GoBack } from "@app/shared/components/go-back/go-back";
|
||||
import { AddressSelect } from "../components/address-select/address-select";
|
||||
import { OrderSummery } from "../components/order-summery/order-summery";
|
||||
import { AddressService } from "@app/features/checkout/services/address-service";
|
||||
|
||||
@Component({
|
||||
selector: "app-address",
|
||||
@ -10,4 +11,8 @@ import { OrderSummery } from "../components/order-summery/order-summery";
|
||||
templateUrl: "./address.html",
|
||||
styleUrl: "./address.css",
|
||||
})
|
||||
export class Address {}
|
||||
export class Address implements OnInit {
|
||||
addressService = inject(AddressService);
|
||||
|
||||
ngOnInit() {}
|
||||
}
|
||||
|
||||
@ -1,6 +1,15 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { inject, Injectable } from "@angular/core";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import { API_URL } from "@core/tokens/api-url-tokens";
|
||||
|
||||
@Injectable({
|
||||
providedIn: "root",
|
||||
})
|
||||
export class AddressService {}
|
||||
export class AddressService {
|
||||
http = inject(HttpClient);
|
||||
apiUrl = inject(API_URL);
|
||||
|
||||
fetchAddresses(userId: number) {
|
||||
return this.http.get(`${this.apiUrl}/user/${userId}/addresses`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
[class.pointer-events-none]="isLoading()"
|
||||
[class.opacity-40]="isLoading()"
|
||||
[class.cursor-block]="isLoading()"
|
||||
class="rounded-none!"
|
||||
>
|
||||
@for (item of cart.items; track item.id) {
|
||||
<app-cart-item
|
||||
@ -22,8 +23,11 @@
|
||||
<p>Total</p>
|
||||
<p>Rs. {{ cart.totalPrice }}</p>
|
||||
</div>
|
||||
|
||||
<li class="pt-4! mt-4 border-t border-gray-200 rounded-none!">
|
||||
<a [routerLink]="`/checkout/address/${cart.id}`" class="btn btn-primary px-4"
|
||||
>Proceed to checkout</a
|
||||
>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
<a [routerLink]="`/checkout/address/${cart.id}`" class="btn btn-primary px-4"
|
||||
>Proceed to checkout</a
|
||||
>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Component, computed, inject, Input, signal } from "@angular/core";
|
||||
import { CartItemModel, CartItemRequest, CartModel } from "@app/core/models/cart.model";
|
||||
import { CartItem } from "../cart-item/cart-item";
|
||||
import { AuthService, AuthState } from "@app/features/auth/services/auth-service";
|
||||
import { AuthService, AuthState } from "@core/services/auth-service";
|
||||
import { CartService } from "@app/core/services/cart-service";
|
||||
import { finalize, tap } from "rxjs";
|
||||
import { RouterLink } from "@angular/router";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user