Remove redundant DTO suffix
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.SearchEntryDTO;
|
||||
import com.backend.unifier.title.model.SearchResponseDTO;
|
||||
import com.backend.unifier.title.model.SearchEntry;
|
||||
import com.backend.unifier.title.model.SearchResponse;
|
||||
|
||||
@Mapper
|
||||
public interface KodikResponseMapper {
|
||||
default SearchResponseDTO toSearchResponseDTO(KodikResponse kodikResponse) {
|
||||
default SearchResponse toSearchResponse(KodikResponse kodikResponse) {
|
||||
if (kodikResponse == null || kodikResponse.results == null) {
|
||||
return new SearchResponseDTO(List.of());
|
||||
return new SearchResponse(List.of());
|
||||
}
|
||||
|
||||
List<SearchEntryDTO> entries = kodikResponse.results.stream()
|
||||
List<SearchEntry> entries = kodikResponse.results.stream()
|
||||
.map(this::toSearchEntryDTO)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new SearchResponseDTO(entries);
|
||||
return new SearchResponse(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")
|
||||
SearchEntryDTO toSearchEntryDTO(KodikResponse.Result result);
|
||||
SearchEntry toSearchEntryDTO(KodikResponse.Result result);
|
||||
|
||||
@Named("extractPosterUrls")
|
||||
default List<String> extractPosterUrls(MaterialData materialData) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.backend.unifier.title.model;
|
||||
|
||||
public record DetailEntryDTO() {
|
||||
public record DetailEntry() {
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.backend.unifier.title.model;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class IdentifierPointer {
|
||||
private String key;
|
||||
private UUID key;
|
||||
private ContentIdentifier identifier;
|
||||
|
||||
public IdentifierPointer(String key, ContentIdentifier identifier) {
|
||||
public IdentifierPointer(UUID key, ContentIdentifier identifier) {
|
||||
this.key = key;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
@@ -12,7 +14,7 @@ public class IdentifierPointer {
|
||||
IdentifierPointer() {
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
public UUID getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.List;
|
||||
import io.soabase.recordbuilder.core.RecordBuilder;
|
||||
|
||||
@RecordBuilder
|
||||
public record SearchEntryDTO(
|
||||
public record SearchEntry(
|
||||
String id,
|
||||
List<String> posterURLs,
|
||||
String title,
|
||||
@@ -15,5 +15,5 @@ public record SearchEntryDTO(
|
||||
String type,
|
||||
String studio,
|
||||
List<String> genres,
|
||||
int durationMin) implements SearchEntryDTOBuilder.With {
|
||||
int durationMin) implements SearchEntryBuilder.With {
|
||||
}
|
||||
@@ -5,6 +5,6 @@ import java.util.List;
|
||||
import io.soabase.recordbuilder.core.RecordBuilder;
|
||||
|
||||
@RecordBuilder
|
||||
public record SearchResponseDTO(List<SearchEntryDTO> result) implements SearchResponseDTOBuilder.With {
|
||||
public record SearchResponse(List<SearchEntry> result) implements SearchResponseBuilder.With {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.backend.unifier.title.resource;
|
||||
|
||||
import com.backend.unifier.title.model.DetailEntryDTO;
|
||||
import com.backend.unifier.title.model.DetailEntry;
|
||||
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
@@ -9,7 +9,7 @@ import jakarta.ws.rs.Path;
|
||||
public class DetailResource {
|
||||
@GET
|
||||
@Path("/detail")
|
||||
public DetailEntryDTO detail(String id) {
|
||||
public DetailEntry 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.SearchResponseDTO;
|
||||
import com.backend.unifier.title.model.SearchResponse;
|
||||
import com.backend.unifier.title.service.KodikResponseConvertService;
|
||||
|
||||
import io.smallrye.mutiny.Uni;
|
||||
@@ -24,7 +24,7 @@ public class SearchResource {
|
||||
|
||||
@GET
|
||||
@Path("/search")
|
||||
public Uni<SearchResponseDTO> search(@QueryParam("title") String title) {
|
||||
public Uni<SearchResponse> 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 SearchResponseDTO searchFast(@QueryParam("title") String title) {
|
||||
public SearchResponse searchFast(@QueryParam("title") String title) {
|
||||
var result = kodikSearchService.search(title);
|
||||
return kodikConvertService.convert(result);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/list")
|
||||
public SearchResponseDTO list() {
|
||||
public SearchResponse list() {
|
||||
var result = kodikSearchService.list();
|
||||
return kodikConvertService.convert(result);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
package com.backend.unifier.title.service;
|
||||
|
||||
import com.backend.unifier.title.model.ContentIdentifier;
|
||||
|
||||
import io.quarkus.redis.datasource.RedisDataSource;
|
||||
import io.quarkus.redis.datasource.value.ValueCommands;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
@ApplicationScoped
|
||||
public class IdentifierPointerService {
|
||||
private ValueCommands<String, ContentIdentifier> countCommands;
|
||||
|
||||
public IdentifierPointerService(RedisDataSource ds) {
|
||||
countCommands = ds.value(ContentIdentifier.class);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.SearchEntryDTO;
|
||||
import com.backend.unifier.title.model.SearchResponseDTO;
|
||||
import com.backend.unifier.title.model.SearchEntry;
|
||||
import com.backend.unifier.title.model.SearchResponse;
|
||||
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -24,40 +24,40 @@ public class KodikResponseConvertService {
|
||||
this.posterUrlNormalizer = posterUrlNormalizer;
|
||||
}
|
||||
|
||||
public SearchResponseDTO convert(KodikResponse response) {
|
||||
public SearchResponse convert(KodikResponse response) {
|
||||
return convertSimple(response);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Uni<SearchResponseDTO> convertAsync(KodikResponse response) {
|
||||
public Uni<SearchResponse> convertAsync(KodikResponse response) {
|
||||
if (response == null || response.results == null) {
|
||||
return Uni.createFrom().item(new SearchResponseDTO(List.of()));
|
||||
return Uni.createFrom().item(new SearchResponse(List.of()));
|
||||
}
|
||||
|
||||
List<Uni<SearchEntryDTO>> entries = convertSimple(response).result()
|
||||
List<Uni<SearchEntry>> entries = convertSimple(response).result()
|
||||
.stream()
|
||||
.map(this::resolveEntryPosters)
|
||||
.toList();
|
||||
|
||||
if (entries.isEmpty()) {
|
||||
return Uni.createFrom().item(new SearchResponseDTO(List.of()));
|
||||
return Uni.createFrom().item(new SearchResponse(List.of()));
|
||||
}
|
||||
|
||||
return Uni.combine().all().unis(entries)
|
||||
.with(list -> new SearchResponseDTO((List<SearchEntryDTO>) list));
|
||||
.with(list -> new SearchResponse((List<SearchEntry>) list));
|
||||
}
|
||||
|
||||
private Uni<SearchEntryDTO> resolveEntryPosters(SearchEntryDTO entry) {
|
||||
private Uni<SearchEntry> resolveEntryPosters(SearchEntry entry) {
|
||||
return posterUrlValidator.resolvePosters(entry.posterURLs())
|
||||
.map(entry::withPosterURLs)
|
||||
.onFailure().recoverWithItem(entry);
|
||||
}
|
||||
|
||||
private SearchResponseDTO convertSimple(KodikResponse response) {
|
||||
return normalizeUrls(responseMapper.toSearchResponseDTO(response));
|
||||
private SearchResponse convertSimple(KodikResponse response) {
|
||||
return normalizeUrls(responseMapper.toSearchResponse(response));
|
||||
}
|
||||
|
||||
private SearchResponseDTO normalizeUrls(SearchResponseDTO response) {
|
||||
private SearchResponse normalizeUrls(SearchResponse response) {
|
||||
var normalizedResults = response.result().stream()
|
||||
.map(r -> r.withPosterURLs(r.posterURLs().stream()
|
||||
.map(posterUrlNormalizer::normalize)
|
||||
|
||||
Reference in New Issue
Block a user