Problem
1)I have to display the count of total users with Incomplete and Complete Profiles.
2)Incomplete Profiles are those which will have 4 fields of String type. Other than that all are Complete Profiles.
Below is my model class fields
@Id
private String id;
private String[] imageIds;
private String concerns;
private String summary;
private String likings;
private String occupation;
private String religion;
private String education;
private String height;
@GeoSpatialIndexed(type = GeoSpatialIndexType.GEO_2DSPHERE)
private double[] location;
private INTERESTS[] interests;
private String fcmId;
private List connections;
private List declined;
private List pending;
Code I have written:
1)In MySql I can apply a direct query which is similar to
a)Select count(*) from X where a is NULL or b IS NULL -- > ForIncompleteProfiles
b)Select count(*) from X where a IS NOT NULL or b IS NOT NULL -- > For CompleteProfiles
But here,
2)I can use findAll() method to retrieve all users in a List of User and then check for each user using if user.getA()or user.getB() any one of the field is null.IF yes,Count for Incomplete Profiles else Count for Completebb Profiles.
Then,I can return both these count's to a frontEndUSer in a HashMap
Can anyone guide me if this is a correct way and if not how to do it in a more efficient way and effective way using spring boot and MongoData Repository.
Below is my code for the same
@RequestMapping(value = "/showprofiles", method = RequestMethod.GET)
public Map showProfiles(HttpServletResponse response) {
int pageSize=2000;
Page<User> users=null;
int page=0;
int countInComplete=0;
int countComplete=0;
Map hm=null;
users = userService.getAllUsers(new PageRequest(page,pageSize));
do {
users = userService.getAllUsers(new PageRequest(page,pageSize));
for (User user : users) {
if (user.getName() == null || user.getGender() == null || user.getInterests() == null || user.getImageIds() == null) {
countInComplete++;
}
else{
countComplete++;
}
}
page++;
}while (users.hasNext());
hm=new HashMap();
hm.put("countComplete",countComplete);
hm.put("countInComplete",countInComplete);
return hm;
}