Skip to content

Commit

Permalink
feat: improve params
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Nov 28, 2024
1 parent 0b57646 commit d44ba72
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -23,20 +26,20 @@
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import ch.xxx.moviemanager.domain.exceptions.ResourceNotFoundException;
import ch.xxx.moviemanager.domain.model.dto.MovieFilterCriteriaDto;
import ch.xxx.moviemanager.domain.model.dto.GenereDto;
import ch.xxx.moviemanager.domain.model.dto.MovieDto;
import ch.xxx.moviemanager.domain.model.dto.MovieFilterCriteriaDto;
import ch.xxx.moviemanager.domain.model.dto.SearchTermDto;
import ch.xxx.moviemanager.usecase.mapper.DefaultMapper;
import ch.xxx.moviemanager.usecase.service.MovieService;

@RestController
@RequestMapping("rest/movie")
public class MovieController {
private static final Logger LOG = LoggerFactory.getLogger(MovieController.class);
private final MovieService service;
private final DefaultMapper mapper;

Expand Down Expand Up @@ -82,11 +85,11 @@ public List<GenereDto> getGeneres() throws InterruptedException {
return generes;
}

@RequestMapping(value = "/pages", params = {
"page" }, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/pages", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public List<MovieDto> getPagesByNumber(@RequestHeader(value = HttpHeaders.AUTHORIZATION) String bearerStr,
@RequestParam("page") Integer page) throws InterruptedException {
List<MovieDto> movies = this.service.findMoviesByPage(page, bearerStr).stream().map(this.mapper::convert)
Pageable pageable) throws InterruptedException {
LOG.debug(String.format("page=%d, size=%d, sort=%s", pageable.getPageNumber(), pageable.getPageSize(), pageable.getSort()));
List<MovieDto> movies = this.service.findMoviesByPage(pageable.getPageNumber(), bearerStr).stream().map(this.mapper::convert)
.toList();
return movies;
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/angular/src/app/services/movies.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class MoviesService {
constructor(private http: HttpClient) {}

public findMoviesByPage(page: number): Observable<Movie[]> {
return this.http.get<Movie[]>("/rest/movie/pages?page=" + page).pipe(
return this.http.get<Movie[]>(`/rest/movie/pages?page=${page}&size=15&sort=title,asc`).pipe(
catchError((error) => {
console.error(JSON.stringify(error));
return throwError(error);
Expand Down

0 comments on commit d44ba72

Please sign in to comment.