Skip to content

Commit 73ed313

Browse files
authored
v2.0.0 - Made namespace optional (#67)
* Made namespace optional * Release 2.0.0 * Increased test coverage
1 parent b19e7ab commit 73ed313

39 files changed

+417
-252
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ You'll need a free [Heroku account](https://signup.heroku.com) to set it up. A f
4343

4444
### Step 1: Host App Installation
4545

46+
There are two installation options for the host app:
47+
48+
#### Option 1: Managed Package (recommended)
49+
50+
1. Click [this link](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t0N000001Bl41QAC) to install the host app package and choose **Install for All Users**.
51+
52+
You'll need to approve access to `https://chart.googleapis.com`. We use this library to draw leaderboads.
53+
54+
1. Set up permissions:
55+
1. Navigate to **Setup > Users > Permission Sets**, click **Quiz Host**
56+
1. Click **Manage Assignements**
57+
1. Click **Add Assignement**
58+
1. Check your user and click **Assign**.
59+
1. Navigate to **Setup > Integrations > Change Data Capture**, enable Change Data Capture for the **Quiz Player** object and **Save**.
60+
61+
#### Option 2: Scratch Org (for development purposes)
62+
4663
We assume that you have a working Salesforce DX environment (Salesforce CLI installed, Dev Hub configured and authorized). See this [Trailhead project](https://trailhead.salesforce.com/en/content/learn/modules/sfdx_app_dev/sfdx_app_dev_setup_dx) for guided steps.
4764

4865
1. Open a Terminal and clone the git repository:
@@ -124,7 +141,7 @@ You can create or import questions by adding records manually or by importing th
124141
Use this table template to save time:
125142
126143
| Label | Answer A | Answer B | Answer C | Answer D | Correct Answer |
127-
| --------- | ---------|----------|----------|----------|--------------- |
144+
| --------- | -------- | -------- | -------- | -------- | -------------- |
128145
| 1 + 1 = ? | 1 | 2 | 3 | 4 | B |
129146
130147
#### Option 2: Importing questions using the Salesforce CLI

package-lock.json

Lines changed: 72 additions & 176 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sfdx-quiz",
3-
"version": "1.4.0",
3+
"version": "2.0.0",
44
"private": true,
55
"description": "Lightning Web Component Quiz App on a Salesforce Org",
66
"engines": {
@@ -19,13 +19,13 @@
1919
"postinstall": "node bin/check-version.js"
2020
},
2121
"devDependencies": {
22-
"@salesforce/eslint-config-lwc": "^0.6.0",
22+
"@salesforce/eslint-config-lwc": "^0.7.0",
2323
"@salesforce/sfdx-lwc-jest": "^0.7.1",
24-
"eslint": "^7.0.0",
24+
"eslint": "^7.1.0",
2525
"husky": "^4.2.5",
26-
"lint-staged": "^10.2.6",
26+
"lint-staged": "^10.2.9",
2727
"prettier": "^2.0.5",
28-
"prettier-plugin-apex": "^1.4.0",
28+
"prettier-plugin-apex": "^1.5.0",
2929
"semver": "^7.3.2"
3030
},
3131
"husky": {

sfdx-project.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"path": "src",
55
"default": true,
66
"package": "Quiz",
7-
"versionName": "ver 1.4.0",
8-
"versionNumber": "1.4.0.NEXT"
7+
"versionName": "ver 2.0.0",
8+
"versionNumber": "2.0.0.NEXT"
99
}
1010
],
1111
"namespace": "",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
global with sharing class QuizAnswer {
2+
@AuraEnabled
3+
global Id id { get; set; }
4+
@AuraEnabled
5+
global Id playerId { get; set; }
6+
@AuraEnabled
7+
global Id questionId { get; set; }
8+
@AuraEnabled
9+
global String answer { get; set; }
10+
11+
global QuizAnswer() {
12+
}
13+
14+
global QuizAnswer(Quiz_Answer__c answer) {
15+
this.id = answer.Id;
16+
this.playerId = answer.Player__c;
17+
this.questionId = answer.Question__c;
18+
this.answer = answer.Answer__c;
19+
}
20+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>48.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

src/main/default/classes/QuizAnswerRestResource.cls

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ global abstract class QuizAnswerRestResource {
77
Object responseData;
88
Integer statusCode;
99
try {
10-
responseData = answerService.create(playerId, answer);
10+
Quiz_Answer__c answerRecord = answerService.create(
11+
playerId,
12+
answer
13+
);
14+
responseData = new QuizAnswer(answerRecord);
1115
statusCode = 200;
1216
} catch (QuizAnswerService.InvalidPhaseException e) {
1317
responseData = new ErrorMessage(

src/main/default/classes/QuizController.cls

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ public with sharing class QuizController {
88
private static final QuizSettingsService settingsService = new QuizSettingsService();
99

1010
@AuraEnabled(cacheable=true)
11-
public static Quiz_Settings__mdt getQuizSettings() {
12-
return settingsService.get();
11+
public static QuizSettings getQuizSettings() {
12+
Quiz_Settings__mdt settings = settingsService.get();
13+
return new QuizSettings(settings);
1314
}
1415

1516
@AuraEnabled(cacheable=true)
@@ -40,7 +41,7 @@ public with sharing class QuizController {
4041
}
4142

4243
@AuraEnabled
43-
public static Quiz_Question__c getCurrentQuestion(Id sessionId) {
44+
public static QuizQuestion getCurrentQuestion(Id sessionId) {
4445
if (sessionId == null) {
4546
throw new AuraHandledException('Missing session Id.');
4647
}
@@ -52,7 +53,7 @@ public with sharing class QuizController {
5253
'Missing current question for session.'
5354
);
5455
}
55-
return question;
56+
return new QuizQuestion(question);
5657
}
5758

5859
@AuraEnabled
@@ -61,23 +62,28 @@ public with sharing class QuizController {
6162
}
6263

6364
@AuraEnabled
64-
public static List<Quiz_Player__c> getPlayersSortedByScore(
65+
public static List<QuizPlayer> getPlayersSortedByScore(
6566
Integer maxFetchCount
6667
) {
67-
return playerService.getPlayersSortedByScore(maxFetchCount);
68+
List<Quiz_Player__c> players = playerService.getPlayersSortedByScore(
69+
maxFetchCount
70+
);
71+
return QuizPlayer.fromRecordList(players);
6872
}
6973

7074
@AuraEnabled
71-
public static Quiz_Session__c getQuizSession() {
72-
return sessionService.getQuizSession();
75+
public static QuizSession getQuizSession() {
76+
Quiz_Session__c session = sessionService.getQuizSession();
77+
return new QuizSession(session);
7378
}
7479

7580
@AuraEnabled
76-
public static Quiz_Session__c triggerNextPhase(Id sessionId) {
81+
public static QuizSession triggerNextPhase(Id sessionId) {
7782
if (sessionId == null) {
7883
throw new AuraHandledException('Missing session Id.');
7984
}
80-
return sessionHelper.triggerNextPhase(sessionId);
85+
Quiz_Session__c session = sessionHelper.triggerNextPhase(sessionId);
86+
return new QuizSession(session);
8187
}
8288

8389
@AuraEnabled

src/main/default/classes/QuizEditorController.cls

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ public with sharing class QuizEditorController {
33
private static final QuizSessionService sessionService = new QuizSessionService();
44

55
@AuraEnabled(cacheable=true)
6-
public static List<Quiz_Question__c> getAllQuestions() {
7-
return questionService.getQuestions();
6+
public static List<QuizQuestion> getAllQuestions() {
7+
List<Quiz_Question__c> questions = questionService.getQuestions();
8+
return QuizQuestion.fromRecordList(questions);
89
}
910

1011
@AuraEnabled
@@ -19,10 +20,17 @@ public with sharing class QuizEditorController {
1920
}
2021

2122
@AuraEnabled(cacheable=true)
22-
public static List<Quiz_Question__c> getSessionQuestions(Id sessionId) {
23+
public static List<Id> getSessionQuestionIds(Id sessionId) {
2324
if (sessionId == null) {
2425
throw new AuraHandledException('Missing session Id.');
2526
}
26-
return sessionService.getSessionQuestions(sessionId);
27+
List<Quiz_Question__c> questions = sessionService.getSessionQuestions(
28+
sessionId
29+
);
30+
List<Id> questionIds = new List<Id>();
31+
for (Quiz_Question__c question : questions) {
32+
questionIds.add(question.Id);
33+
}
34+
return questionIds;
2735
}
2836
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
global with sharing class QuizPlayer {
2+
@AuraEnabled
3+
global Id id { get; set; }
4+
@AuraEnabled
5+
global String name { get; set; }
6+
@AuraEnabled
7+
global Decimal score { get; set; }
8+
@AuraEnabled
9+
global Decimal rank { get; set; }
10+
11+
global QuizPlayer() {
12+
}
13+
14+
global QuizPlayer(Quiz_Player__c player) {
15+
this.id = player.Id;
16+
this.name = player.Name;
17+
this.score = player.Score__c;
18+
this.rank = player.Ranking__c;
19+
}
20+
21+
global static List<QuizPlayer> fromRecordList(
22+
List<Quiz_Player__c> records
23+
) {
24+
List<QuizPlayer> players = new List<QuizPlayer>();
25+
for (Quiz_Player__c record : records) {
26+
players.add(new QuizPlayer(record));
27+
}
28+
return players;
29+
}
30+
}

0 commit comments

Comments
 (0)