fix
This commit is contained in:
parent
9f1d3fa92d
commit
365eb02330
@ -33,6 +33,8 @@ dependencies {
|
||||
runtimeOnly 'com.mysql:mysql-connector-j'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.12.4'
|
||||
}
|
||||
|
||||
jar {
|
||||
|
@ -2,16 +2,27 @@ package com.s477603.movies.web;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import com.s477603.movies.document.Movie;
|
||||
import com.s477603.movies.document.MoviesCommonResponse;
|
||||
import com.s477603.movies.service.IMDBService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/movies")
|
||||
public class MoviesController {
|
||||
@ -33,6 +44,35 @@ public class MoviesController {
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/trending/download")
|
||||
public ResponseEntity trendingGenerate() throws IOException {
|
||||
|
||||
MoviesCommonResponse trending = imdbService.getTrending(1);
|
||||
XmlMapper xmlMapper = new XmlMapper();
|
||||
String xml = xmlMapper.writeValueAsString(trending);
|
||||
FileWriter fw = new FileWriter("trending.xml");
|
||||
|
||||
fw.write(xml);
|
||||
|
||||
File file = new File("trending.xml");
|
||||
|
||||
HttpHeaders header = new HttpHeaders();
|
||||
header.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=trending.xml");
|
||||
header.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
header.add("Pragma", "no-cache");
|
||||
header.add("Expires", "0");
|
||||
|
||||
Path path = Paths.get(file.getAbsolutePath());
|
||||
ByteArrayResource resource = new ByteArrayResource(Files.readAllBytes(path));
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.headers(header)
|
||||
.contentLength(file.length())
|
||||
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||
.body(resource);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/search")
|
||||
public ResponseEntity search(@RequestParam(name = "query") String query, @RequestParam(name = "page", defaultValue = "1") int page) {
|
||||
MoviesCommonResponse search = imdbService.searchMovies(query, page);
|
||||
|
@ -4,6 +4,6 @@ REFRESH_TOKEN_PRIVATE_KEY_PATH: "access-refresh-token-keys/refresh-token-private
|
||||
REFRESH_TOKEN_PUBLIC_KEY_PATH: "access-refresh-token-keys/refresh-token-public.key"
|
||||
TMDB_API_KEY: "467188b6746d2763198f8fdc0ae4bc9e"
|
||||
|
||||
DB_URL: jdbc:mysql://localhost:3306/movies?useSSL=false
|
||||
DB_URL: jdbc:mysql://localhost:3306/movies?allowPublicKeyRetrieval=true&useSSL=false
|
||||
DB_USERNAME: root
|
||||
DB_PASSWORD: marcin
|
@ -1,8 +1,8 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/movies?useSSL=false
|
||||
username: root
|
||||
password: marcin
|
||||
url: ${DB_URL}
|
||||
username: ${DB_USERNAME}
|
||||
password: ${DB_PASSWORD}
|
||||
profiles:
|
||||
active: prod
|
||||
|
||||
|
1
trending.xml
Normal file
1
trending.xml
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user