From f1666446aa59e226d9c55edc868c8713cf8f6861 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Thu, 20 Jun 2024 10:27:36 +0400 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/nekontakte/NekontakteApplication.java | 6 ++++-- .../example/nekontakte/users/api/AdminUserController.java | 5 +---- .../example/nekontakte/users/api/UserSignupController.java | 6 +----- .../java/com/example/nekontakte/users/model/UserEntity.java | 1 - 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/nekontakte/src/main/java/com/example/nekontakte/NekontakteApplication.java b/nekontakte/src/main/java/com/example/nekontakte/NekontakteApplication.java index 6d68828..8bbfab5 100644 --- a/nekontakte/src/main/java/com/example/nekontakte/NekontakteApplication.java +++ b/nekontakte/src/main/java/com/example/nekontakte/NekontakteApplication.java @@ -28,8 +28,10 @@ public class NekontakteApplication implements CommandLineRunner { @Override public void run(String... args) throws Exception { _logger.info("Create default user values"); - // UserEntity admin = new UserEntity("admin", "admin", UserRole.ADMIN); - // userService.create(admin); + if (userService.getAll().isEmpty()) { + UserEntity admin = new UserEntity("admin", "admin", UserRole.ADMIN); + userService.create(admin); + } _logger.info(String.format("users count: %s", userService.getAll().size())); } diff --git a/nekontakte/src/main/java/com/example/nekontakte/users/api/AdminUserController.java b/nekontakte/src/main/java/com/example/nekontakte/users/api/AdminUserController.java index 0d87cf8..d67622a 100644 --- a/nekontakte/src/main/java/com/example/nekontakte/users/api/AdminUserController.java +++ b/nekontakte/src/main/java/com/example/nekontakte/users/api/AdminUserController.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.Objects; @Controller + @RequestMapping(AdminUserController.URL) public class AdminUserController { public static final String URL = Constants.ADMIN_PREFIX + "/user"; @@ -39,10 +40,6 @@ public class AdminUserController { this.userService = userService; } - private UserEntity toEntity(UserDTO dto) { - return modelMapper.map(dto, UserEntity.class); - } - private UserDTO toDTO(UserEntity entity) { return modelMapper.map(entity, UserDTO.class); } diff --git a/nekontakte/src/main/java/com/example/nekontakte/users/api/UserSignupController.java b/nekontakte/src/main/java/com/example/nekontakte/users/api/UserSignupController.java index 30ae0b4..1c9fc71 100644 --- a/nekontakte/src/main/java/com/example/nekontakte/users/api/UserSignupController.java +++ b/nekontakte/src/main/java/com/example/nekontakte/users/api/UserSignupController.java @@ -2,7 +2,6 @@ package com.example.nekontakte.users.api; import java.util.Objects; -import org.modelmapper.ModelMapper; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -26,13 +25,10 @@ public class UserSignupController { private static final String USER_ATTRIBUTE = "user"; private final UserService userService; - private final ModelMapper modelMapper; public UserSignupController( - UserService userService, - ModelMapper modelMapper) { + UserService userService) { this.userService = userService; - this.modelMapper = modelMapper; } private UserEntity toEntity(UserSignupDto dto) { diff --git a/nekontakte/src/main/java/com/example/nekontakte/users/model/UserEntity.java b/nekontakte/src/main/java/com/example/nekontakte/users/model/UserEntity.java index 3f91e84..22e0369 100644 --- a/nekontakte/src/main/java/com/example/nekontakte/users/model/UserEntity.java +++ b/nekontakte/src/main/java/com/example/nekontakte/users/model/UserEntity.java @@ -6,7 +6,6 @@ import java.util.HashSet; import java.util.Set; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.crypto.password.PasswordEncoder; import com.example.nekontakte.core.model.BaseEntity; import com.example.nekontakte.posts.model.PostEntity;