CREATE DATABASE screenmatch;
org.springframework.boot spring-boot-starter-data-jpa<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
import jakarta.persistence.*;
@Entity
@Table(name = "series")
public class Serie {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(unique = true, nullable = false)
private String titulo;
private Integer totalTemporadas;
private Double evaluacion;
private String genero;
private String actores;
private String poster;
@Column(length = 2000)
private String sinopsis;
public Serie() {
}
public Serie(DatosSerie datos) {
this.titulo = datos.titulo();
this.totalTemporadas = datos.totalTemporadas();
this.genero = datos.genero();
this.actores = datos.actores();
this.poster = datos.poster();
this.sinopsis = datos.sinopsis();
try {
this.evaluacion = Double.valueOf(datos.evaluacion());
} catch (Exception e) {
this.evaluacion = 0.0;
}
}
public Long getId() {
return id;
}
public String getTitulo() {
return titulo;
}
public Integer getTotalTemporadas() {
return totalTemporadas;
}
public Double getEvaluacion() {
return evaluacion;
}
public String getGenero() {
return genero;
}
public String getActores() {
return actores;
}
public String getPoster() {
return poster;
}
public String getSinopsis() {
return sinopsis;
}
public void setId(Long id) {
this.id = id;
}
public void setTitulo(String titulo) {
this.titulo = titulo;
}
public void setTotalTemporadas(Integer totalTemporadas) {
this.totalTemporadas = totalTemporadas;
}
public void setEvaluacion(Double evaluacion) {
this.evaluacion = evaluacion;
}
public void setGenero(String genero) {
this.genero = genero;
}
public void setActores(String actores) {
this.actores = actores;
}
public void setPoster(String poster) {
this.poster = poster;
}
public void setSinopsis(String sinopsis) {
this.sinopsis = sinopsis;
}
@Override
public String toString() {
return "Serie{" +
"id=" + id +
", titulo='" + titulo + '\'' +
", totalTemporadas=" + totalTemporadas +
", evaluacion=" + evaluacion +
", genero='" + genero + '\'' +
", actores='" + actores + '\'' +
", poster='" + poster + '\'' +
", sinopsis='" + sinopsis + '\'' +
'}';
}
}
import org.springframework.data.jpa.repository.JpaRepository;
public interface SerieRepository extends JpaRepository<Serie, Long> {
boolean existsByTituloIgnoreCase(String titulo);
}
spring.datasource.url=${DB_URL}
spring.datasource.username=${DB_USERNAME}
spring.datasource.password=${DB_PASSWORD}
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
$env:DB_URL="jdbc:postgresql://localhost:5432/screenmatch"
$env:DB_USERNAME="postgres"
$env:DB_PASSWORD="tu_clave"
set DB_URL=jdbc:postgresql://localhost:5432/screenmatch
set DB_USERNAME=postgres
set DB_PASSWORD=tu_clave
import java.util.Scanner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class Principal {
@Autowired
private SerieRepository repositorio;
private final Scanner teclado = new Scanner(System.in);
private final ConsumoApi consumoApi = new ConsumoApi();
private final ConvierteDatos conversor = new ConvierteDatos();
private final String URL_BASE = "https://www.omdbapi.com/?t=";
private final String API_KEY = "&apikey=TU_API_KEY";
public void muestraElMenu() {
System.out.println("Escribe el nombre de la serie:");
var nombreSerie = teclado.nextLine();
var json = consumoApi.obtenerDatos(URL_BASE + nombreSerie.replace(" ", "+") + API_KEY);
DatosSerie datos = conversor.obtenerDatos(json, DatosSerie.class);
Serie serie = new Serie(datos);
if (!repositorio.existsByTituloIgnoreCase(serie.getTitulo())) {
repositorio.save(serie);
System.out.println("Serie