Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Rubén Ramírez
/
MangAffinity
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7f5889c9
authored
Apr 20, 2025
by
Rubén Ramírez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat: [BibliotecaPersonal]: Añadida una función en la propia clase para añadir a favoritos
parent
0c90caed
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
src/main/java/com/ujaen/tfg/mangaffinity/entidades/BibliotecaPersonal.java
src/main/java/com/ujaen/tfg/mangaffinity/entidades/BibliotecaPersonal.java
View file @
7f5889c9
package
com
.
ujaen
.
tfg
.
mangaffinity
.
entidades
;
import
com.ujaen.tfg.mangaffinity.excepciones.NumeroMaximoFavoritos
;
import
jakarta.persistence.*
;
import
lombok.*
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
@Entity
...
...
@@ -23,7 +27,29 @@ public class BibliotecaPersonal {
@OneToMany
(
mappedBy
=
"bibliotecaPersonal"
)
private
Set
<
BibliotecaPersonalRecurso
>
recursos
=
new
HashSet
<>();
@ElementCollection
@CollectionTable
(
name
=
"favoritos_usuario"
,
joinColumns
=
@JoinColumn
(
name
=
"biblioteca_id"
))
@Column
(
name
=
"recurso_id"
)
private
List
<
Long
>
favoritos
=
new
ArrayList
<>();
public
BibliotecaPersonal
(
Usuario
usuario
)
{
this
.
usuario
=
usuario
;
}
public
void
anadirFavorito
(
Long
recursoId
)
{
if
(
favoritos
.
contains
(
recursoId
))
return
;
if
(
favoritos
.
size
()
>=
4
)
{
throw
new
NumeroMaximoFavoritos
();
}
favoritos
.
add
(
recursoId
);
}
public
void
eliminarFavorito
(
Long
recursoId
)
{
favoritos
.
remove
(
recursoId
);
}
public
List
<
Long
>
obtenerFavoritos
()
{
return
List
.
copyOf
(
favoritos
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment