diff --git a/src/main/java/com/mediamanager/model/Album.java b/src/main/java/com/mediamanager/model/Album.java index 6bedc3a..d55621f 100644 --- a/src/main/java/com/mediamanager/model/Album.java +++ b/src/main/java/com/mediamanager/model/Album.java @@ -41,6 +41,10 @@ public class Album { @OneToMany(mappedBy = "album", cascade = CascadeType.ALL, orphanRemoval = true) private List albumArtists = new ArrayList<>(); + // Relacionamento ManyToMany com Genre através da tabela de junção + @OneToMany(mappedBy = "album", cascade = CascadeType.ALL, orphanRemoval = true) + private List albumGenres = new ArrayList<>(); // ← ADICIONE ESSA LINHA + @Column(name = "created_at", nullable = false, updatable = false) private LocalDateTime createdAt; @@ -81,6 +85,31 @@ public class Album { .collect(Collectors.toList()); } + // ========== ADICIONE ESSES MÉTODOS PARA GENRE ========== + + // Métodos helper para Genre (ManyToMany) + public void addGenre(Genre genre) { + AlbumHasGenre albumHasGenre = new AlbumHasGenre(); + albumHasGenre.setAlbum(this); + albumHasGenre.setGenre(genre); + albumGenres.add(albumHasGenre); + } + + public void removeGenre(Genre genre) { + albumGenres.removeIf(ag -> + ag.getGenre() != null && ag.getGenre().getId().equals(genre.getId()) + ); + } + + // Método conveniente para pegar só os gêneros + public List getGenres() { + return albumGenres.stream() + .map(AlbumHasGenre::getGenre) + .collect(Collectors.toList()); + } + + // ========== FIM DOS MÉTODOS DE GENRE ========== + // Getters and Setters public Integer getId() { return id; @@ -154,6 +183,18 @@ public class Album { this.albumArtists = albumArtists; } + // ========== ADICIONE ESSES GETTERS/SETTERS ========== + + public List getAlbumGenres() { + return albumGenres; + } + + public void setAlbumGenres(List albumGenres) { + this.albumGenres = albumGenres; + } + + // ========== FIM DOS GETTERS/SETTERS DE GENRE ========== + public LocalDateTime getCreatedAt() { return createdAt; }