package com.awesometickets.business.services;

import com.awesometickets.business.entities.User;
import com.awesometickets.business.entities.repositories.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserRepository userRepo;

    public void createUserWithPhoneNum(String phoneNum) {
        if (!isPhoneNumExist(phoneNum)) {
            User user = new User();
            user.setPhoneNum(phoneNum);
            user.setRemainPurchase(4);
            userRepo.save(user);
        }
    }

    public boolean isPhoneNumExist(String phoneNum) {
        return userRepo.findByPhoneNum(phoneNum).size() > 0;
    }
}

@@ -363,16 +363,181 @@
 rRepo;%0A%0A
+    /**%0A     * Create a user with his phone number, do nothing if the phone number exists.%0A     *%0A     * @param phoneNum The phone number to save a new user%0A     */%0A
     publ
@@ -578,32 +578,32 @@
 ing phoneNum) %7B%0A
-
         if (!isP
@@ -704,16 +704,67 @@
 neNum);%0A
+            // The default purchase count is four.%0A
         
@@ -844,16 +844,127 @@
 %0A    %7D%0A%0A
+    /**%0A     * Check if a phone number exists.%0A     *%0A     * @param phoneNum The phone number to check%0A     */%0A
     publ

add user after a phone number check