From 49925a922b15595f1b604681c21dbd5809eaec51 Mon Sep 17 00:00:00 2001 From: seo-young Date: Wed, 21 Feb 2024 15:08:12 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20User=20=EB=8F=84=EB=A9=94=EC=9D=B8=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/application/dto/UserRequest.java | 24 +++++++++++++++ .../user/application/mapper/UserMapper.java | 15 ++++++++++ .../service/UserCreateService.java | 20 +++++++++++++ .../user/domain/entity/User.java | 30 +++++++++++++++++++ .../domain/repository/UserRepository.java | 7 +++++ .../user/domain/service/UserSaveService.java | 19 ++++++++++++ .../user/presentation/UserController.java | 20 +++++++++++++ 7 files changed, 135 insertions(+) create mode 100644 src/main/java/com/mookive/mookive_backend/user/application/dto/UserRequest.java create mode 100644 src/main/java/com/mookive/mookive_backend/user/application/mapper/UserMapper.java create mode 100644 src/main/java/com/mookive/mookive_backend/user/application/service/UserCreateService.java create mode 100644 src/main/java/com/mookive/mookive_backend/user/domain/entity/User.java create mode 100644 src/main/java/com/mookive/mookive_backend/user/domain/repository/UserRepository.java create mode 100644 src/main/java/com/mookive/mookive_backend/user/domain/service/UserSaveService.java create mode 100644 src/main/java/com/mookive/mookive_backend/user/presentation/UserController.java diff --git a/src/main/java/com/mookive/mookive_backend/user/application/dto/UserRequest.java b/src/main/java/com/mookive/mookive_backend/user/application/dto/UserRequest.java new file mode 100644 index 0000000..4702827 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/user/application/dto/UserRequest.java @@ -0,0 +1,24 @@ +package com.mookive.mookive_backend.user.application.dto; + +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +public class UserRequest { + + @Getter + @NoArgsConstructor + public static class UserCreateRequest { + + private String name; + private String email; + private String profileUrl; + + @Builder + public UserCreateRequest(String name, String email, String profileUrl) { + this.name = name; + this.email = email; + this.profileUrl = profileUrl; + } + } +} diff --git a/src/main/java/com/mookive/mookive_backend/user/application/mapper/UserMapper.java b/src/main/java/com/mookive/mookive_backend/user/application/mapper/UserMapper.java new file mode 100644 index 0000000..88a8bc3 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/user/application/mapper/UserMapper.java @@ -0,0 +1,15 @@ +package com.mookive.mookive_backend.user.application.mapper; + +import com.mookive.mookive_backend.user.application.dto.UserRequest; +import com.mookive.mookive_backend.user.domain.entity.User; + +public class UserMapper { + + public static User mapToUser(UserRequest.UserCreateRequest request) { + return User.builder() + .name(request.getName()) + .email(request.getEmail()) + .profileUrl(request.getProfileUrl()) + .build(); + } +} diff --git a/src/main/java/com/mookive/mookive_backend/user/application/service/UserCreateService.java b/src/main/java/com/mookive/mookive_backend/user/application/service/UserCreateService.java new file mode 100644 index 0000000..4f75da1 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/user/application/service/UserCreateService.java @@ -0,0 +1,20 @@ +package com.mookive.mookive_backend.user.application.service; + +import com.mookive.mookive_backend.user.application.dto.UserRequest; +import com.mookive.mookive_backend.user.application.mapper.UserMapper; +import com.mookive.mookive_backend.user.domain.entity.User; +import com.mookive.mookive_backend.user.domain.service.UserSaveService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class UserCreateService { + + private final UserSaveService userSaveService; + + public void createUser(UserRequest.UserCreateRequest userCreateRequest) { + User user = UserMapper.mapToUser(userCreateRequest); + userSaveService.saveUser(user); + } +} diff --git a/src/main/java/com/mookive/mookive_backend/user/domain/entity/User.java b/src/main/java/com/mookive/mookive_backend/user/domain/entity/User.java new file mode 100644 index 0000000..c85583e --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/user/domain/entity/User.java @@ -0,0 +1,30 @@ +package com.mookive.mookive_backend.user.domain.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class User { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + private String email; + private String profileUrl; + + @Builder + public User(String name, String email, String profileUrl) { + this.name = name; + this.email = email; + this.profileUrl = profileUrl; + } +} diff --git a/src/main/java/com/mookive/mookive_backend/user/domain/repository/UserRepository.java b/src/main/java/com/mookive/mookive_backend/user/domain/repository/UserRepository.java new file mode 100644 index 0000000..bb9ee16 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/user/domain/repository/UserRepository.java @@ -0,0 +1,7 @@ +package com.mookive.mookive_backend.user.domain.repository; + +import com.mookive.mookive_backend.user.domain.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserRepository extends JpaRepository { +} diff --git a/src/main/java/com/mookive/mookive_backend/user/domain/service/UserSaveService.java b/src/main/java/com/mookive/mookive_backend/user/domain/service/UserSaveService.java new file mode 100644 index 0000000..e35a7c0 --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/user/domain/service/UserSaveService.java @@ -0,0 +1,19 @@ +package com.mookive.mookive_backend.user.domain.service; + +import com.mookive.mookive_backend.user.domain.entity.User; +import com.mookive.mookive_backend.user.domain.repository.UserRepository; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@Transactional +@RequiredArgsConstructor +public class UserSaveService { + + private final UserRepository userRepository; + + public void saveUser(User user) { + userRepository.save(user); + } +} diff --git a/src/main/java/com/mookive/mookive_backend/user/presentation/UserController.java b/src/main/java/com/mookive/mookive_backend/user/presentation/UserController.java new file mode 100644 index 0000000..046663e --- /dev/null +++ b/src/main/java/com/mookive/mookive_backend/user/presentation/UserController.java @@ -0,0 +1,20 @@ +package com.mookive.mookive_backend.user.presentation; + +import com.mookive.mookive_backend.user.application.dto.UserRequest; +import com.mookive.mookive_backend.user.application.service.UserCreateService; +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 UserController { + + private final UserCreateService userCreateService; + + @PostMapping("/user/create") + void createUser(@RequestBody UserRequest.UserCreateRequest userCreateRequest) { + userCreateService.createUser(userCreateRequest); + } +}