Fix MB API deserialization: primary-type and secondary-types are strings not objects
This commit is contained in:
@@ -1,30 +1,25 @@
|
||||
package com.discdrop.client.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.util.List;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ReleaseGroupBrowseResponse(
|
||||
List<ReleaseGroup> releaseGroups,
|
||||
int releaseGroupCount
|
||||
@JsonProperty("release-groups") List<ReleaseGroup> releaseGroups,
|
||||
@JsonProperty("release-group-count") int releaseGroupCount
|
||||
) {
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ReleaseGroup(
|
||||
String id,
|
||||
String title,
|
||||
String firstReleaseDate,
|
||||
PrimaryType primaryType,
|
||||
List<SecondaryType> secondaryTypes,
|
||||
List<ArtistCredit> artistCredit
|
||||
@JsonProperty("first-release-date") String firstReleaseDate,
|
||||
@JsonProperty("primary-type") String primaryType,
|
||||
@JsonProperty("secondary-types") List<String> secondaryTypes,
|
||||
@JsonProperty("artist-credit") List<ArtistCredit> artistCredit
|
||||
) {
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record PrimaryType(String id, String name) {}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record SecondaryType(String id, String name) {}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ArtistCredit(Artist artist) {
|
||||
public record ArtistCredit(@JsonProperty("artist") Artist artist) {
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record Artist(String id, String name) {}
|
||||
}
|
||||
|
||||
@@ -43,15 +43,14 @@ public class ReleaseGroupService {
|
||||
total = Math.min(page.releaseGroupCount(), MAX_RELEASE_GROUPS);
|
||||
|
||||
for (var rg : page.releaseGroups()) {
|
||||
String primaryType = rg.primaryType() != null ? rg.primaryType().name() : "Other";
|
||||
String primaryType = rg.primaryType() != null ? rg.primaryType() : "Other";
|
||||
|
||||
if (!monitoredTypes.contains(primaryType)) continue;
|
||||
|
||||
String secondaryTypes = "[]";
|
||||
if (rg.secondaryTypes() != null && !rg.secondaryTypes().isEmpty()) {
|
||||
try {
|
||||
secondaryTypes = json.writeValueAsString(
|
||||
rg.secondaryTypes().stream().map(s -> s.name()).toList());
|
||||
secondaryTypes = json.writeValueAsString(rg.secondaryTypes());
|
||||
} catch (Exception e) {
|
||||
secondaryTypes = "[]";
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.discdrop.service.ReleaseGroupService;
|
||||
import io.quarkus.qute.Location;
|
||||
import io.quarkus.qute.Template;
|
||||
import io.quarkus.qute.TemplateInstance;
|
||||
import io.vertx.core.Vertx;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
@@ -29,9 +28,6 @@ public class ArtistController {
|
||||
@Inject
|
||||
FeedService feedService;
|
||||
|
||||
@Inject
|
||||
Vertx vertx;
|
||||
|
||||
@Inject
|
||||
@Location("fragments/search-results")
|
||||
Template searchResultsTemplate;
|
||||
@@ -63,15 +59,11 @@ public class ArtistController {
|
||||
public Response trackArtist(@PathParam("mbid") String mbid) {
|
||||
var artist = artistService.addArtist(mbid);
|
||||
var types = getMonitoredTypes(artist);
|
||||
vertx.executeBlocking(promise -> {
|
||||
releaseGroupService.fetchAndCache(artist.mbid(), artist.name(), types);
|
||||
promise.complete();
|
||||
});
|
||||
releaseGroupService.fetchAndCache(artist.mbid(), artist.name(), types);
|
||||
var allArtists = artistService.findAll();
|
||||
var listHtml = artistListTemplate.data("artists", allArtists).render();
|
||||
var emptySearch = searchResultsTemplate.data("artists", List.of()).render();
|
||||
var combined = emptySearch + listHtml;
|
||||
return Response.ok(combined).build();
|
||||
return Response.ok(emptySearch + listHtml).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
|
||||
Reference in New Issue
Block a user