content: package com.example.demo.controllers;
  
  import jakarta.validation.Valid;
  
  import org.springframework.http.HttpStatus;
  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.RequestMapping;
  import org.springframework.web.bind.annotation.ResponseStatus;
  import org.springframework.web.bind.annotation.RestController;
  
  import com.example.demo.application.signup.SignupService;
  import com.example.demo.controllers.dtos.SignupRequestDto;
  import com.example.demo.controllers.dtos.SignupResultDto;
  import com.example.demo.exceptions.UserAlreadyExistsException;
  
  @RestController
  @RequestMapping("/users")
  public class UserController {
      private final SignupService signupService;
  
      public UserController(SignupService signupService) {
          this.signupService = signupService;
      }
  
      @PostMapping
      @ResponseStatus(HttpStatus.CREATED)
      public SignupResultDto signup(
              @Valid @RequestBody SignupRequestDto signupRequestDto) {
          String accessToken = signupService.signup(
                  signupRequestDto.username().trim(),
                  signupRequestDto.password().trim());
  
          return new SignupResultDto(accessToken);
      }
  
      @ExceptionHandler(UserAlreadyExistsException.class)
      @ResponseStatus(HttpStatus.BAD_REQUEST)
      public String alreadyExists() {
          return "User Already Exists";
      }
  }
  