fix lazy big

This commit is contained in:
yannick.blanken@csc-online.eu 2022-05-27 09:23:22 +02:00
parent 53e5b33402
commit 013c46f533
5 changed files with 82 additions and 4 deletions

View File

@ -30,10 +30,10 @@ public class UserEntity extends AbstractEntity{
@OneToMany(fetch = FetchType.EAGER, mappedBy = "user", cascade = CascadeType.ALL)
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user", cascade = CascadeType.ALL)
private List<CustomerDeviceEntity> customerDeviceEntities;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "user", cascade = CascadeType.ALL)
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user", cascade = CascadeType.ALL)
private List<CustomerVehicleEntity> customerVehicleEntities;

View File

@ -1,9 +1,11 @@
package eu.csc.ODPAppVehOwnServer.persistence.services;
import eu.csc.ODPAppVehOwnServer.persistence.entity.UserEntity;
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.DeviceArticleEntity;
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.DeviceEntity;
import eu.csc.ODPAppVehOwnServer.persistence.respository.DeviceArticleRepository;
import eu.csc.ODPAppVehOwnServer.persistence.respository.DeviceRepository;
import eu.csc.ODPAppVehOwnServer.persistence.respository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -17,6 +19,23 @@ public class CustomerService {
private UtilsService utilsService;
@Autowired
private DeviceService deviceService;
private UserRepository userRepository;
public List<UserEntity> findAll() {
return userRepository.findAll();
}
public UserEntity addCustomer(String email, String password) {
var user = new UserEntity();
user.setEmail(email);
user.setPassword(password);
userRepository.save(user);
return user;
}
}

View File

@ -1,11 +1,13 @@
package eu.csc.ODPAppVehOwnServer.com;
import lombok.ToString;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.util.Collection;
@ToString
public class JwtAuthentication implements Authentication {
private final String token;
private UserDetails principal;
@ -39,7 +41,7 @@ public class JwtAuthentication implements Authentication {
@Override
public boolean isAuthenticated() {
return false;
return true;
}
@Override

View File

@ -1,6 +1,10 @@
package eu.csc.ODPAppVehOwnServer.controller.registration;
import eu.csc.ODPAppVehOwnServer.controller.AbstractRestController;
import lombok.var;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -8,5 +12,15 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("reg/vehicles")
public class VehicleRegistrationController extends AbstractRestController {
@GetMapping
public ResponseEntity getUserVehicles(){
var user = getLoggedInUser();
return ResponseEntity.ok(user);
}
}

View File

@ -0,0 +1,43 @@
package eu.csc.ODPAppVehOwnServer.shell;
import eu.csc.ODPAppVehOwnServer.persistence.services.CustomerService;
import eu.csc.ODPAppVehOwnServer.persistence.services.DeviceService;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;
@ShellComponent
public class UserCommands extends BaseCommands{
@Autowired
private CustomerService customerService;
@Autowired
private PasswordEncoder passwordEncoder;
@ShellMethod(value = "list Customers", key = {"c_l"})
public String listVehicles(){
for (var item:customerService.findAll()
) {
addMessageString(item.toString());
}
return getMessageString();
}
@ShellMethod(value = "add Customer", key = {"c_a", "c-a"})
public String addCustomer(String email, String password){
addMessageString(customerService.addCustomer(email, passwordEncoder.encode(password)).toString());
return getMessageString();
}
}