Skip to content

Commit b0696f2

Browse files
committed
Initial Commit
1 parent c3df6e4 commit b0696f2

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/main/java/com/webservice/mobile/app/service/impl/UserServiceImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,35 @@
33
import com.webservice.mobile.app.UserRepository;
44
import com.webservice.mobile.app.io.entity.UserEntity;
55
import com.webservice.mobile.app.service.UserService;
6+
import com.webservice.mobile.app.shared.Utils;
67
import com.webservice.mobile.app.shared.dto.UserDTO;
78
import org.springframework.beans.BeanUtils;
89
import org.springframework.beans.factory.annotation.Autowired;
910
import org.springframework.stereotype.Service;
11+
import sun.rmi.runtime.Log;
1012

1113
@Service
1214
public 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();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

0 commit comments

Comments
 (0)