This commit is contained in:
GME 2019-03-30 19:58:41 +01:00
parent 26ed8856f2
commit ecd98a7171
4 changed files with 47 additions and 19 deletions

View file

@ -55,6 +55,20 @@ public class User {
this.approved = approved; this.approved = approved;
} }
public User(String name, String firstname,String user_hash, String email, String password, long creation_date, long modification_date, long phone, String association, boolean verified, boolean approved) {
this.name = name;
this.firstname = firstname;
this.user_hash = user_hash;
this.email = email;
this.password = password;
this.creation_date = creation_date;
this.modification_date = modification_date;
this.phone = phone;
this.association = association;
this.verified = verified;
this.approved = approved;
}
public User(String name, String firstname, String user_hash, int phone, String association){ public User(String name, String firstname, String user_hash, int phone, String association){
this.name = name; this.name = name;
this.firstname = firstname; this.firstname = firstname;
@ -68,25 +82,22 @@ public class User {
public int getUserId() { public int getUserId() {
return userId; return userId;
} }
public void setUserId(int userId) {this.userId = userId;} public void setUserId(int userId) {this.userId = userId;}
public String getName() { public String getName() {
return name; return name;
} }
public void setUser_hash(String user_hash){this.user_hash = user_hash;}
public String getUser_hash(){return user_hash;}
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public String getUser_hash(){return user_hash;}
public void setUser_hash(String user_hash){this.user_hash = user_hash;}
public String getFirstname() { public String getFirstname() {
return firstname; return firstname;
} }
public void setFirstname(String firstname) { public void setFirstname(String firstname) {
this.firstname = firstname; this.firstname = firstname;
} }
@ -94,7 +105,6 @@ public class User {
public String getEmail() { public String getEmail() {
return email; return email;
} }
public void setEmail(String email) { public void setEmail(String email) {
this.email = email; this.email = email;
} }
@ -102,7 +112,6 @@ public class User {
public String getPassword() { public String getPassword() {
return password; return password;
} }
public void setPassword(String password) { public void setPassword(String password) {
this.password = password; this.password = password;
} }
@ -110,7 +119,6 @@ public class User {
public long getCreation_date() { public long getCreation_date() {
return creation_date; return creation_date;
} }
public void setCreation_date(long creation_date) { public void setCreation_date(long creation_date) {
this.creation_date = creation_date; this.creation_date = creation_date;
} }
@ -118,19 +126,19 @@ public class User {
public long getModification_date() { public long getModification_date() {
return modification_date; return modification_date;
} }
public void setModification_date(long modification_date) { public void setModification_date(long modification_date) {
this.modification_date = modification_date; this.modification_date = modification_date;
} }
public long getPhone(){return phone;} public long getPhone(){return phone;}
public void setPhone(int phone){this.phone=phone;} public void setPhone(int phone){this.phone=phone;}
public String getAssociation(){return association;}
public void setAssociation(){this.association=association;}
public boolean isVerified() { public boolean isVerified() {
return verified; return verified;
} }
public void setVerified(boolean verified) { public void setVerified(boolean verified) {
this.verified = verified; this.verified = verified;
} }
@ -138,7 +146,6 @@ public class User {
public boolean isApproved() { public boolean isApproved() {
return approved; return approved;
} }
public void setApproved(boolean approved) { public void setApproved(boolean approved) {
this.approved = approved; this.approved = approved;
} }
@ -153,6 +160,8 @@ public class User {
", password='" + password + '\'' + ", password='" + password + '\'' +
", creation_date=" + creation_date + ", creation_date=" + creation_date +
", modification_date=" + modification_date + ", modification_date=" + modification_date +
", phone= "+phone+
", association= "+association+
", verified=" + verified + ", verified=" + verified +
", approved=" + approved + ", approved=" + approved +
", user_hash='" + user_hash + '\'' + ", user_hash='" + user_hash + '\'' +

View file

@ -3,7 +3,6 @@ package restImplementation;
import blockchain.query.QueryWrapper; import blockchain.query.QueryWrapper;
import blockchain.query.TransactionWrapper; import blockchain.query.TransactionWrapper;
import org.hyperledger.fabric.sdk.BlockEvent; import org.hyperledger.fabric.sdk.BlockEvent;
import javax.json.Json; import javax.json.Json;
import javax.json.JsonArray; import javax.json.JsonArray;
import javax.json.JsonObject; import javax.json.JsonObject;
@ -72,9 +71,9 @@ public class BlockchainQueryImplementation {
} }
public void registerUser(List<String> userInfo){ public void registerUser(String[] userInfo){
TransactionWrapper transactionWrapper = new TransactionWrapper(); TransactionWrapper transactionWrapper = new TransactionWrapper();
transactionWrapper.sendTransaction("registerUser",new String[]{userInfo.get(0),userInfo.get(1),userInfo.get(2),userInfo.get(3),userInfo.get(4)}); transactionWrapper.sendTransaction("registerUser",userInfo);
} }

View file

@ -27,15 +27,28 @@ public class BlockchainQueryResource {
} }
} }
/* /*
@RequestMapping(value = "/registerUser", method = RequestMethod.POST, produces = "application/json") @RequestMapping(value = "/registerUser", method = RequestMethod.POST, produces = "application/json")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
public ResponseEntity<StringResponse> login(@Valid @RequestBody User user){ public ResponseEntity<StringResponse> registerUser(@Valid @RequestBody User user){
try{
BlockchainQueryImplementation blockchainQueryImplementation = new BlockchainQueryImplementation();
String[] userInfos = new String[]{user.getUser_hash(),user.getName(),user.getFirstname(),""+user.getPhone(),user.getAssociation()};
blockchainQueryImplementation.registerUser(userInfos);
StringResponse response = new StringResponse("OK");
return ResponseEntity.status(HttpStatus.OK).body(response);
}catch (Exception e){
StringResponse response = new StringResponse("Error: "+e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}
} }
*/ */
} }

View file

@ -6,6 +6,7 @@ import database.user.User;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import restImplementation.BlockchainQueryImplementation;
import restImplementation.DatabaseUserImplementation; import restImplementation.DatabaseUserImplementation;
import javax.validation.Valid; import javax.validation.Valid;
@ -20,10 +21,16 @@ public class DatabaseUserResource {
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
public ResponseEntity<StringResponse> saveUser(@Valid @RequestBody User user){ public ResponseEntity<StringResponse> saveUser(@Valid @RequestBody User user){
try{ try{
DatabaseUserImplementation databaseUserImplementation = new DatabaseUserImplementation(); DatabaseUserImplementation databaseUserImplementation = new DatabaseUserImplementation();
Map<String,String> response = databaseUserImplementation.saveUser(user); Map<String,String> response = databaseUserImplementation.saveUser(user);
if(Boolean.parseBoolean(response.get("response"))){ if(Boolean.parseBoolean(response.get("response"))){
StringResponse responseS = new StringResponse("Ok",response.get("userHash")); 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); return ResponseEntity.status(HttpStatus.OK).body(responseS);
}else { }else {
StringResponse responseS = new StringResponse("User already exist"); StringResponse responseS = new StringResponse("User already exist");