diff --git a/src/main/java/com/mookive/mookive_backend/playlist/application/dto/request/PlaylistRequest.java b/src/main/java/com/mookive/mookive_backend/playlist/application/dto/request/PlaylistRequest.java new file mode 100644 index 0000000..5e7467f --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/playlist/application/dto/request/PlaylistRequest.java @@ -0,0 +1,21 @@ +package com.mookive.mookive_backend.playlist.application.dto.request; + +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +public class PlaylistRequest { + + @Getter + @NoArgsConstructor + public static class PlaylistCreateRequest { + private Long userId; + private String name; + + @Builder + public PlaylistCreateRequest(Long userId, String name) { + this.userId = userId; + this.name = name; + } + } +} diff --git a/src/main/java/com/mookive/mookive_backend/playlist/application/mapper/PlaylistMapper.java b/src/main/java/com/mookive/mookive_backend/playlist/application/mapper/PlaylistMapper.java new file mode 100644 index 0000000..61bfb9c --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/playlist/application/mapper/PlaylistMapper.java @@ -0,0 +1,15 @@ +package com.mookive.mookive_backend.playlist.application.mapper; + +import com.mookive.mookive_backend.playlist.application.dto.request.PlaylistRequest; +import com.mookive.mookive_backend.playlist.domain.entity.Playlist; +import com.mookive.mookive_backend.user.domain.entity.User; + +public class PlaylistMapper { + + public static Playlist mapToPlaylist(User user, PlaylistRequest.PlaylistCreateRequest playlistCreateRequest) { + return Playlist.builder() + .name(playlistCreateRequest.getName()) + .user(user) + .build(); + } +} diff --git a/src/main/java/com/mookive/mookive_backend/playlist/application/service/PlaylistCreateService.java b/src/main/java/com/mookive/mookive_backend/playlist/application/service/PlaylistCreateService.java new file mode 100644 index 0000000..b516265 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/playlist/application/service/PlaylistCreateService.java @@ -0,0 +1,27 @@ +package com.mookive.mookive_backend.playlist.application.service; + +import com.mookive.mookive_backend.playlist.application.dto.request.PlaylistRequest; +import com.mookive.mookive_backend.playlist.application.mapper.PlaylistMapper; +import com.mookive.mookive_backend.playlist.domain.entity.Playlist; +import com.mookive.mookive_backend.playlist.domain.service.PlaylistSaveService; +import com.mookive.mookive_backend.user.domain.entity.User; +import com.mookive.mookive_backend.user.domain.service.UserQueryService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class PlaylistCreateService { + + private final UserQueryService userQueryService; + private final PlaylistSaveService playlistSaveService; + + public void createPlaylist(PlaylistRequest.PlaylistCreateRequest playlistCreateRequest) { + System.out.println("playlistCreateRequest = " + playlistCreateRequest.getName()); + Long userId = playlistCreateRequest.getUserId(); + System.out.println("userId = " + userId); + User user = userQueryService.findById(userId); + Playlist playlist = PlaylistMapper.mapToPlaylist(user, playlistCreateRequest); + playlistSaveService.savePlaylist(playlist); + } +} diff --git a/src/main/java/com/mookive/mookive_backend/playlist/domain/service/PlaylistSaveService.java b/src/main/java/com/mookive/mookive_backend/playlist/domain/service/PlaylistSaveService.java new file mode 100644 index 0000000..709234b --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/playlist/domain/service/PlaylistSaveService.java @@ -0,0 +1,17 @@ +package com.mookive.mookive_backend.playlist.domain.service; + +import com.mookive.mookive_backend.playlist.domain.entity.Playlist; +import com.mookive.mookive_backend.playlist.domain.repository.PlaylistRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class PlaylistSaveService { + + private final PlaylistRepository playlistRepository; + + public void savePlaylist(Playlist playlist) { + playlistRepository.save(playlist); + } +} diff --git a/src/main/java/com/mookive/mookive_backend/playlist/presentation/PlaylistController.java b/src/main/java/com/mookive/mookive_backend/playlist/presentation/PlaylistController.java new file mode 100644 index 0000000..e2e4cf3 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/playlist/presentation/PlaylistController.java @@ -0,0 +1,20 @@ +package com.mookive.mookive_backend.playlist.presentation; + +import com.mookive.mookive_backend.playlist.application.dto.request.PlaylistRequest; +import com.mookive.mookive_backend.playlist.application.service.PlaylistCreateService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class PlaylistController { + + private final PlaylistCreateService playlistCreateService; + + @PostMapping("/playlist") + public void createPlaylist(@RequestBody PlaylistRequest.PlaylistCreateRequest playlistCreateRequest) { + playlistCreateService.createPlaylist(playlistCreateRequest); + } +}