Skip to content

Commit

Permalink
created editorial methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yvasyliev committed Mar 2, 2024
1 parent 157c12c commit f0983fe
Show file tree
Hide file tree
Showing 23 changed files with 243 additions and 68 deletions.
24 changes: 0 additions & 24 deletions src/main/java/io/github/yvasyliev/deezer/DeezerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,6 @@ private static DeezerClient create(
RadioService radioService = asyncBuilder.target(RadioService.class, API_HOST);
SearchService searchService = asyncBuilder.target(SearchService.class, API_HOST);

pagingMethodFactories.put(Pattern.compile(EditorialService.EDITORIALS), pagingMethodFactory(
editorialService::getAllEditorials,
editorialService::getAllEditorialsAsync
));
pagingMethodFactories.put(Pattern.compile("/editorial/(\\d+)/releases"), pagingMethodFactory(
editorialService::getEditorialReleases,
editorialService::getEditorialReleasesAsync
));
pagingMethodFactories.put(Pattern.compile("/editorial/(\\d+)/selection"), pagingMethodFactory(
editorialService::getEditorialSelection,
editorialService::getEditorialSelectionAsync
));
pagingMethodFactories.put(Pattern.compile(GenreService.GENRES), pagingMethodFactory(
genreService::getAllGenres,
genreService::getAllGenresAsync
Expand Down Expand Up @@ -285,10 +273,6 @@ public Method<Chart> getChart(long chartId) {

// EDITORIAL METHODS

public PagingMethod<Editorial> getEditorial() {
return pagingMethod(editorialService::getAllEditorials, editorialService::getAllEditorialsAsync);
}

public Method<Editorial> getEditorial(long editorialId) {
return method(editorialService::getEditorial, editorialService::getEditorialAsync, editorialId);
}
Expand All @@ -297,14 +281,6 @@ public Method<Chart> getEditorialCharts(long editorialId) {
return method(editorialService::getEditorialCharts, editorialService::getEditorialChartsAsync, editorialId);
}

public PagingMethod<Album> getEditorialReleases(long editorialId) {
return pagingMethod(editorialService::getEditorialReleases, editorialService::getEditorialReleasesAsync, editorialId);
}

public PagingMethod<Album> getEditorialSelection(long editorialId) {
return pagingMethod(editorialService::getEditorialSelection, editorialService::getEditorialSelectionAsync, editorialId);
}

// GENRE METHODS

public Method<Genre> getGenre(long genreId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import io.github.yvasyliev.deezer.objects.Album;
import io.github.yvasyliev.deezer.objects.Chart;
import io.github.yvasyliev.deezer.objects.Editorial;
import io.github.yvasyliev.deezer.objects.Page;
import io.github.yvasyliev.deezer.v2.methods.PagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.Map;
import java.util.concurrent.CompletableFuture;
Expand All @@ -25,10 +26,10 @@ public interface EditorialService extends DeezerService {
CompletableFuture<Editorial> getEditorialAsync(@Param("editorialId") long editorialId);

@RequestLine(GET + EDITORIALS)
Page<Editorial> getAllEditorials(@QueryMap Map<String, Object> queryParams);
Page<Editorial, PagingMethod<Editorial>> getEditorials(@QueryMap Map<String, Object> queryParams);

@RequestLine(GET + EDITORIALS)
CompletableFuture<Page<Editorial>> getAllEditorialsAsync(@QueryMap Map<String, Object> queryParams);
CompletableFuture<Page<Editorial, PagingMethod<Editorial>>> getEditorialsAsync(@QueryMap Map<String, Object> queryParams);

@RequestLine(GET + EDITORIAL_CHARTS)
Chart getEditorialCharts(@Param("editorialId") long editorialId);
Expand All @@ -37,14 +38,14 @@ public interface EditorialService extends DeezerService {
CompletableFuture<Chart> getEditorialChartsAsync(@Param("editorialId") long editorialId);

@RequestLine(GET + EDITORIAL_RELEASES)
Page<Album> getEditorialReleases(@Param("editorialId") long editorialId, @QueryMap Map<String, Object> queryParams);
Page<Album, PagingMethod<Album>> getEditorialReleases(@Param("editorialId") long editorialId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + EDITORIAL_RELEASES)
CompletableFuture<Page<Album>> getEditorialReleasesAsync(@Param("editorialId") long editorialId, @QueryMap Map<String, Object> queryParams);
CompletableFuture<Page<Album, PagingMethod<Album>>> getEditorialReleasesAsync(@Param("editorialId") long editorialId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + EDITORIAL_SELECTION)
Page<Album> getEditorialSelection(@Param("editorialId") long editorialId, @QueryMap Map<String, Object> queryParams);
Page<Album, PagingMethod<Album>> getEditorialSelection(@Param("editorialId") long editorialId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + EDITORIAL_SELECTION)
CompletableFuture<Page<Album>> getEditorialSelectionAsync(@Param("editorialId") long editorialId, @QueryMap Map<String, Object> queryParams);
CompletableFuture<Page<Album, PagingMethod<Album>>> getEditorialSelectionAsync(@Param("editorialId") long editorialId, @QueryMap Map<String, Object> queryParams);
}
40 changes: 39 additions & 1 deletion src/main/java/io/github/yvasyliev/deezer/v2/DeezerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
import io.github.yvasyliev.deezer.objects.Album;
import io.github.yvasyliev.deezer.objects.Artist;
import io.github.yvasyliev.deezer.objects.Chart;
import io.github.yvasyliev.deezer.objects.Editorial;
import io.github.yvasyliev.deezer.objects.Playlist;
import io.github.yvasyliev.deezer.objects.Podcast;
import io.github.yvasyliev.deezer.objects.Track;
import io.github.yvasyliev.deezer.objects.User;
import io.github.yvasyliev.deezer.service.AlbumService;
import io.github.yvasyliev.deezer.service.ArtistService;
import io.github.yvasyliev.deezer.service.ChartService;
import io.github.yvasyliev.deezer.service.EditorialService;
import io.github.yvasyliev.deezer.service.SearchService;
import io.github.yvasyliev.deezer.v2.json.creators.AbstractPagingMethodCreator;
import io.github.yvasyliev.deezer.v2.json.creators.AdvancedSearchMethodCreator;
Expand Down Expand Up @@ -46,6 +48,11 @@
import io.github.yvasyliev.deezer.v2.methods.chart.GetChartPlaylists;
import io.github.yvasyliev.deezer.v2.methods.chart.GetChartPodcasts;
import io.github.yvasyliev.deezer.v2.methods.chart.GetChartTracks;
import io.github.yvasyliev.deezer.v2.methods.editorial.GetEditorial;
import io.github.yvasyliev.deezer.v2.methods.editorial.GetEditorialCharts;
import io.github.yvasyliev.deezer.v2.methods.editorial.GetEditorialReleases;
import io.github.yvasyliev.deezer.v2.methods.editorial.GetEditorialSelection;
import io.github.yvasyliev.deezer.v2.methods.editorial.GetEditorials;
import io.github.yvasyliev.deezer.v2.methods.search.AdvancedSearchAlbum;
import io.github.yvasyliev.deezer.v2.methods.chart.GetChartAlbums;
import io.github.yvasyliev.deezer.v2.methods.search.SearchAlbum;
Expand All @@ -66,6 +73,7 @@ public class DeezerClient {
private final AlbumService albumService;
private final ArtistService artistService;
private final ChartService chartService;
private final EditorialService editorialService;
private final SearchService searchService;

public static DeezerClient create() {
Expand All @@ -92,10 +100,14 @@ private static DeezerClient create(
pagingMethodDeserializer.put(Pattern.compile("/chart/(\\d+)/playlists"), GetChartPlaylists.class);
pagingMethodDeserializer.put(Pattern.compile("/chart/(\\d+)/podcasts"), GetChartPodcasts.class);
pagingMethodDeserializer.put(Pattern.compile("/chart/(\\d+)/tracks"), GetChartTracks.class);
pagingMethodDeserializer.put(Pattern.compile(EditorialService.EDITORIALS), GetEditorials.class);
pagingMethodDeserializer.put(Pattern.compile("/editorial/(\\d+)/releases"), GetEditorialReleases.class);
pagingMethodDeserializer.put(Pattern.compile("/editorial/(\\d+)/selection"), GetEditorialSelection.class);

AbstractPagingMethodCreator<AlbumService> albumPagingMethodCreator = new PagingMethodCreator<>();
AbstractPagingMethodCreator<ArtistService> artistPagingMethodCreator = new PagingMethodCreator<>();
AbstractPagingMethodCreator<ChartService> chartPagingMethodCreator = new PagingMethodCreator<>();
AbstractPagingMethodCreator<EditorialService> editorialPagingMethodCreator = new PagingMethodCreator<>();
AbstractPagingMethodCreator<SearchService> searchMethodCreator = new SearchMethodCreator();
AbstractPagingMethodCreator<SearchService> advancedSearchMethodCreator = new AdvancedSearchMethodCreator();

Expand Down Expand Up @@ -125,6 +137,9 @@ private static DeezerClient create(
.registerTypeAdapter(GetChartPlaylists.class, chartPagingMethodCreator)
.registerTypeAdapter(GetChartPodcasts.class, chartPagingMethodCreator)
.registerTypeAdapter(GetChartTracks.class, chartPagingMethodCreator)
.registerTypeAdapter(GetEditorials.class, editorialPagingMethodCreator)
.registerTypeAdapter(GetEditorialReleases.class, editorialPagingMethodCreator)
.registerTypeAdapter(GetEditorialSelection.class, editorialPagingMethodCreator)
.registerTypeAdapter(SearchAlbum.class, searchMethodCreator)
.registerTypeAdapter(AdvancedSearchAlbum.class, advancedSearchMethodCreator);

Expand All @@ -143,23 +158,26 @@ private static DeezerClient create(
AlbumService albumService = asyncFeignBuilder.target(AlbumService.class, API_HOST);
ArtistService artistService = asyncFeignBuilder.target(ArtistService.class, API_HOST);
ChartService chartService = asyncFeignBuilder.target(ChartService.class, API_HOST);
EditorialService editorialService = asyncFeignBuilder.target(EditorialService.class, API_HOST);
SearchService searchService = asyncFeignBuilder.target(SearchService.class, API_HOST);

Stream.of(
albumPagingMethodCreator,
artistPagingMethodCreator,
chartPagingMethodCreator,
editorialPagingMethodCreator,
searchMethodCreator,
advancedSearchMethodCreator
).forEach(deezerService -> deezerService.setGson(gson));

albumPagingMethodCreator.setDeezerService(albumService);
artistPagingMethodCreator.setDeezerService(artistService);
chartPagingMethodCreator.setDeezerService(chartService);
editorialPagingMethodCreator.setDeezerService(editorialService);
searchMethodCreator.setDeezerService(searchService);
advancedSearchMethodCreator.setDeezerService(searchService);

return new DeezerClient(gson, albumService, artistService, chartService, searchService);
return new DeezerClient(gson, albumService, artistService, chartService, editorialService, searchService);
}

public Method<Album> getAlbum(long albumId) {
Expand Down Expand Up @@ -231,6 +249,26 @@ public PagingMethod<Track> getChartTracks(long chartId) {
return new GetChartTracks(gson, chartService, chartId);
}

public Method<Editorial> getEditorial(long editorialId) {
return new GetEditorial(editorialService, editorialId);
}

public PagingMethod<Editorial> getEditorials() {
return new GetEditorials(gson, editorialService);
}

public Method<Chart> getEditorialCharts(long editorialId) {
return new GetEditorialCharts(editorialService, editorialId);
}

public PagingMethod<Album> getEditorialReleases(long editorialId) {
return new GetEditorialReleases(gson, editorialService, editorialId);
}

public PagingMethod<Album> getEditorialSelection(long editorialId) {
return new GetEditorialSelection(gson, editorialService, editorialId);
}

public SearchMethod<Album> searchAlbums(String q) {
return new SearchAlbum(gson, searchService, q);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.github.yvasyliev.deezer.v2.methods;

import com.google.gson.Gson;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import io.github.yvasyliev.deezer.objects.Pageable;
import io.github.yvasyliev.deezer.service.DeezerService;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
public abstract class ObjectServicePagingMethod<T extends Pageable, S extends DeezerService> extends ServicePagingMethod<T, S> {
@Expose(serialize = false)
@SerializedName(value = OBJECT_ID)
protected final long objectId;

public ObjectServicePagingMethod(Gson gson, S deezerService, long objectId) {
super(gson, deezerService);
this.objectId = objectId;
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
package io.github.yvasyliev.deezer.v2.methods;

import com.google.gson.Gson;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import io.github.yvasyliev.deezer.objects.Pageable;
import io.github.yvasyliev.deezer.service.DeezerService;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
public abstract class ServicePagingMethod<T extends Pageable, S extends DeezerService> extends PagingMethod<T> {
protected final S deezerService;

@Expose(serialize = false)
@SerializedName(value = OBJECT_ID)
protected final long objectId;

public ServicePagingMethod(Gson gson, S deezerService, long objectId) {
public ServicePagingMethod(Gson gson, S deezerService) {
super(gson);
this.deezerService = deezerService;
this.objectId = objectId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import io.github.yvasyliev.deezer.objects.User;
import io.github.yvasyliev.deezer.service.AlbumService;
import io.github.yvasyliev.deezer.v2.methods.PagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetAlbumFans extends ServicePagingMethod<User, AlbumService> {
public class GetAlbumFans extends ObjectServicePagingMethod<User, AlbumService> {
public GetAlbumFans(Gson gson, AlbumService albumService, long albumId) {
super(gson, albumService, albumId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import io.github.yvasyliev.deezer.objects.Track;
import io.github.yvasyliev.deezer.service.AlbumService;
import io.github.yvasyliev.deezer.v2.methods.PagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetAlbumTracks extends ServicePagingMethod<Track, AlbumService> {
public class GetAlbumTracks extends ObjectServicePagingMethod<Track, AlbumService> {
public GetAlbumTracks(Gson gson, AlbumService albumService, long albumId) {
super(gson, albumService, albumId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import io.github.yvasyliev.deezer.objects.Album;
import io.github.yvasyliev.deezer.service.ArtistService;
import io.github.yvasyliev.deezer.v2.methods.PagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetArtistAlbums extends ServicePagingMethod<Album, ArtistService> {
public class GetArtistAlbums extends ObjectServicePagingMethod<Album, ArtistService> {
public GetArtistAlbums(Gson gson, ArtistService artistService, long artistId) {
super(gson, artistService, artistId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import io.github.yvasyliev.deezer.objects.User;
import io.github.yvasyliev.deezer.service.ArtistService;
import io.github.yvasyliev.deezer.v2.methods.PagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetArtistFans extends ServicePagingMethod<User, ArtistService> {
public class GetArtistFans extends ObjectServicePagingMethod<User, ArtistService> {
public GetArtistFans(Gson gson, ArtistService artistService, long artistId) {
super(gson, artistService, artistId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import io.github.yvasyliev.deezer.objects.Playlist;
import io.github.yvasyliev.deezer.service.ArtistService;
import io.github.yvasyliev.deezer.v2.methods.PagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetArtistPlaylists extends ServicePagingMethod<Playlist, ArtistService> {
public class GetArtistPlaylists extends ObjectServicePagingMethod<Playlist, ArtistService> {
public GetArtistPlaylists(Gson gson, ArtistService artistService, long artistId) {
super(gson, artistService, artistId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import io.github.yvasyliev.deezer.objects.Track;
import io.github.yvasyliev.deezer.service.ArtistService;
import io.github.yvasyliev.deezer.v2.methods.PagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetArtistRadio extends ServicePagingMethod<Track, ArtistService> {
public class GetArtistRadio extends ObjectServicePagingMethod<Track, ArtistService> {
public GetArtistRadio(Gson gson, ArtistService artistService, long artistId) {
super(gson, artistService, artistId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import io.github.yvasyliev.deezer.objects.Artist;
import io.github.yvasyliev.deezer.service.ArtistService;
import io.github.yvasyliev.deezer.v2.methods.PagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetArtistRelated extends ServicePagingMethod<Artist, ArtistService> {
public class GetArtistRelated extends ObjectServicePagingMethod<Artist, ArtistService> {
public GetArtistRelated(Gson gson, ArtistService artistService, long artistId) {
super(gson, artistService, artistId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import io.github.yvasyliev.deezer.objects.Track;
import io.github.yvasyliev.deezer.service.ArtistService;
import io.github.yvasyliev.deezer.v2.methods.PagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetArtistTop extends ServicePagingMethod<Track, ArtistService> {
public class GetArtistTop extends ObjectServicePagingMethod<Track, ArtistService> {
public GetArtistTop(Gson gson, ArtistService artistService, long artistId) {
super(gson, artistService, artistId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import io.github.yvasyliev.deezer.objects.Album;
import io.github.yvasyliev.deezer.service.ChartService;
import io.github.yvasyliev.deezer.v2.methods.PagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetChartAlbums extends ServicePagingMethod<Album, ChartService> {
public class GetChartAlbums extends ObjectServicePagingMethod<Album, ChartService> {
public GetChartAlbums(Gson gson, ChartService chartService, long chartId) {
super(gson, chartService, chartId);
}
Expand Down
Loading

0 comments on commit f0983fe

Please sign in to comment.