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