Skip to content

Commit

Permalink
merge: apple bug 임시조치
Browse files Browse the repository at this point in the history
Fix/#132 apple bug fix
  • Loading branch information
hong-sile authored Aug 30, 2024
2 parents 87fe368 + ca94f57 commit f5c0d41
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/main/java/play/pluv/PluvApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync;

@SpringBootApplication
@EnableJpaAuditing(dateTimeProviderRef = "localDateTimeProvider")
@ConfigurationPropertiesScan
@EnableAsync
public class PluvApplication {

public static void main(String[] args) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/play/pluv/oauth/apple/AppleApiClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package play.pluv.oauth.apple;

import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED_VALUE;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -11,7 +12,6 @@
import org.springframework.web.service.annotation.PostExchange;
import play.pluv.oauth.apple.dto.AppleAddMusicRequest;
import play.pluv.oauth.apple.dto.AppleCreatePlayListRequest;
import play.pluv.oauth.apple.dto.AppleCreatePlayListResponse;
import play.pluv.oauth.apple.dto.AppleMusicSongs;
import play.pluv.oauth.apple.dto.ApplePlayListMusicResponses;
import play.pluv.oauth.apple.dto.ApplePlayListResponses;
Expand Down Expand Up @@ -48,8 +48,8 @@ AppleMusicSongs searchMusicByIsrc(
@RequestParam("filter[isrc]") final String isrc
);

@PostExchange(url = "https://api.music.apple.com/v1/me/library/playlists")
AppleCreatePlayListResponse createPlayList(
@PostExchange(url = "https://api.music.apple.com/v1/me/library/playlists", contentType = APPLICATION_JSON_VALUE)
String createPlayList(
@RequestHeader("Authorization") final String developerToken,
@RequestHeader("Music-User-Token") final String musicUserToken,
@RequestBody final AppleCreatePlayListRequest request
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/play/pluv/oauth/apple/AppleConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import play.pluv.music.domain.MusicId;
import play.pluv.oauth.apple.dto.AppleAddMusicRequest;
import play.pluv.oauth.apple.dto.AppleCreatePlayListRequest;
import play.pluv.oauth.apple.dto.ApplePlayListResponses;
import play.pluv.oauth.apple.dto.AppleTokenResponse;
import play.pluv.oauth.application.SocialLoginClient;
import play.pluv.oauth.domain.OAuthMemberInfo;
Expand Down Expand Up @@ -106,8 +107,15 @@ public List<PlayListMusic> getMusics(final String playListId, final String music
@Override
public PlayListId createPlayList(final String musicUserToken, final String name) {
final AppleCreatePlayListRequest request = AppleCreatePlayListRequest.from(name);
return appleApiClient.createPlayList(developerAuthorization, musicUserToken, request)
.getId();
appleApiClient.createPlayList(developerAuthorization, musicUserToken, request);
try {
Thread.sleep(1000 * 90);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
final ApplePlayListResponses playLists = appleApiClient.getPlayList(developerAuthorization,
musicUserToken);
return playLists.recentPlayListIds();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package play.pluv.oauth.apple.dto;

import static java.util.Comparator.comparing;
import static play.pluv.playlist.domain.MusicStreaming.APPLE;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import play.pluv.playlist.domain.PlayList;
Expand All @@ -11,6 +13,14 @@ public record ApplePlayListResponses(
List<ApplePlayListResponse> data
) {

public PlayListId recentPlayListIds() {
return data.stream()
.sorted(comparing(ApplePlayListResponse::recentUpdatedDate).reversed())
.limit(1)
.map(ApplePlayListResponse::toPlayList)
.toList().get(0).getPlayListId();
}

public List<PlayList> toPlayLists() {
return data.stream()
.map(ApplePlayListResponse::toPlayList)
Expand All @@ -21,6 +31,10 @@ private record ApplePlayListResponse(
String id, PlayListAttributes attributes
) {

private LocalDateTime recentUpdatedDate() {
return attributes.lastModifiedDate();
}

private PlayList toPlayList() {
return PlayList.builder()
.playListId(new PlayListId(id, APPLE))
Expand All @@ -30,7 +44,7 @@ private PlayList toPlayList() {
}

private record PlayListAttributes(
Artwork artwork, String name
Artwork artwork, String name, LocalDateTime lastModifiedDate
) {

public String artworkUrl() {
Expand Down

0 comments on commit f5c0d41

Please sign in to comment.