Merge remote-tracking branch 'origin/frontend'

This commit is contained in:
s452111 2020-01-19 20:22:57 +01:00
commit 377d556d73
4 changed files with 65 additions and 19 deletions

View File

@ -1,4 +1,4 @@
function sendJSON() {
function sendGetRequest() {
let result = document.querySelector('.result');
let fuel_type = document.getElementById('fuel_type');
let seats = document.getElementsByClassName('seats')[0];
@ -10,14 +10,12 @@
let body_type = document.getElementById('body_type');
let gearbox = document.getElementById('gearbox');
let drive_type = document.getElementById('drive_type');
let req = new XMLHttpRequest();
let request = new XMLHttpRequest();
// let url = "https://jsonplaceholder.typicode.com/photos";
// let url = "https://webhook.site/b1792c3d-cd5a-4c29-8e9c-1ff9f84653eb";
let url = "http://34.65.132.148:8080";
// let url = "http://34.65.132.148:8080";
let url = "http://localhost:8080/api/cars/search";
var params = [];
if(fuel_type.value != -1){
params.push("fuel_type="+fuel_type.options[fuel_type.value].text);
}
@ -48,7 +46,6 @@
if(drive_type.value != -1){
params.push("drive_type="+drive_type.value);
}
var buff = "";
if(params.length>0){
buff += "?";
@ -60,19 +57,14 @@
}
console.log("Debug: " + buff);
// Create a state change callback
req.open("GET", url+buff, true);
req.setRequestHeader("Content-Type", "text/html");
req.send();
req.onreadystatechange = function () {
if (req.readyState === 4 && req.status === 200) {
request.open("GET", url+buff, true);
request.setRequestHeader("Content-Type", "text/html");
request.send();
request.onreadystatechange = function () {
if (request.readyState === 4 && request.status === 200) {
// Print received data from server
result.innerHTML = this.responseText;
}
};
}

View File

@ -151,7 +151,7 @@
</div>
<div class="form-group">
<input value="Szukaj" class="primary-btn" onclick="sendJSON()" />
<input value="Szukaj" class="primary-btn" onclick="sendGetRequest()" />
<div class="result">
<!-- result list-->
</div>

View File

@ -0,0 +1,55 @@
package com.cars.car4you.api;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
@RestController
public class SimpleController {
@GetMapping("/error")
public String errorPage() {
return "error";
}
@GetMapping("/")
public byte[] homePage() throws IOException {
byte[] array = Files.readAllBytes(Paths.get("src/main/client/html/search.html"));
return array;
}
@GetMapping("/{name}")
public byte[] getPageByName(@PathVariable String name) throws IOException {
System.out.println("Wczytuję stronę: " + name);
byte[] array = Files.readAllBytes(Paths.get("src/main/client/html/" + name));
return array;
}
@GetMapping("/{dir}/{name}")
public ResponseEntity<byte[]> getPageContents(
@PathVariable String name,
@PathVariable String dir) throws IOException {
byte[] array = Files.readAllBytes(Paths.get("src/main/client/html/"+dir+"/"+name));
HttpHeaders responseHeaders = new HttpHeaders();
if(name.matches("(.*\\.js)")) {
responseHeaders.set("Content-Type", "text/javascript");
}else{
//dodatkowe content-types
}
return ResponseEntity.ok()
.headers(responseHeaders)
.body(array);
}
}

View File

@ -1,7 +1,6 @@
package com.cars.car4you.repository;
import com.cars.car4you.model.Car;
import com.cars.car4you.model.CarType;
import org.springframework.stereotype.Repository;
import java.util.List;