From 5bbbe0f975eef0e4f38070dd37a4efc27e65062d Mon Sep 17 00:00:00 2001 From: GoF9490 Date: Fri, 17 Mar 2023 21:29:59 +0900 Subject: [PATCH 1/9] feat : createPlaylist --- .../server/auth/config/WebSecurityConfig.java | 4 +- .../handler/OAuth2MemberSuccessHandler.java | 8 ++-- .../controller/PlaylistController.java | 30 ++++++++++++ .../playlist/dto/LikePlaylistResponseDto.java | 44 ------------------ .../playlist/dto/PlaylistCreateDto.java | 20 ++++++++ .../server/playlist/dto/PlaylistItemDto.java | 19 -------- .../playlist/dto/PlaylistItemResponseDto.java | 18 -------- .../server/playlist/dto/PlaylistPatchDto.java | 21 --------- .../server/playlist/dto/PlaylistPostDto.java | 22 --------- .../playlist/dto/PlaylistResponseDto.java | 46 +++++++++---------- .../dto/SimplePlaylistResponseDto.java | 32 ------------- .../main/server/playlist/entity/Playlist.java | 39 ++++++++++------ .../playlist/service/PlaylistService.java | 36 +++++++++++++++ .../main/server/song/dto/SongCreateDto.java | 18 ++++++++ .../main/server/song/dto/SongResponseDto.java | 28 +++++++++++ .../com/main/server/song/entity/Song.java | 31 ++++++++----- .../main/server/song/service/SongService.java | 14 ++++++ 17 files changed, 220 insertions(+), 210 deletions(-) create mode 100644 server/src/main/java/com/main/server/playlist/controller/PlaylistController.java delete mode 100644 server/src/main/java/com/main/server/playlist/dto/LikePlaylistResponseDto.java create mode 100644 server/src/main/java/com/main/server/playlist/dto/PlaylistCreateDto.java delete mode 100644 server/src/main/java/com/main/server/playlist/dto/PlaylistItemDto.java delete mode 100644 server/src/main/java/com/main/server/playlist/dto/PlaylistItemResponseDto.java delete mode 100644 server/src/main/java/com/main/server/playlist/dto/PlaylistPatchDto.java delete mode 100644 server/src/main/java/com/main/server/playlist/dto/PlaylistPostDto.java delete mode 100644 server/src/main/java/com/main/server/playlist/dto/SimplePlaylistResponseDto.java create mode 100644 server/src/main/java/com/main/server/playlist/service/PlaylistService.java create mode 100644 server/src/main/java/com/main/server/song/dto/SongCreateDto.java create mode 100644 server/src/main/java/com/main/server/song/dto/SongResponseDto.java create mode 100644 server/src/main/java/com/main/server/song/service/SongService.java diff --git a/server/src/main/java/com/main/server/auth/config/WebSecurityConfig.java b/server/src/main/java/com/main/server/auth/config/WebSecurityConfig.java index 51ee4e0..dc44936 100644 --- a/server/src/main/java/com/main/server/auth/config/WebSecurityConfig.java +++ b/server/src/main/java/com/main/server/auth/config/WebSecurityConfig.java @@ -71,10 +71,10 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { CorsConfigurationSource corsConfigurationSource() { CorsConfiguration config = new CorsConfiguration(); - config.setAllowedOrigins(Arrays.asList(domain)); + config.setAllowedOrigins(Arrays.asList("http://localhost:3000", "http://localhost:3001", "http://localhost:8080")); config.setAllowedMethods(Arrays.asList("*")); config.setAllowedHeaders(Arrays.asList("*")); -// config.setAllowCredentials(true); + config.setAllowCredentials(true); config.addExposedHeader("Authorization"); config.addExposedHeader("Refresh"); diff --git a/server/src/main/java/com/main/server/auth/handler/OAuth2MemberSuccessHandler.java b/server/src/main/java/com/main/server/auth/handler/OAuth2MemberSuccessHandler.java index 4da0bd4..9f86e09 100644 --- a/server/src/main/java/com/main/server/auth/handler/OAuth2MemberSuccessHandler.java +++ b/server/src/main/java/com/main/server/auth/handler/OAuth2MemberSuccessHandler.java @@ -64,10 +64,10 @@ private URI createURI(String accessToken, String refreshToken) { .newInstance() .scheme("http") .host("localhost") -// .port(8080) - .port(3000) -// .path("/receive-token.html") - .path("/") + .port(8080) +// .port(3000) + .path("/receive-token.html") +// .path("/") .queryParams(queryParams) .build() .toUri(); diff --git a/server/src/main/java/com/main/server/playlist/controller/PlaylistController.java b/server/src/main/java/com/main/server/playlist/controller/PlaylistController.java new file mode 100644 index 0000000..626ace1 --- /dev/null +++ b/server/src/main/java/com/main/server/playlist/controller/PlaylistController.java @@ -0,0 +1,30 @@ +package com.main.server.playlist.controller; + +import com.main.server.playlist.dto.PlaylistCreateDto; +import com.main.server.playlist.dto.PlaylistResponseDto; +import com.main.server.playlist.entity.Playlist; +import com.main.server.playlist.service.PlaylistService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/playlists") +public class PlaylistController { + + private final PlaylistService playlistService; + + @PostMapping + public ResponseEntity createPlaylist(@RequestBody PlaylistCreateDto dto, @AuthenticationPrincipal String email) { + Playlist playlist = playlistService.createPlaylist(dto, email); + + return ResponseEntity.status(HttpStatus.CREATED) + .body(PlaylistResponseDto.createByEntity(playlist)); + } +} diff --git a/server/src/main/java/com/main/server/playlist/dto/LikePlaylistResponseDto.java b/server/src/main/java/com/main/server/playlist/dto/LikePlaylistResponseDto.java deleted file mode 100644 index 0d98678..0000000 --- a/server/src/main/java/com/main/server/playlist/dto/LikePlaylistResponseDto.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.main.server.playlist.dto; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; - -import java.time.LocalDateTime; -import java.util.List; - -@AllArgsConstructor -@Getter -@Setter -@Builder -public class LikePlaylistResponseDto { - - private long playlistId; - - private long memberId; - - private String name; - - private String content; - - - private boolean status; // ? - - private String title; - - private int like; // 좋아요 갯수? - - private Boolean likeState; // 눌럿음? - - // private Boolean bookmarkState; - - private List playlistItems; - - // private List categoryList; - - private LocalDateTime createdAt; - - private LocalDateTime modifiedAt; -} - diff --git a/server/src/main/java/com/main/server/playlist/dto/PlaylistCreateDto.java b/server/src/main/java/com/main/server/playlist/dto/PlaylistCreateDto.java new file mode 100644 index 0000000..dbc6c22 --- /dev/null +++ b/server/src/main/java/com/main/server/playlist/dto/PlaylistCreateDto.java @@ -0,0 +1,20 @@ +package com.main.server.playlist.dto; + +import com.main.server.song.dto.SongCreateDto; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class PlaylistCreateDto { + + private String title; + + private String thumbnail; + + private List songList; +} diff --git a/server/src/main/java/com/main/server/playlist/dto/PlaylistItemDto.java b/server/src/main/java/com/main/server/playlist/dto/PlaylistItemDto.java deleted file mode 100644 index 1456a2e..0000000 --- a/server/src/main/java/com/main/server/playlist/dto/PlaylistItemDto.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.main.server.playlist.dto; - - -import lombok.Getter; -import lombok.Setter; - -import javax.validation.constraints.NotBlank; - -@Getter -@Setter -public class PlaylistItemDto { - - @NotBlank(message = "영상을 추가하세요.") - private String url; - private String channelTitle; - private String thumbnail; - private String title; - private String videoId; // 직접 설정 ? -} diff --git a/server/src/main/java/com/main/server/playlist/dto/PlaylistItemResponseDto.java b/server/src/main/java/com/main/server/playlist/dto/PlaylistItemResponseDto.java deleted file mode 100644 index 4997b1d..0000000 --- a/server/src/main/java/com/main/server/playlist/dto/PlaylistItemResponseDto.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.main.server.playlist.dto; - - - -import lombok.Builder; -import lombok.Data; -import lombok.Getter; -import lombok.Setter; - -@Builder -@Getter -public class PlaylistItemResponseDto { - private String channelTitle; - private String thumbnail; - private String title; - private String url; - private String videoId; -} diff --git a/server/src/main/java/com/main/server/playlist/dto/PlaylistPatchDto.java b/server/src/main/java/com/main/server/playlist/dto/PlaylistPatchDto.java deleted file mode 100644 index a04e3f6..0000000 --- a/server/src/main/java/com/main/server/playlist/dto/PlaylistPatchDto.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.main.server.playlist.dto; - -import lombok.Getter; -import lombok.Setter; - -import java.util.List; - -@Getter -@Setter -public class PlaylistPatchDto { - private long playlistId; - - private String title; - - private List playlistItems; - - private List categoryList; - - private boolean status; // ? - -} \ No newline at end of file diff --git a/server/src/main/java/com/main/server/playlist/dto/PlaylistPostDto.java b/server/src/main/java/com/main/server/playlist/dto/PlaylistPostDto.java deleted file mode 100644 index 964e201..0000000 --- a/server/src/main/java/com/main/server/playlist/dto/PlaylistPostDto.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.main.server.playlist.dto; - -import lombok.Getter; -import lombok.Setter; - -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import java.util.List; - -@Getter -@Setter -public class PlaylistPostDto { - - @NotBlank(message = "제목을 입력하세요.") - private String title; - - private List playlistItems; - - private List categoryList; - - private boolean status; // ? -} \ No newline at end of file diff --git a/server/src/main/java/com/main/server/playlist/dto/PlaylistResponseDto.java b/server/src/main/java/com/main/server/playlist/dto/PlaylistResponseDto.java index 1d54e4f..369c65f 100644 --- a/server/src/main/java/com/main/server/playlist/dto/PlaylistResponseDto.java +++ b/server/src/main/java/com/main/server/playlist/dto/PlaylistResponseDto.java @@ -1,39 +1,39 @@ package com.main.server.playlist.dto; - +import com.main.server.playlist.entity.Playlist; +import com.main.server.song.dto.SongResponseDto; +import lombok.AccessLevel; import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; -import java.time.LocalDateTime; import java.util.List; +import java.util.stream.Collectors; -@AllArgsConstructor -@Getter -@Setter -@Builder +@Data +@AllArgsConstructor(access = AccessLevel.PRIVATE) public class PlaylistResponseDto { - private long playlistId; - - private long memberId; - - private String name; - private String content; - - private boolean status; + private Long playlistId; private String title; - private int like; - - private List playlistItems; + private String author; - private List categoryList; + private String thumbnail; - private LocalDateTime createdAt; + private List songList; - private LocalDateTime modifiedAt; + private Integer songCount; + public static PlaylistResponseDto createByEntity(Playlist playlist) { + return new PlaylistResponseDto( + playlist.getPlaylistId(), + playlist.getTitle(), + playlist.getMember().getNickname(), + playlist.getThumbnail(), + playlist.getSongs().stream() + .map(SongResponseDto::createByEntity) + .collect(Collectors.toList()), + playlist.getSongs().size()); + } } diff --git a/server/src/main/java/com/main/server/playlist/dto/SimplePlaylistResponseDto.java b/server/src/main/java/com/main/server/playlist/dto/SimplePlaylistResponseDto.java deleted file mode 100644 index 58ec0dd..0000000 --- a/server/src/main/java/com/main/server/playlist/dto/SimplePlaylistResponseDto.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.main.server.playlist.dto; - - - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; - -import java.time.LocalDateTime; -import java.util.List; - -@AllArgsConstructor -@Getter -@Setter -@Builder -public class SimplePlaylistResponseDto { - private long playlistId; - - private String title; - - private List playlistItems; - - private boolean status; - - private List categoryList; - - private LocalDateTime createdAt; - - private LocalDateTime modifiedAt; - -} \ No newline at end of file diff --git a/server/src/main/java/com/main/server/playlist/entity/Playlist.java b/server/src/main/java/com/main/server/playlist/entity/Playlist.java index de2e1f9..2fa899d 100644 --- a/server/src/main/java/com/main/server/playlist/entity/Playlist.java +++ b/server/src/main/java/com/main/server/playlist/entity/Playlist.java @@ -5,19 +5,18 @@ import com.main.server.comment.entity.Comment; import com.main.server.like.entity.Like; import com.main.server.member.entity.Member; +import com.main.server.playlist.dto.PlaylistCreateDto; import com.main.server.song.entity.Song; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import javax.persistence.*; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; @Entity @Getter -@Setter -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class Playlist extends Auditable { @Id @@ -26,26 +25,40 @@ public class Playlist extends Auditable { @Column(length = 100,nullable = false) private String title; - //length @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "MEMBER_ID") private Member member; + private String thumbnail; - @OneToMany(mappedBy = "playlist") - private List comments = new ArrayList<>(); - - @OneToMany(mappedBy = "playlist") + @OneToMany(mappedBy = "playlist", cascade = CascadeType.ALL) private List songs = new ArrayList<>(); - @OneToMany(mappedBy = "playlist") - private List likes = new ArrayList<>(); + public static Playlist createByDto(PlaylistCreateDto dto, Member member) { + return new Playlist( + dto.getTitle(), + member, + dto.getThumbnail()); + } + + public Playlist addSongs(List adds) { + adds.stream() + .map(song -> song.setPlaylist(this)) + .collect(Collectors.toList()); + List editSongs = new ArrayList<>(this.songs); + editSongs.addAll(adds); + this.songs = editSongs; + return this; + } - public Playlist(String title, Member member) { + private Playlist(String title, + Member member, + String thumbnail) { this.title = title; this.member = member; + this.thumbnail = thumbnail; } } diff --git a/server/src/main/java/com/main/server/playlist/service/PlaylistService.java b/server/src/main/java/com/main/server/playlist/service/PlaylistService.java new file mode 100644 index 0000000..f020100 --- /dev/null +++ b/server/src/main/java/com/main/server/playlist/service/PlaylistService.java @@ -0,0 +1,36 @@ +package com.main.server.playlist.service; + +import com.main.server.member.service.MemberService; +import com.main.server.playlist.dto.PlaylistCreateDto; +import com.main.server.playlist.entity.Playlist; +import com.main.server.playlist.repository.PlaylistRepository; +import com.main.server.song.entity.Song; +import com.main.server.song.service.SongService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@Transactional +@RequiredArgsConstructor +public class PlaylistService { + + private final PlaylistRepository playlistRepository; + private final SongService songService; + private final MemberService memberService; + + public Playlist createPlaylist(PlaylistCreateDto dto, String email) { + List songList = dto.getSongList().stream() + .map(Song::createByDto) + .collect(Collectors.toList()); + + Playlist playlist = Playlist + .createByDto(dto, memberService.findByEmail(email)) + .addSongs(songList); + + return playlistRepository.save(playlist); + } +} diff --git a/server/src/main/java/com/main/server/song/dto/SongCreateDto.java b/server/src/main/java/com/main/server/song/dto/SongCreateDto.java new file mode 100644 index 0000000..f0e5b64 --- /dev/null +++ b/server/src/main/java/com/main/server/song/dto/SongCreateDto.java @@ -0,0 +1,18 @@ +package com.main.server.song.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class SongCreateDto { + + @NotBlank(message = "영상을 추가하세요.") + private String videoId; + private String title; + private String thumbnail; +} diff --git a/server/src/main/java/com/main/server/song/dto/SongResponseDto.java b/server/src/main/java/com/main/server/song/dto/SongResponseDto.java new file mode 100644 index 0000000..476e6af --- /dev/null +++ b/server/src/main/java/com/main/server/song/dto/SongResponseDto.java @@ -0,0 +1,28 @@ +package com.main.server.song.dto; + +import com.main.server.song.entity.Song; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class SongResponseDto { + + private Long songId; + + private String videoId; + + private String title; + + private String thumbnail; + + public static SongResponseDto createByEntity(Song song) { + return new SongResponseDto( + song.getSongId(), + song.getVideoId(), + song.getTitle(), + song.getThumbnail()); + } +} diff --git a/server/src/main/java/com/main/server/song/entity/Song.java b/server/src/main/java/com/main/server/song/entity/Song.java index a5b3d7e..4a70e00 100644 --- a/server/src/main/java/com/main/server/song/entity/Song.java +++ b/server/src/main/java/com/main/server/song/entity/Song.java @@ -2,6 +2,8 @@ import com.main.server.audit.Auditable; import com.main.server.playlist.entity.Playlist; +import com.main.server.song.dto.SongCreateDto; +import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -10,33 +12,38 @@ @Entity @Getter -@Setter -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class Song { @Id @GeneratedValue (strategy = GenerationType.IDENTITY) private Long songId; - // PLAYLIST_ID @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "PLAYLIST_ID") private Playlist playlist; - //length - @Column(length = 100, nullable = false) + private String videoId; + private String title; - //length - @Column(length = 1000, nullable = false) - private String url; - //length + private String thumbnail; + public static Song createByDto(SongCreateDto dto) { + return new Song( + dto.getVideoId(), + dto.getTitle(), + dto.getThumbnail()); + } - public Song(Playlist playlist, Long songId, String title, String url) { + public Song setPlaylist(Playlist playlist) { this.playlist = playlist; - this.songId = songId; + return this; + } + + private Song(String videoId, String title, String thumbnail) { + this.videoId = videoId; this.title = title; - this.url = url; + this.thumbnail = thumbnail; } } diff --git a/server/src/main/java/com/main/server/song/service/SongService.java b/server/src/main/java/com/main/server/song/service/SongService.java new file mode 100644 index 0000000..29802d1 --- /dev/null +++ b/server/src/main/java/com/main/server/song/service/SongService.java @@ -0,0 +1,14 @@ +package com.main.server.song.service; + +import com.main.server.song.repository.SongRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class SongService { + + private final SongRepository songRepository; +} From 38028331171a284679e1b2f62e15ee6bf343ae58 Mon Sep 17 00:00:00 2001 From: GoF9490 Date: Fri, 17 Mar 2023 21:35:44 +0900 Subject: [PATCH 2/9] fix : SpringBootTest webEnviroment.RANDOM_PORT --- .../src/test/java/com/main/server/ServerApplicationTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/test/java/com/main/server/ServerApplicationTests.java b/server/src/test/java/com/main/server/ServerApplicationTests.java index 8cb5814..5c83e7f 100644 --- a/server/src/test/java/com/main/server/ServerApplicationTests.java +++ b/server/src/test/java/com/main/server/ServerApplicationTests.java @@ -5,7 +5,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.web.socket.server.standard.ServerEndpointExporter; -@SpringBootTest +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) class ServerApplicationTests { @Test From 1206101f30fb53a3b1d9b029b2bd05126c2617de Mon Sep 17 00:00:00 2001 From: GoF9490 Date: Sun, 19 Mar 2023 23:37:03 +0900 Subject: [PATCH 3/9] feat : getPlaylistById --- .../com/main/server/chat/config/WebSocketConfig.java | 1 - .../com/main/server/chat/service/ChatroomService.java | 9 --------- .../java/com/main/server/exception/ExceptionCode.java | 3 ++- .../java/com/main/server/member/entity/Member.java | 2 +- .../playlist/controller/PlaylistController.java | 11 +++++++---- .../playlist/repository/PlaylistRepository.java | 6 ++++-- .../main/server/playlist/service/PlaylistService.java | 7 +++++++ .../com/main/server/song/service/SongService.java | 3 +++ server/src/main/resources/application-local.yml | 2 +- 9 files changed, 25 insertions(+), 19 deletions(-) diff --git a/server/src/main/java/com/main/server/chat/config/WebSocketConfig.java b/server/src/main/java/com/main/server/chat/config/WebSocketConfig.java index 2240027..f971781 100644 --- a/server/src/main/java/com/main/server/chat/config/WebSocketConfig.java +++ b/server/src/main/java/com/main/server/chat/config/WebSocketConfig.java @@ -8,7 +8,6 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter; @Configuration -@EnableWebSocket @EnableWebSocketMessageBroker @RequiredArgsConstructor public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { diff --git a/server/src/main/java/com/main/server/chat/service/ChatroomService.java b/server/src/main/java/com/main/server/chat/service/ChatroomService.java index 6620685..47e42c9 100644 --- a/server/src/main/java/com/main/server/chat/service/ChatroomService.java +++ b/server/src/main/java/com/main/server/chat/service/ChatroomService.java @@ -41,13 +41,4 @@ public Chatroom findVerifiedRoomId(Long chatroomId) { public Chatroom save(Chatroom chatroom) { return chatroomRepository.save(chatroom); } - -// public void sendMessage(WebSocketSession session, T message) { -// log.info("sendMessage is used"); -// try { -// session.sendMessage(new TextMessage(objectMapper.writeValueAsString(message))); -// } catch (IOException e) { -// log.error(e.getMessage(), e); -// } -// } } diff --git a/server/src/main/java/com/main/server/exception/ExceptionCode.java b/server/src/main/java/com/main/server/exception/ExceptionCode.java index 55c3b8e..895166d 100644 --- a/server/src/main/java/com/main/server/exception/ExceptionCode.java +++ b/server/src/main/java/com/main/server/exception/ExceptionCode.java @@ -7,7 +7,8 @@ public enum ExceptionCode { MEMBER_NOT_FOUND(400, "member not found"), MEMBER_EXISTS(400, "member exists"), INVALID_TOKEN(400, "invalid token"), - NO_PERMISSION(400, "no permission"); + NO_PERMISSION(400, "no permission"), + PLAYLIST_NOT_FOUND(400, "playlist not found"); @Getter private int status; diff --git a/server/src/main/java/com/main/server/member/entity/Member.java b/server/src/main/java/com/main/server/member/entity/Member.java index e5c0da6..85477f6 100644 --- a/server/src/main/java/com/main/server/member/entity/Member.java +++ b/server/src/main/java/com/main/server/member/entity/Member.java @@ -34,7 +34,7 @@ public class Member extends Auditable { // private String password; // // length - @ElementCollection(fetch = FetchType.EAGER) + @ElementCollection(fetch = FetchType.LAZY) private List roles = new ArrayList<>(); diff --git a/server/src/main/java/com/main/server/playlist/controller/PlaylistController.java b/server/src/main/java/com/main/server/playlist/controller/PlaylistController.java index 626ace1..e2c9545 100644 --- a/server/src/main/java/com/main/server/playlist/controller/PlaylistController.java +++ b/server/src/main/java/com/main/server/playlist/controller/PlaylistController.java @@ -8,10 +8,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @@ -27,4 +24,10 @@ public ResponseEntity createPlaylist(@RequestBody PlaylistCreateDto dto, @Authen return ResponseEntity.status(HttpStatus.CREATED) .body(PlaylistResponseDto.createByEntity(playlist)); } + + @GetMapping("/{playlist-id}") + public ResponseEntity getPlaylist(@PathVariable("playlist-id") Long playlistId) { + return ResponseEntity.status(HttpStatus.OK) + .body(PlaylistResponseDto.createByEntity(playlistService.findPlaylistById(playlistId))); + } } diff --git a/server/src/main/java/com/main/server/playlist/repository/PlaylistRepository.java b/server/src/main/java/com/main/server/playlist/repository/PlaylistRepository.java index e2424c3..03c279d 100644 --- a/server/src/main/java/com/main/server/playlist/repository/PlaylistRepository.java +++ b/server/src/main/java/com/main/server/playlist/repository/PlaylistRepository.java @@ -2,10 +2,12 @@ import com.main.server.playlist.entity.Playlist; +import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; public interface PlaylistRepository extends JpaRepository { - - // Optional findPlaylistId(Long playlistId); - no property + @Override + @EntityGraph(attributePaths = {"member", "songs"}) + Optional findById(Long playlistId); } diff --git a/server/src/main/java/com/main/server/playlist/service/PlaylistService.java b/server/src/main/java/com/main/server/playlist/service/PlaylistService.java index f020100..8a7cc89 100644 --- a/server/src/main/java/com/main/server/playlist/service/PlaylistService.java +++ b/server/src/main/java/com/main/server/playlist/service/PlaylistService.java @@ -1,5 +1,7 @@ package com.main.server.playlist.service; +import com.main.server.exception.BusinessLogicException; +import com.main.server.exception.ExceptionCode; import com.main.server.member.service.MemberService; import com.main.server.playlist.dto.PlaylistCreateDto; import com.main.server.playlist.entity.Playlist; @@ -33,4 +35,9 @@ public Playlist createPlaylist(PlaylistCreateDto dto, String email) { return playlistRepository.save(playlist); } + + public Playlist findPlaylistById(Long playlistId) { + return playlistRepository.findById(playlistId) + .orElseThrow(() -> new BusinessLogicException(ExceptionCode.PLAYLIST_NOT_FOUND)); + } } diff --git a/server/src/main/java/com/main/server/song/service/SongService.java b/server/src/main/java/com/main/server/song/service/SongService.java index 29802d1..3f4322f 100644 --- a/server/src/main/java/com/main/server/song/service/SongService.java +++ b/server/src/main/java/com/main/server/song/service/SongService.java @@ -1,10 +1,13 @@ package com.main.server.song.service; +import com.main.server.song.entity.Song; import com.main.server.song.repository.SongRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @Service @Transactional @RequiredArgsConstructor diff --git a/server/src/main/resources/application-local.yml b/server/src/main/resources/application-local.yml index cff42aa..5b104ce 100644 --- a/server/src/main/resources/application-local.yml +++ b/server/src/main/resources/application-local.yml @@ -13,7 +13,7 @@ spring: properties: hibernate: format_sql: true - show-sql: true + show-sql: false logging: level: From b9b645a188269a2d3b9634547a5fbde53543e6a9 Mon Sep 17 00:00:00 2001 From: GoF9490 Date: Mon, 20 Mar 2023 09:26:23 +0900 Subject: [PATCH 4/9] fix : testVer --- .../java/com/main/server/member/entity/Member.java | 12 ------------ .../playlist/controller/PlaylistController.java | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/server/src/main/java/com/main/server/member/entity/Member.java b/server/src/main/java/com/main/server/member/entity/Member.java index 85477f6..129eb15 100644 --- a/server/src/main/java/com/main/server/member/entity/Member.java +++ b/server/src/main/java/com/main/server/member/entity/Member.java @@ -5,14 +5,11 @@ import lombok.*; import javax.persistence.*; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @Entity @Getter -//@Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) - // 주석 = 바꿔야 할 부분 public class Member extends Auditable { @Id @@ -21,24 +18,17 @@ public class Member extends Auditable { @Column(length = 100, nullable = false, unique = true) private String nickname; - // length @Column(length = 100, nullable = false, unique = true) private String email; - // length @Column(length = 500) private String picture; -// @Column(length = 1000, nullable = false) -// private String password; -// // length - @ElementCollection(fetch = FetchType.LAZY) private List roles = new ArrayList<>(); - @Builder public Member( String nickname, String email, @@ -49,6 +39,4 @@ public Member( String nickname, this.picture = picture; this.roles = roles; } - - } diff --git a/server/src/main/java/com/main/server/playlist/controller/PlaylistController.java b/server/src/main/java/com/main/server/playlist/controller/PlaylistController.java index e2c9545..9247d99 100644 --- a/server/src/main/java/com/main/server/playlist/controller/PlaylistController.java +++ b/server/src/main/java/com/main/server/playlist/controller/PlaylistController.java @@ -19,7 +19,7 @@ public class PlaylistController { @PostMapping public ResponseEntity createPlaylist(@RequestBody PlaylistCreateDto dto, @AuthenticationPrincipal String email) { - Playlist playlist = playlistService.createPlaylist(dto, email); + Playlist playlist = playlistService.createPlaylist(dto, "admin@google.com"); return ResponseEntity.status(HttpStatus.CREATED) .body(PlaylistResponseDto.createByEntity(playlist)); From 6c87c43d43903bb5e74f51173170c597b7a46631 Mon Sep 17 00:00:00 2001 From: GoF9490 Date: Mon, 20 Mar 2023 11:06:21 +0900 Subject: [PATCH 5/9] feat : jws simple verify RefreshToken --- .../auth/filter/JwtVerificationFilter.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/com/main/server/auth/filter/JwtVerificationFilter.java b/server/src/main/java/com/main/server/auth/filter/JwtVerificationFilter.java index 325f832..fa4ce5d 100644 --- a/server/src/main/java/com/main/server/auth/filter/JwtVerificationFilter.java +++ b/server/src/main/java/com/main/server/auth/filter/JwtVerificationFilter.java @@ -64,16 +64,26 @@ private Map verifyJws(HttpServletRequest request, return claims; } + /** + * 계정이 있는지 없는지만 검증하고있다. + * 스케쥴러가 없어서 RefreshToken을 db에 저장하면 데이터가 정리가 안되고 계속해서 쌓일것. + * 보안 필요. + */ + String jws = request.getHeader("Refresh"); - Member member = null; -// memberRepository.findByEmail(jwtTokenizer.getUsername(jws)) -// .orElseThrow(() -> new BusinessLogicException(ExceptionCode.INVALID_TOKEN)); + Member member = + memberService.findByEmail(jwtTokenizer.getUsername(jws)); String accessToken = jwtTokenizer.delegateAccessToken( member.getEmail(), authorityUtils.createRoles(member.getEmail())); + + String refreshToken = + jwtTokenizer.delegateRefreshToken(member.getEmail()); + response.setHeader("Authorization", "Bearer " + accessToken); + response.setHeader("Refresh", refreshToken); Claims claims = jwtTokenizer.getClaims(accessToken).getBody(); return claims; From ccb8045fd0d6b95397e3008b2b68a9a5453fa01a Mon Sep 17 00:00:00 2001 From: GoF9490 Date: Mon, 20 Mar 2023 14:38:07 +0900 Subject: [PATCH 6/9] test : createPlaylistSuccess & findPlaylistSuccess --- .../auth/filter/JwtVerificationFilter.java | 1 - .../com/main/server/member/entity/Member.java | 1 + .../playlist/service/PlaylistServiceTest.java | 104 ++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 server/src/test/java/com/main/server/playlist/service/PlaylistServiceTest.java diff --git a/server/src/main/java/com/main/server/auth/filter/JwtVerificationFilter.java b/server/src/main/java/com/main/server/auth/filter/JwtVerificationFilter.java index fa4ce5d..bbaff90 100644 --- a/server/src/main/java/com/main/server/auth/filter/JwtVerificationFilter.java +++ b/server/src/main/java/com/main/server/auth/filter/JwtVerificationFilter.java @@ -34,7 +34,6 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { - try { Map claims = verifyJws(request, response); setAuthenticationToContext(claims); diff --git a/server/src/main/java/com/main/server/member/entity/Member.java b/server/src/main/java/com/main/server/member/entity/Member.java index 129eb15..e92b6a6 100644 --- a/server/src/main/java/com/main/server/member/entity/Member.java +++ b/server/src/main/java/com/main/server/member/entity/Member.java @@ -7,6 +7,7 @@ import javax.persistence.*; import java.util.ArrayList; import java.util.List; + @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/server/src/test/java/com/main/server/playlist/service/PlaylistServiceTest.java b/server/src/test/java/com/main/server/playlist/service/PlaylistServiceTest.java new file mode 100644 index 0000000..626a2ba --- /dev/null +++ b/server/src/test/java/com/main/server/playlist/service/PlaylistServiceTest.java @@ -0,0 +1,104 @@ +package com.main.server.playlist.service; + +import com.main.server.member.entity.Member; +import com.main.server.member.repository.MemberRepository; +import com.main.server.playlist.dto.PlaylistCreateDto; +import com.main.server.playlist.entity.Playlist; +import com.main.server.playlist.repository.PlaylistRepository; +import com.main.server.song.dto.SongCreateDto; +import com.main.server.song.entity.Song; +import com.main.server.song.repository.SongRepository; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.EntityManager; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; + +@Transactional +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +class PlaylistServiceTest { + + @Autowired + PlaylistService playlistService; + + @Autowired + MemberRepository memberRepository; + + @Autowired + PlaylistRepository playlistRepository; + + @Autowired + SongRepository songRepository; + + @Autowired + EntityManager em; + + @Test + @DisplayName("플레이리스트 생성이 성공적으로 이루어져야 합니다.") + public void createPlaylistSuccess() throws Exception { + //given + Member member = Member.builder() + .nickname("tester") + .email("tester@test.com") + .build(); + + memberRepository.save(member); + + PlaylistCreateDto dto = new PlaylistCreateDto("foo", null, + IntStream.range(1, 11) + .mapToObj(i -> new SongCreateDto("video" + i, "title" + i, "thumb" + i)) + .collect(Collectors.toList())); + + //when + Playlist playlist = playlistService.createPlaylist(dto, member.getEmail()); + + //then + assertThat(playlistRepository.count()).isEqualTo(1); + assertThat(songRepository.count()).isEqualTo(10); + } + + @Test + @DisplayName("플레이리스트 ID 조회가 성공적으로 이루어져야 합니다.") + public void findPlaylistSuccess() throws Exception { + //given + Member member = memberRepository.save(Member.builder() + .nickname("tester") + .email("tester@test.com") + .build()); + + PlaylistCreateDto dto = new PlaylistCreateDto("foo", null, null); + + List songList = IntStream.range(1, 11) + .mapToObj(i -> new SongCreateDto("video" + i, "title" + i, "thumb" + i)) + .map(Song::createByDto) + .collect(Collectors.toList()); + + Playlist playlist = Playlist + .createByDto(dto, member) + .addSongs(songList); + + playlistRepository.save(playlist); + + //when + Playlist findPlaylist = playlistService.findPlaylistById(playlist.getPlaylistId()); + + em.flush(); + em.clear(); + + //then + assertThat(playlist.getPlaylistId()).isEqualTo(findPlaylist.getPlaylistId()); + assertThat(playlist.getMember().getEmail()).isEqualTo(findPlaylist.getMember().getEmail()); + assertThat(playlist.getTitle()).isEqualTo(findPlaylist.getTitle()); + assertThat(playlist.getSongs().size()).isEqualTo(findPlaylist.getSongs().size()); + assertThat(playlist.getSongs().get(0).getTitle()).isEqualTo(findPlaylist.getSongs().get(0).getTitle()); + } +} \ No newline at end of file From dd7edcac716ee3d3e9d91338bbaf7598e0a11536 Mon Sep 17 00:00:00 2001 From: ssaalbob Date: Mon, 20 Mar 2023 18:23:35 +0900 Subject: [PATCH 7/9] =?UTF-8?q?=EC=9E=84=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/main/server/board/entity/Board.java | 56 ------------------- .../board/repository/BoardRepository.java | 16 ------ .../board/service/FindBoardService.java | 22 -------- .../com/main/server/board/status/Status.java | 6 -- 4 files changed, 100 deletions(-) delete mode 100644 server/src/main/java/com/main/server/board/entity/Board.java delete mode 100644 server/src/main/java/com/main/server/board/repository/BoardRepository.java delete mode 100644 server/src/main/java/com/main/server/board/service/FindBoardService.java delete mode 100644 server/src/main/java/com/main/server/board/status/Status.java diff --git a/server/src/main/java/com/main/server/board/entity/Board.java b/server/src/main/java/com/main/server/board/entity/Board.java deleted file mode 100644 index 66aea34..0000000 --- a/server/src/main/java/com/main/server/board/entity/Board.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.main.server.board.entity; - - -import com.main.server.audit.Auditable; -import com.main.server.like.entity.Like; -import com.main.server.member.entity.Member; -import com.main.server.playlist.entity.Playlist; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import javax.persistence.*; -import java.util.ArrayList; -import java.util.List; - -@Entity -@Getter@Setter -@NoArgsConstructor - -public class Board extends Auditable { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long boardId; - - @ManyToOne - @JoinColumn(name = "MEMBER_ID") - private Member member; - // MEMBER_ID - - @ManyToOne - @JoinColumn(name = "Playlist_ID") - private Playlist playlist; - // Board_ID - - @Column(length = 100,nullable = false) - private String content; - //length - - - @Column(length = 100,nullable = false) - private String title; - //length - - @OneToMany(fetch = FetchType.LAZY,mappedBy = "board", cascade = {CascadeType.PERSIST, CascadeType.REMOVE}) - private List likes = new ArrayList<>(); - - public Like addLike(Like like) { - List newLike = new ArrayList<>(likes); - newLike.add(like); - this.likes = newLike; - return like; - } - - - } diff --git a/server/src/main/java/com/main/server/board/repository/BoardRepository.java b/server/src/main/java/com/main/server/board/repository/BoardRepository.java deleted file mode 100644 index 87d853a..0000000 --- a/server/src/main/java/com/main/server/board/repository/BoardRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.main.server.board.repository; - -import com.main.server.board.entity.Board; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.Optional; - -public interface BoardRepository extends JpaRepository { - - - Optional findByBoardId(Long boardId); - - - - -} diff --git a/server/src/main/java/com/main/server/board/service/FindBoardService.java b/server/src/main/java/com/main/server/board/service/FindBoardService.java deleted file mode 100644 index 775ed04..0000000 --- a/server/src/main/java/com/main/server/board/service/FindBoardService.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.main.server.board.service; - -import com.main.server.board.entity.Board; -import com.main.server.board.repository.BoardRepository; -import com.main.server.exception.BusinessLogicException; -import com.main.server.exception.ExceptionCode; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import javax.transaction.Transactional; - -@Service -@Transactional -@RequiredArgsConstructor -public class FindBoardService { - private final BoardRepository boardRepository; - - public Board id(Long id) { - return boardRepository.findById(id) - .orElseThrow(() -> new BusinessLogicException(ExceptionCode.BOARD_NOT_FOUND)); - } -} diff --git a/server/src/main/java/com/main/server/board/status/Status.java b/server/src/main/java/com/main/server/board/status/Status.java deleted file mode 100644 index 41dd865..0000000 --- a/server/src/main/java/com/main/server/board/status/Status.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.main.server.board.status; - - -public class Status { - // 숨김상태같은거 만들어서 삭제 누르면 숨김상태로 변환 -} From b458a5746dfffd3636b21facc038a9e20ebc740d Mon Sep 17 00:00:00 2001 From: GoF9490 <81549749+GoF9490@users.noreply.github.com> Date: Mon, 20 Mar 2023 18:35:41 +0900 Subject: [PATCH 8/9] fix : serverApplicationTests disabled --- .../main/server/ServerApplicationTests.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/server/src/test/java/com/main/server/ServerApplicationTests.java b/server/src/test/java/com/main/server/ServerApplicationTests.java index 8d6abaa..5fd0daf 100644 --- a/server/src/test/java/com/main/server/ServerApplicationTests.java +++ b/server/src/test/java/com/main/server/ServerApplicationTests.java @@ -1,14 +1,14 @@ -package com.main.server; +// package com.main.server; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.web.socket.server.standard.ServerEndpointExporter; +// import org.junit.jupiter.api.Test; +// import org.springframework.boot.test.context.SpringBootTest; +// import org.springframework.context.annotation.Bean; +// import org.springframework.web.socket.server.standard.ServerEndpointExporter; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class ServerApplicationTests { +// @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +// class ServerApplicationTests { -// @Test -// void contextLoads() { -// } -} +// // @Test +// // void contextLoads() { +// // } +// } From 04201ae3a2e8090475de20712f572727b0ab1f43 Mon Sep 17 00:00:00 2001 From: GoF9490 <81549749+GoF9490@users.noreply.github.com> Date: Mon, 20 Mar 2023 18:36:33 +0900 Subject: [PATCH 9/9] fix : PlaylistServiceTest disabled --- .../playlist/service/PlaylistServiceTest.java | 208 +++++++++--------- 1 file changed, 104 insertions(+), 104 deletions(-) diff --git a/server/src/test/java/com/main/server/playlist/service/PlaylistServiceTest.java b/server/src/test/java/com/main/server/playlist/service/PlaylistServiceTest.java index 626a2ba..6f43fc3 100644 --- a/server/src/test/java/com/main/server/playlist/service/PlaylistServiceTest.java +++ b/server/src/test/java/com/main/server/playlist/service/PlaylistServiceTest.java @@ -1,104 +1,104 @@ -package com.main.server.playlist.service; - -import com.main.server.member.entity.Member; -import com.main.server.member.repository.MemberRepository; -import com.main.server.playlist.dto.PlaylistCreateDto; -import com.main.server.playlist.entity.Playlist; -import com.main.server.playlist.repository.PlaylistRepository; -import com.main.server.song.dto.SongCreateDto; -import com.main.server.song.entity.Song; -import com.main.server.song.repository.SongRepository; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; - -import javax.persistence.EntityManager; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.*; - -@Transactional -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class PlaylistServiceTest { - - @Autowired - PlaylistService playlistService; - - @Autowired - MemberRepository memberRepository; - - @Autowired - PlaylistRepository playlistRepository; - - @Autowired - SongRepository songRepository; - - @Autowired - EntityManager em; - - @Test - @DisplayName("플레이리스트 생성이 성공적으로 이루어져야 합니다.") - public void createPlaylistSuccess() throws Exception { - //given - Member member = Member.builder() - .nickname("tester") - .email("tester@test.com") - .build(); - - memberRepository.save(member); - - PlaylistCreateDto dto = new PlaylistCreateDto("foo", null, - IntStream.range(1, 11) - .mapToObj(i -> new SongCreateDto("video" + i, "title" + i, "thumb" + i)) - .collect(Collectors.toList())); - - //when - Playlist playlist = playlistService.createPlaylist(dto, member.getEmail()); - - //then - assertThat(playlistRepository.count()).isEqualTo(1); - assertThat(songRepository.count()).isEqualTo(10); - } - - @Test - @DisplayName("플레이리스트 ID 조회가 성공적으로 이루어져야 합니다.") - public void findPlaylistSuccess() throws Exception { - //given - Member member = memberRepository.save(Member.builder() - .nickname("tester") - .email("tester@test.com") - .build()); - - PlaylistCreateDto dto = new PlaylistCreateDto("foo", null, null); - - List songList = IntStream.range(1, 11) - .mapToObj(i -> new SongCreateDto("video" + i, "title" + i, "thumb" + i)) - .map(Song::createByDto) - .collect(Collectors.toList()); - - Playlist playlist = Playlist - .createByDto(dto, member) - .addSongs(songList); - - playlistRepository.save(playlist); - - //when - Playlist findPlaylist = playlistService.findPlaylistById(playlist.getPlaylistId()); - - em.flush(); - em.clear(); - - //then - assertThat(playlist.getPlaylistId()).isEqualTo(findPlaylist.getPlaylistId()); - assertThat(playlist.getMember().getEmail()).isEqualTo(findPlaylist.getMember().getEmail()); - assertThat(playlist.getTitle()).isEqualTo(findPlaylist.getTitle()); - assertThat(playlist.getSongs().size()).isEqualTo(findPlaylist.getSongs().size()); - assertThat(playlist.getSongs().get(0).getTitle()).isEqualTo(findPlaylist.getSongs().get(0).getTitle()); - } -} \ No newline at end of file +// package com.main.server.playlist.service; + +// import com.main.server.member.entity.Member; +// import com.main.server.member.repository.MemberRepository; +// import com.main.server.playlist.dto.PlaylistCreateDto; +// import com.main.server.playlist.entity.Playlist; +// import com.main.server.playlist.repository.PlaylistRepository; +// import com.main.server.song.dto.SongCreateDto; +// import com.main.server.song.entity.Song; +// import com.main.server.song.repository.SongRepository; +// import org.assertj.core.api.Assertions; +// import org.junit.jupiter.api.DisplayName; +// import org.junit.jupiter.api.Test; +// import org.springframework.beans.factory.annotation.Autowired; +// import org.springframework.boot.test.context.SpringBootTest; +// import org.springframework.transaction.annotation.Transactional; + +// import javax.persistence.EntityManager; +// import java.util.List; +// import java.util.stream.Collectors; +// import java.util.stream.IntStream; + +// import static org.assertj.core.api.Assertions.*; +// import static org.junit.jupiter.api.Assertions.*; + +// @Transactional +// @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +// class PlaylistServiceTest { + +// @Autowired +// PlaylistService playlistService; + +// @Autowired +// MemberRepository memberRepository; + +// @Autowired +// PlaylistRepository playlistRepository; + +// @Autowired +// SongRepository songRepository; + +// @Autowired +// EntityManager em; + +// @Test +// @DisplayName("플레이리스트 생성이 성공적으로 이루어져야 합니다.") +// public void createPlaylistSuccess() throws Exception { +// //given +// Member member = Member.builder() +// .nickname("tester") +// .email("tester@test.com") +// .build(); + +// memberRepository.save(member); + +// PlaylistCreateDto dto = new PlaylistCreateDto("foo", null, +// IntStream.range(1, 11) +// .mapToObj(i -> new SongCreateDto("video" + i, "title" + i, "thumb" + i)) +// .collect(Collectors.toList())); + +// //when +// Playlist playlist = playlistService.createPlaylist(dto, member.getEmail()); + +// //then +// assertThat(playlistRepository.count()).isEqualTo(1); +// assertThat(songRepository.count()).isEqualTo(10); +// } + +// @Test +// @DisplayName("플레이리스트 ID 조회가 성공적으로 이루어져야 합니다.") +// public void findPlaylistSuccess() throws Exception { +// //given +// Member member = memberRepository.save(Member.builder() +// .nickname("tester") +// .email("tester@test.com") +// .build()); + +// PlaylistCreateDto dto = new PlaylistCreateDto("foo", null, null); + +// List songList = IntStream.range(1, 11) +// .mapToObj(i -> new SongCreateDto("video" + i, "title" + i, "thumb" + i)) +// .map(Song::createByDto) +// .collect(Collectors.toList()); + +// Playlist playlist = Playlist +// .createByDto(dto, member) +// .addSongs(songList); + +// playlistRepository.save(playlist); + +// //when +// Playlist findPlaylist = playlistService.findPlaylistById(playlist.getPlaylistId()); + +// em.flush(); +// em.clear(); + +// //then +// assertThat(playlist.getPlaylistId()).isEqualTo(findPlaylist.getPlaylistId()); +// assertThat(playlist.getMember().getEmail()).isEqualTo(findPlaylist.getMember().getEmail()); +// assertThat(playlist.getTitle()).isEqualTo(findPlaylist.getTitle()); +// assertThat(playlist.getSongs().size()).isEqualTo(findPlaylist.getSongs().size()); +// assertThat(playlist.getSongs().get(0).getTitle()).isEqualTo(findPlaylist.getSongs().get(0).getTitle()); +// } +// }