use of com.zavada.entity.UserEntity in project Logos_Materials_October_2017 by VolodymyrZavada.
the class SpringBootConsulttionTestProjectApplication method addAdmin.
static void addAdmin(ConfigurableApplicationContext context) {
String adminEmail = "admin@gmail.com";
String adminPassword = "123";
UserRepository userRepository = context.getBean(UserRepository.class);
UserEntity entity = userRepository.findUserByEmail(adminEmail);
if (entity == null) {
PasswordEncoder encoder = context.getBean(PasswordEncoder.class);
entity = new UserEntity();
entity.setEmail(adminEmail);
entity.setPassword(encoder.encode(adminPassword));
entity.setRole(Role.ROLE_ADMIN);
userRepository.save(entity);
}
}
use of com.zavada.entity.UserEntity in project Logos_Materials_October_2017 by VolodymyrZavada.
the class UserController method editUserProfile.
@GetMapping("/edit/{userId}")
public String editUserProfile(@PathVariable("userId") int userId, Model model, Principal principal) {
UserEntity entity = userService.findUserByEmail(principal.getName());
if (userId != entity.getId())
return "redirect:/user";
EditUserRequest request = UserMapper.entityToEditUser(entity);
model.addAttribute("editModel", request);
return "user/edit";
}
use of com.zavada.entity.UserEntity in project Logos_Materials_October_2017 by VolodymyrZavada.
the class UserController method createAdvertisementForm.
@PostMapping("/{userId}/create")
public String createAdvertisementForm(@ModelAttribute("advModel") CreateAdvRequest request, @PathVariable("userId") int userId) throws IOException {
UserEntity entity = userService.findUserById(userId);
Car car = CarMapper.advRequestToCar(request);
car.setUser(entity);
carService.saveCar(car);
CustomFileUtils.createFolder("car_" + car.getId());
CustomFileUtils.createImage("car_" + car.getId(), request.getCarImage());
return "redirect:/user";
}
use of com.zavada.entity.UserEntity in project Logos_Materials_October_2017 by VolodymyrZavada.
the class UserController method createAdvertisement.
// --- Advertisement
@GetMapping("/{userId}/create")
public String createAdvertisement(@PathVariable("userId") int userId, Model model, Principal principal) {
UserEntity entity = userService.findUserByEmail(principal.getName());
CreateAdvRequest advRequest = new CreateAdvRequest();
advRequest.setEntity(entity);
model.addAttribute("title", "Create Advertisement");
// model.addAttribute("userId", userId);
model.addAttribute("advModel", advRequest);
model.addAttribute("colors", Color.values());
model.addAttribute("fuelTypes", FuelType.values());
model.addAttribute("bodyTypes", BodyType.values());
return "user/create-adv";
}
use of com.zavada.entity.UserEntity in project Logos_Materials_October_2017 by VolodymyrZavada.
the class UserMapper method editRequestToEntity.
public static UserEntity editRequestToEntity(EditUserRequest request) {
UserEntity entity = new UserEntity();
entity.setId(request.getId());
entity.setEmail(request.getEmail());
entity.setAge(request.getAge());
entity.setFirstName(request.getFirstName());
entity.setLastName(request.getLastName());
entity.setImagePath(request.getFile().getOriginalFilename());
// <----
entity.setPassword(request.getPassword());
entity.setRole(Role.ROLE_USER);
return entity;
}
Aggregations