I have 2 list for Organizations, one that followed by users and another is the all Organizations in the database, I made 2 loops inside each others to set the value of followed
for original list with true
if user following this organization (that can be known from user organizations list)
List<Organization> organizationList = getServiceInstance().getOrganizationService().findOrganizationList();
List<Organization> organizations = getServiceInstance().getOrganizationService().findFollowedOrganizationList(userId);
for (Organization fOrg: organizations) {
for (Organization organization : organizationList) {
if (Objects.equals(fOrg.id, organization.id)) {
fOrg.followed = true;
}
}
}
I believe there is better way to do this.