Skip to content

Commit 71fc0b5

Browse files
committed
Move the interfaces from RestFramework class as independent.
1 parent 50fcab8 commit 71fc0b5

18 files changed

+82
-69
lines changed

demo-app/main/default/classes/CustomerWebServiceDemo.cls

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ global with sharing class CustomerWebServiceDemo {
2828
}
2929

3030
public class CustomersProcessorV1 extends libak_RestProcessor {
31-
protected override libak_RestFramework.IRestResponse handleGet() {
31+
protected override libak_IRestResponse handleGet() {
3232
List<Account> accounts = [
3333
SELECT Id, Name, Phone, BillingStreet, BillingCity, BillingState, BillingPostalCode
3434
FROM Account
@@ -42,7 +42,7 @@ global with sharing class CustomerWebServiceDemo {
4242
}
4343
}
4444

45-
protected override libak_RestFramework.IRestResponse handlePost() {
45+
protected override libak_IRestResponse handlePost() {
4646
Account newAccount = (Account)JSON.deserialize(this.request.requestBody.toString(), Account.class);
4747
insert newAccount;
4848

@@ -51,7 +51,7 @@ global with sharing class CustomerWebServiceDemo {
5151
}
5252

5353
public class CustomerProcessorV1 extends libak_RestProcessor {
54-
protected override libak_RestFramework.IRestResponse handleGet() {
54+
protected override libak_IRestResponse handleGet() {
5555
List<Account> accounts = [
5656
SELECT Id, Name, Phone, BillingStreet, BillingCity, BillingState, BillingPostalCode
5757
FROM Account
@@ -65,7 +65,7 @@ global with sharing class CustomerWebServiceDemo {
6565
}
6666
}
6767

68-
protected override libak_RestFramework.IRestResponse handlePut() {
68+
protected override libak_IRestResponse handlePut() {
6969
String accountId = this.getUriParam('customer_sf_id');
7070
List<Account> existingAccounts = [SELECT Id FROM Account WHERE Id = :accountId];
7171

@@ -79,7 +79,7 @@ global with sharing class CustomerWebServiceDemo {
7979
return new libak_JsonResponse(updatedAccount);
8080
}
8181

82-
protected override libak_RestFramework.IRestResponse handleDelete() {
82+
protected override libak_IRestResponse handleDelete() {
8383
String accountId = this.getUriParam('customer_sf_id');
8484
List<Account> existingAccounts = [SELECT Id FROM Account WHERE Id = :accountId];
8585

force-app/main/default/classes/libak_ErrorResponse.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* The `libak_ErrorResponse` class represents an error REST response. It allows developers to construct
33
* responses with custom error messages, status codes, and details.
44
*/
5-
public class libak_ErrorResponse implements libak_RestFramework.IRestResponse {
5+
public class libak_ErrorResponse implements libak_IRestResponse {
66
@TestVisible
77
private Integer statusCode;
88
@TestVisible

force-app/main/default/classes/libak_ErrorResponseFactory.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* The `libak_ErrorResponseFactory` class is responsible for creating error responses based on exceptions.
33
* It maps exception types to appropriate HTTP status codes and error messages.
44
*/
5-
public class libak_ErrorResponseFactory implements libak_RestFramework.IErrorResponseFactory {
5+
public class libak_ErrorResponseFactory implements libak_IErrorResponseFactory {
66
private Map<String, Integer> httpStatusByErrorType = new Map<String, Integer>{
77
libak_RestFramework.InvalidUriException.class.getName() => libak_RestFramework.HTTP_CODE_BAD_REQUEST,
88
libak_RestFramework.MethodNotAllowedException.class.getName() => libak_RestFramework.HTTP_CODE_METHOD_NOT_ALLOWED
@@ -14,7 +14,7 @@ public class libak_ErrorResponseFactory implements libak_RestFramework.IErrorRes
1414
* @param exc The exception for which to create an error response.
1515
* @return An error response based on the exception.
1616
*/
17-
public libak_RestFramework.IRestResponse newErrorRestResponse(Exception exc) {
17+
public libak_IRestResponse newErrorRestResponse(Exception exc) {
1818
Integer statusCode = this.httpStatusByErrorType.get(exc.getTypeName());
1919
return statusCode != null
2020
? new libak_ErrorResponse(statusCode, exc)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* The `libak_IErrorResponseFactory` interface defines a method for creating error responses.
3+
*/
4+
public interface libak_IErrorResponseFactory {
5+
libak_IRestResponse newErrorRestResponse(Exception exc);
6+
}
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>62.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* The `libak_IRestLogger` interface defines methods for logging REST-related information.
3+
*/
4+
public interface libak_IRestLogger {
5+
void initLog(RestRequest request);
6+
void addErrorDetails(Exception exc);
7+
void createLog();
8+
}
9+
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>62.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* The `libak_IRestResponse` interface defines a method for sending REST responses.
3+
*/
4+
public interface libak_IRestResponse {
5+
void sendResponse();
6+
}
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>62.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

force-app/main/default/classes/libak_RestFramework.cls

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ public class libak_RestFramework {
5050
* @param errorResponseFactoryType The type of the error response factory to use for creating error responses (optional, can be null).
5151
*/
5252
public static void handleRequest(Type routerType, Type loggerType, Type errorResponseFactoryType) {
53-
IRestResponse response;
54-
IErrorResponseFactory errorResponseFactory;
55-
IRestLogger restLogger;
53+
libak_IRestResponse response;
54+
libak_IErrorResponseFactory errorResponseFactory;
55+
libak_IRestLogger restLogger;
5656
try {
57-
errorResponseFactory = (IErrorResponseFactory)errorResponseFactoryType?.newInstance();
58-
restLogger = (IRestLogger)loggerType?.newInstance();
57+
errorResponseFactory = (libak_IErrorResponseFactory)errorResponseFactoryType?.newInstance();
58+
restLogger = (libak_IRestLogger)loggerType?.newInstance();
5959
restLogger?.initLog(RestContext.request);
6060
libak_RestRouter router = ((libak_RestRouter)routerType.newInstance()).setRoutes();
6161
libak_RestProcessor processor = router
@@ -70,29 +70,6 @@ public class libak_RestFramework {
7070
}
7171
}
7272

73-
/**
74-
* The `IRestResponse` interface defines a method for sending REST responses.
75-
*/
76-
public interface IRestResponse {
77-
void sendResponse();
78-
}
79-
80-
/**
81-
* The `IErrorResponseFactory` interface defines a method for creating error responses.
82-
*/
83-
public interface IErrorResponseFactory {
84-
IRestResponse newErrorRestResponse(Exception exc);
85-
}
86-
87-
/**
88-
* The `IRestLogger` interface defines methods for logging REST-related information.
89-
*/
90-
public interface IRestLogger {
91-
void initLog(RestRequest request);
92-
void addErrorDetails(Exception exc);
93-
void createLog();
94-
}
95-
9673
/**
9774
* This exception is thrown when an invalid URI is encountered. It represents a client error (HTTP 400 Bad Request).
9875
*/

0 commit comments

Comments
 (0)