-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/#101 히스토리 조회
- Loading branch information
Showing
18 changed files
with
708 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/play/pluv/history/application/HistoryReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package play.pluv.history.application; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import play.pluv.history.domain.History; | ||
import play.pluv.history.domain.TransferFailMusic; | ||
import play.pluv.history.domain.TransferredMusic; | ||
import play.pluv.history.domain.repository.HistoryRepository; | ||
import play.pluv.history.domain.repository.TransferFailMusicRepository; | ||
import play.pluv.history.domain.repository.TransferredMusicRepository; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class HistoryReader { | ||
|
||
private final HistoryRepository historyRepository; | ||
private final TransferredMusicRepository transferredMusicRepository; | ||
private final TransferFailMusicRepository transferFailMusicRepository; | ||
|
||
public List<History> readByMemberId(final Long memberId) { | ||
return historyRepository.findByMemberId(memberId); | ||
} | ||
|
||
public History readById(final Long historyId) { | ||
return historyRepository.readById(historyId); | ||
} | ||
|
||
public List<TransferredMusic> readTransferredMusics(final Long historyId) { | ||
return transferredMusicRepository.findByHistoryId(historyId); | ||
} | ||
|
||
public List<TransferFailMusic> readTransferFailMusics(final Long historyId) { | ||
return transferFailMusicRepository.findByHistoryId(historyId); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/play/pluv/history/application/HistoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package play.pluv.history.application; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import play.pluv.history.domain.History; | ||
import play.pluv.history.domain.TransferFailMusic; | ||
import play.pluv.history.domain.TransferredMusic; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class HistoryService { | ||
|
||
private final HistoryReader historyReader; | ||
|
||
@Transactional(readOnly = true) | ||
public List<History> findHistories(final Long memberId) { | ||
return historyReader.readByMemberId(memberId); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public History findHistory(final Long historyId, final Long memberId) { | ||
final History history = historyReader.readById(historyId); | ||
history.validateOwner(memberId); | ||
return history; | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<TransferFailMusic> findTransferFailMusics(final Long historyId, final Long memberId) { | ||
return historyReader.readTransferFailMusics(historyId); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<TransferredMusic> findTransferredMusics(final Long historyId, final Long memberId) { | ||
return historyReader.readTransferredMusics(historyId); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/play/pluv/history/application/dto/HistoryDetailResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package play.pluv.history.application.dto; | ||
|
||
import play.pluv.history.domain.History; | ||
|
||
public record HistoryDetailResponse( | ||
Long id, | ||
Integer totalSongCount, | ||
Integer transferredSongCount, | ||
String title, | ||
String imageUrl, | ||
String source, | ||
String destination | ||
) { | ||
|
||
public static HistoryDetailResponse from(final History history) { | ||
return new HistoryDetailResponse( | ||
history.getId(), | ||
history.getTotalSongCount(), | ||
history.getTransferredSongCount(), | ||
history.getTitle(), | ||
history.getThumbNailUrl(), | ||
history.getSource().getName(), | ||
history.getDestination().getName() | ||
); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/play/pluv/history/application/dto/HistoryListResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package play.pluv.history.application.dto; | ||
|
||
import static java.util.Comparator.comparing; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import play.pluv.history.domain.History; | ||
|
||
public record HistoryListResponse( | ||
Long id, | ||
Integer transferredSongCount, | ||
LocalDate transferredDate, | ||
String title, | ||
String imageUrl | ||
) { | ||
|
||
public static List<HistoryListResponse> createList(final List<History> histories) { | ||
return histories.stream() | ||
.map(HistoryListResponse::from) | ||
.sorted(comparing(HistoryListResponse::transferredDate).reversed()) | ||
.toList(); | ||
} | ||
|
||
private static HistoryListResponse from(final History history) { | ||
return new HistoryListResponse( | ||
history.getId(), history.getTransferredSongCount(), history.getCreatedAt().toLocalDate(), | ||
history.getTitle(), history.getThumbNailUrl() | ||
); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/play/pluv/history/application/dto/HistoryMusicResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package play.pluv.history.application.dto; | ||
|
||
import java.util.List; | ||
import play.pluv.history.domain.TransferFailMusic; | ||
import play.pluv.history.domain.TransferredMusic; | ||
|
||
public record HistoryMusicResponse( | ||
String title, | ||
String imageUrl, | ||
String artistNames | ||
) { | ||
|
||
public static HistoryMusicResponse from(final TransferredMusic transferredMusic) { | ||
return new HistoryMusicResponse( | ||
transferredMusic.getTitle(), transferredMusic.getImageUrl(), | ||
transferredMusic.getArtistNames() | ||
); | ||
} | ||
|
||
public static HistoryMusicResponse from(final TransferFailMusic transferFailMusic) { | ||
return new HistoryMusicResponse( | ||
transferFailMusic.getTitle(), transferFailMusic.getImageUrl(), | ||
transferFailMusic.getArtistNames() | ||
); | ||
} | ||
|
||
public static List<HistoryMusicResponse> createListFromTransferFail( | ||
final List<TransferFailMusic> transferFailMusics | ||
) { | ||
return transferFailMusics.stream() | ||
.map(HistoryMusicResponse::from) | ||
.toList(); | ||
} | ||
|
||
public static List<HistoryMusicResponse> createListFromTransferred( | ||
final List<TransferredMusic> transferredMusics | ||
) { | ||
return transferredMusics.stream() | ||
.map(HistoryMusicResponse::from) | ||
.toList(); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/play/pluv/history/controller/HistoryController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package play.pluv.history.controller; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import play.pluv.base.BaseResponse; | ||
import play.pluv.history.application.HistoryService; | ||
import play.pluv.history.application.dto.HistoryDetailResponse; | ||
import play.pluv.history.application.dto.HistoryListResponse; | ||
import play.pluv.history.application.dto.HistoryMusicResponse; | ||
import play.pluv.security.JwtMemberId; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class HistoryController { | ||
|
||
private final HistoryService historyService; | ||
|
||
@GetMapping("/history/me") | ||
public BaseResponse<List<HistoryListResponse>> getHistories(final JwtMemberId jwtMemberId) { | ||
final var histories = historyService.findHistories(jwtMemberId.memberId()); | ||
final List<HistoryListResponse> historyListResponses = HistoryListResponse | ||
.createList(histories); | ||
return BaseResponse.ok(historyListResponses); | ||
} | ||
|
||
@GetMapping("/history/{id}") | ||
public BaseResponse<HistoryDetailResponse> getHistory( | ||
final JwtMemberId jwtMemberId, @PathVariable final Long id | ||
) { | ||
final var history = historyService.findHistory(id, jwtMemberId.memberId()); | ||
final HistoryDetailResponse response = HistoryDetailResponse.from(history); | ||
return BaseResponse.ok(response); | ||
} | ||
|
||
@GetMapping("/history/{id}/music/fail") | ||
public BaseResponse<List<HistoryMusicResponse>> getTransferFailMusics( | ||
final JwtMemberId jwtMemberId, @PathVariable final Long id | ||
) { | ||
final var transferFailMusics = historyService.findTransferFailMusics( | ||
id, jwtMemberId.memberId() | ||
); | ||
final List<HistoryMusicResponse> responses = HistoryMusicResponse | ||
.createListFromTransferFail(transferFailMusics); | ||
return BaseResponse.ok(responses); | ||
} | ||
|
||
@GetMapping("/history/{id}/music/success") | ||
public BaseResponse<List<HistoryMusicResponse>> getTransferredMusics( | ||
final JwtMemberId jwtMemberId, @PathVariable final Long id | ||
) { | ||
final var transferredMusics = historyService.findTransferredMusics(id, jwtMemberId.memberId()); | ||
final List<HistoryMusicResponse> responses = HistoryMusicResponse | ||
.createListFromTransferred(transferredMusics); | ||
return BaseResponse.ok(responses); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.