Skip to content

Commit

Permalink
New API to get Karma Points Metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
saipradeep_ravipati committed Jan 4, 2024
1 parent e000288 commit f4bd0cf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/sunbird/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,8 @@ public class Constants {
public static final String TABLE_KARMA_POINTS_LOOK_UP ="user_karma_points_credit_lookup";
public static final String TABLE_KARMA_POINTS ="user_karma_points";

public static final String TABLE_USER_KARMA_POINTS_SUMMARY ="user_karma_points_summary";

private Constants() {
throw new IllegalStateException("Utility class");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ public ResponseEntity<Map<String, Object>> claimACBPKarmaPoints(@RequestBody Cla
karmaPointsService.claimKarmaPoints(request);
return new ResponseEntity<>(HttpStatus.OK);
}

@PostMapping("/v1/user/totalkarmapoints")
public ResponseEntity<Map<String, Object>> totalKarmaPoints(@RequestHeader("x-authenticated-userid") String userId){
Map<String, Object> karmaPointsDataMap = karmaPointsService.userTotalKarmaPoints(userId);
return new ResponseEntity<>(karmaPointsDataMap, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public interface KarmaPointsService {
public Map<String, Object> fetchKarmaPointsData(String userId, KarmaPointsRequest request) ;
public Map<String, Object> fetchKarmaPointsUserCourse(String userId, Map<String, Object> requestBody) ;
public void claimKarmaPoints(ClaimKarmaPointsRequest request);
public Map<String, Object> userTotalKarmaPoints(String userId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,16 @@ public void claimKarmaPoints(ClaimKarmaPointsRequest request) {
logger.info("UserID and CourseId successfully Published to : " + serverProperties.getClaimKarmaPointsTopic());
}

public void fetchKarmaPoints(){

public Map<String, Object> userTotalKarmaPoints(String userId){
Map<String, Object> whereMap = new HashMap<>();
whereMap.put(Constants.KARMA_POINTS_USER_ID, userId);
List<Map<String, Object>> userKpList = cassandraOperation.getRecordsByProperties(Constants.KEYSPACE_SUNBIRD,
Constants.TABLE_USER_KARMA_POINTS_SUMMARY, whereMap, null);
Map<String, Object> resultMap = new HashMap<>();
Map<String, Object> result = new HashMap<>();
if(userKpList !=null && !userKpList.isEmpty())
result = userKpList.get(0);
resultMap.put(Constants.KARMA_POINTS_LIST, result);
return resultMap;
}
}

0 comments on commit f4bd0cf

Please sign in to comment.