Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#68 음악 히스토리 추가 #72

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/main/java/play/pluv/history/application/HistoryUpdater.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package play.pluv.history.application;

import java.util.List;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import play.pluv.history.domain.History;
import play.pluv.history.domain.repository.HistoryRepository;
import play.pluv.member.domain.Member;
import play.pluv.music.domain.DestinationMusic;
import play.pluv.playlist.domain.PlayListMusic;

@Component
public class HistoryUpdater {

private final HistoryRepository historyRepository;

public HistoryUpdater(final HistoryRepository historyRepository) {
this.historyRepository = historyRepository;
}

@Transactional
public Long createHistory(
final String title, final String thumbNailUrl, final Member member,
final List<PlayListMusic> cantTransferredMusics, final int canTransferSongCount
) {
final History history = History.builder()
.transferFailSongCount(cantTransferredMusics.size())
.thumbNailUrl(thumbNailUrl)
.memberId(member.getId())
.transferredSongCount(canTransferSongCount)
.title(title)
.build();

final History savedHistory = historyRepository.save(history);

return savedHistory.getId();
}

public void appendTransferredMusics(
final Long historyId, final List<DestinationMusic> transferredMusics
) {

}
}
44 changes: 44 additions & 0 deletions src/main/java/play/pluv/history/domain/History.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package play.pluv.history.domain;

import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import play.pluv.base.BaseEntity;

@Entity
@NoArgsConstructor(access = PROTECTED)
@Getter
public class History extends BaseEntity {

@Id
@GeneratedValue(strategy = IDENTITY)
private Long id;

private String title;

private String thumbNailUrl;

private int transferredSongCount;

private int transferFailSongCount;

private Long memberId;

@Builder
public History(
final String title, final String thumbNailUrl, final int transferredSongCount,
final int transferFailSongCount, final Long memberId
) {
this.title = title;
this.thumbNailUrl = thumbNailUrl;
this.transferredSongCount = transferredSongCount;
this.transferFailSongCount = transferFailSongCount;
this.memberId = memberId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package play.pluv.history.domain.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import play.pluv.history.domain.History;

public interface HistoryRepository extends JpaRepository<History, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import play.pluv.member.domain.Member;
import play.pluv.music.domain.MusicStreaming;
import play.pluv.playlist.domain.MusicStreaming;
import play.pluv.oauth.application.SocialLoginClientComposite;
import play.pluv.oauth.domain.OAuthMemberInfo;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/play/pluv/login/controller/LoginController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package play.pluv.login.controller;

import static play.pluv.music.domain.MusicStreaming.SPOTIFY;
import static play.pluv.music.domain.MusicStreaming.YOUTUBE;
import static play.pluv.playlist.domain.MusicStreaming.SPOTIFY;
import static play.pluv.playlist.domain.MusicStreaming.YOUTUBE;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Optional;
import play.pluv.music.domain.DestinationMusic;
import play.pluv.music.domain.MusicId;
import play.pluv.music.domain.MusicStreaming;
import play.pluv.playlist.domain.MusicStreaming;
import play.pluv.music.domain.SourceMusic;

public interface MusicExplorer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import org.springframework.stereotype.Component;
import play.pluv.music.domain.DestinationMusic;
import play.pluv.music.domain.MusicId;
import play.pluv.music.domain.MusicStreaming;
import play.pluv.music.domain.SourceMusic;
import play.pluv.music.exception.MusicException;
import play.pluv.playlist.domain.MusicStreaming;

@Component
public class MusicExplorerComposite {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import play.pluv.music.application.dto.MusicSearchResponse;
import play.pluv.music.domain.DestinationMusic;
import play.pluv.music.domain.MusicId;
import play.pluv.music.domain.MusicStreaming;
import play.pluv.playlist.domain.MusicStreaming;
import play.pluv.music.domain.SourceMusic;

@Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;
import play.pluv.music.domain.MusicId;
import play.pluv.music.domain.MusicStreaming;
import play.pluv.playlist.domain.MusicStreaming;

public record MusicAddRequest(
String playListName,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/play/pluv/music/controller/MusicController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package play.pluv.music.controller;

import static play.pluv.music.domain.MusicStreaming.SPOTIFY;
import static play.pluv.music.domain.MusicStreaming.YOUTUBE;
import static play.pluv.playlist.domain.MusicStreaming.SPOTIFY;
import static play.pluv.playlist.domain.MusicStreaming.YOUTUBE;

import java.util.List;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/play/pluv/music/domain/MusicId.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package play.pluv.music.domain;

import play.pluv.playlist.domain.MusicStreaming;

public record MusicId(
MusicStreaming musicStreaming,
String id
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/play/pluv/music/domain/SourceMusic.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SourceMusic {
//Nullable
private final String isrcCode;

public Optional<String> getIsrcCode(){
public Optional<String> getIsrcCode() {
return Optional.ofNullable(isrcCode);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package play.pluv.oauth.application;

import play.pluv.music.domain.MusicStreaming;
import play.pluv.playlist.domain.MusicStreaming;
import play.pluv.oauth.domain.OAuthMemberInfo;

public interface SocialLoginClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.Optional;
import java.util.Set;
import org.springframework.stereotype.Component;
import play.pluv.music.domain.MusicStreaming;
import play.pluv.playlist.domain.MusicStreaming;
import play.pluv.oauth.domain.OAuthMemberInfo;
import play.pluv.oauth.exception.OAuthException;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/play/pluv/oauth/domain/OAuthMemberInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import jakarta.persistence.Embeddable;
import jakarta.persistence.Enumerated;
import play.pluv.music.domain.MusicStreaming;
import play.pluv.playlist.domain.MusicStreaming;

@Embeddable
public record OAuthMemberInfo(
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/play/pluv/oauth/google/GoogleConnector.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package play.pluv.oauth.google;

import static play.pluv.music.domain.MusicStreaming.YOUTUBE;
import static play.pluv.playlist.domain.MusicStreaming.YOUTUBE;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -13,7 +13,7 @@
import play.pluv.music.application.MusicExplorer;
import play.pluv.music.domain.DestinationMusic;
import play.pluv.music.domain.MusicId;
import play.pluv.music.domain.MusicStreaming;
import play.pluv.playlist.domain.MusicStreaming;
import play.pluv.music.domain.SourceMusic;
import play.pluv.oauth.application.SocialLoginClient;
import play.pluv.oauth.domain.OAuthMemberInfo;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package play.pluv.oauth.google.dto;

import static play.pluv.music.domain.MusicStreaming.YOUTUBE;
import static play.pluv.playlist.domain.MusicStreaming.YOUTUBE;

import play.pluv.oauth.domain.OAuthMemberInfo;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package play.pluv.oauth.google.dto;

import static play.pluv.music.domain.MusicStreaming.YOUTUBE;
import static play.pluv.playlist.domain.MusicStreaming.YOUTUBE;

import play.pluv.playlist.domain.PlayListId;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package play.pluv.oauth.google.dto;

import static play.pluv.music.domain.MusicStreaming.YOUTUBE;
import static play.pluv.playlist.domain.MusicStreaming.YOUTUBE;

import java.util.List;
import play.pluv.playlist.domain.PlayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package play.pluv.oauth.google.dto;

import static play.pluv.music.domain.MusicStreaming.YOUTUBE;
import static play.pluv.playlist.domain.MusicStreaming.YOUTUBE;

import java.util.List;
import java.util.Optional;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/play/pluv/oauth/spotify/SpotifyApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ SpotifyCreatePlayListResponse createPlayList(
@RequestBody final SpotifyCreatePlayListRequest request
);

//최대 100개까지만 한 번에 가능 //추후 webflux로 바꾸기
//최대 100개까지만 한 번에 가능
//추후 webflux로 바꾸기
@PostExchange(url = "https://api.spotify.com/v1/playlists/{playListId}/tracks")
void addMusics(
@RequestHeader("Authorization") final String accessToken,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/play/pluv/oauth/spotify/SpotifyConnector.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package play.pluv.oauth.spotify;

import static java.lang.String.format;
import static play.pluv.music.domain.MusicStreaming.SPOTIFY;
import static play.pluv.playlist.domain.MusicStreaming.SPOTIFY;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -14,7 +14,6 @@
import play.pluv.music.application.MusicExplorer;
import play.pluv.music.domain.DestinationMusic;
import play.pluv.music.domain.MusicId;
import play.pluv.music.domain.MusicStreaming;
import play.pluv.music.domain.SourceMusic;
import play.pluv.oauth.application.SocialLoginClient;
import play.pluv.oauth.domain.OAuthMemberInfo;
Expand All @@ -24,6 +23,7 @@
import play.pluv.oauth.spotify.dto.SpotifyPlayListResponses;
import play.pluv.oauth.spotify.dto.SpotifyUserResponse;
import play.pluv.playlist.application.PlayListConnector;
import play.pluv.playlist.domain.MusicStreaming;
import play.pluv.playlist.domain.PlayList;
import play.pluv.playlist.domain.PlayListId;
import play.pluv.playlist.domain.PlayListMusic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package play.pluv.oauth.spotify.dto;

import static play.pluv.music.domain.MusicStreaming.SPOTIFY;
import static play.pluv.playlist.domain.MusicStreaming.SPOTIFY;

import java.util.List;
import play.pluv.playlist.domain.PlayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package play.pluv.oauth.spotify.dto;

import static play.pluv.music.domain.MusicStreaming.SPOTIFY;
import static play.pluv.playlist.domain.MusicStreaming.SPOTIFY;

import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package play.pluv.oauth.spotify.dto;

import static play.pluv.music.domain.MusicStreaming.SPOTIFY;
import static play.pluv.playlist.domain.MusicStreaming.SPOTIFY;

import play.pluv.oauth.domain.OAuthMemberInfo;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package play.pluv.playlist.application;

import java.util.List;
import play.pluv.music.domain.MusicStreaming;
import play.pluv.playlist.domain.MusicStreaming;
import play.pluv.playlist.domain.PlayList;
import play.pluv.playlist.domain.PlayListId;
import play.pluv.playlist.domain.PlayListMusic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.Optional;
import java.util.Set;
import org.springframework.stereotype.Component;
import play.pluv.music.domain.MusicStreaming;
import play.pluv.playlist.domain.MusicStreaming;
import play.pluv.playlist.domain.PlayList;
import play.pluv.playlist.domain.PlayListMusic;
import play.pluv.playlist.exception.PlayListException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import play.pluv.music.domain.MusicStreaming;
import play.pluv.playlist.domain.MusicStreaming;
import play.pluv.playlist.domain.PlayList;
import play.pluv.playlist.domain.PlayListMusic;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package play.pluv.playlist.controller;

import static play.pluv.music.domain.MusicStreaming.SPOTIFY;
import static play.pluv.music.domain.MusicStreaming.YOUTUBE;
import static play.pluv.playlist.domain.MusicStreaming.SPOTIFY;
import static play.pluv.playlist.domain.MusicStreaming.YOUTUBE;

import java.util.List;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package play.pluv.music.domain;
package play.pluv.playlist.domain;

import static play.pluv.music.exception.MusicExceptionType.MUSIC_STREAMING_NOT_FOUND;
import static play.pluv.playlist.exception.PlayListExceptionType.PLAYLIST_PROVIDER_NOT_FOUND;

import java.util.Arrays;
import lombok.Getter;
import play.pluv.music.exception.MusicException;
import play.pluv.playlist.exception.PlayListException;

@Getter
public enum MusicStreaming {
Expand All @@ -23,6 +23,6 @@ public static MusicStreaming from(final String name) {
return Arrays.stream(values())
.filter(streaming -> streaming.getName().equals(name))
.findAny()
.orElseThrow(() -> new MusicException(MUSIC_STREAMING_NOT_FOUND));
.orElseThrow(() -> new PlayListException(PLAYLIST_PROVIDER_NOT_FOUND));
}
}
2 changes: 0 additions & 2 deletions src/main/java/play/pluv/playlist/domain/PlayListId.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package play.pluv.playlist.domain;

import play.pluv.music.domain.MusicStreaming;

public record PlayListId(
String id,
MusicStreaming musicStreaming
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/play/pluv/api/LoginApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static play.pluv.music.domain.MusicStreaming.SPOTIFY;
import static play.pluv.music.domain.MusicStreaming.YOUTUBE;
import static play.pluv.playlist.domain.MusicStreaming.SPOTIFY;
import static play.pluv.playlist.domain.MusicStreaming.YOUTUBE;

import org.junit.jupiter.api.Test;
import play.pluv.login.application.dto.GoogleLoginRequest;
Expand Down
Loading
Loading