Skip to content

Commit

Permalink
renamed classes, created UserService
Browse files Browse the repository at this point in the history
  • Loading branch information
yvasyliev committed Jun 14, 2024
1 parent 3ed796b commit 93b5a07
Show file tree
Hide file tree
Showing 45 changed files with 203 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public interface DeezerService {
String GET = "GET ";
String POST = "POST ";
}
114 changes: 114 additions & 0 deletions src/main/java/io/github/yvasyliev/deezer/service/UserService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package io.github.yvasyliev.deezer.service;

import api.deezer.objects.GetPermissionsResponse;
import feign.Param;
import feign.QueryMap;
import feign.RequestLine;
import io.github.yvasyliev.deezer.objects.Album;
import io.github.yvasyliev.deezer.objects.Artist;
import io.github.yvasyliev.deezer.objects.Playlist;
import io.github.yvasyliev.deezer.objects.Track;
import io.github.yvasyliev.deezer.objects.User;
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;

public interface UserService extends DeezerService {
String USER = "/user/{userId}";
String USER_ALBUMS = "/user/{userId}/albums";
String USER_ARTISTS = "/user/{userId}/artist";
String USER_CHART = "/user/{userId}/charts";
String USER_ALBUM_CHART = "/user/{userId}/charts/albums";
String USER_ARTIST_CHART = "/user/{userId}/charts/artists";
String USER_PLAYLIST_CHART = "/user/{userId}/charts/playlists";
String USER_TRACK_CHART = "/user/{userId}/charts/tracks";
String USER_FLOW = "/user/{userId}/flow";
String USER_FOLLOWINGS = "/user/{userId}/followings";
String USER_FOLLOWERS = "/user/{userId}/followers";
String USER_HISTORY = "/user/{userId}/history";
String USER_NOTIFICATIONS = "/user/{userId}/notifications";
String USER_PERMISSIONS = "/user/{userId}/permissions";

@RequestLine(GET + USER)
User getUser(@Param("userId") long userId);

@RequestLine(GET + USER)
CompletableFuture<User> getUserAsync(@Param("userId") long userId);

@RequestLine(GET + USER_ALBUMS)
Page<Album, PagingMethod<Album>> getUserAlbums(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_ALBUMS)
CompletableFuture<Page<Album, PagingMethod<Album>>> getUserAlbumsAsync(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_ARTISTS)
Page<Artist, PagingMethod<Artist>> getUserArtists(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_ARTISTS)
CompletableFuture<Page<Artist, PagingMethod<Artist>>> getUserArtistsAsync(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_CHART)
Page<Track, PagingMethod<Track>> getUserCharts(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_CHART)
CompletableFuture<Page<Track, PagingMethod<Track>>> getUserChartsAsync(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_ALBUM_CHART)
Page<Album, PagingMethod<Album>> getUserAlbumChart(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_ALBUM_CHART)
CompletableFuture<Page<Album, PagingMethod<Album>>> getUserAlbumChartAsync(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_ARTIST_CHART)
Page<Artist, PagingMethod<Artist>> getUserArtistChart(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_PLAYLIST_CHART)
Page<Playlist, PagingMethod<Playlist>> getUserPlaylistChart(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_PLAYLIST_CHART)
CompletableFuture<Page<Playlist, PagingMethod<Playlist>>> getUserPlaylistChartAsync(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_TRACK_CHART)
Page<Track, PagingMethod<Track>> getUserTrackChart(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_TRACK_CHART)
CompletableFuture<Page<Track, PagingMethod<Track>>> getUserTracksChartAsync(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_FLOW)
Page<Track, PagingMethod<Track>> getUserFlow(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_FLOW)
CompletableFuture<Page<Track, PagingMethod<Track>>> getUserFlowAsync(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_FOLLOWINGS)
Page<User, PagingMethod<User>> getUserFollowings(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_FOLLOWINGS)
CompletableFuture<Page<User, PagingMethod<User>>> getUserFollowingsAsync(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_FOLLOWERS)
Page<User, PagingMethod<User>> getUserFollowers(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_FOLLOWERS)
CompletableFuture<Page<User, PagingMethod<User>>> getUserFollowersAsync(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_HISTORY)
Page<Track, PagingMethod<Track>> getUserHistory(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_HISTORY)
CompletableFuture<Page<Track, PagingMethod<Track>>> getUserHistoryAsync(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(POST + USER_NOTIFICATIONS)
Boolean sendUserNotification(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(POST + USER_NOTIFICATIONS)
CompletableFuture<Boolean> sendUserNotificationAsync(@Param("userId") long userId, @QueryMap Map<String, Object> queryParams);

@RequestLine(GET + USER_PERMISSIONS)
GetPermissionsResponse getUserPermissions(@Param("userId") long userId);

@RequestLine(GET + USER_PERMISSIONS)
CompletableFuture<GetPermissionsResponse> getUserPermissionsAsync(@Param("userId") long userId);
}
9 changes: 5 additions & 4 deletions src/main/java/io/github/yvasyliev/deezer/v2/DeezerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializer;
import com.google.gson.ToNumberPolicy;
import feign.AsyncFeign;
import feign.Logger;
Expand Down Expand Up @@ -35,7 +36,6 @@
import io.github.yvasyliev.deezer.v2.json.creators.AdvancedSearchMethodCreator;
import io.github.yvasyliev.deezer.v2.json.creators.PagingMethodCreator;
import io.github.yvasyliev.deezer.v2.json.creators.SearchMethodCreator;
import io.github.yvasyliev.deezer.v2.json.deserializers.AbstractMethodDeserializer;
import io.github.yvasyliev.deezer.v2.json.deserializers.AdvancedSearchMethodDeserializer;
import io.github.yvasyliev.deezer.v2.json.deserializers.MethodDeserializer;
import io.github.yvasyliev.deezer.v2.logger.DeezerLogger;
Expand Down Expand Up @@ -100,13 +100,15 @@
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Setter;

import java.time.Duration;
import java.time.LocalDate;
import java.util.function.Function;
import java.util.stream.Stream;

@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Setter
public class DeezerClient {
private static final String API_HOST = "https://api.deezer.com";
private final Gson gson;
Expand Down Expand Up @@ -137,8 +139,7 @@ private static DeezerClient create(
Function<AsyncFeign.AsyncBuilder<Object>, AsyncFeign.AsyncBuilder<Object>> asyncFeignBuilderCreator,
String accessToken
) {

AbstractMethodDeserializer<Method<?>> methodDeserializer = MethodDeserializer
JsonDeserializer<Method<?>> methodDeserializer = MethodDeserializer
.builder()
.classMap("/album/(\\d+)/fans", GetAlbumFans.class)
.classMap("/album/(\\d+)/tracks", GetAlbumTracks.class)
Expand Down Expand Up @@ -177,7 +178,7 @@ private static DeezerClient create(
.classMap(SearchService.SEARCH_USER, SearchUser.class)
.build();

AbstractMethodDeserializer<AdvancedSearchMethod<?>> advancedSearchMethodDeserializer = AdvancedSearchMethodDeserializer
JsonDeserializer<AdvancedSearchMethod<?>> advancedSearchMethodDeserializer = AdvancedSearchMethodDeserializer
.builder()
.classMap(SearchService.SEARCH, AdvancedSearch.class)
.classMap(SearchService.SEARCH_ALBUM, AdvancedSearchAlbum.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
public abstract class ObjectServiceMethod<T, S extends DeezerService> extends ServiceMethod<T, S> {
public abstract class AbstractObjectServiceMethod<T, S extends DeezerService> extends AbstractServiceMethod<T, S> {
@Expose
@SerializedName(value = OBJECT_ID)
protected final long objectId;

public ObjectServiceMethod(S deezerService, long objectId) {
public AbstractObjectServiceMethod(S deezerService, long objectId) {
super(deezerService);
this.objectId = objectId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import lombok.EqualsAndHashCode;

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

public ObjectServicePagingMethod(Gson gson, S deezerService, long objectId) {
public AbstractObjectServicePagingMethod(Gson gson, S deezerService, long objectId) {
super(gson, deezerService);
this.objectId = objectId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

@AllArgsConstructor
@EqualsAndHashCode
public abstract class ServiceMethod<T, S extends DeezerService> implements Method<T> {
public abstract class AbstractServiceMethod<T, S extends DeezerService> implements Method<T> {
protected final S deezerService;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import io.github.yvasyliev.deezer.objects.Pageable;
import io.github.yvasyliev.deezer.service.DeezerService;

public abstract class ServicePagingMethod<T extends Pageable, S extends DeezerService> extends PagingMethod<T> {
public abstract class AbstractServicePagingMethod<T extends Pageable, S extends DeezerService> extends PagingMethod<T> {
protected final S deezerService;

public ServicePagingMethod(Gson gson, S deezerService) {
public AbstractServicePagingMethod(Gson gson, S deezerService) {
super(gson);
this.deezerService = deezerService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import io.github.yvasyliev.deezer.objects.Album;
import io.github.yvasyliev.deezer.service.AlbumService;
import io.github.yvasyliev.deezer.v2.methods.ObjectServiceMethod;
import io.github.yvasyliev.deezer.v2.methods.AbstractObjectServiceMethod;

import java.util.concurrent.CompletableFuture;

public class GetAlbum extends ObjectServiceMethod<Album, AlbumService> {
public class GetAlbum extends AbstractObjectServiceMethod<Album, AlbumService> {
public GetAlbum(AlbumService albumService, long albumId) {
super(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.User;
import io.github.yvasyliev.deezer.service.AlbumService;
import io.github.yvasyliev.deezer.v2.methods.PagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.AbstractObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetAlbumFans extends ObjectServicePagingMethod<User, AlbumService> {
public class GetAlbumFans extends AbstractObjectServicePagingMethod<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.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.AbstractObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetAlbumTracks extends ObjectServicePagingMethod<Track, AlbumService> {
public class GetAlbumTracks extends AbstractObjectServicePagingMethod<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 @@ -2,11 +2,11 @@

import io.github.yvasyliev.deezer.objects.Artist;
import io.github.yvasyliev.deezer.service.ArtistService;
import io.github.yvasyliev.deezer.v2.methods.ObjectServiceMethod;
import io.github.yvasyliev.deezer.v2.methods.AbstractObjectServiceMethod;

import java.util.concurrent.CompletableFuture;

public class GetArtist extends ObjectServiceMethod<Artist, ArtistService> {
public class GetArtist extends AbstractObjectServiceMethod<Artist, ArtistService> {
public GetArtist(ArtistService artistService, long artistId) {
super(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.ArtistService;
import io.github.yvasyliev.deezer.v2.methods.PagingMethod;
import io.github.yvasyliev.deezer.v2.methods.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.AbstractObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetArtistAlbums extends ObjectServicePagingMethod<Album, ArtistService> {
public class GetArtistAlbums extends AbstractObjectServicePagingMethod<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.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.AbstractObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetArtistFans extends ObjectServicePagingMethod<User, ArtistService> {
public class GetArtistFans extends AbstractObjectServicePagingMethod<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.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.AbstractObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetArtistPlaylists extends ObjectServicePagingMethod<Playlist, ArtistService> {
public class GetArtistPlaylists extends AbstractObjectServicePagingMethod<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.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.AbstractObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetArtistRadio extends ObjectServicePagingMethod<Track, ArtistService> {
public class GetArtistRadio extends AbstractObjectServicePagingMethod<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.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.AbstractObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetArtistRelated extends ObjectServicePagingMethod<Artist, ArtistService> {
public class GetArtistRelated extends AbstractObjectServicePagingMethod<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.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.AbstractObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

public class GetArtistTop extends ObjectServicePagingMethod<Track, ArtistService> {
public class GetArtistTop extends AbstractObjectServicePagingMethod<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 @@ -2,11 +2,11 @@

import io.github.yvasyliev.deezer.objects.Chart;
import io.github.yvasyliev.deezer.service.ChartService;
import io.github.yvasyliev.deezer.v2.methods.ServiceMethod;
import io.github.yvasyliev.deezer.v2.methods.AbstractServiceMethod;

import java.util.concurrent.CompletableFuture;

public class GetChart extends ServiceMethod<Chart, ChartService> {
public class GetChart extends AbstractServiceMethod<Chart, ChartService> {
public GetChart(ChartService chartService) {
super(chartService);
}
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.ObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.methods.AbstractObjectServicePagingMethod;
import io.github.yvasyliev.deezer.v2.objects.Page;

import java.util.concurrent.CompletableFuture;

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

0 comments on commit 93b5a07

Please sign in to comment.