import br.com.alura.screenmatch.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> obterSries(){
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());
}
}
package br.com.alura.screenmatch.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");
}
}
package br.com.alura.screenmatch.dto;
import br.com.alura.screenmatch.model.Categoria;
public record SerieDTO(Long id, String titulo, Integer totalTemporadas, Double avaliacao, Categoria genero, String atores, String poster, String sinopse) {
}