Skip to content

Commit

Permalink
fix: import
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Oct 21, 2023
1 parent 4e42e28 commit 7b98811
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public boolean importMovie(int movieDbId, String bearerStr) throws InterruptedEx
List<Genere> generes = new ArrayList<>(this.genereRep.findAll());
for (GenereDto g : result.getGenres()) {
Genere genereEntity = generes.stream()
.filter(myGenere -> myGenere.getGenereId() != null && myGenere.getGenereId().equals(g.getId()))
.filter(myGenere -> Optional.ofNullable(myGenere.getGenereId()).stream().anyMatch(myGenereId -> myGenereId.equals(g.getId())))
.findFirst().orElse(this.mapper.convert(g));
if (genereEntity.getId() == null) {
genereEntity = genereRep.save(genereEntity);
Expand All @@ -190,8 +190,9 @@ public boolean importMovie(int movieDbId, String bearerStr) throws InterruptedEx
LOG.info("Start import Movie with Id: {movieDbId}", movieDbId);
MovieDto movieDto = this.movieDbRestClient.fetchMovie(this.decrypt(user.getMoviedbkey(), user.getUuid()),
movieDbId);
Movie movieEntity = this.movieRep.findByMovieId(movieDto.getMovieId(), user.getId()).orElse(null);
if (movieEntity == null) {
Optional<Movie> movieOpt = this.movieRep.findByMovieId(movieDto.getMovieId(), user.getId());
Movie movieEntity = movieOpt.isPresent() ? movieOpt.get() : null;
if (movieOpt.isEmpty()) {
LOG.info("Movie not found by id");
List<Movie> movies = this.movieRep.findByTitleAndRelDate(movieDto.getTitle(), movieDto.getReleaseDate(),
this.userDetailService.getCurrentUser(bearerStr).getId());
Expand Down Expand Up @@ -255,6 +256,7 @@ public boolean importMovie(int movieDbId, String bearerStr) throws InterruptedEx
}
}
}
LOG.info("Finished import");
return true;
}

Expand Down

0 comments on commit 7b98811

Please sign in to comment.