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

139
pom.xml
View File

@ -1,73 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<modelVersion>4.0.0</modelVersion> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.boot</groupId> <parent>
<artifactId>spring-boot-starter-parent</artifactId> <groupId>org.springframework.boot</groupId>
<version>3.5.0</version> <artifactId>spring-boot-starter-parent</artifactId>
<relativePath/> <!-- lookup parent from repository --> <version>3.5.0</version>
</parent> <relativePath /> <!-- lookup parent from repository -->
<groupId>com.backend.search.kodik.service</groupId> </parent>
<artifactId>anyame-backend</artifactId> <groupId>com.backend.search.kodik.service</groupId>
<version>0.0.1-SNAPSHOT</version> <artifactId>anyame-backend</artifactId>
<name>anyame-backend</name> <version>0.0.1-SNAPSHOT</version>
<description>Kodik search service for anyame</description> <name>anyame-backend</name>
<url/> <description>Kodik search service for anyame</description>
<licenses> <url />
<license/> <licenses>
</licenses> <license />
<developers> </licenses>
<developer/> <developers>
</developers> <developer />
<scm> </developers>
<connection/> <scm>
<developerConnection/> <connection />
<tag/> <developerConnection />
<url/> <tag />
</scm> <url />
<properties> </scm>
<java.version>21</java.version> <properties>
<java.version>21</java.version>
<retrofit.version>3.0.0</retrofit.version> <retrofit.version>3.0.0</retrofit.version>
<spring-dotenv.version>4.0.0</spring-dotenv.version> <spring-dotenv.version>4.0.0</spring-dotenv.version>
</properties> <springdoc-openapi-starter.version>2.8.9</springdoc-openapi-starter.version>
<dependencies> </properties>
<dependency> <dependencies>
<groupId>org.springframework.boot</groupId> <dependency>
<artifactId>spring-boot-starter-web</artifactId> <groupId>org.springframework.boot</groupId>
</dependency> <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.squareup.retrofit2</groupId> <groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId> <artifactId>retrofit</artifactId>
<version>${retrofit.version}</version> <version>${retrofit.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.squareup.retrofit2</groupId> <groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-jackson</artifactId> <artifactId>converter-jackson</artifactId>
<version>${retrofit.version}</version> <version>${retrofit.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>me.paulschwarz</groupId> <groupId>me.paulschwarz</groupId>
<artifactId>spring-dotenv</artifactId> <artifactId>spring-dotenv</artifactId>
<version>${spring-dotenv.version}</version> <version>${spring-dotenv.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc-openapi-starter.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -2,12 +2,26 @@ package com.backend.search.service.anyame_backend;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; 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 @SpringBootApplication
public class AnyameBackendApplication { public class AnyameBackendApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(AnyameBackendApplication.class, args); 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; package com.backend.search.service.anyame_backend.api.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List; import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
public class MaterialData { public class MaterialData {
public String title; public String title;
@ -80,4 +82,4 @@ public class MaterialData {
public List<String> designers; public List<String> designers;
public List<String> operators; public List<String> operators;
} }

View File

@ -29,9 +29,10 @@ public class SearchController {
@GetMapping("/search") @GetMapping("/search")
public KodikResponse search(@RequestParam("title") String title) { public KodikResponse search(@RequestParam("title") String title) {
try { 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()) { 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()); throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "bad response, code: " + response.code());
} }
return response.body(); return response.body();