Compare commits

..

2 Commits

Author SHA1 Message Date
c97c1a9c5a Configure CORS, ignore unkown properties of MaterialData 2025-06-20 00:40:56 +05:00
f145b17527 Generate OpenAPI v3 2025-06-20 00:39:11 +05:00
4 changed files with 96 additions and 72 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@ -31,6 +32,7 @@
<retrofit.version>3.0.0</retrofit.version>
<spring-dotenv.version>4.0.0</spring-dotenv.version>
<springdoc-openapi-starter.version>2.8.9</springdoc-openapi-starter.version>
</properties>
<dependencies>
<dependency>
@ -53,6 +55,11 @@
<artifactId>spring-dotenv</artifactId>
<version>${spring-dotenv.version}</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc-openapi-starter.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -2,6 +2,9 @@ package com.backend.search.service.anyame_backend;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@SpringBootApplication
public class AnyameBackendApplication {
@ -10,4 +13,15 @@ public class AnyameBackendApplication {
SpringApplication.run(AnyameBackendApplication.class, args);
}
// TODO: Research if this is good approach or not?
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("http://localhost:3000");
}
};
}
}

View File

@ -1,9 +1,11 @@
package com.backend.search.service.anyame_backend.api.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
public class MaterialData {
public String title;

View File

@ -29,9 +29,10 @@ public class SearchController {
@GetMapping("/search")
public KodikResponse search(@RequestParam("title") String title) {
try {
Response<KodikResponse> response = kodikAPI.search(tokenProvider.getKodikToken(), title, 5, 1).execute();
Response<KodikResponse> response = kodikAPI.search(tokenProvider.getKodikToken(), title, 100, 1).execute();
if (!response.isSuccessful()) {
log.info("failed search request with title {}, response code {}, message {}", title, response.code(), response.message());
log.info("failed search request with title {}, response code {}, message {}", title, response.code(),
response.message());
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "bad response, code: " + response.code());
}
return response.body();