Search in sources :

Example 1 with UserEntity

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);
    }
}
Also used : UserRepository(com.zavada.repository.UserRepository) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) UserEntity(com.zavada.entity.UserEntity)

Example 2 with UserEntity

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";
}
Also used : EditUserRequest(com.zavada.domain.EditUserRequest) UserEntity(com.zavada.entity.UserEntity) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with UserEntity

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";
}
Also used : Car(com.zavada.entity.Car) UserEntity(com.zavada.entity.UserEntity) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 4 with UserEntity

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";
}
Also used : CreateAdvRequest(com.zavada.domain.CreateAdvRequest) UserEntity(com.zavada.entity.UserEntity) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 5 with UserEntity

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;
}
Also used : UserEntity(com.zavada.entity.UserEntity)

Aggregations

UserEntity (com.zavada.entity.UserEntity)10 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 UserRepository (com.zavada.repository.UserRepository)2 PasswordEncoder (org.springframework.security.crypto.password.PasswordEncoder)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 CreateAdvRequest (com.zavada.domain.CreateAdvRequest)1 EditUserRequest (com.zavada.domain.EditUserRequest)1 UserProfileRequest (com.zavada.domain.UserProfileRequest)1 Car (com.zavada.entity.Car)1