Search in sources :

Example 1 with Favorite

use of com.ctrip.framework.apollo.portal.entity.po.Favorite in project apollo by ctripcorp.

the class FavoriteService method addFavorite.

public Favorite addFavorite(Favorite favorite) {
    UserInfo user = userService.findByUserId(favorite.getUserId());
    if (user == null) {
        throw new BadRequestException("user not exist");
    }
    UserInfo loginUser = userInfoHolder.getUser();
    // user can only add himself favorite app
    if (!loginUser.equals(user)) {
        throw new BadRequestException("add favorite fail. " + "because favorite's user is not current login user.");
    }
    Favorite checkedFavorite = favoriteRepository.findByUserIdAndAppId(loginUser.getUserId(), favorite.getAppId());
    if (checkedFavorite != null) {
        return checkedFavorite;
    }
    favorite.setPosition(POSITION_DEFAULT);
    favorite.setDataChangeCreatedBy(user.getUserId());
    favorite.setDataChangeLastModifiedBy(user.getUserId());
    return favoriteRepository.save(favorite);
}
Also used : Favorite(com.ctrip.framework.apollo.portal.entity.po.Favorite) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo)

Example 2 with Favorite

use of com.ctrip.framework.apollo.portal.entity.po.Favorite in project apollo by ctripcorp.

the class FavoriteService method deleteFavorite.

public void deleteFavorite(long favoriteId) {
    Favorite favorite = favoriteRepository.findOne(favoriteId);
    checkUserOperatePermission(favorite);
    favoriteRepository.delete(favorite);
}
Also used : Favorite(com.ctrip.framework.apollo.portal.entity.po.Favorite)

Example 3 with Favorite

use of com.ctrip.framework.apollo.portal.entity.po.Favorite in project apollo by ctripcorp.

the class FavoriteServiceTest method instanceOfFavorite.

private Favorite instanceOfFavorite(String userId, String appId) {
    Favorite favorite = new Favorite();
    favorite.setAppId(appId);
    favorite.setUserId(userId);
    favorite.setDataChangeCreatedBy(userId);
    favorite.setDataChangeLastModifiedBy(userId);
    return favorite;
}
Also used : Favorite(com.ctrip.framework.apollo.portal.entity.po.Favorite)

Example 4 with Favorite

use of com.ctrip.framework.apollo.portal.entity.po.Favorite in project apollo by ctripcorp.

the class FavoriteServiceTest method testSearchByAppId.

@Test
@Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testSearchByAppId() {
    List<Favorite> favorites = favoriteService.search(null, "test0621-04", new PageRequest(0, 10));
    Assert.assertEquals(3, favorites.size());
}
Also used : Favorite(com.ctrip.framework.apollo.portal.entity.po.Favorite) PageRequest(org.springframework.data.domain.PageRequest) AbstractIntegrationTest(com.ctrip.framework.apollo.portal.AbstractIntegrationTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 5 with Favorite

use of com.ctrip.framework.apollo.portal.entity.po.Favorite in project apollo by ctripcorp.

the class FavoriteServiceTest method testSearchByUserId.

@Test
@Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testSearchByUserId() {
    List<Favorite> favorites = favoriteService.search(testUser, null, new PageRequest(0, 10));
    Assert.assertEquals(4, favorites.size());
}
Also used : Favorite(com.ctrip.framework.apollo.portal.entity.po.Favorite) PageRequest(org.springframework.data.domain.PageRequest) AbstractIntegrationTest(com.ctrip.framework.apollo.portal.AbstractIntegrationTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Aggregations

Favorite (com.ctrip.framework.apollo.portal.entity.po.Favorite)10 AbstractIntegrationTest (com.ctrip.framework.apollo.portal.AbstractIntegrationTest)6 Test (org.junit.Test)6 Sql (org.springframework.test.context.jdbc.Sql)6 PageRequest (org.springframework.data.domain.PageRequest)5 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)1 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)1