-+-+-
This commit is contained in:
parent
d1b53d51b6
commit
537fffe177
@ -112,7 +112,6 @@ public class GameClientMvcController {
|
||||
}
|
||||
|
||||
@PostMapping(value = {"", "/{id}"})
|
||||
@Secured({UserRole.AsString.ADMIN})
|
||||
public String saveClient(@PathVariable(required = false) Long id,
|
||||
@ModelAttribute @Valid SupportClientDTO clientDTO,
|
||||
BindingResult bindingResult,
|
||||
|
@ -1,10 +1,5 @@
|
||||
package premium_store.model;
|
||||
|
||||
import org.h2.engine.User;
|
||||
import premium_store.controller.DTO.ClientDTO;
|
||||
import premium_store.controller.DTO.TankDTO;
|
||||
import premium_store.controller.DTO.UserSignupDto;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -30,7 +25,7 @@ public class GameClient {
|
||||
@Column(name = "balance")
|
||||
private Integer balance;
|
||||
|
||||
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
|
||||
@OneToMany(fetch = FetchType.EAGER)
|
||||
private List<Tank> tanks = new ArrayList<>();
|
||||
|
||||
private UserRole role;
|
||||
@ -89,14 +84,10 @@ public class GameClient {
|
||||
return tanks;
|
||||
}
|
||||
|
||||
public void setTank(Tank tank){
|
||||
public void setTanks(Tank tank){
|
||||
this.tanks.add(tank);
|
||||
}
|
||||
|
||||
public void setTanks(List<Tank> tanks){
|
||||
this.tanks = tanks;
|
||||
}
|
||||
|
||||
public UserRole getRole() {
|
||||
return role;
|
||||
}
|
||||
@ -116,12 +107,12 @@ public class GameClient {
|
||||
|
||||
GameClient gameClient = (GameClient) o;
|
||||
|
||||
return Objects.equals(id, gameClient.id) && Objects.equals(login, gameClient.login);
|
||||
return Objects.equals(id, gameClient.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, login);
|
||||
return Objects.hash(id);
|
||||
}
|
||||
|
||||
//преобразование данных по объекту в строчку
|
||||
|
@ -112,8 +112,8 @@ public class GameClientService implements UserDetailsService {
|
||||
currentGameClient.setBalance(newBalance);
|
||||
}
|
||||
|
||||
if(newTank != null){
|
||||
currentGameClient.setTank(newTank);
|
||||
if(newTank != null && !currentGameClient.getTanks().contains(newTank)){
|
||||
currentGameClient.setTanks(newTank);
|
||||
}
|
||||
|
||||
return gameClientRepository.save(currentGameClient);
|
||||
@ -137,8 +137,8 @@ public class GameClientService implements UserDetailsService {
|
||||
currentGameClient.setEmail(clientDTO.getEmail());
|
||||
currentGameClient.setBalance(clientDTO.getBalance());
|
||||
|
||||
if(clientDTO.getTankId() != null){
|
||||
currentGameClient.setTank(tankRepository.getById(clientDTO.getTankId()));
|
||||
if(clientDTO.getTankId() != null && !currentGameClient.getTanks().contains(tankRepository.getById(clientDTO.getTankId()))){
|
||||
currentGameClient.setTanks(tankRepository.getById(clientDTO.getTankId()));
|
||||
}
|
||||
|
||||
return gameClientRepository.save(currentGameClient);
|
||||
@ -162,9 +162,11 @@ public class GameClientService implements UserDetailsService {
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
final GameClient clientEntity = findByLogin(username);
|
||||
|
||||
if (clientEntity == null) {
|
||||
throw new UsernameNotFoundException(username);
|
||||
}
|
||||
|
||||
return new org.springframework.security.core.userdetails.User(
|
||||
clientEntity.getLogin(), clientEntity.getPassword(), Collections.singleton(clientEntity.getRole()));
|
||||
}
|
||||
|
@ -46,7 +46,7 @@
|
||||
required="true"
|
||||
/>
|
||||
<label for="name" class="form-label">Танк: </label>
|
||||
<select id="tank" class="form-select" th:field="${supportClientDTO.tankId}" required="true">
|
||||
<select id="level" class="form-select" th:field="${supportClientDTO.tankId}" required="true">
|
||||
<option th:each="value: ${tanks}"
|
||||
th:value="${value.id}"
|
||||
th:text="${value.name}">
|
||||
|
Loading…
x
Reference in New Issue
Block a user