-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUsuarioController.java
More file actions
50 lines (45 loc) · 1.79 KB
/
Copy pathUsuarioController.java
File metadata and controls
50 lines (45 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package application.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import application.record.GenericResponse;
import application.record.UsuarioDTO;
import application.service.UsuarioService;
@RestController
@RequestMapping("/usuarios")
public class UsuarioController {
@Autowired
private UsuarioService usuarioService;
@PostMapping
public GenericResponse insert(@RequestBody UsuarioDTO usuario) {
// if(usuario.nomeDeUsuario().trim().length() == 0) {
// throw new ResponseStatusException(
// HttpStatus.BAD_REQUEST, "Nome de Usuário Não Definido"
// );
// }
// if(usuario.senha().trim().length() == 0) {
// throw new ResponseStatusException(
// HttpStatus.BAD_REQUEST, "Senha de Usuário Não Definido"
// );
// }
String returnMessage = "";
if(usuario.nomeDeUsuario().trim().length() == 0) {
returnMessage = "Nome de Usuário Não Definido";
}
if(usuario.senha().trim().length() == 0) {
if(returnMessage.length() > 0)
returnMessage += ", ";
returnMessage += "Senha de Usuário Não Definido";
}
if(returnMessage.length() > 0) {
throw new ResponseStatusException(
HttpStatus.BAD_REQUEST, returnMessage
);
}
return usuarioService.insert(usuario);
}
}