-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jhsong76
committed
Jan 2, 2024
1 parent
2fe619d
commit 18a2b97
Showing
10 changed files
with
143 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.hackerton.demo.domain.User; | ||
|
||
import com.hackerton.demo.domain.Keyword.Keyword; | ||
import com.hackerton.demo.domain.common.BaseEntity; | ||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.OneToMany; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PUBLIC) | ||
@AllArgsConstructor | ||
public class User extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "user_id") | ||
private Long id; | ||
|
||
private String nickName; | ||
|
||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL) | ||
private List<Keyword> keywordList = new ArrayList<>(); | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/hackerton/demo/domain/User/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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.hackerton.demo.domain.User; | ||
|
||
import com.hackerton.demo.domain.User.request.LoginDto; | ||
import com.hackerton.demo.domain.common.ApiResponse; | ||
import com.hackerton.demo.domain.common.ApiResponseStatus; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import lombok.RequiredArgsConstructor; | ||
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; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/users") | ||
public class UserController { | ||
private final UserService userService; | ||
|
||
@PostMapping("/sign-ip") | ||
@Operation(summary = "기본 회원가입 API", description = "닉네임을 입력받아 회원가입을 진행합니다.") | ||
@ApiResponses({ | ||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "SIGN_IN_SUCCESS", description = "로그인 성공"), | ||
}) | ||
public ResponseEntity<ApiResponse<UserDto>> login(@RequestBody LoginDto request){ | ||
ApiResponse<UserDto> response = new ApiResponse<>(ApiResponseStatus.SIGN_IN_SUCCESS, userService.login(request)); | ||
return ResponseEntity.ok(response); | ||
} | ||
} |
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,11 @@ | ||
package com.hackerton.demo.domain.User; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder | ||
@Getter | ||
public class UserDto { | ||
private Long id; | ||
private String nickName; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/hackerton/demo/domain/User/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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.hackerton.demo.domain.User; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserRepository extends JpaRepository<User, Long> { | ||
|
||
boolean existsByNickName(String nickName); | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/hackerton/demo/domain/User/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,32 @@ | ||
package com.hackerton.demo.domain.User; | ||
|
||
import com.hackerton.demo.domain.User.request.LoginDto; | ||
import com.hackerton.demo.domain.common.ApiResponse; | ||
import com.hackerton.demo.domain.common.ApiResponseStatus; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class UserService { | ||
private final UserRepository userRepository; | ||
|
||
@Transactional | ||
public UserDto login(LoginDto request) { | ||
|
||
User user = new User(); | ||
user.setNickName(request.getNickName()); | ||
|
||
userRepository.save(user); | ||
|
||
UserDto userDto = UserDto.builder() | ||
.id(user.getId()) | ||
.nickName(user.getNickName()) | ||
.build(); | ||
|
||
return userDto; | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/hackerton/demo/domain/User/request/LoginDto.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.hackerton.demo.domain.User.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class LoginDto { | ||
@NotBlank(message = "닉네임을 입력해주세요.") | ||
private String nickName; | ||
} |
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