Skip to content

Commit

Permalink
Implement get movie by imdb id
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoxtygen committed Mar 24, 2023
1 parent 32e5252 commit a1116b2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/main/java/com/codeplanks/movies/MovieController.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package com.codeplanks.movies;

import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/v1/movies")
public class MovieController {
@Autowired
private MovieService movieService;

@GetMapping
public ResponseEntity<List<Movie>> getAllMovies() {
return new ResponseEntity<List<Movie>>(movieService.allMovies(), HttpStatus.OK);
}



@GetMapping("/{imdbId}")
public ResponseEntity<Optional<Movie>> getSingleMovieByImdbId(@PathVariable String imdbId) {
return new ResponseEntity<Optional<Movie>>(movieService.singleMovieByImdbId(imdbId), HttpStatus.OK);
}

}
4 changes: 3 additions & 1 deletion src/main/java/com/codeplanks/movies/MovieRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface MovieRepository extends MongoRepository<Movie, ObjectId> {

Optional<Movie> findMovieByImdbId(String imdbId);
}
8 changes: 8 additions & 0 deletions src/main/java/com/codeplanks/movies/MovieService.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.codeplanks.movies;

import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class MovieService {
Expand All @@ -12,4 +14,10 @@ public class MovieService {
public List<Movie> allMovies(){
return movieRepository.findAll();
}


public Optional<Movie> singleMovieByImdbId(String id) {
return movieRepository.findMovieByImdbId(id);
}

}

0 comments on commit a1116b2

Please sign in to comment.