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);
}
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);
}
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;
}
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());
}
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());
}
Aggregations