Skip to content

Commit

Permalink
Feat 유저 회원가입
Browse files Browse the repository at this point in the history
  • Loading branch information
seongjunnoh committed Jul 12, 2024
1 parent 1596b9b commit d2af01b
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 3 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,6 +23,9 @@ public class UserController {
/**
* 회원가입
*/
// @PostMapping("/signup")
@PostMapping("/signup")
public BaseResponse<PostUserResponse> signup(@RequestBody PostUserRequest postUserRequest) {
return new BaseResponse<>(userService.signup(postUserRequest));
}

}
15 changes: 15 additions & 0 deletions src/main/java/space/space_spring/dao/UserDao.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
22 changes: 22 additions & 0 deletions src/main/java/space/space_spring/domain/Space.java
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 11 additions & 1 deletion src/main/java/space/space_spring/domain/User.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}

}
42 changes: 42 additions & 0 deletions src/main/java/space/space_spring/domain/UserSpace.java
Original file line number Diff line number Diff line change
@@ -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;


}
5 changes: 4 additions & 1 deletion src/main/java/space/space_spring/dto/PostUserRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
12 changes: 12 additions & 0 deletions src/main/java/space/space_spring/dto/PostUserResponse.java
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 7 additions & 0 deletions src/main/java/space/space_spring/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit d2af01b

Please sign in to comment.