@Test public void subscribe() throws Exception { TravelerGroupEntity group = endpoint.insert("Adventure", TEST_IMG, user); endpoint.subscribe(group.getWebsafeId(), user); TravelerGroupEntity adventure = ofy().load().entity(group).now(); assertTrue(adventure.getPostCount() == 1L); }
public void subscribe(@Nonnull String groupId, @Nonnull User user) { final Key<Account> accountKey = Key.create(user.getUserId()); final Key<TravelerGroupEntity> groupKey = Key.create(groupId); Map<Key<Object>, Object> fetched = ofy().load().keys(accountKey, groupKey); Account account = (Account) fetched.get(accountKey); TravelerGroupEntity group = (TravelerGroupEntity) fetched.get(groupKey); ofy().transact(() -> { Account updatedAccount = account.toBuilder().subscribedGroupKey(groupKey).build(); TravelerGroupEntity updatedGroup = group.withSubscriberCount(group.getSubscriberCount() + 1); ofy().save().entities(updatedAccount, updatedGroup).now(); }); }
TravelerGroupController extends Controller { public void subscribe(@Nonnull String groupId, @Nonnull User user) { final Key<Account> accountKey = Key.create(user.getUserId()); final Key<TravelerGroupEntity> groupKey = Key.create(groupId); Map<Key<Object>, Object> fetched = ofy().load().keys(accountKey, groupKey); Account account = (Account) fetched.get(accountKey); TravelerGroupEntity group = (TravelerGroupEntity) fetched.get(groupKey); ofy().transact(() -> { Account updatedAccount = account.toBuilder().subscribedGroupKey(groupKey).build(); TravelerGroupEntity updatedGroup = group.withSubscriberCount(group.getSubscriberCount() + 1); ofy().save().entities(updatedAccount, updatedGroup).now(); }); } }
TravelerGroupController extends Controller { public void subscribe(@Nonnull String groupId, @Nonnull User user) { final Key<Account> accountKey = Key.create(user.getUserId()); final Key<TravelerGroupEntity> groupKey = Key.create(groupId); Map<Key<Object>, Object> fetched = ofy().load().keys(accountKey, groupKey); Account account = (Account) fetched.get(accountKey); TravelerGroupEntity group = (TravelerGroupEntity) fetched.get(groupKey); ofy().transact(() -> { Account updatedAccount = account.toBuilder().subscribedGroupKey(groupKey).build(); TravelerGroupEntity updatedGroup = group.withSubscriberCount(group.getSubscriberCount() + 1); ofy().save().entities(updatedAccount, updatedGroup).now(); }); }  }
TravelerGroupController extends Controller { public void subscribe(@Nonnull String groupId, @Nonnull User user) { final Key<Account> accountKey = Key.create(user.getUserId()); final Key<TravelerGroupEntity> groupKey = Key.create(groupId); Map<Key<Object>, Object> fetched = ofy().load().keys(accountKey, groupKey); Account account = (Account) fetched.get(accountKey); TravelerGroupEntity group = (TravelerGroupEntity) fetched.get(groupKey); ofy().transact(() -> { Account updatedAccount = account.toBuilder().subscribedGroupKey(groupKey).build(); TravelerGroupEntity updatedGroup = group.withSubscriberCount(group.getSubscriberCount() + 1); ofy().save().entities(updatedAccount, updatedGroup).now(); }); }  TravelerGroupEntity getGroup(@Nonnull String id, @Nonnull User user); TravelerGroupEntity insertGroup(String displayName, String imageName); TravelerGroupEntity updateGroup(String groupId, Optional<String> name); CollectionResponse<TravelerGroupEntity> listGroups(Optional<GroupSorter> sorter,
      Optional<Integer> limit, Optional<String> cursor, User user); CollectionResponse<Account> listGroupUsers(String groupId, Optional<Integer> limit,
      Optional<String> cursor); void subscribe(@Nonnull String groupId, @Nonnull User user); void unsubscribe(@Nonnull String groupId, @Nonnull User user); Collection<TravelerGroupEntity> listSubscribedGroups(@Nonnull String userId); Collection<TravelerGroupEntity> searchGroups(@Nonnull String q); void setup(); void setupDev(); }
TravelerGroupController extends Controller { public void subscribe(@Nonnull String groupId, @Nonnull User user) { final Key<Account> accountKey = Key.create(user.getUserId()); final Key<TravelerGroupEntity> groupKey = Key.create(groupId); Map<Key<Object>, Object> fetched = ofy().load().keys(accountKey, groupKey); Account account = (Account) fetched.get(accountKey); TravelerGroupEntity group = (TravelerGroupEntity) fetched.get(groupKey); ofy().transact(() -> { Account updatedAccount = account.toBuilder().subscribedGroupKey(groupKey).build(); TravelerGroupEntity updatedGroup = group.withSubscriberCount(group.getSubscriberCount() + 1); ofy().save().entities(updatedAccount, updatedGroup).now(); }); }  TravelerGroupEntity getGroup(@Nonnull String id, @Nonnull User user); TravelerGroupEntity insertGroup(String displayName, String imageName); TravelerGroupEntity updateGroup(String groupId, Optional<String> name); CollectionResponse<TravelerGroupEntity> listGroups(Optional<GroupSorter> sorter,
      Optional<Integer> limit, Optional<String> cursor, User user); CollectionResponse<Account> listGroupUsers(String groupId, Optional<Integer> limit,
      Optional<String> cursor); void subscribe(@Nonnull String groupId, @Nonnull User user); void unsubscribe(@Nonnull String groupId, @Nonnull User user); Collection<TravelerGroupEntity> listSubscribedGroups(@Nonnull String userId); Collection<TravelerGroupEntity> searchGroups(@Nonnull String q); void setup(); void setupDev();  }