Skip to content

Commit 9d1dc08

Browse files
authored
Merge pull request #150 from dnd-side-project/refactor/first-sprint
fix(Cd, Song): CD z-index๊ฐ’ ์ถ”๊ฐ€, Song ์ˆœ์„œ orderIndex ์ถ”๊ฐ€
2 parents 08eda6e + 7700ca1 commit 9d1dc08

36 files changed

+147
-106
lines changed

โ€Žapi-server/src/main/java/com/example/demo/domain/songs/dto/SongResponseDto.javaโ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ public record SongResponseDto(
66
String youtubeUrl,
77
String youtubeTitle,
88
String youtubeThumbnail,
9-
Long youtubeLength // ์ดˆ ๋‹จ์œ„
9+
Long youtubeLength, // ์ดˆ ๋‹จ์œ„
10+
Long orderIndex
1011
) {}

โ€Žapi-server/src/main/java/com/example/demo/domain/songs/dto/YouTubeVideoInfoDto.javaโ€Ž

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@ public record YouTubeVideoInfoDto(
1717
@Schema(description = "์˜์ƒ ๊ธธ์ด (MM:SS)", example = "03:21")
1818
String duration,
1919

20+
@Schema(description = "๊ณก ์ˆœ์„œ", example = "1")
21+
Long orderIndex,
22+
2023
@Schema(description = "์œ ํšจํ•œ ์˜์ƒ ์—ฌ๋ถ€", example = "true")
2124
boolean valid
25+
26+
2227
) {
23-
public static YouTubeVideoInfoDto valid(String link, String title, String thumbnailUrl, String duration) {
24-
return new YouTubeVideoInfoDto(link, title, thumbnailUrl, SongMapper.formatDuration(duration), true);
28+
public static YouTubeVideoInfoDto valid(String link, String title, String thumbnailUrl, Long orderIndex, String duration) {
29+
return new YouTubeVideoInfoDto(link, title, thumbnailUrl, SongMapper.formatDuration(duration),orderIndex,true);
2530
}
2631

2732
public static YouTubeVideoInfoDto invalid(String link) {
28-
return new YouTubeVideoInfoDto(link, null, null, null, false);
33+
return new YouTubeVideoInfoDto(link, null, null, null, null, false);
2934
}
3035
}
3136

โ€Žapi-server/src/main/java/com/example/demo/domain/songs/entity/Song.javaโ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public class Song {
3232

3333
@Column("youtube_length")
3434
private Long youtubeLength; // ์ดˆ ๋‹จ์œ„
35+
36+
@Column("order_index")
37+
private Long orderIndex;
3538
}
3639

3740

โ€Žapi-server/src/main/java/com/example/demo/domain/songs/service/YouTubeSongService.javaโ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package com.example.demo.domain.songs.service;
22

3-
import com.example.demo.domain.songs.dto.SongResponseDto;
43
import com.example.demo.domain.songs.dto.YouTubeVideoInfoDto;
54

65
import java.util.List;
76
import reactor.core.publisher.Flux;
8-
import reactor.core.publisher.Mono;
97

108
public interface YouTubeSongService {
119

โ€Žapi-server/src/main/java/com/example/demo/domain/songs/service/YouTubeSongServiceImpl.javaโ€Ž

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.*;
1313
import java.util.function.Function;
1414
import java.util.stream.Collectors;
15+
import java.util.stream.IntStream;
1516

1617
@Service
1718
@RequiredArgsConstructor
@@ -35,12 +36,15 @@ public Flux<YouTubeVideoInfoDto> fetchYouTubeInfo(List<String> links) {
3536
.flatMapMany(response -> {
3637
Map<String, YouTubeVideoResponse.Item> itemMap = fetchVideoItemMap(response.items());
3738

38-
List<YouTubeVideoInfoDto> result = links.stream()
39-
.map(link -> {
40-
String videoId = linkToVideoId.get(link);
41-
return mapToDto(link, videoId, itemMap);
42-
})
43-
.toList();
39+
List<YouTubeVideoInfoDto> result =
40+
IntStream.range(0, links.size())
41+
.mapToObj(i -> {
42+
String link = links.get(i);
43+
Long orderIndex = (long) (i + 1); // ์š”์ฒญ ์ˆœ์„œ(1-based)
44+
String videoId = linkToVideoId.get(link);
45+
return mapToDto(link, videoId, itemMap, orderIndex);
46+
})
47+
.toList();
4448

4549
return Flux.fromIterable(result);
4650
});
@@ -76,7 +80,10 @@ private Map<String, YouTubeVideoResponse.Item> fetchVideoItemMap(List<YouTubeVid
7680
/**
7781
* ๋งํฌ์™€ videoId, itemMap์„ ๋ฐ”ํƒ•์œผ๋กœ Dto ๋ณ€ํ™˜
7882
*/
79-
private YouTubeVideoInfoDto mapToDto(String link, String videoId, Map<String, YouTubeVideoResponse.Item> itemMap) {
83+
private YouTubeVideoInfoDto mapToDto(String link,
84+
String videoId,
85+
Map<String, YouTubeVideoResponse.Item> itemMap,
86+
Long orderIndex) {
8087
if (videoId == null || !itemMap.containsKey(videoId)) {
8188
return YouTubeVideoInfoDto.invalid(link);
8289
}
@@ -87,6 +94,7 @@ private YouTubeVideoInfoDto mapToDto(String link, String videoId, Map<String, Yo
8794
link,
8895
item.snippet().title(),
8996
item.snippet().thumbnails().high().url(),
97+
orderIndex,
9098
item.contentDetails().duration()
9199
);
92100
}

โ€Žmain-server/src/main/java/com/example/demo/domain/cd/controller/CdController.javaโ€Ž

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.example.demo.domain.cd.controller;
22

3-
import com.example.demo.domain.cd.dto.request.GetCdListRequestDto;
4-
import com.example.demo.domain.cd.dto.request.SaveCdRequestDto;
5-
import com.example.demo.domain.cd.dto.response.CdListResponseDto;
6-
import com.example.demo.domain.cd.dto.response.CdResponse;
3+
import com.example.demo.domain.cd.dto.request.GetCdListRequest;
4+
import com.example.demo.domain.cd.dto.request.SaveCdRequest;
5+
import com.example.demo.domain.cd.dto.response.CdListResponse;
6+
import com.example.demo.domain.cd.dto.response.GetCdResponse;
77
import com.example.demo.domain.cd.service.CdService;
88
import io.swagger.v3.oas.annotations.Operation;
99
import io.swagger.v3.oas.annotations.media.Content;
@@ -32,12 +32,12 @@ public class CdController {
3232
@ApiResponse(
3333
responseCode = "200",
3434
content = @Content(
35-
schema = @Schema(implementation = CdResponse.class)
35+
schema = @Schema(implementation = GetCdResponse.class)
3636
)
3737
)
3838
}
3939
)
40-
public ResponseEntity<CdResponse> getSingleCd (@PathVariable("playlistId") Long playListId) {
40+
public ResponseEntity<GetCdResponse> getSingleCd (@PathVariable("playlistId") Long playListId) {
4141
return ResponseEntity.ok().body(cdService.getCdByPlaylistId(playListId));
4242
}
4343

@@ -49,13 +49,13 @@ public ResponseEntity<CdResponse> getSingleCd (@PathVariable("playlistId") Long
4949
@ApiResponse(
5050
responseCode = "200",
5151
content = @Content(
52-
schema = @Schema(implementation = CdListResponseDto.class)
52+
schema = @Schema(implementation = CdListResponse.class)
5353
)
5454
)
5555
}
5656
)
57-
public ResponseEntity<CdListResponseDto> getCdList (@RequestBody GetCdListRequestDto getCdListRequestDto) {
58-
List<Long> playListIdList = getCdListRequestDto.playlistIds();
57+
public ResponseEntity<CdListResponse> getCdList (@RequestBody GetCdListRequest getCdListRequest) {
58+
List<Long> playListIdList = getCdListRequest.playlistIds();
5959
return ResponseEntity.ok().body(cdService.getAllCdByPlaylistIdList(playListIdList));
6060
}
6161

@@ -67,7 +67,7 @@ public ResponseEntity<CdListResponseDto> getCdList (@RequestBody GetCdListReques
6767
description = "playlistId, cdItems",
6868
required = true,
6969
content = @Content(
70-
schema = @Schema(implementation = SaveCdRequestDto.class)
70+
schema = @Schema(implementation = SaveCdRequest.class)
7171
)
7272
),
7373

@@ -80,8 +80,8 @@ public ResponseEntity<CdListResponseDto> getCdList (@RequestBody GetCdListReques
8080
)
8181
}
8282
)
83-
public ResponseEntity<String> saveCd (@PathVariable("playlistId") Long playlistId, @RequestBody SaveCdRequestDto saveCdRequestDto) {
84-
cdService.saveCdItemList(playlistId, saveCdRequestDto.cdItems());
83+
public ResponseEntity<String> saveCd (@PathVariable("playlistId") Long playlistId, @RequestBody SaveCdRequest saveCdRequest) {
84+
cdService.saveCdItemList(playlistId, saveCdRequest.cdItems());
8585
return ResponseEntity.ok().body("CD๊ฐ€ ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค");
8686
}
8787

@@ -98,8 +98,8 @@ public ResponseEntity<String> saveCd (@PathVariable("playlistId") Long playlistI
9898
)
9999
}
100100
)
101-
public ResponseEntity<String> replaceCd (@PathVariable("playlistId") Long playlistId, @RequestBody SaveCdRequestDto saveCdRequestDto) {
102-
cdService.replaceCdItemList(playlistId,saveCdRequestDto.cdItems());
101+
public ResponseEntity<String> replaceCd (@PathVariable("playlistId") Long playlistId, @RequestBody SaveCdRequest saveCdRequest) {
102+
cdService.replaceCdItemList(playlistId, saveCdRequest.cdItems());
103103
return ResponseEntity.ok().body("CD๊ฐ€ ์ˆ˜์ •๋˜์—ˆ์Šต๋‹ˆ๋‹ค");
104104
}
105105
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.example.demo.domain.cd.dto.request;
22

33
public record CdItemRequest(Long propId,
4-
Long xCoordinate, Long yCoordinate, Long height, Long width, Long scale, Long angle) {
4+
Long xCoordinate, Long yCoordinate, Long zCoordinate, Long height, Long width, Long scale, Long angle) {
55
}

main-server/src/main/java/com/example/demo/domain/cd/dto/request/GetCdListRequestDto.java renamed to main-server/src/main/java/com/example/demo/domain/cd/dto/request/GetCdListRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
import java.util.List;
44

5-
public record GetCdListRequestDto(List<Long> playlistIds) {
5+
public record GetCdListRequest(List<Long> playlistIds) {
66
}

main-server/src/main/java/com/example/demo/domain/cd/dto/request/SaveCdRequestDto.java renamed to main-server/src/main/java/com/example/demo/domain/cd/dto/request/SaveCdRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
import java.util.List;
44

5-
public record SaveCdRequestDto (List<CdItemRequest> cdItems){
5+
public record SaveCdRequest(List<CdItemRequest> cdItems){
66
}

โ€Žmain-server/src/main/java/com/example/demo/domain/cd/dto/response/CdItemResponse.javaโ€Ž

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.List;
1010

1111
@Builder
12-
@Schema(description = "CD ์•„์ดํ…œ ์ •๋ณด (๋Œ€ํ‘œ CD ํ•˜๋‚˜)")
12+
@Schema(description = "CD ์•„์ดํ…œ ์ •๋ณด")
1313
public record CdItemResponse(
1414

1515
@Schema(description = "CD ์•„์ดํ…œ ID", example = "301")
@@ -27,6 +27,9 @@ public record CdItemResponse(
2727
@Schema(description = "Y ์ขŒํ‘œ", example = "20")
2828
Long yCoordinate,
2929

30+
@Schema(description = "Z ์ขŒํ‘œ", example = "20")
31+
Long zCoordinate,
32+
3033
@Schema(description = "Height", example = "5")
3134
Long height,
3235

@@ -49,6 +52,7 @@ public static CdItemResponse from(CdItemView v, String imageUrl) {
4952
v.getTheme(),
5053
v.getXCoordinate(),
5154
v.getYCoordinate(),
55+
v.getZCoordinate(),
5256
v.getHeight(),
5357
v.getWidth(),
5458
v.getScale(),

0 commit comments

Comments
ย (0)