package urlshortener.aeternum.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import urlshortener.common.repository.UserRepository;

import javax.servlet.http.HttpServletRequest;

@RestController
public class SignUp {
    private static final Logger LOG = LoggerFactory
        .getLogger(SignUp.class);

    @Autowired
    protected UserRepository userRepository;

    @RequestMapping(value = "/signUp", method = RequestMethod.POST)
    public ResponseEntity<String> signUp(@RequestParam("user") String username,
                                           @RequestParam("email") String email,
                                           @RequestParam("pass") String pass,
                                           @RequestParam("repass") String repass,
                                           HttpServletRequest request) {
        // TODO
        if (true) {
            LOG.info("System statistics");
            return new ResponseEntity<String>("\"Usuario creado correctamente\"", HttpStatus
                .CREATED);
        } else {
            LOG.info("Error to get the system statistics");
            return new ResponseEntity<String>("\"Usuario no creado\"",HttpStatus.BAD_REQUEST);
        }
    }
}

@@ -292,16 +292,56 @@
 ion.*;%0A%0A
+import urlshortener.common.domain.User;%0A
 import u
@@ -432,16 +432,38 @@
 Request;
+%0Aimport java.sql.Date;
 %0A%0A@RestC
@@ -1103,24 +1103,25 @@
 uest) %7B%0A
+%0A
         
 // TODO%0A
@@ -1116,32 +1116,264 @@
     
-// TODO%0A        if (true
+if ((username == null) %7C%7C (username.trim().equals(%22%22))) %7B%0A            LOG.info(%22Invalid username.%22);%0A            return new ResponseEntity%3CString%3E(%22%5C%22Invalid username.%5C%22%22,HttpStatus.BAD_REQUEST);%0A        %7D else if((pass == null) %7C%7C (pass.trim().equals(%22%22))
 ) %7B%0A
@@ -1398,25 +1398,25 @@
 fo(%22
-System statistics
+Invalid password.
 %22);%0A
@@ -1468,41 +1468,243 @@
 (%22%5C%22
-Usuario creado correctamente
+Invalid password.%5C%22%22,HttpStatus.BAD_REQUEST);%0A        %7D else if((repass == null) %7C%7C !repass.equals(pass)) %7B%0A            LOG.info(%22Passwords doesn't match.%22);%0A            return new ResponseEntity%3CString%3E(%22%5C%22Passwords doesn't match.
 %5C%22%22,
- 
 Http
@@ -1713,113 +1713,773 @@
 atus
-%0A                .CREATED);%0A        %7D else %7B%0A            LOG.info(%22Error to get the system statistics%22);%0A
+.BAD_REQUEST);%0A        %7D else if((email == null) %7C%7C (email.trim().equals(%22%22))) %7B%0A            LOG.info(%22Invalid email.%22);%0A            return new ResponseEntity%3CString%3E(%22%5C%22Invalid email.%5C%22%22,HttpStatus.BAD_REQUEST);%0A        %7D else %7B%0A            // check if user exists%0A            if (userRepository.findByName(username) != null) %7B%0A                LOG.info(%22User already exists.%22);%0A                return new ResponseEntity%3CString%3E(%22%5C%22User already exists.%5C%22%22,HttpStatus.BAD_REQUEST);%0A            %7D else %7B%0A                User user = new User(username, pass, email, true, new Date(System.currentTimeMillis()));%0A                user = userRepository.save(user);%0A                LOG.info(user!=null?%22%5B%22+user.getName()+%22%5D saved%22:%22%5B%22+user.getName()+%22%5D was not saved%22);%0A    
     
@@ -2529,23 +2529,32 @@
 %5C%22Us
-uario no
+er successfully
  crea
-do
+ted.
 %5C%22%22,
@@ -2560,37 +2560,47 @@
 ,HttpStatus.
-BAD_REQUEST);
+CREATED);%0A            %7D
 %0A        %7D%0A 

Add signUp funcionallity