diff --git a/src/main/java/org/cmh/backend/authentication/controller/AuthenticationController.java b/src/main/java/org/cmh/backend/authentication/controller/AuthenticationController.java index 1f2c243..35568cd 100644 --- a/src/main/java/org/cmh/backend/authentication/controller/AuthenticationController.java +++ b/src/main/java/org/cmh/backend/authentication/controller/AuthenticationController.java @@ -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> register(@RequestBody RegisterRequest request) { - Map response = new HashMap<>(); + @PostMapping("/register") + public ResponseEntity 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; +} +