Revize 0f69d5e8
Přidáno uživatelem Petr Urban před asi 2 roky(ů)
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/UserController.java | ||
---|---|---|
3 | 3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.User; |
4 | 4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.UserService; |
5 | 5 |
import org.springframework.beans.factory.annotation.Autowired; |
6 |
import org.springframework.http.ResponseEntity; |
|
6 | 7 |
import org.springframework.web.bind.annotation.*; |
7 | 8 |
|
8 | 9 |
/** |
... | ... | |
26 | 27 |
* @return message |
27 | 28 |
*/ |
28 | 29 |
@PostMapping(value = "/register") |
29 |
public String registerUser(@RequestBody User user) {
|
|
30 |
public ResponseEntity<String> registerUser(@RequestBody User user) {
|
|
30 | 31 |
int statusCode = userService.registerUser(user); |
31 |
return "user register"; |
|
32 |
|
|
33 |
if (statusCode == -1) { |
|
34 |
return ResponseEntity.badRequest().body("{\"message\": \"User already exists!\"}"); |
|
35 |
} else { |
|
36 |
return ResponseEntity.ok().body("{\"message\": \"Successfully signed up\"}"); |
|
37 |
} |
|
32 | 38 |
} |
33 | 39 |
|
34 | 40 |
/** |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/UserServiceImpl.java | ||
---|---|---|
40 | 40 |
if (userRepository.findByName(user.getName()) != null) { |
41 | 41 |
return -1; |
42 | 42 |
} |
43 |
|
|
44 |
user.setPassword(encryptPassword(password)); |
|
45 |
|
|
43 | 46 |
//save the user |
44 | 47 |
User u = userRepository.save(user); |
45 | 48 |
|
Také k dispozici: Unified diff
Changes by 1step