diff --git a/build.gradle b/build.gradle index 539c12b0..954ba70f 100644 --- a/build.gradle +++ b/build.gradle @@ -33,6 +33,7 @@ dependencies { testRuntimeOnly 'org.junit.platform:junit-platform-launcher' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' // JPA 스타터 추가 runtimeOnly 'com.h2database:h2' // test용 db인 h2Database 추가 + implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0' // p6spy 설정 추가 } tasks.named('test') { diff --git a/src/main/java/space/space_spring/controller/UserController.java b/src/main/java/space/space_spring/controller/UserController.java index 6eb8c4c3..8921a751 100644 --- a/src/main/java/space/space_spring/controller/UserController.java +++ b/src/main/java/space/space_spring/controller/UserController.java @@ -4,8 +4,11 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import space.space_spring.dto.PostUserRequest; +import space.space_spring.dto.PostUserResponse; import space.space_spring.response.BaseResponse; import space.space_spring.service.UserService; @@ -20,6 +23,9 @@ public class UserController { /** * 회원가입 */ -// @PostMapping("/signup") + @PostMapping("/signup") + public BaseResponse signup(@RequestBody PostUserRequest postUserRequest) { + return new BaseResponse<>(userService.signup(postUserRequest)); + } } diff --git a/src/main/java/space/space_spring/dao/UserDao.java b/src/main/java/space/space_spring/dao/UserDao.java index 4fb92c9a..4fdee3ba 100644 --- a/src/main/java/space/space_spring/dao/UserDao.java +++ b/src/main/java/space/space_spring/dao/UserDao.java @@ -1,9 +1,24 @@ package space.space_spring.dao; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; +import space.space_spring.domain.User; +import space.space_spring.dto.PostUserRequest; @Repository +@Transactional public class UserDao { + @PersistenceContext + private EntityManager em; + public Long saveUser(PostUserRequest postUserRequest) { + User user = new User(); + user.saveUser(postUserRequest.getEmail(), postUserRequest.getPassword(), postUserRequest.getUserName()); + + em.persist(user); + return user.getUserId(); + } } diff --git a/src/main/java/space/space_spring/domain/Space.java b/src/main/java/space/space_spring/domain/Space.java new file mode 100644 index 00000000..0a5c5ea0 --- /dev/null +++ b/src/main/java/space/space_spring/domain/Space.java @@ -0,0 +1,22 @@ +package space.space_spring.domain; + +import jakarta.annotation.Nullable; +import jakarta.persistence.*; +import lombok.Getter; + +@Entity +@Getter +@Table(name = "Spaces") +public class Space extends BaseEntity { + + @Id @GeneratedValue + @Column(name = "space_id") + private Long spaceId; + + @Column(name = "space_name") + private String spaceName; + + @Column(name = "space_profile_img") + @Nullable + private String spaceProfileImg; +} diff --git a/src/main/java/space/space_spring/domain/User.java b/src/main/java/space/space_spring/domain/User.java index a9bf96a1..c742e92d 100644 --- a/src/main/java/space/space_spring/domain/User.java +++ b/src/main/java/space/space_spring/domain/User.java @@ -1,14 +1,17 @@ package space.space_spring.domain; +import jakarta.annotation.Nullable; import jakarta.persistence.*; +import lombok.Getter; @Entity @Table(name = "Users") +@Getter public class User extends BaseEntity { @Id @GeneratedValue @Column(name = "user_id") - private Long id; + private Long userId; @Column(name = "email") private String email; @@ -20,6 +23,13 @@ public class User extends BaseEntity { private String userName; @Column(name = "jwt_token") + @Nullable private String jwt; + public void saveUser(String email, String password, String userName) { + this.email = email; + this.password = password; + this.userName = userName; + } + } diff --git a/src/main/java/space/space_spring/domain/UserSpace.java b/src/main/java/space/space_spring/domain/UserSpace.java new file mode 100644 index 00000000..5d44ee9b --- /dev/null +++ b/src/main/java/space/space_spring/domain/UserSpace.java @@ -0,0 +1,42 @@ +package space.space_spring.domain; + +import jakarta.annotation.Nullable; +import jakarta.persistence.*; +import lombok.Getter; + +@Entity +@Getter +@Table(name = "User_Space") +public class UserSpace extends BaseEntity { + + @Id @GeneratedValue + @Column(name = "user_space_id") + private Long userSpaceId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "space_id") + private Space space; + + @Column(name = "user_name") + private String userName; + + @Column(name = "user_profile_img") + @Nullable + private String userProfileImg; + + @Column(name = "user_profile_msg") + @Nullable + private String userProfileMsg; + + @Column(name = "user_auth") + private String userAuth; + + @Column(name = "space_order") + private int spaceOrder; + + +} diff --git a/src/main/java/space/space_spring/dto/PostUserRequest.java b/src/main/java/space/space_spring/dto/PostUserRequest.java index 0c87e3cd..63d9a3f2 100644 --- a/src/main/java/space/space_spring/dto/PostUserRequest.java +++ b/src/main/java/space/space_spring/dto/PostUserRequest.java @@ -4,9 +4,12 @@ import lombok.NoArgsConstructor; import lombok.Setter; -@Getter @Setter @NoArgsConstructor +@Getter +@Setter +@NoArgsConstructor public class PostUserRequest { private String email; private String password; + private String userName; } diff --git a/src/main/java/space/space_spring/dto/PostUserResponse.java b/src/main/java/space/space_spring/dto/PostUserResponse.java new file mode 100644 index 00000000..44eb73d6 --- /dev/null +++ b/src/main/java/space/space_spring/dto/PostUserResponse.java @@ -0,0 +1,12 @@ +package space.space_spring.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class PostUserResponse { + + private Long userId; +// private String jwt; +} diff --git a/src/main/java/space/space_spring/service/UserService.java b/src/main/java/space/space_spring/service/UserService.java index 14159a31..911b2b59 100644 --- a/src/main/java/space/space_spring/service/UserService.java +++ b/src/main/java/space/space_spring/service/UserService.java @@ -3,10 +3,17 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import space.space_spring.dao.UserDao; +import space.space_spring.dto.PostUserRequest; +import space.space_spring.dto.PostUserResponse; @Service @RequiredArgsConstructor public class UserService { private final UserDao userDao; + + public PostUserResponse signup(PostUserRequest postUserRequest) { + Long savedUserId = userDao.saveUser(postUserRequest); + return new PostUserResponse(savedUserId); + } }