Skip to content

Commit

Permalink
feat: 회원가입 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yslle committed Jul 4, 2024
1 parent a7345df commit a3d98f3
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 2 deletions.
29 changes: 29 additions & 0 deletions src/main/java/com/umc/dream/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.umc.dream.controller;

import com.umc.dream.apiPayload.ApiResponse;
import com.umc.dream.domain.User;
import com.umc.dream.dto.UserRequestDTO;
import com.umc.dream.dto.UserResponseDTO;
import com.umc.dream.service.UserService.UserService;
import com.umc.dream.converter.UserConverter;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
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;

@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class UserController {

private final UserService userService;

@Operation(summary = "회원가입 API")
@PostMapping("/join")
public ApiResponse<UserResponseDTO.JoinResultDTO> join(@RequestBody UserRequestDTO.JoinDto request){
User user = userService.join(request);
return ApiResponse.onSuccess(UserConverter.toJoinResultDTO(user));
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/umc/dream/converter/UserConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.umc.dream.converter;

import com.umc.dream.domain.User;
import com.umc.dream.domain.enums.Role;
import com.umc.dream.dto.UserRequestDTO;
import com.umc.dream.dto.UserResponseDTO;

import java.time.LocalDateTime;

public class UserConverter {
public static UserResponseDTO.JoinResultDTO toJoinResultDTO(User user) {
return UserResponseDTO.JoinResultDTO.builder()
.userId(user.getId())
.createdAt(LocalDateTime.now())
.build();
}


public static User toUser(UserRequestDTO.JoinDto joinDto) {
return User.builder()
.name(joinDto.getName())
.account(joinDto.getAccount())
.password(joinDto.getPassword())
.role(Role.NORMAL)
.build();
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/umc/dream/domain/Dream.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Dream extends BaseEntity {
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "users_id", nullable = false)
@JoinColumn(name = "user_id", nullable = false)
private User user;

private LocalDate date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Character extends BaseEntity {
public class People extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/umc/dream/dto/UserRequestDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.umc.dream.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;

public class UserRequestDTO {

@Getter
public static class JoinDto {
@NotBlank
String name;
@NotNull
String account;
@NotNull
String password;
@NotNull
String passwordConfirm;
}

}
21 changes: 21 additions & 0 deletions src/main/java/com/umc/dream/dto/UserResponseDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.umc.dream.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

public class UserResponseDTO {

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class JoinResultDTO{
Long userId;
LocalDateTime createdAt;
}

}
7 changes: 7 additions & 0 deletions src/main/java/com/umc/dream/repository/UserRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.umc.dream.repository;

import com.umc.dream.domain.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,8 @@
package com.umc.dream.service.UserService;

import com.umc.dream.domain.User;
import com.umc.dream.dto.UserRequestDTO;

public interface UserService {
User join(UserRequestDTO.JoinDto request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.umc.dream.service.UserService;

import com.umc.dream.converter.UserConverter;
import com.umc.dream.domain.User;
import com.umc.dream.dto.UserRequestDTO;
import com.umc.dream.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {

private final UserRepository userRepository;

@Override
public User join(UserRequestDTO.JoinDto request) {
User user = UserConverter.toUser(request);
return userRepository.save(user);
}

}

0 comments on commit a3d98f3

Please sign in to comment.