Search in sources :

Example 1 with UserDTO

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;
}
Also used : User(com.github.lybgeek.mongodb.model.User) PropertyMap(org.modelmapper.PropertyMap) UserDTO(com.github.lybgeek.mongodb.dto.UserDTO) ModelMapper(org.modelmapper.ModelMapper) Bean(org.springframework.context.annotation.Bean)

Example 2 with UserDTO

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);
    }
}
Also used : UserDTO(com.github.lybgeek.mongodb.dto.UserDTO)

Example 3 with UserDTO

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);
}
Also used : Address(com.github.lybgeek.mongodb.model.Address) UserDTO(com.github.lybgeek.mongodb.dto.UserDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with UserDTO

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;
}
Also used : User(com.github.lybgeek.mongodb.model.User) PageQuery(com.github.lybgeek.mongodb.common.page.PageQuery) UserDTO(com.github.lybgeek.mongodb.dto.UserDTO)

Example 5 with UserDTO

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;
}
Also used : User(com.github.lybgeek.mongodb.model.User) UserDTO(com.github.lybgeek.mongodb.dto.UserDTO) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserDTO (com.github.lybgeek.mongodb.dto.UserDTO)5 User (com.github.lybgeek.mongodb.model.User)3 PageQuery (com.github.lybgeek.mongodb.common.page.PageQuery)1 Address (com.github.lybgeek.mongodb.model.Address)1 Test (org.junit.Test)1 ModelMapper (org.modelmapper.ModelMapper)1 PropertyMap (org.modelmapper.PropertyMap)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Bean (org.springframework.context.annotation.Bean)1 Transactional (org.springframework.transaction.annotation.Transactional)1