增加Userdto传递用户注册信息
This commit is contained in:
@ -4,6 +4,7 @@ import co.jp.app.common.ApiResponse;
|
|||||||
import co.jp.app.common.ResultCode;
|
import co.jp.app.common.ResultCode;
|
||||||
import co.jp.app.dto.LoginDto;
|
import co.jp.app.dto.LoginDto;
|
||||||
import co.jp.app.dto.RegistrationDto;
|
import co.jp.app.dto.RegistrationDto;
|
||||||
|
import co.jp.app.dto.UserDto;
|
||||||
import co.jp.app.service.JwtService;
|
import co.jp.app.service.JwtService;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@ -37,15 +38,20 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/register")
|
@PostMapping("/register")
|
||||||
public ResponseEntity<?> registerUser(@Valid @RequestBody RegistrationDto registrationDto) {
|
public ResponseEntity<ApiResponse<UserDto>> registerUser(@Valid @RequestBody RegistrationDto registrationDto) {
|
||||||
|
|
||||||
UserEntity registeredUser = userService.registerNewUser(registrationDto);
|
UserEntity registeredUser = userService.registerNewUser(registrationDto);
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(ApiResponse.success(registeredUser.getEmail()));
|
UserDto userDto = new UserDto();
|
||||||
|
|
||||||
|
userDto.setEmail(registeredUser.getEmail());
|
||||||
|
userDto.setName(registeredUser.getName());
|
||||||
|
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).body(ApiResponse.success(userDto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public ResponseEntity<?> authenticateUser(@Valid @RequestBody LoginDto loginDto) {
|
public ResponseEntity<ApiResponse<Map<String, String>>> authenticateUser(@Valid @RequestBody LoginDto loginDto) {
|
||||||
|
|
||||||
Authentication authentication = authenticationManager.authenticate(
|
Authentication authentication = authenticationManager.authenticate(
|
||||||
new UsernamePasswordAuthenticationToken(loginDto.getEmail(), loginDto.getPassword())
|
new UsernamePasswordAuthenticationToken(loginDto.getEmail(), loginDto.getPassword())
|
||||||
|
24
src/main/java/co/jp/app/dto/UserDto.java
Normal file
24
src/main/java/co/jp/app/dto/UserDto.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package co.jp.app.dto;
|
||||||
|
|
||||||
|
public class UserDto {
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user