Skip to content

Commit

Permalink
[feat] Playlist 생성하는 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
syyling committed Mar 7, 2024
1 parent 8a7f290 commit 7855695
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 7855695

Please sign in to comment.