Skip to content

Commit

Permalink
Merge pull request #9 from meruff/pagination
Browse files Browse the repository at this point in the history
Add Pagination
  • Loading branch information
meruff authored Sep 4, 2022
2 parents bd0b557 + 62f940e commit c4296b4
Show file tree
Hide file tree
Showing 41 changed files with 1,541 additions and 1,262 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ finished.
- ~~Convert to Lightning Web Components ⚡~~
- ~~Convert to Salesforce DX Project~~
- ~~Add a custom Trailhead API~~
- Dark mode? 😎
- Pagination / loading more.
- ~~Dark mode~~
- ~~Pagination / loading more.~~
- Handle deactivating Trailblazers who go private / 404.
- Remove `Badge__c`.

Expand Down
19 changes: 10 additions & 9 deletions force-app/main/default/classes/CertificationData.cls
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/**
* @author meruff
* @date 3/18/20
*
* A class to deserialize Trailhead Certification data from the API into.
*/
* @description A class to deserialize Trailhead Certification data from the API into.
*
* @author meruff
*
* @date 3/18/20
*/
public class CertificationData {
public String error { get; set; }

@AuraEnabled
public List<certificationsList> certificationsList { get; set; }
public List<CertificationsList> certificationsList { get; set; }

public class certificationsList {
public class CertificationsList {
@AuraEnabled
public String dateExpired { get; set; }

Expand All @@ -32,4 +33,4 @@ public class CertificationData {
@AuraEnabled
public String certificationImageUrl { get; set; }
}
}
}
62 changes: 40 additions & 22 deletions force-app/main/default/classes/GetTrailblazerInfoAsync.cls
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,22 @@ public class GetTrailblazerInfoAsync implements Queueable, Database.AllowsCallou
}

Trailblazer__c trailblazer = trailblazers[0];
getProfileData(trailblazer, TrailheadHelper.buildCalloutURL(trailblazer, TrailheadHelper.PROFILE_PATH));
getRankData(trailblazer, TrailheadHelper.buildCalloutURL(trailblazer, TrailheadHelper.RANK_PATH));
getSuperbadgeData(trailblazer, TrailheadHelper.buildCalloutURL(trailblazer, TrailheadHelper.SUPERBADGES_PATH));
getCertificationData(trailblazer, TrailheadHelper.buildCalloutURL(trailblazer, TrailheadHelper.CERTIFICATIONS_PATH));
getProfileData(
trailblazer,
TrailheadHelper.buildCalloutURL(trailblazer, TrailheadHelper.PROFILE_PATH)
);
getRankData(
trailblazer,
TrailheadHelper.buildCalloutURL(trailblazer, TrailheadHelper.RANK_PATH)
);
getSuperbadgeData(
trailblazer,
TrailheadHelper.buildCalloutURL(trailblazer, TrailheadHelper.SUPERBADGES_PATH)
);
getCertificationData(
trailblazer,
TrailheadHelper.buildCalloutURL(trailblazer, TrailheadHelper.CERTIFICATIONS_PATH)
);

if (!String.isBlank(trailblazer.Profile_Handle__c)) {
upsert trailblazer Profile_Handle__c;
Expand Down Expand Up @@ -54,8 +66,10 @@ public class GetTrailblazerInfoAsync implements Queueable, Database.AllowsCallou
* @return a string representing a successful callout.
*/
public static String getProfileData(Trailblazer__c trailblazer, String resBody) {
if (resBody.contains(TrailheadHelper.HEROKU_ERROR) || String.isBlank(resBody)) {
return TrailheadHelper.buildErrorAsJSON('Application Error, please try again. API may be down.');
if (resBody.contains(TrailheadHelper.API_ERROR) || String.isBlank(resBody)) {
return TrailheadHelper.buildErrorAsJSON(
'Application Error, please try again. API may be down.'
);
}

ProfileData data = (ProfileData) JSON.deserialize(
Expand All @@ -77,9 +91,11 @@ public class GetTrailblazerInfoAsync implements Queueable, Database.AllowsCallou
trailblazer.Job_Role__c = data.profileUser.TBID_Role;

if (!String.isBlank(data.profileUser.TrailblazerId)) {
trailblazer.Profile_Link__c = TrailheadHelper.TRAILHEAD_ME + data.profileUser.TrailblazerId;
trailblazer.Profile_Link__c =
TrailheadHelper.TRAILHEAD_ME + data.profileUser.TrailblazerId;
} else {
trailblazer.Profile_Link__c = TrailheadHelper.TRAILHEAD_ME_USERID + data.profileUser.Id;
trailblazer.Profile_Link__c =
TrailheadHelper.TRAILHEAD_ME_USERID + data.profileUser.Id;
}
}

Expand All @@ -95,14 +111,14 @@ public class GetTrailblazerInfoAsync implements Queueable, Database.AllowsCallou
* @return a string representing a successful callout.
*/
public static String getRankData(Trailblazer__c trailblazer, String resBody) {
if (resBody.contains(TrailheadHelper.HEROKU_ERROR) || String.isBlank(resBody)) {
return TrailheadHelper.buildErrorAsJSON('Application Error, please try again. API may be down.');
if (resBody.contains(TrailheadHelper.API_ERROR) || String.isBlank(resBody)) {
return TrailheadHelper.buildErrorAsJSON(
'Application Error, please try again. API may be down.'
);
}

TrailheadGraphQlData data = (TrailheadGraphQlData) JSON.deserialize(
resBody
.replaceAll('__c', '')
.replaceAll('__', ''),
resBody.replaceAll('__c', '').replaceAll('__', ''),
TrailheadGraphQlData.class
);

Expand Down Expand Up @@ -130,14 +146,14 @@ public class GetTrailblazerInfoAsync implements Queueable, Database.AllowsCallou
* @return a string representing a successful callout.
*/
public static String getSuperbadgeData(Trailblazer__c trailblazer, String resBody) {
if (resBody.contains(TrailheadHelper.HEROKU_ERROR) || String.isBlank(resBody)) {
return TrailheadHelper.buildErrorAsJSON('Application Error, please try again. API may be down.');
if (resBody.contains(TrailheadHelper.API_ERROR) || String.isBlank(resBody)) {
return TrailheadHelper.buildErrorAsJSON(
'Application Error, please try again. API may be down.'
);
}

TrailheadGraphQlData data = (TrailheadGraphQlData) JSON.deserialize(
resBody
.replaceAll('__c', '')
.replaceAll('__', ''),
resBody.replaceAll('__c', '').replaceAll('__', ''),
TrailheadGraphQlData.class
);

Expand All @@ -148,7 +164,7 @@ public class GetTrailblazerInfoAsync implements Queueable, Database.AllowsCallou
if (data.profile?.earnedAwards?.edges != null) {
Integer count = 0;

for (TrailheadGraphQlData.edges edge : data.profile?.earnedAwards?.edges) {
for (TrailheadGraphQlData.Edges edge : data.profile?.earnedAwards?.edges) {
if (edge.node.award.type == 'SUPERBADGE') {
count++;
}
Expand All @@ -169,8 +185,10 @@ public class GetTrailblazerInfoAsync implements Queueable, Database.AllowsCallou
* @return a string representing a successful callout.
*/
public static String getCertificationData(Trailblazer__c trailblazer, String resBody) {
if (resBody.contains(TrailheadHelper.HEROKU_ERROR) || String.isBlank(resBody)) {
return TrailheadHelper.buildErrorAsJSON('Application Error, please try again. API may be down.');
if (resBody.contains(TrailheadHelper.API_ERROR) || String.isBlank(resBody)) {
return TrailheadHelper.buildErrorAsJSON(
'Application Error, please try again. API may be down.'
);
}

CertificationData data = (CertificationData) JSON.deserialize(
Expand All @@ -188,4 +206,4 @@ public class GetTrailblazerInfoAsync implements Queueable, Database.AllowsCallou

return TrailheadHelper.SUCCESS;
}
}
}
Loading

0 comments on commit c4296b4

Please sign in to comment.