Skip to content
Snippets Groups Projects
Commit ec55516a authored by Hugo BAYOUD's avatar Hugo BAYOUD
Browse files

change bars filename to bar

parent 9ecce39a
No related branches found
No related tags found
1 merge request!1Resolve "[FRONT] Créer la page : choix des bars"
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
......@@ -50,14 +50,14 @@ export class AuthService {
}
public refreshToken(): Observable<string> {
return this.http.get<string>('/api/auth/refresh_token');
return this.http.get<string>('/api/v1/auth/refresh_token');
}
public signup(user: User): Observable<User> {
return this.http.post<User>('/api/auth/signup', user);
return this.http.post<User>('/api/v1/auth/signup', user);
}
public signin(credentials: { email: string, password: string}): Observable<string> {
return this.http.post<string>('/api/auth/signin', credentials);
return this.http.post<string>('/api/v1/auth/signin', credentials);
}
}
......@@ -6,12 +6,12 @@ import { Bar } from '../models/bar.model';
@Injectable({
providedIn: 'root'
})
export class BarsService {
export class BarService {
constructor(private http: HttpClient) {}
// authInterceptor add the token in the HTTP request
public getAllBars(): Observable<Bar[]> {
return this.http.get<Bar[]>('/api/bars');
}
public getAll(): Observable<Bar[]> {
return this.http.get<Bar[]>('/api/v1/bars');
}
}
......@@ -22,7 +22,7 @@ export class NotificationService {
.then((sub: PushSubscription) => {
console.log(`l'utilisateur a accepté les notifications`, sub);
this.http.post(`/api/notifications`, sub)
this.http.post(`/api/v1/notifications`, sub)
.subscribe(
() => {
console.log(`La souscription a bien été enregistrée pour cet utilisateur`);
......@@ -37,6 +37,6 @@ export class NotificationService {
}
public sendTestNotification(): void {
this.http.get('/api/notifications/test').subscribe();
this.http.get('/api/v1/notifications/test').subscribe();
}
}
......@@ -11,6 +11,6 @@ export class UserService {
// on crée un interceptor pour ajouter le token dans la requete HTTP
public getCurrentUser(): Observable<User> {
return this.http.get<User>('/api/user/current');
return this.http.get<User>('/api/v1/user/current');
}
}
import { Action } from "@ngrx/store";
import { Bar } from "../../models/bar.model";
export enum BarsActionsTypes {
export enum BarActionsTypes {
FETCH_BARS = '[bars/api] fetch all bars',
FETCH_BARS_SUCCESS = '[bars/api] fetch bars success'
FETCH_BARS_SUCCESS = '[bars/api] fetch bars success',
FETCH_BARS_FAILED = '[bars/api] fetch bars failed'
}
export class FetchBars implements Action {
readonly type = BarsActionsTypes.FETCH_BARS;
readonly type = BarActionsTypes.FETCH_BARS;
}
export class FetchBarsSuccess implements Action {
readonly type = BarsActionsTypes.FETCH_BARS_SUCCESS;
readonly type = BarActionsTypes.FETCH_BARS_SUCCESS;
constructor(public payload: Bar[]) {}
}
export type BarsAction = FetchBars | FetchBarsSuccess;
\ No newline at end of file
export class FetchBarsFailed implements Action {
readonly type = BarActionsTypes.FETCH_BARS_FAILED;
constructor(public payload: string) {}
}
export type BarsActions = FetchBars | FetchBarsSuccess | FetchBarsFailed;
\ No newline at end of file
import { Actions, createEffect, ofType } from "@ngrx/effects";
import { Injectable } from "@angular/core";
import { catchError, map, mergeMap } from "rxjs/operators";
import { EMPTY, of } from "rxjs";
import { BarActionsTypes, FetchBarsFailed, FetchBarsSuccess } from "../actions/bar.actions";
import { BarService } from "../../services/bar.service";
import { Bar } from "../../models/bar.model";
@Injectable()
export class BarEffects {
constructor(
private actions$: Actions,
private barService: BarService
) {}
loadBars$ = createEffect(() => this.actions$.pipe(
ofType(BarActionsTypes.FETCH_BARS),
mergeMap(() => this.barService.getAll()
.pipe(
map((bars: Bar[]) => (new FetchBarsSuccess(bars))),
catchError(() => of(new FetchBarsFailed('failed fetching all bars')))
))
));
}
\ No newline at end of file
import { Injectable } from "@angular/core";
import { Actions, Effect, ofType } from "@ngrx/effects";
import { Store } from "@ngrx/store";
import { catchError, map, switchMap } from "rxjs/operators";
import { State } from "../../../share/store";
import { Bar } from "../../models/bar.model";
import { BarsService } from "../../services/bars.service";
import { BarsActionsTypes, FetchBarsSuccess } from "../actions/bars.actions";
@Injectable()
export class BarsEffect {
constructor(
private actions$: Actions,
private store: Store<State>,
private barssService: BarsService
) {}
@Effect()
FetchBars$ = this.actions$.pipe(
ofType(BarsActionsTypes.FETCH_BARS),
switchMap(() => {
return this.barssService.getAllBars();
}),
map((bars: Bar[]) => {
return new FetchBarsSuccess(bars);
})
);
}
\ No newline at end of file
import { ActionReducerMap } from "@ngrx/store";
import { authReducer, AuthState } from "./reducers/auth.reducers";
import { barsReducer, BarsState } from "./reducers/bars.reducers";
import { barReducer, BarState } from "./reducers/bar.reducers";
export interface State {
auth: AuthState;
bars: BarsState;
bars: BarState;
}
export const reducersMap: ActionReducerMap<State> = {
auth: authReducer,
bars: barsReducer
bars: barReducer
};
\ No newline at end of file
import { Bar } from "../../models/bar.model";
import { BarsAction, BarsActionsTypes } from "../actions/bars.actions";
import { BarsActions, BarActionsTypes } from "../actions/bar.actions";
export interface BarsState {
export interface BarState {
bars: Bar[];
currentBar: Bar;
error: string;
}
const defaultBarState = {
bars: [],
currentBar: null
currentBar: null,
error: '',
}
export function barsReducer(state: BarsState = defaultBarState, action: BarsAction): BarsState {
export function barReducer(state: BarState = defaultBarState, action: BarsActions): BarState {
switch (action.type) {
case BarsActionsTypes.FETCH_BARS_SUCCESS: {
case BarActionsTypes.FETCH_BARS_SUCCESS: {
return {
...state,
bars: action.payload
};
}
case BarActionsTypes.FETCH_BARS_FAILED: {
return {
...state,
error: action.payload
};
}
}
return state;
......
import { createFeatureSelector, createSelector } from "@ngrx/store";
import { BarsState } from "../reducers/bars.reducers";
import { BarState } from "../reducers/bar.reducers";
export const baseSelector = createFeatureSelector('bars');
export const allBarsSelector = createSelector(baseSelector, (barsState: BarsState) => barsState?.bars);
export const allBarsSelector = createSelector(baseSelector, (barState: BarState) => barState?.bars);
export const currentBarSelector = createSelector(baseSelector, (barsState: BarsState) => barsState?.currentBar);
\ No newline at end of file
export const currentBarSelector = createSelector(baseSelector, (barState: BarState) => barState?.currentBar);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment