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