use of com.github.lybgeek.mongodb.dto.UserDTO in project springboot-learning by lyb-geek.
the class ModelMapperConfig method modelMapper.
@Bean
public ModelMapper modelMapper() {
ModelMapper modelMapper = new ModelMapper();
PropertyMap<User, UserDTO> propertyUser2UserDTOMap = new PropertyMap<User, UserDTO>() {
@Override
protected void configure() {
skip(source.getGender(), destination.getGender());
}
};
modelMapper.addMappings(propertyUser2UserDTOMap);
return modelMapper;
}
use of com.github.lybgeek.mongodb.dto.UserDTO in project springboot-learning by lyb-geek.
the class UserController method saveUser.
private void saveUser(@Valid UserDTO userDTO, Result<UserDTO> result) {
try {
UserDTO dbUserDTO = userService.saveUser(userDTO);
result.setData(dbUserDTO);
} catch (Exception e) {
log.error(e.getMessage(), e);
result.setMessage(e.getMessage());
result.setStatus(Result.fail);
}
}
use of com.github.lybgeek.mongodb.dto.UserDTO in project springboot-learning by lyb-geek.
the class MongodbApplicationTest method testAddUser.
@Test
public void testAddUser() {
Address address = Address.builder().province("北京").city("北京").detailAddr("test1").build();
UserDTO userDTO = UserDTO.builder().userName("张三1").realName("张三").email("zhangsan@qq.com").password("1234561").address(address).gender(1).build();
UserDTO dto = userService.saveUser(userDTO);
// User dto = userDao.saveUser(User.builder().userName("张三1").email("zhangsan1@qq.com").password("1234561").gender(
// Gender.MALE).address(address).build());
Assert.assertNotNull(dto);
System.out.println(dto);
}
use of com.github.lybgeek.mongodb.dto.UserDTO in project springboot-learning by lyb-geek.
the class UserServiceImpl method pageUsers.
@Override
public PageResult<User> pageUsers(PageQuery<UserDTO> pageQuery) {
UserDTO userDTO = pageQuery.getQueryParams();
User dbUser = getUser(userDTO);
PageQuery<User> dbPageQuery = new PageQuery<>();
dbPageQuery.setQueryParams(dbUser);
dbPageQuery.setPageSize(pageQuery.getPageSize() == null ? 10 : pageQuery.getPageSize());
dbPageQuery.setPageNum(pageQuery.getPageNum() == null ? 1 : pageQuery.getPageNum());
PageResult<User> pageResult = userDao.pageUsers(dbPageQuery);
return pageResult;
}
use of com.github.lybgeek.mongodb.dto.UserDTO in project springboot-learning by lyb-geek.
the class UserServiceImpl method saveUser.
@Override
@Transactional
public UserDTO saveUser(UserDTO userDTO) {
User user = getUser(userDTO);
User dbUser = userDao.saveUser(user);
if (ValidateTransaction.YES.getValue().equals(userDTO.getValidateRollBack())) {
throw new RuntimeException("验证事务回滚");
}
UserDTO dbUserDTO = modelMapper.map(dbUser, UserDTO.class);
dbUserDTO.setGender(dbUser.getGender().getValue());
return dbUserDTO;
}
Aggregations