Работа с сущностью Клиент. Добавление поля логин и пароль.
This commit is contained in:
parent
ce4fbf0aeb
commit
fc65e71ffa
@ -40,7 +40,6 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||||
http.headers().frameOptions().sameOrigin().and()
|
http.headers().frameOptions().sameOrigin().and()
|
||||||
@ -74,9 +73,4 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||||||
.requestMatchers("/templates/**")
|
.requestMatchers("/templates/**")
|
||||||
.requestMatchers("/webjars/**");
|
.requestMatchers("/webjars/**");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
|
||||||
auth.userDetailsService(userService);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -17,7 +17,7 @@ public class ClientDTO {
|
|||||||
|
|
||||||
public ClientDTO(GameClient gameClient){
|
public ClientDTO(GameClient gameClient){
|
||||||
this.id = gameClient.getId();
|
this.id = gameClient.getId();
|
||||||
this.nickName = gameClient.getNickName();
|
this.nickName = gameClient.getLogin();
|
||||||
this.email = gameClient.getEmail();
|
this.email = gameClient.getEmail();
|
||||||
this.balance = gameClient.getBalance();
|
this.balance = gameClient.getBalance();
|
||||||
this.tanks = gameClient.getTanks().stream()
|
this.tanks = gameClient.getTanks().stream()
|
||||||
|
@ -3,12 +3,11 @@ package premium_store.controller.DTO;
|
|||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import premium_store.model.GameClient;
|
import premium_store.model.GameClient;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
//класс, который соединяет танки клиента в одну строчку (нам так захотелось)
|
//класс, который соединяет танки клиента в одну строчку (нам так захотелось)
|
||||||
public class SupportClientDTO {
|
public class SupportClientDTO {
|
||||||
private long id;
|
private long id;
|
||||||
private String nickName;
|
private String login;
|
||||||
|
private String password;
|
||||||
private String email;
|
private String email;
|
||||||
private Integer balance;
|
private Integer balance;
|
||||||
private Long tankId;
|
private Long tankId;
|
||||||
@ -17,7 +16,8 @@ public class SupportClientDTO {
|
|||||||
|
|
||||||
public SupportClientDTO(GameClient gameClient){
|
public SupportClientDTO(GameClient gameClient){
|
||||||
this.id = gameClient.getId();
|
this.id = gameClient.getId();
|
||||||
this.nickName = gameClient.getNickName();
|
this.login = gameClient.getLogin();
|
||||||
|
this.password = gameClient.getPassword();
|
||||||
this.email = gameClient.getEmail();
|
this.email = gameClient.getEmail();
|
||||||
this.balance = gameClient.getBalance();
|
this.balance = gameClient.getBalance();
|
||||||
|
|
||||||
@ -38,12 +38,20 @@ public class SupportClientDTO {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNickName(){
|
public String getLogin(){
|
||||||
return nickName;
|
return login;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNickName(String nickName) {
|
public void setLogin(String login) {
|
||||||
this.nickName = nickName;
|
this.login = login;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword(){
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEmail(){
|
public String getEmail(){
|
||||||
|
@ -75,7 +75,7 @@ public class ClientMvcController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(id == null || id <= 0){
|
if(id == null || id <= 0){
|
||||||
gameClientService.addClient(clientDTO.getNickName(), clientDTO.getNickName(), clientDTO.getBalance());
|
gameClientService.addClient(clientDTO.getLogin(), clientDTO.getLogin(), clientDTO.getPassword(), clientDTO.getBalance());
|
||||||
} else {
|
} else {
|
||||||
gameClientService.updateClient(clientDTO);
|
gameClientService.updateClient(clientDTO);
|
||||||
}
|
}
|
||||||
|
@ -34,19 +34,21 @@ public class GameClientController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/")
|
@PostMapping("/")
|
||||||
public ClientDTO createClient(@RequestParam("nickName") String nickName,
|
public ClientDTO createClient(@RequestParam("login") String login,
|
||||||
|
@RequestParam("password") String password,
|
||||||
@RequestParam("email") String email,
|
@RequestParam("email") String email,
|
||||||
@RequestParam("balance") Integer balance) {
|
@RequestParam("balance") Integer balance) {
|
||||||
return new ClientDTO(gameClientService.addClient(nickName, email, balance));
|
return new ClientDTO(gameClientService.addClient(login, email, password, balance));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
public ClientDTO updateClient(@PathVariable Long id,
|
public ClientDTO updateClient(@PathVariable Long id,
|
||||||
@RequestParam("nickName") String nickName,
|
@RequestParam("login") String login,
|
||||||
|
@RequestParam("password") String password,
|
||||||
@RequestParam("email") String email,
|
@RequestParam("email") String email,
|
||||||
@RequestParam("balance") Integer balance,
|
@RequestParam("balance") Integer balance,
|
||||||
@RequestParam("tankId") Long tankId) {
|
@RequestParam("tankId") Long tankId) {
|
||||||
return new ClientDTO(gameClientService.updateClient(id, nickName, email, balance, tankService.findTank(tankId)));
|
return new ClientDTO(gameClientService.updateClient(id, login, password, email, balance, tankService.findTank(tankId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
|
@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import premium_store.controller.DTO.ClientDTO;
|
|
||||||
import premium_store.controller.DTO.UserSignupDto;
|
import premium_store.controller.DTO.UserSignupDto;
|
||||||
import premium_store.model.GameClient;
|
import premium_store.model.GameClient;
|
||||||
import premium_store.service.UserService;
|
import premium_store.service.UserService;
|
||||||
@ -43,7 +42,7 @@ public class UserSignupMvcController {
|
|||||||
try {
|
try {
|
||||||
final GameClient user = userService.createUser(
|
final GameClient user = userService.createUser(
|
||||||
userSignupDto.getLogin(), userSignupDto.getPassword(), userSignupDto.getPasswordConfirm());
|
userSignupDto.getLogin(), userSignupDto.getPassword(), userSignupDto.getPasswordConfirm());
|
||||||
return "redirect:/login?created=" + user.getNickName();
|
return "redirect:/login?created=" + user.getLogin();
|
||||||
} catch (ValidationException e) {
|
} catch (ValidationException e) {
|
||||||
model.addAttribute("errors", e.getMessage());
|
model.addAttribute("errors", e.getMessage());
|
||||||
return "signup";
|
return "signup";
|
||||||
|
@ -13,12 +13,15 @@ public class GameClient {
|
|||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(name = "nickName", nullable = false, length = 255)
|
@Column(name = "login", nullable = false, length = 255)
|
||||||
private String nickName;
|
private String login;
|
||||||
|
|
||||||
@Column(name = "email", nullable = false, length = 255)
|
@Column(name = "email", nullable = false, length = 255)
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
|
@Column(name = "password", nullable = false, length = 255)
|
||||||
|
private String password;
|
||||||
|
|
||||||
@Column(name = "balance")
|
@Column(name = "balance")
|
||||||
private Integer balance;
|
private Integer balance;
|
||||||
|
|
||||||
@ -27,9 +30,10 @@ public class GameClient {
|
|||||||
|
|
||||||
public GameClient(){ }
|
public GameClient(){ }
|
||||||
|
|
||||||
public GameClient(String nickName, String email, Integer balance){
|
public GameClient(String login, String email, String password, Integer balance){
|
||||||
this.nickName = nickName;
|
this.login = login;
|
||||||
this.email = email;
|
this.email = email;
|
||||||
|
this.password = password;
|
||||||
this.balance = balance;
|
this.balance = balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,12 +41,12 @@ public class GameClient {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNickName(){
|
public String getLogin(){
|
||||||
return nickName;
|
return login;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNickName(String nickName){
|
public void setLogin(String login){
|
||||||
this.nickName = nickName;
|
this.login = login;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEmail(){
|
public String getEmail(){
|
||||||
@ -53,6 +57,14 @@ public class GameClient {
|
|||||||
this.email = email;
|
this.email = email;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password){
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword(){
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getBalance(){
|
public Integer getBalance(){
|
||||||
return balance;
|
return balance;
|
||||||
}
|
}
|
||||||
@ -93,7 +105,7 @@ public class GameClient {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "Client{" +
|
return "Client{" +
|
||||||
"id=" + id +
|
"id=" + id +
|
||||||
", nickName='" + nickName + '\'' +
|
", nickName='" + login + '\'' +
|
||||||
", email='" + email + '\'' +
|
", email='" + email + '\'' +
|
||||||
", balance='" + balance + '\'' +
|
", balance='" + balance + '\'' +
|
||||||
", tanks='" + tanks.stream().map(Object::toString).collect(Collectors.joining(", ")) + '\'' +
|
", tanks='" + tanks.stream().map(Object::toString).collect(Collectors.joining(", ")) + '\'' +
|
||||||
|
@ -3,7 +3,6 @@ package premium_store.service;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import premium_store.controller.DTO.ClientDTO;
|
|
||||||
import premium_store.controller.DTO.SupportClientDTO;
|
import premium_store.controller.DTO.SupportClientDTO;
|
||||||
import premium_store.model.GameClient;
|
import premium_store.model.GameClient;
|
||||||
import premium_store.model.Tank;
|
import premium_store.model.Tank;
|
||||||
@ -28,8 +27,8 @@ public class GameClientService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public GameClient addClient(String newNickName, String newEmail, Integer newBallance) {
|
public GameClient addClient(String login, String newEmail, String password, Integer newBallance) {
|
||||||
final GameClient gameClient = new GameClient(newNickName, newEmail, newBallance);
|
final GameClient gameClient = new GameClient(login, newEmail, password, newBallance);
|
||||||
validatorUtil.validate(gameClient);
|
validatorUtil.validate(gameClient);
|
||||||
|
|
||||||
return gameClientRepository.save(gameClient);
|
return gameClientRepository.save(gameClient);
|
||||||
@ -48,15 +47,19 @@ public class GameClientService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public GameClient updateClient(Long id, String newNickName, String newEmail, Integer newBalance, Tank newTank) {
|
public GameClient updateClient(Long id, String login, String newPassword, String newEmail, Integer newBalance, Tank newTank) {
|
||||||
if (id <= 0) {
|
if (id <= 0) {
|
||||||
throw new IllegalArgumentException("Invalid id");
|
throw new IllegalArgumentException("Invalid id");
|
||||||
}
|
}
|
||||||
|
|
||||||
final GameClient currentGameClient = findClient(id);
|
final GameClient currentGameClient = findClient(id);
|
||||||
|
|
||||||
if (StringUtils.hasText(newNickName)){
|
if (StringUtils.hasText(login)){
|
||||||
currentGameClient.setNickName(newNickName);
|
currentGameClient.setLogin(login);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(StringUtils.hasText(newPassword)){
|
||||||
|
currentGameClient.setPassword(newPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StringUtils.hasText(newEmail)){
|
if(StringUtils.hasText(newEmail)){
|
||||||
@ -82,7 +85,8 @@ public class GameClientService {
|
|||||||
|
|
||||||
final GameClient currentGameClient = findClient(clientDTO.getId());
|
final GameClient currentGameClient = findClient(clientDTO.getId());
|
||||||
|
|
||||||
currentGameClient.setNickName(clientDTO.getNickName());
|
currentGameClient.setLogin(clientDTO.getLogin());
|
||||||
|
currentGameClient.setPassword(clientDTO.getPassword());
|
||||||
currentGameClient.setEmail(clientDTO.getEmail());
|
currentGameClient.setEmail(clientDTO.getEmail());
|
||||||
currentGameClient.setBalance(clientDTO.getBalance());
|
currentGameClient.setBalance(clientDTO.getBalance());
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public class UserService implements UserDetailsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new org.springframework.security.core.userdetails.User(
|
return new org.springframework.security.core.userdetails.User(
|
||||||
userEntity.getNickName(), userEntity.getEmail(), Collections.emptyList());
|
userEntity.getLogin(), userEntity.getEmail(), Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ class PremiumStoreApplicationTests {
|
|||||||
void testClientRead() {
|
void testClientRead() {
|
||||||
gameClientService.deleteAllClients();
|
gameClientService.deleteAllClients();
|
||||||
|
|
||||||
GameClient client = gameClientService.addClient("3tankista73", "fff@mail.ru", 3400);
|
GameClient client = gameClientService.addClient("3tankista73", "fff@mail.ru", "user", 3400);
|
||||||
log.info(client.toString());
|
log.info(client.toString());
|
||||||
|
|
||||||
GameClient findClient = gameClientService.findClient(client.getId());
|
GameClient findClient = gameClientService.findClient(client.getId());
|
||||||
@ -126,10 +126,10 @@ class PremiumStoreApplicationTests {
|
|||||||
void testClientCreate() {
|
void testClientCreate() {
|
||||||
gameClientService.deleteAllClients();
|
gameClientService.deleteAllClients();
|
||||||
|
|
||||||
GameClient firstClient = gameClientService.addClient("Barbarian", "dsfg@gmail.com", 56000);
|
GameClient firstClient = gameClientService.addClient("Barbarian", "dsfg@gmail.com", "user", 56000);
|
||||||
log.info(firstClient.toString());
|
log.info(firstClient.toString());
|
||||||
|
|
||||||
GameClient secondClient = gameClientService.addClient("KorbenDallas", "tankoviyGeniy@mail.ru", 37000);
|
GameClient secondClient = gameClientService.addClient("KorbenDallas", "tankoviyGeniy@mail.ru", "user", 37000);
|
||||||
log.info(secondClient.toString());
|
log.info(secondClient.toString());
|
||||||
|
|
||||||
Assertions.assertEquals(gameClientService.findAllClients().size(), 2);
|
Assertions.assertEquals(gameClientService.findAllClients().size(), 2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user