File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
src/main/java/com/webservice/mobile/app Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 33import com .webservice .mobile .app .UserRepository ;
44import com .webservice .mobile .app .io .entity .UserEntity ;
55import com .webservice .mobile .app .service .UserService ;
6+ import com .webservice .mobile .app .shared .Utils ;
67import com .webservice .mobile .app .shared .dto .UserDTO ;
78import org .springframework .beans .BeanUtils ;
89import org .springframework .beans .factory .annotation .Autowired ;
910import org .springframework .stereotype .Service ;
11+ import sun .rmi .runtime .Log ;
1012
1113@ Service
1214public class UserServiceImpl implements UserService {
1315
1416 @ Autowired
1517 UserRepository userRepository ;
1618
19+ @ Autowired
20+ Utils utils ;
21+
1722 @ Override
1823 public UserDTO createUser (UserDTO userDTO ) {
1924
2025
2126 if (userRepository .findUserByEmail (userDTO .getEmail ()) !=null )
2227 throw new RuntimeException ("Record Already Exists" );
2328
24-
2529 UserEntity userEntity = new UserEntity ();
2630 BeanUtils .copyProperties (userDTO ,userEntity );
2731
32+ String autoGeneratedPublicUserID = utils .generateUserId (30 );
33+ userEntity .setUserId (autoGeneratedPublicUserID );
2834 userEntity .setEncryptedPassword ("test" );
29- userEntity .setUserId ("testUserId" );
3035
3136 UserEntity storedUSerDeatils =userRepository .save (userEntity );
3237 UserDTO returnValue = new UserDTO ();
Original file line number Diff line number Diff line change 1+ package com .webservice .mobile .app .shared ;
2+
3+ import org .springframework .stereotype .Component ;
4+
5+ import java .util .Random ;
6+
7+ @ Component
8+ public class Utils {
9+
10+ private final Random RANDOM = new Random ();
11+ private final String ALPHABETS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ;
12+
13+ public String generateUserId (int length ){
14+ return generateRandomString (length );
15+
16+ }
17+
18+ private String generateRandomString (int length ) {
19+ StringBuilder returnValue = new StringBuilder (length );
20+ for (int i =0 ;i <length ;i ++){
21+ returnValue .append (ALPHABETS .charAt (RANDOM .nextInt (ALPHABETS .length ())));
22+
23+ }
24+ return new String (returnValue );
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments