Skip to content

Commit

Permalink
Merge pull request #6 from syyling/feat/1
Browse files Browse the repository at this point in the history
[feat] User 도메인 저장 기능 추가
  • Loading branch information
syyling authored Feb 21, 2024
2 parents ba1d2c5 + b56b89a commit b6526c7
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 0 deletions.
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;
}
}
}
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();
}
}
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);
}
}
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;
}
}
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> {
}
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);
}
}
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);
}
}

0 comments on commit b6526c7

Please sign in to comment.