-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] 로그인 구현
- Loading branch information
Showing
25 changed files
with
984 additions
and
18 deletions.
There are no files selected for viewing
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
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
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
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
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
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,14 @@ | ||
package com.leets.xcellentbe.domain.user; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum Role { | ||
GUEST("ROLE_GUEST", "비회원"), | ||
USER("ROLE_USER", "회원"); | ||
|
||
private final String key; | ||
private final String title; | ||
} |
27 changes: 26 additions & 1 deletion
27
src/main/java/com/leets/xcellentbe/domain/user/controller/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 |
---|---|---|
@@ -1,12 +1,37 @@ | ||
package com.leets.xcellentbe.domain.user.controller; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
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 com.leets.xcellentbe.domain.user.dto.UserLoginRequestDto; | ||
import com.leets.xcellentbe.domain.user.dto.UserSignUpRequestDto; | ||
import com.leets.xcellentbe.domain.user.service.UserService; | ||
import com.leets.xcellentbe.global.response.GlobalResponseDto; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequestMapping("/user") | ||
@RequestMapping("/api/user") | ||
@RequiredArgsConstructor | ||
public class UserController { | ||
// private final UserService userService; | ||
// | ||
// @PostMapping("/auth/register") | ||
// @Operation(summary = "회원가입", description = "회원가입을 합니다.") | ||
// public ResponseEntity<GlobalResponseDto<String>> register(@RequestBody UserSignUpRequestDto userSignUpRequestDto) { | ||
// return ResponseEntity.status(HttpStatus.CREATED) | ||
// .body(GlobalResponseDto.success(userService.register(userSignUpRequestDto), HttpStatus.CREATED.value())); | ||
// } | ||
// | ||
// @Operation(summary = "로그인", description = "사용자의 이메일과 비밀번호로 로그인합니다.") | ||
// @PostMapping("/auth/login") | ||
// public String login(@RequestBody UserLoginRequestDto userLoginRequestDto) { | ||
// // 로그인 로직 처리 | ||
// return "로그인 성공"; | ||
// } | ||
} |
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
5 changes: 5 additions & 0 deletions
5
src/main/java/com/leets/xcellentbe/domain/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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
package com.leets.xcellentbe.domain.user.domain.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.leets.xcellentbe.domain.user.domain.User; | ||
|
||
public interface UserRepository extends JpaRepository<User, Long> { | ||
Optional<User> findByEmail(String email); | ||
Optional<User> findByCustomId(String customId);; | ||
Optional<User> findByRefreshToken(String refreshToken); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/leets/xcellentbe/domain/user/dto/UserLoginRequestDto.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,12 @@ | ||
package com.leets.xcellentbe.domain.user.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor | ||
@Getter | ||
public class UserLoginRequestDto { | ||
private String email; | ||
private String password; | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/leets/xcellentbe/domain/user/dto/UserSignUpRequestDto.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,21 @@ | ||
package com.leets.xcellentbe.domain.user.dto; | ||
|
||
import java.time.LocalDate; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor | ||
@Getter | ||
public class UserSignUpRequestDto { | ||
|
||
private String email; | ||
private String customId; | ||
private String userName; | ||
private String password; | ||
private String phoneNumber; | ||
private int userBirthYear; | ||
private int userBirthMonth; | ||
private int userBirthDay; | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/leets/xcellentbe/domain/user/exception/UserAlreadyExistsException.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,10 @@ | ||
package com.leets.xcellentbe.domain.user.exception; | ||
|
||
import com.leets.xcellentbe.global.error.ErrorCode; | ||
import com.leets.xcellentbe.global.error.exception.CommonException; | ||
|
||
public class UserAlreadyExistsException extends CommonException { | ||
public UserAlreadyExistsException() { | ||
super(ErrorCode.USER_ALREADY_EXISTS); | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
src/main/java/com/leets/xcellentbe/domain/user/service/UserService.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,41 @@ | ||
package com.leets.xcellentbe.domain.user.service; | ||
|
||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.leets.xcellentbe.domain.user.domain.User; | ||
import com.leets.xcellentbe.domain.user.exception.UserAlreadyExistsException; | ||
|
||
import com.leets.xcellentbe.domain.user.domain.repository.UserRepository; | ||
import com.leets.xcellentbe.domain.user.dto.UserSignUpRequestDto; | ||
|
||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class UserService { | ||
|
||
private final UserRepository userRepository; | ||
private final PasswordEncoder passwordEncoder; | ||
|
||
public String register(UserSignUpRequestDto userSignUpRequestDto) { | ||
|
||
if (userRepository.findByEmail(userSignUpRequestDto.getEmail()).isPresent()) { | ||
throw new UserAlreadyExistsException(); | ||
} | ||
if (userRepository.findByCustomId(userSignUpRequestDto.getCustomId()).isPresent()) { | ||
throw new UserAlreadyExistsException(); | ||
} | ||
|
||
User user = User.create(userSignUpRequestDto.getCustomId(), userSignUpRequestDto.getEmail(), userSignUpRequestDto.getUserName(), | ||
userSignUpRequestDto.getPassword(), userSignUpRequestDto.getPhoneNumber(), userSignUpRequestDto.getUserBirthYear(), userSignUpRequestDto.getUserBirthDay(), userSignUpRequestDto.getUserBirthMonth()); | ||
|
||
user.passwordEncode(passwordEncoder); | ||
userRepository.save(user); | ||
|
||
return "회원가입이 완료되었습니다."; | ||
} | ||
|
||
} |
Oops, something went wrong.