通过DTO规范化数据交换
This commit is contained in:
parent
feec889732
commit
80ae2fb8d3
@ -1,6 +1,7 @@
|
||||
package org.cmh.backend.authentication.controller;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.cmh.backend.authentication.service.UserService;
|
||||
@ -12,9 +13,6 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
class AuthenticationController {
|
||||
|
||||
@ -26,17 +24,14 @@ class AuthenticationController {
|
||||
return "Hello SpringBoot!";
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
public ResponseEntity<Map<String, Object>> register(@RequestBody RegisterRequest request) {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
|
||||
@PostMapping("/register")
|
||||
public ResponseEntity<RegisterResponse> register(@RequestBody RegisterRequest request) {
|
||||
boolean isRegistered = userService.registerUser(request.getUsername(), request.getPassword(), request.getContactInfo());
|
||||
if (isRegistered) {
|
||||
response.put("message", "Registration successful!");
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
return new ResponseEntity<>(new RegisterResponse("Registration successful!"), HttpStatus.OK);
|
||||
} else {
|
||||
response.put("message", "Registration failed! User already exist");
|
||||
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
|
||||
return new ResponseEntity<>(new RegisterResponse("Registration failed! User already exist"), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,3 +47,10 @@ class RegisterRequest {
|
||||
private String contactInfo;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
class RegisterResponse {
|
||||
private String message;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user