@Controller
package br.com.ScreenMatch2.controller;
import br.com.ScreenMatch2.dto.SerieDTO;
import br.com.ScreenMatch2.repository.SerieRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.stream.Collectors;
@RestController
public class SerieController {
@Autowired
private SerieRepository repositorio;
@GetMapping("/series")
public List<SerieDTO> obterSeries(){
return repositorio.findAll()
.stream()
.map(s-> new SerieDTO(s.getId(), s.getTitulo(),
s.getTotalTemporadas(), s.getAvaliacao(), s.getGenero(),
s.getAtores(), s.getPoster(), s.getSinopse()))
.collect(Collectors.toList());
}
}
CONFIG
package br.com.ScreenMatch2.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfiguration implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://127.0.0.1:5500")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "TRACE", "CONNECT");
}
}
DTO
package br.com.ScreenMatch2.dto;
import br.com.ScreenMatch2.model.Categoria;
public record SerieDTO( Long id, String titulo, Integer totalTemporadas, Double avaliacao,
Categoria genero, String atores,
String poster, String sinopse) {
}