content: package com.genuinecoder.springboottest.controller;
  
  import com.genuinecoder.springboottest.model.MyUser;
  import com.genuinecoder.springboottest.model.MyUserRepository;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  import org.springframework.security.crypto.password.PasswordEncoder;
  import org.springframework.web.ErrorResponse;
  import org.springframework.web.bind.annotation.ExceptionHandler;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RestController;
  import org.springframework.web.server.ServerErrorException;
  
  import java.time.Year;
  
  @RestController
  public class RegistrationController {
  
      private final MyUserRepository myUserRepository;
      private final PasswordEncoder passwordEncoder;
  
      public RegistrationController(MyUserRepository myUserRepository, PasswordEncoder passwordEncoder) {
          this.myUserRepository = myUserRepository;
          this.passwordEncoder = passwordEncoder;
      }
  
      @PostMapping("/register/user")
      public MyUser createUser(@RequestBody MyUser user) {
          user.setPassword(passwordEncoder.encode(user.getPassword()));
          return myUserRepository.save(user);
      }
  
      @ExceptionHandler(IllegalArgumentException.class)
      public ResponseEntity<ErrorResponse> handleException(IllegalArgumentException exp) {
          return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
                  .body(new ServerErrorException("NPE", exp));
      }
  
      int getYear() {
          return Year.now().getValue();
      }
  }
  