Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# MovieApi

user name : user
password : 123456abcd

I have also enabled swagger for testing. Therefore it can be access at the URL http://localhost/swagger-ui.html

88 changes: 86 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,41 @@
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<artifactId>spring-boot-starter-jooq</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>

<build>
Expand All @@ -46,6 +64,72 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>

<!-- Specify the maven code generator plugin -->
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.11.11</version>

<!-- The plugin should hook into the generate goal -->
<executions>
<execution>
<phase>none</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>

<!-- Specify the plugin configuration.
The configuration format is the same as for the standalone code generator -->
<configuration>

<!-- JDBC connection parameters -->
<jdbc>
<driver>com.mysql.cj.jdbc.Driver</driver>
<url>jdbc:mysql://localhost/moviedb</url>
<!-- Put your locked schema here -->

<user>root</user>
<password>admin</password>
</jdbc>

<!-- Generator parameters -->
<generator>
<database>
<name>org.jooq.meta.mysql.MySQLDatabase</name>
<includes>.*</includes>
<excludes></excludes>

<inputSchema>moviedb</inputSchema>
<outputSchemaToDefault>true</outputSchemaToDefault>

<includeTables>true</includeTables>
<includeRoutines>false</includeRoutines>
<includePackages>false</includePackages>
<includeUDTs>false</includeUDTs>
<includeSequences>false</includeSequences>
<includePrimaryKeys>true</includePrimaryKeys>
<includeUniqueKeys>false</includeUniqueKeys>
<includeForeignKeys>false</includeForeignKeys>

</database>
<target>
<packageName>com.zirius.zerp</packageName>
<directory>target/generated-sources/jooq</directory>
</target>

<generate>
<javaTimeTypes>true</javaTimeTypes>
<pojos>true</pojos>
<daos>true</daos>
</generate>


</generator>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableFeignClients
public class MovieApiApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.zirius.zerp.movieApi.configuration;

import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableFeignClients
public class FeignConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.zirius.zerp.movieApi.configuration;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.zirius.zerp.movieApi.configuration;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@EnableWebSecurity
@ConditionalOnProperty(value = "app.security.basic.enabled", havingValue = "", matchIfMissing = true)
class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
http.csrf().disable();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.zirius.zerp.movieApi.controller;

import com.zirius.zerp.movieApi.model.domain.Movie;
import com.zirius.zerp.movieApi.model.dto.MovieDto;
import com.zirius.zerp.movieApi.service.MovieApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
public class MovieApiController {

@Autowired
private MovieApiService movieApiService;

/**
* This getter collects the information from our locally stored database.
*
* @param type type of the content such as movie , series
* @param year year of the release
*
* @return list of movies wrapped in response object
*/
@GetMapping("/localdb")
public ResponseEntity<List<Movie>> getFromLocalDB(@RequestHeader(name="title",required = false) String title,
@RequestHeader(name = "type", required = true) String type,
@RequestHeader(name = "year", required = true) Integer year) {
return new ResponseEntity<>(movieApiService.getMovieInfo(title, type, year), HttpStatus.OK);
}

/**
* This getter gather information from an online db of movies called OMDB
*
* @param movieTitle
* @param type
* @param year
* @return
*/
@GetMapping("/omdb")
public ResponseEntity<String> getFromOMDB(@RequestHeader(name = "title", required = true) String movieTitle,
@RequestHeader(name = "type", required = true) String type,
@RequestHeader(name = "year", required = true) Integer year) {
return new ResponseEntity<>(movieApiService.getOMDBMovieInfo(movieTitle, type, year), HttpStatus.OK);
}

/**
* Add a movie information into out local database for movies
*
* @param movie object
* @return response entity with the information of created movie and status of the operation
*/
@PostMapping("/localdb/add")
public ResponseEntity<Integer> addMovieInformation( @RequestBody Movie movie) {
// make sure that the movie id is not set
movie.setId(null);
return new ResponseEntity<>(movieApiService.saveMovie(movie),HttpStatus.CREATED);
}

/**
* Update an existing movie in our local movie database.
*
* @param movie object for update
* @return response entity with the status of the operation
*/
@PostMapping("/localdb/update")
public ResponseEntity<Void> updateMovieInformation( @RequestBody Movie movie) {

if(movie.getId() != null) {
movieApiService.saveMovie(movie);
} else {
throw new RuntimeException("Movie id shouldn't be null for updating");
}

return new ResponseEntity<>(HttpStatus.OK);
}

}
22 changes: 22 additions & 0 deletions src/main/java/com/zirius/zerp/movieApi/feign/OMDBClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.zirius.zerp.movieApi.feign;

import com.zirius.zerp.movieApi.model.dto.MovieDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

@FeignClient(name = "omdb",url = "${app.omdb.url}")
public interface OMDBClient {

@RequestMapping(value = "/?apikey={apikey}&s={s}&type={type}&y={year}", method = GET)
@ResponseBody
public String get(@PathVariable(value = "apikey",required = true) String apikey,
@PathVariable(value = "s",required = true) String title,
@PathVariable(value = "type") String type,
@PathVariable("y") Integer year);

}
Loading