diff --git a/src/main/frontend/src/app/modules/material/pages/edit/edit.component.html b/src/main/frontend/src/app/modules/material/pages/edit/edit.component.html index 5fee3dc..894cbd8 100644 --- a/src/main/frontend/src/app/modules/material/pages/edit/edit.component.html +++ b/src/main/frontend/src/app/modules/material/pages/edit/edit.component.html @@ -18,14 +18,16 @@ let-control="control" let-field="field">
-
- + {{field.label}} diff --git a/src/main/frontend/src/app/modules/shared/service/api.service.ts b/src/main/frontend/src/app/modules/shared/service/api.service.ts index 5fd7f19..ef987a5 100644 --- a/src/main/frontend/src/app/modules/shared/service/api.service.ts +++ b/src/main/frontend/src/app/modules/shared/service/api.service.ts @@ -1,10 +1,10 @@ import {Injectable, OnDestroy} from '@angular/core'; -import {HttpClient, HttpHeaders, HttpParams} from "@angular/common/http"; +import {HttpClient} from "@angular/common/http"; import {Observable, Subject} from "rxjs"; import {environment} from "../../../../environments/environment"; import {AppState} from "../app-state"; import {Router} from "@angular/router"; -import {share, takeUntil} from "rxjs/operators"; +import {map, share, takeUntil} from "rxjs/operators"; @Injectable({ providedIn: 'root' @@ -24,50 +24,44 @@ export class ApiService implements OnDestroy { this._destroy$.complete() } - get(url: string, needAuthentication = true, options: any = {}): Observable { + get(url: string, needAuthentication = true, requestOptions: ApiRequestOptions = new ApiRequestOptions()): Observable { + // @ts-ignore return this.executeHttpRequest( - httpOptions => this.http.get(environment.apiUrl + url, httpOptions), + httpOptions => this.http.get(environment.apiUrl + url, httpOptions), needAuthentication, - options + requestOptions ) } - post(url: string, body: any = {}, needAuthentication = true, options: any = {}): Observable { + post(url: string, body: any = {}, needAuthentication = true, requestOptions: ApiRequestOptions = new ApiRequestOptions()): Observable { + // @ts-ignore return this.executeHttpRequest( - httpOptions => this.http.post(environment.apiUrl + url, body, httpOptions), + httpOptions => this.http.post(environment.apiUrl + url, body, httpOptions), needAuthentication, - options + requestOptions ) } - put(url: string, body: any = {}, needAuthentication = true, options: any = {}): Observable { + put(url: string, body: any = {}, needAuthentication = true, requestOptions: ApiRequestOptions = new ApiRequestOptions()): Observable { + // @ts-ignore return this.executeHttpRequest( - httpOptions => this.http.put(environment.apiUrl + url, body, httpOptions), + httpOptions => this.http.put(environment.apiUrl + url, body, httpOptions), needAuthentication, - options + requestOptions ) } - delete(url: string, needAuthentication = true, options: any = {}): Observable { + delete(url: string, needAuthentication = true, requestOptions: ApiRequestOptions = new ApiRequestOptions()): Observable { + // @ts-ignore return this.executeHttpRequest( - httpOptions => this.http.delete(environment.apiUrl + url, httpOptions), + httpOptions => this.http.delete(environment.apiUrl + url, httpOptions), needAuthentication, - options + requestOptions ) } - private executeHttpRequest(requestFn: (httpOptions?: { - headers?: HttpHeaders | { - [header: string]: string | string[]; - }; - observe?: 'body'; - params?: HttpParams | { - [param: string]: string | string[]; - }; - reportProgress?: boolean; - responseType?: 'json'; - withCredentials?: boolean; - }) => Observable, needAuthentication = true, httpOptions: any = {}): Observable { + private executeHttpRequest(requestFn: (httpOptions) => Observable, needAuthentication = true, requestOptions: ApiRequestOptions = new ApiRequestOptions()): Observable { + const httpOptions = {withCredentials: false, observe: 'response'} if (needAuthentication) { if (this.checkAuthenticated()) { if (httpOptions) { @@ -80,8 +74,11 @@ export class ApiService implements OnDestroy { } } - const result$ = requestFn(httpOptions) - .pipe(takeUntil(this._destroy$), share()) + const result$ = requestOptions.takeFullResponse + ? requestFn(httpOptions) + .pipe(takeUntil(this._destroy$), share()) + : requestFn(httpOptions) + .pipe(takeUntil(this._destroy$), map(r => r.body), share()) const errorCheckSubscription = result$.subscribe({ next: () => this.appState.isServerOnline = true, @@ -102,3 +99,10 @@ export class ApiService implements OnDestroy { this.router.navigate(['/account/login']) } } + +export class ApiRequestOptions { + constructor( + public takeFullResponse = false + ) { + } +} diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/rest/RecipeController.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/rest/RecipeController.kt index acc6bea..56a9dce 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/rest/RecipeController.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/rest/RecipeController.kt @@ -49,7 +49,7 @@ class RecipeImageController(val recipeImageService: RecipeImageService) { @ResponseStatus(HttpStatus.CREATED) fun save(@PathVariable recipeId: Long, image: MultipartFile): ResponseEntity { val id = recipeImageService.save(image, recipeId) - return ResponseEntity.created(URI.create("$RECIPE_CONTROLLER_PATH/$recipeId/image/$id")).build() + return ResponseEntity.created(URI.create("/$RECIPE_CONTROLLER_PATH/$recipeId/image/$id")).build() } @DeleteMapping("{recipeId}/image/{id}")