Skip to content

Commit

Permalink
ÃHttpClientInMemoryWebApiModule
Browse files Browse the repository at this point in the history
  • Loading branch information
Babali42 committed Oct 13, 2024
1 parent 51c286a commit dec7333
Show file tree
Hide file tree
Showing 34 changed files with 634 additions and 642 deletions.
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@angular/core": "^17.3.11",
"@angular/platform-browser": "^17.3.11",
"@angular/platform-browser-dynamic": "^17.3.11",
"angular-in-memory-web-api": "^0.17.0",
"eslint": "^8.10.0",
"rxjs": "~7.5.0",
"zone.js": "~0.14.7"
Expand All @@ -25,16 +26,16 @@
"@angular-devkit/build-angular": "^17.3.8",
"@angular-eslint/eslint-plugin": "^17.2.0",
"@angular/cli": "~17.3.8",
"@types/jasmine": "~5.1.0",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"eslint-config-prettier": "^9.1.0",
"typescript": "~5.4.5",
"jasmine-core": "~5.1.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"@types/jasmine": "~5.1.0"
"typescript": "~5.4.5"
}
}
24 changes: 24 additions & 0 deletions src/app/adapters/secondary/beats-adapter-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {catchError, Observable, throwError} from "rxjs";
import { Beat } from "src/app/domain/beat";
import {IManageBeats} from "../../domain/ports/secondary/i-manage-beats";
import {HttpClient, HttpErrorResponse} from "@angular/common/http";
import {Injectable} from "@angular/core";

@Injectable({ providedIn: 'root' })
export class BeatsAdapterService implements IManageBeats {
private heroesUrl = 'api/beats'; // URL to web api

constructor(private http: HttpClient) { }

getBeat(name: string): Observable<Beat> {
const url = `${this.heroesUrl}/${name}`;
return this.http.get<Beat>(url).pipe(
catchError((error: HttpErrorResponse) => this.handleHttpError(error))
);
}

private handleHttpError(error: HttpErrorResponse): Observable<never> {
console.error('An error occurred:', error.message);
return throwError(() => new Error(`An error occurred: ${error.message}`));
}
}
11 changes: 1 addition & 10 deletions src/app/adapters/secondary/genres-adapter.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { HttpClient } from '@angular/common/http';

import { catchError, Observable } from 'rxjs';
import IManageGenres from "../../domain/ports/secondary/i-manage-genres";
Expand All @@ -10,23 +10,14 @@ export class GenresAdapterService implements IManageGenres {

private heroesUrl = 'api/genres'; // URL to web api

httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};

constructor(private http: HttpClient) { }

/** GET heroes from the server */
getGenres(): Observable<Genre[]> {
return this.http.get<Genre[]>(this.heroesUrl).pipe(
catchError(this.handleHttpError())
);
}

/**
* Handle Http operation that failed.
* Throw an HeroOperation
*/
private handleHttpError() {
return (error: any): Observable<any> => {
throw new Error(error.body.error);
Expand Down
Loading

0 comments on commit dec7333

Please sign in to comment.