-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from syyling/feat/1
[feat] User 도메인 저장 기능 추가
- Loading branch information
Showing
7 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/main/java/com/mookive/mookive_backend/user/application/dto/UserRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/mookive/mookive_backend/user/application/mapper/UserMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/mookive/mookive_backend/user/application/service/UserCreateService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/mookive/mookive_backend/user/domain/entity/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/mookive/mookive_backend/user/domain/repository/UserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<User, Long> { | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/mookive/mookive_backend/user/domain/service/UserSaveService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/mookive/mookive_backend/user/presentation/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |