Skip to content
This repository was archived by the owner on May 21, 2026. It is now read-only.

Commit 4ed254f

Browse files
Revert "Fix Games and Visual Novels search returning empty/errors (#61)"
This reverts commit e9f6152.
1 parent e9f6152 commit 4ed254f

8 files changed

Lines changed: 400 additions & 149 deletions

File tree

src/main/java/com/espacogeek/geek/data/api/impl/GamesAndVNsApiImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ public MediaModel getDetails(Integer id) {
8787

8888
for (Game result : searchGames) {
8989
if ((long) result.getId() != (long) 0L) {
90-
media = new MediaModel();
9190
var reference = new ExternalReferenceModel(null, String.valueOf(result.getId()), media, typeReference);
91+
media = new MediaModel();
9292

9393
List<String> genresName = new ArrayList<>();
9494
result.getGenresList().forEach((genre) -> {
@@ -114,6 +114,7 @@ public MediaModel getDetails(Integer id) {
114114
}
115115
media.setAlternativeTitles(new java.util.LinkedHashSet<>(alternativeTitles));
116116
media.setExternalReference(new java.util.LinkedHashSet<>(List.of(reference)));
117+
media.setMediaCategory(category);
117118
}
118119
}
119120

@@ -155,7 +156,8 @@ public List<MediaModel> doSearch(String search, MediaCategoryModel mediaCategory
155156
}
156157
media.setAlternativeTitles(new java.util.LinkedHashSet<>(alternativeTitles));
157158
media.setExternalReference(new java.util.LinkedHashSet<>(List.of(reference)));
158-
media.setMediaCategory(mediaCategoryModel);
159+
160+
media.setMediaCategory(category);
159161

160162
medias.add(media);
161163
}

src/main/java/com/espacogeek/geek/data/impl/GenericMediaDataControllerImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
import jakarta.persistence.Id;
3737
import jakarta.persistence.ManyToMany;
38-
import jakarta.persistence.ManyToOne;
3938
import jakarta.persistence.OneToMany;
4039

4140
@Component("genericMediaDataController")
@@ -327,7 +326,7 @@ public MediaModel updateBasicAttributes(MediaModel media, MediaModel result, Typ
327326
field.setAccessible(true);
328327
for (Field rawField : rawMedia.getClass().getDeclaredFields()) {
329328
rawField.setAccessible(true);
330-
if (field.isAnnotationPresent(OneToMany.class) || field.isAnnotationPresent(ManyToMany.class) || field.isAnnotationPresent(ManyToOne.class) || field.isAnnotationPresent(Id.class)) continue;
329+
if (field.isAnnotationPresent(OneToMany.class) || field.isAnnotationPresent(ManyToMany.class) || field.isAnnotationPresent(Id.class)) continue;
331330
if (field.getName().equals(rawField.getName())) {
332331
try {
333332
field.set(media, rawField.get(rawMedia));

src/main/java/com/espacogeek/geek/repositories/MediaRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import com.espacogeek.geek.models.TypeReferenceModel;
1616

1717
@Repository
18-
public interface MediaRepository extends JpaRepository<MediaModel, Integer> {
18+
public interface MediaRepository extends JpaRepository<MediaModel, Integer>, MediaRepositoryCustom {
1919

2020
// if at some time the queries become more complex, see https://www.jooq.org/
2121
// and https://persistence.blazebit.com/.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.espacogeek.geek.repositories;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
import org.springframework.data.domain.Page;
7+
import org.springframework.data.domain.Pageable;
8+
import org.springframework.data.web.PageableDefault;
9+
10+
import com.espacogeek.geek.models.MediaModel;
11+
12+
public interface MediaRepositoryCustom {
13+
14+
/**
15+
* Finds media by matching name or alternative title within a specific media
16+
* category.
17+
*
18+
* This query searches for MediaModel entities where the name or any alternative
19+
* title matches the provided name or alternativeTitle parameters. It filters
20+
* the
21+
* results to only include those within the specified media category. The
22+
* requestedFields parameter is optional and can be used to return only the
23+
* selected fields of the entities.
24+
*
25+
* @param name The name of the media to search for.
26+
* @param alternativeTitle The alternative title of the media to search for.
27+
* @param category The ID of the media category to filter results by.
28+
* @param requestedFields A map of fields to return. If not provided, all
29+
* fields will be returned.
30+
* @return a Page of MediaModel objects that match the search criteria.
31+
*/
32+
public Page<MediaModel> findMediaByNameOrAlternativeTitleAndMediaCategory(
33+
String name,
34+
String alternativeTitle,
35+
Integer category,
36+
Map<String, List<String>> requestedFields,
37+
@PageableDefault(size = 10, page = 0) Pageable pageable);
38+
}

0 commit comments

Comments
 (0)