Remove redundant DTO suffix

This commit is contained in:
2026-03-22 01:31:47 +05:00
parent f4374d5d59
commit b132924f6b
10 changed files with 44 additions and 32 deletions

View File

@@ -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.SearchEntryDTO; import com.backend.unifier.title.model.SearchEntry;
import com.backend.unifier.title.model.SearchResponseDTO; import com.backend.unifier.title.model.SearchResponse;
@Mapper @Mapper
public interface KodikResponseMapper { public interface KodikResponseMapper {
default SearchResponseDTO toSearchResponseDTO(KodikResponse kodikResponse) { default SearchResponse toSearchResponse(KodikResponse kodikResponse) {
if (kodikResponse == null || kodikResponse.results == null) { 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) .map(this::toSearchEntryDTO)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.collect(Collectors.toList()); .collect(Collectors.toList());
return new SearchResponseDTO(entries); return new SearchResponse(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")
SearchEntryDTO toSearchEntryDTO(KodikResponse.Result result); SearchEntry toSearchEntryDTO(KodikResponse.Result result);
@Named("extractPosterUrls") @Named("extractPosterUrls")
default List<String> extractPosterUrls(MaterialData materialData) { default List<String> extractPosterUrls(MaterialData materialData) {

View File

@@ -1,4 +1,4 @@
package com.backend.unifier.title.model; package com.backend.unifier.title.model;
public record DetailEntryDTO() { public record DetailEntry() {
} }

View File

@@ -1,10 +1,12 @@
package com.backend.unifier.title.model; package com.backend.unifier.title.model;
import java.util.UUID;
public class IdentifierPointer { public class IdentifierPointer {
private String key; private UUID key;
private ContentIdentifier identifier; private ContentIdentifier identifier;
public IdentifierPointer(String key, ContentIdentifier identifier) { public IdentifierPointer(UUID key, ContentIdentifier identifier) {
this.key = key; this.key = key;
this.identifier = identifier; this.identifier = identifier;
} }
@@ -12,7 +14,7 @@ public class IdentifierPointer {
IdentifierPointer() { IdentifierPointer() {
} }
public String getKey() { public UUID getKey() {
return key; return key;
} }

View File

@@ -5,7 +5,7 @@ import java.util.List;
import io.soabase.recordbuilder.core.RecordBuilder; import io.soabase.recordbuilder.core.RecordBuilder;
@RecordBuilder @RecordBuilder
public record SearchEntryDTO( public record SearchEntry(
String id, String id,
List<String> posterURLs, List<String> posterURLs,
String title, String title,
@@ -15,5 +15,5 @@ public record SearchEntryDTO(
String type, String type,
String studio, String studio,
List<String> genres, List<String> genres,
int durationMin) implements SearchEntryDTOBuilder.With { int durationMin) implements SearchEntryBuilder.With {
} }

View File

@@ -5,6 +5,6 @@ import java.util.List;
import io.soabase.recordbuilder.core.RecordBuilder; import io.soabase.recordbuilder.core.RecordBuilder;
@RecordBuilder @RecordBuilder
public record SearchResponseDTO(List<SearchEntryDTO> result) implements SearchResponseDTOBuilder.With { public record SearchResponse(List<SearchEntry> result) implements SearchResponseBuilder.With {
} }

View File

@@ -1,6 +1,6 @@
package com.backend.unifier.title.resource; 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.GET;
import jakarta.ws.rs.Path; import jakarta.ws.rs.Path;
@@ -9,7 +9,7 @@ import jakarta.ws.rs.Path;
public class DetailResource { public class DetailResource {
@GET @GET
@Path("/detail") @Path("/detail")
public DetailEntryDTO detail(String id) { public DetailEntry detail(String id) {
return null; return null;
} }
} }

View File

@@ -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.SearchResponseDTO; import com.backend.unifier.title.model.SearchResponse;
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<SearchResponseDTO> search(@QueryParam("title") String title) { public Uni<SearchResponse> 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 SearchResponseDTO searchFast(@QueryParam("title") String title) { public SearchResponse 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 SearchResponseDTO list() { public SearchResponse list() {
var result = kodikSearchService.list(); var result = kodikSearchService.list();
return kodikConvertService.convert(result); return kodikConvertService.convert(result);
} }

View File

@@ -1,8 +1,18 @@
package com.backend.unifier.title.service; 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; import jakarta.enterprise.context.ApplicationScoped;
@ApplicationScoped @ApplicationScoped
public class IdentifierPointerService { public class IdentifierPointerService {
private ValueCommands<String, ContentIdentifier> countCommands;
public IdentifierPointerService(RedisDataSource ds) {
countCommands = ds.value(ContentIdentifier.class);
}
} }

View File

@@ -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.SearchEntryDTO; import com.backend.unifier.title.model.SearchEntry;
import com.backend.unifier.title.model.SearchResponseDTO; import com.backend.unifier.title.model.SearchResponse;
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 SearchResponseDTO convert(KodikResponse response) { public SearchResponse convert(KodikResponse response) {
return convertSimple(response); return convertSimple(response);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Uni<SearchResponseDTO> convertAsync(KodikResponse response) { public Uni<SearchResponse> convertAsync(KodikResponse response) {
if (response == null || response.results == null) { 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() .stream()
.map(this::resolveEntryPosters) .map(this::resolveEntryPosters)
.toList(); .toList();
if (entries.isEmpty()) { 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) 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()) return posterUrlValidator.resolvePosters(entry.posterURLs())
.map(entry::withPosterURLs) .map(entry::withPosterURLs)
.onFailure().recoverWithItem(entry); .onFailure().recoverWithItem(entry);
} }
private SearchResponseDTO convertSimple(KodikResponse response) { private SearchResponse convertSimple(KodikResponse response) {
return normalizeUrls(responseMapper.toSearchResponseDTO(response)); return normalizeUrls(responseMapper.toSearchResponse(response));
} }
private SearchResponseDTO normalizeUrls(SearchResponseDTO response) { private SearchResponse normalizeUrls(SearchResponse 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)