Some model rename
This commit is contained in:
@@ -11,22 +11,22 @@ import org.mapstruct.Named;
|
|||||||
|
|
||||||
import com.backend.metadata.kodik.api.model.KodikResponse;
|
import com.backend.metadata.kodik.api.model.KodikResponse;
|
||||||
import com.backend.metadata.kodik.api.model.MaterialData;
|
import com.backend.metadata.kodik.api.model.MaterialData;
|
||||||
import com.backend.unifier.title.model.SearchEntry;
|
import com.backend.unifier.title.model.ContentSearchEntry;
|
||||||
import com.backend.unifier.title.model.SearchResponse;
|
import com.backend.unifier.title.model.SearchEntries;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface KodikResponseMapper {
|
public interface KodikResponseMapper {
|
||||||
default SearchResponse toSearchResponse(KodikResponse kodikResponse) {
|
default SearchEntries toSearchEntries(KodikResponse kodikResponse) {
|
||||||
if (kodikResponse == null || kodikResponse.results == null) {
|
if (kodikResponse == null || kodikResponse.results == null) {
|
||||||
return new SearchResponse(List.of());
|
return new SearchEntries(List.of());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SearchEntry> entries = kodikResponse.results.stream()
|
List<ContentSearchEntry> entries = kodikResponse.results.stream()
|
||||||
.map(this::toSearchEntryDTO)
|
.map(this::toContentSearchEntry)
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
return new SearchResponse(entries);
|
return new SearchEntries(entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mapping(target = "id", source = "result", qualifiedByName = "extractID")
|
@Mapping(target = "id", source = "result", qualifiedByName = "extractID")
|
||||||
@@ -39,7 +39,7 @@ public interface KodikResponseMapper {
|
|||||||
@Mapping(target = "studio", source = "materialData", qualifiedByName = "extractStudio")
|
@Mapping(target = "studio", source = "materialData", qualifiedByName = "extractStudio")
|
||||||
@Mapping(target = "genres", source = "materialData", qualifiedByName = "extractGenres")
|
@Mapping(target = "genres", source = "materialData", qualifiedByName = "extractGenres")
|
||||||
@Mapping(target = "durationMin", source = "materialData", qualifiedByName = "extractDurationMin")
|
@Mapping(target = "durationMin", source = "materialData", qualifiedByName = "extractDurationMin")
|
||||||
SearchEntry toSearchEntryDTO(KodikResponse.Result result);
|
ContentSearchEntry toContentSearchEntry(KodikResponse.Result result);
|
||||||
|
|
||||||
@Named("extractPosterUrls")
|
@Named("extractPosterUrls")
|
||||||
default List<String> extractPosterUrls(MaterialData materialData) {
|
default List<String> extractPosterUrls(MaterialData materialData) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.backend.unifier.title.model;
|
package com.backend.unifier.title.model;
|
||||||
|
|
||||||
public record DetailEntry() {
|
public record ContentDetailEntry() {
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ import java.util.List;
|
|||||||
import io.soabase.recordbuilder.core.RecordBuilder;
|
import io.soabase.recordbuilder.core.RecordBuilder;
|
||||||
|
|
||||||
@RecordBuilder
|
@RecordBuilder
|
||||||
public record SearchEntry(
|
public record ContentSearchEntry(
|
||||||
String id,
|
String id,
|
||||||
List<String> posterURLs,
|
List<String> posterURLs,
|
||||||
String title,
|
String title,
|
||||||
@@ -15,5 +15,5 @@ public record SearchEntry(
|
|||||||
String type,
|
String type,
|
||||||
String studio,
|
String studio,
|
||||||
List<String> genres,
|
List<String> genres,
|
||||||
int durationMin) implements SearchEntryBuilder.With {
|
int durationMin) implements ContentSearchEntryBuilder.With {
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,6 @@ import java.util.List;
|
|||||||
import io.soabase.recordbuilder.core.RecordBuilder;
|
import io.soabase.recordbuilder.core.RecordBuilder;
|
||||||
|
|
||||||
@RecordBuilder
|
@RecordBuilder
|
||||||
public record SearchResponse(List<SearchEntry> result) implements SearchResponseBuilder.With {
|
public record SearchEntries(List<ContentSearchEntry> result) implements SearchEntriesBuilder.With {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package com.backend.unifier.title.resource;
|
package com.backend.unifier.title.resource;
|
||||||
|
|
||||||
import com.backend.unifier.title.model.DetailEntry;
|
import com.backend.unifier.title.model.ContentDetailEntry;
|
||||||
|
|
||||||
|
import io.smallrye.openapi.internal.models.media.Content;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ import jakarta.ws.rs.Path;
|
|||||||
public class DetailResource {
|
public class DetailResource {
|
||||||
@GET
|
@GET
|
||||||
@Path("/detail")
|
@Path("/detail")
|
||||||
public DetailEntry detail(String id) {
|
public ContentDetailEntry detail(String id) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.backend.unifier.title.resource;
|
|||||||
import org.eclipse.microprofile.rest.client.inject.RestClient;
|
import org.eclipse.microprofile.rest.client.inject.RestClient;
|
||||||
|
|
||||||
import com.backend.unifier.title.api.KodikSearchService;
|
import com.backend.unifier.title.api.KodikSearchService;
|
||||||
import com.backend.unifier.title.model.SearchResponse;
|
import com.backend.unifier.title.model.SearchEntries;
|
||||||
import com.backend.unifier.title.service.KodikResponseConvertService;
|
import com.backend.unifier.title.service.KodikResponseConvertService;
|
||||||
|
|
||||||
import io.smallrye.mutiny.Uni;
|
import io.smallrye.mutiny.Uni;
|
||||||
@@ -24,7 +24,7 @@ public class SearchResource {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/search")
|
@Path("/search")
|
||||||
public Uni<SearchResponse> search(@QueryParam("title") String title) {
|
public Uni<SearchEntries> search(@QueryParam("title") String title) {
|
||||||
return kodikSearchService.searchAsync(title)
|
return kodikSearchService.searchAsync(title)
|
||||||
.onItem().ifNotNull()
|
.onItem().ifNotNull()
|
||||||
.transformToUni(response -> kodikConvertService.convertAsync(response));
|
.transformToUni(response -> kodikConvertService.convertAsync(response));
|
||||||
@@ -32,14 +32,14 @@ public class SearchResource {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/search-fast")
|
@Path("/search-fast")
|
||||||
public SearchResponse searchFast(@QueryParam("title") String title) {
|
public SearchEntries searchFast(@QueryParam("title") String title) {
|
||||||
var result = kodikSearchService.search(title);
|
var result = kodikSearchService.search(title);
|
||||||
return kodikConvertService.convert(result);
|
return kodikConvertService.convert(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/list")
|
@Path("/list")
|
||||||
public SearchResponse list() {
|
public SearchEntries list() {
|
||||||
var result = kodikSearchService.list();
|
var result = kodikSearchService.list();
|
||||||
return kodikConvertService.convert(result);
|
return kodikConvertService.convert(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import org.mapstruct.factory.Mappers;
|
|||||||
|
|
||||||
import com.backend.metadata.kodik.api.model.KodikResponse;
|
import com.backend.metadata.kodik.api.model.KodikResponse;
|
||||||
import com.backend.unifier.title.mapper.KodikResponseMapper;
|
import com.backend.unifier.title.mapper.KodikResponseMapper;
|
||||||
import com.backend.unifier.title.model.SearchEntry;
|
import com.backend.unifier.title.model.ContentSearchEntry;
|
||||||
import com.backend.unifier.title.model.SearchResponse;
|
import com.backend.unifier.title.model.SearchEntries;
|
||||||
|
|
||||||
import io.smallrye.mutiny.Uni;
|
import io.smallrye.mutiny.Uni;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
@@ -24,40 +24,40 @@ public class KodikResponseConvertService {
|
|||||||
this.posterUrlNormalizer = posterUrlNormalizer;
|
this.posterUrlNormalizer = posterUrlNormalizer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SearchResponse convert(KodikResponse response) {
|
public SearchEntries convert(KodikResponse response) {
|
||||||
return convertSimple(response);
|
return convertSimple(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Uni<SearchResponse> convertAsync(KodikResponse response) {
|
public Uni<SearchEntries> convertAsync(KodikResponse response) {
|
||||||
if (response == null || response.results == null) {
|
if (response == null || response.results == null) {
|
||||||
return Uni.createFrom().item(new SearchResponse(List.of()));
|
return Uni.createFrom().item(new SearchEntries(List.of()));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Uni<SearchEntry>> entries = convertSimple(response).result()
|
List<Uni<ContentSearchEntry>> entries = convertSimple(response).result()
|
||||||
.stream()
|
.stream()
|
||||||
.map(this::resolveEntryPosters)
|
.map(this::resolveEntryPosters)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
if (entries.isEmpty()) {
|
if (entries.isEmpty()) {
|
||||||
return Uni.createFrom().item(new SearchResponse(List.of()));
|
return Uni.createFrom().item(new SearchEntries(List.of()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Uni.combine().all().unis(entries)
|
return Uni.combine().all().unis(entries)
|
||||||
.with(list -> new SearchResponse((List<SearchEntry>) list));
|
.with(list -> new SearchEntries((List<ContentSearchEntry>) list));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Uni<SearchEntry> resolveEntryPosters(SearchEntry entry) {
|
private Uni<ContentSearchEntry> resolveEntryPosters(ContentSearchEntry entry) {
|
||||||
return posterUrlValidator.resolvePosters(entry.posterURLs())
|
return posterUrlValidator.resolvePosters(entry.posterURLs())
|
||||||
.map(entry::withPosterURLs)
|
.map(entry::withPosterURLs)
|
||||||
.onFailure().recoverWithItem(entry);
|
.onFailure().recoverWithItem(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SearchResponse convertSimple(KodikResponse response) {
|
private SearchEntries convertSimple(KodikResponse response) {
|
||||||
return normalizeUrls(responseMapper.toSearchResponse(response));
|
return normalizeUrls(responseMapper.toSearchEntries(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
private SearchResponse normalizeUrls(SearchResponse response) {
|
private SearchEntries normalizeUrls(SearchEntries response) {
|
||||||
var normalizedResults = response.result().stream()
|
var normalizedResults = response.result().stream()
|
||||||
.map(r -> r.withPosterURLs(r.posterURLs().stream()
|
.map(r -> r.withPosterURLs(r.posterURLs().stream()
|
||||||
.map(posterUrlNormalizer::normalize)
|
.map(posterUrlNormalizer::normalize)
|
||||||
|
|||||||
Reference in New Issue
Block a user