113 lines
4.7 KiB
Java
113 lines
4.7 KiB
Java
package restService;
|
|
|
|
import com.sun.org.apache.xpath.internal.operations.Bool;
|
|
import database.user.User;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import restImplementation.BlockchainQueryImplementation;
|
|
import restImplementation.DatabaseUserImplementation;
|
|
|
|
import javax.validation.Valid;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
//@RestController
|
|
//@RequestMapping(value = "/api/rest/user")
|
|
public class DatabaseUserResource {
|
|
|
|
/*
|
|
@RequestMapping(value = "/save", method = RequestMethod.POST,produces = "application/json")
|
|
@ResponseStatus(HttpStatus.CREATED)
|
|
public ResponseEntity<StringResponse> saveUser(@Valid @RequestBody User user){
|
|
try{
|
|
|
|
DatabaseUserImplementation databaseUserImplementation = new DatabaseUserImplementation();
|
|
Map<String,String> response = databaseUserImplementation.saveUser(user);
|
|
if(Boolean.parseBoolean(response.get("response"))){
|
|
StringResponse responseS = new StringResponse("Ok",response.get("userHash"));
|
|
|
|
BlockchainQueryImplementation blockchainQueryImplementation = new BlockchainQueryImplementation();
|
|
String[] userInfos = new String[]{response.get("userHash"),user.getName(),user.getFirstname(),""+user.getPhone(),user.getAssociation()};
|
|
blockchainQueryImplementation.registerUser(userInfos);
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(responseS);
|
|
}else {
|
|
StringResponse responseS = new StringResponse("User already exist");
|
|
return ResponseEntity.status(HttpStatus.FOUND).body(responseS);
|
|
}
|
|
}catch (Exception e){
|
|
StringResponse responseS = new StringResponse(e.getMessage());
|
|
return ResponseEntity.status(HttpStatus.CONFLICT).body(responseS);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/login", method = RequestMethod.POST,produces = "application/json")
|
|
@ResponseStatus(HttpStatus.OK)
|
|
public ResponseEntity<StringResponse> login(@Valid @RequestBody User user){
|
|
try{
|
|
DatabaseUserImplementation databaseUserImplementation = new DatabaseUserImplementation();
|
|
Map<String,String> response = databaseUserImplementation.userLogger(user);
|
|
switch (response.get("response")){
|
|
case "Not Exist" : {
|
|
StringResponse responseS = new StringResponse("User Not Found");
|
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(responseS);
|
|
}
|
|
case "Not Allowed" :{
|
|
StringResponse responseS = new StringResponse("Wrong Password!");
|
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(responseS);
|
|
}
|
|
case "" :{
|
|
StringResponse responseS = new StringResponse("Error");
|
|
return ResponseEntity.status(HttpStatus.CONFLICT).body(responseS);
|
|
}
|
|
case "Ok":{
|
|
StringResponse responseS = new StringResponse("Ok",response.get("userHash"));
|
|
return ResponseEntity.status(HttpStatus.OK).body(responseS);
|
|
}
|
|
default:{
|
|
StringResponse responseS = new StringResponse("Error");
|
|
return ResponseEntity.status(HttpStatus.CONFLICT).body(responseS);
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
StringResponse responseS = new StringResponse(e.getMessage());
|
|
return ResponseEntity.status(HttpStatus.CONFLICT).body(responseS);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping(value = "/get", produces = "application/json")
|
|
@ResponseBody
|
|
public ResponseEntity<User> getUser(@RequestBody User user){
|
|
try{
|
|
DatabaseUserImplementation databaseUserImplementation = new DatabaseUserImplementation();
|
|
User response = databaseUserImplementation.getUser(user.getEmail(), user.getPassword());
|
|
if(response != null){
|
|
User userResponse = new User();
|
|
userResponse.setUser_hash(response.getUser_hash());
|
|
userResponse.setUserId(response.getUserId());
|
|
return ResponseEntity.status(HttpStatus.OK).body(userResponse);
|
|
}else{
|
|
return new ResponseEntity("Error", HttpStatus.NOT_FOUND);
|
|
}
|
|
}catch (Exception e){
|
|
return new ResponseEntity(e.getMessage(), HttpStatus.CONFLICT);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping(value = "/update")
|
|
@ResponseStatus(HttpStatus.OK)
|
|
public ResponseEntity updateUser(@RequestBody User user){
|
|
return new ResponseEntity(null, HttpStatus.OK);
|
|
}
|
|
*/
|
|
|
|
}
|