-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from TrueSparrowSystems/delete-account-note
Implement API Endpoint for Delete Account Note
- Loading branch information
Showing
23 changed files
with
504 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/main/java/com/salessparrow/api/controllers/AccountNoteController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.salessparrow.api.controllers; | ||
|
||
import org.slf4j.Logger; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.salessparrow.api.dto.formatter.CreateNoteFormatterDto; | ||
import com.salessparrow.api.dto.formatter.GetNoteDetailsFormatterDto; | ||
import com.salessparrow.api.dto.formatter.GetNotesListFormatterDto; | ||
import com.salessparrow.api.dto.requestMapper.NoteDto; | ||
import com.salessparrow.api.services.accountNotes.CreateAccountNoteService; | ||
import com.salessparrow.api.services.accountNotes.DeleteAccountNoteService; | ||
import com.salessparrow.api.services.accountNotes.GetAccountNoteDetailsService; | ||
import com.salessparrow.api.services.accountNotes.GetAccountNotesListService; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.validation.Valid; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/accounts/{account_id}/notes") | ||
@Validated | ||
public class AccountNoteController { | ||
|
||
private Logger logger = org.slf4j.LoggerFactory.getLogger(AccountNoteController.class); | ||
|
||
@Autowired | ||
private GetAccountNotesListService getNotesListService; | ||
|
||
@Autowired | ||
private GetAccountNoteDetailsService getNoteDetailsService; | ||
|
||
@Autowired | ||
private CreateAccountNoteService createNoteService; | ||
|
||
@Autowired | ||
private DeleteAccountNoteService deleteAccountNoteService; | ||
|
||
@PostMapping("") | ||
public ResponseEntity<CreateNoteFormatterDto> addNoteToAccount( | ||
HttpServletRequest request, | ||
@PathVariable("account_id") String accountId, | ||
@Valid @RequestBody NoteDto note | ||
) { | ||
logger.info("Create Note request received"); | ||
|
||
CreateNoteFormatterDto createNoteFormatterDto = createNoteService.createNote(request, accountId, note); | ||
|
||
return ResponseEntity.ok().body(createNoteFormatterDto); | ||
} | ||
|
||
@GetMapping("") | ||
public ResponseEntity<GetNotesListFormatterDto> getNotesList( | ||
HttpServletRequest request, | ||
@PathVariable("account_id") String accountId | ||
) { | ||
logger.info("Get Note List request received"); | ||
|
||
GetNotesListFormatterDto getNotesListResponse = getNotesListService.getNotesList(request, accountId); | ||
|
||
return ResponseEntity.ok().body(getNotesListResponse); | ||
} | ||
|
||
@GetMapping("/{note_id}") | ||
public ResponseEntity<GetNoteDetailsFormatterDto> getNoteFromAccount( | ||
HttpServletRequest request, | ||
@PathVariable("account_id") String accountId, | ||
@PathVariable("note_id") String noteId | ||
) { | ||
logger.info("Get Note request received"); | ||
|
||
GetNoteDetailsFormatterDto getNoteDetailsResponse = getNoteDetailsService.getNoteDetails(request, noteId); | ||
|
||
return ResponseEntity.ok().body(getNoteDetailsResponse); | ||
} | ||
|
||
@DeleteMapping("/{note_id}") | ||
public ResponseEntity<GetNoteDetailsFormatterDto> deleteNote( | ||
HttpServletRequest request, | ||
@PathVariable("account_id") String accountId, | ||
@PathVariable("note_id") String noteId | ||
) { | ||
logger.info("Delete Note request received"); | ||
|
||
deleteAccountNoteService.deleteAccountNote(request, accountId, noteId); | ||
|
||
return ResponseEntity.noContent().build(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...Actions/createNote/CreateNoteFactory.java → .../createAccountNote/CreateNoteFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tions/createNote/CreateNoteInterface.java → ...reateAccountNote/CreateNoteInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ions/createNote/CreateSalesforceNote.java → ...eateAccountNote/CreateSalesforceNote.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../java/com/salessparrow/api/lib/crmActions/deleteAccountNote/DeleteAccountNoteFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.salessparrow.api.lib.crmActions.deleteAccountNote; | ||
|
||
import org.slf4j.Logger; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.salessparrow.api.domain.User; | ||
import com.salessparrow.api.exception.CustomException; | ||
import com.salessparrow.api.lib.errorLib.ErrorObject; | ||
import com.salessparrow.api.lib.globalConstants.UserConstants; | ||
|
||
/** | ||
* DeleteAccountNoteFactory is a factory class for the DeleteAccountNote action for the CRM. | ||
*/ | ||
@Component | ||
public class DeleteAccountNoteFactory { | ||
private Logger logger = org.slf4j.LoggerFactory.getLogger(DeleteAccountNoteFactory.class); | ||
|
||
@Autowired | ||
DeleteSalesforceAccountNote getSalesforceNoteDetails; | ||
|
||
@Autowired | ||
DeleteSalesforceAccountNote deleteAccountSalesforceNote; | ||
|
||
/** | ||
* deleteAccountNote is a method that makes call to delete note based on user kind. | ||
* | ||
* @param user | ||
* @param noteId | ||
* | ||
* @return void | ||
*/ | ||
public void deleteAccountNote(User user, String noteId) { | ||
logger.info("Delete Account Note Factory called"); | ||
|
||
switch(user.getUserKind()) { | ||
case UserConstants.SALESFORCE_USER_KIND: | ||
deleteAccountSalesforceNote.deleteAccountNote(user, noteId); | ||
break; | ||
default: | ||
throw new CustomException( | ||
new ErrorObject( | ||
"l_ca_dan_danf_dn_1", | ||
"something_went_wrong", | ||
"Invalid user kind.")); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ava/com/salessparrow/api/lib/crmActions/deleteAccountNote/DeleteAccountNoteInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.salessparrow.api.lib.crmActions.deleteAccountNote; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import com.salessparrow.api.domain.User; | ||
|
||
/** | ||
* DeleteAccountNoteInterface is an interface for the DeleteAccountNote action for the CRM. | ||
*/ | ||
@Component | ||
public interface DeleteAccountNoteInterface { | ||
public void deleteAccountNote(User user, String noteId); | ||
} |
83 changes: 83 additions & 0 deletions
83
...va/com/salessparrow/api/lib/crmActions/deleteAccountNote/DeleteSalesforceAccountNote.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.salessparrow.api.lib.crmActions.deleteAccountNote; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.salessparrow.api.domain.User; | ||
import com.salessparrow.api.exception.CustomException; | ||
import com.salessparrow.api.lib.Util; | ||
import com.salessparrow.api.lib.errorLib.ErrorObject; | ||
import com.salessparrow.api.lib.globalConstants.SalesforceConstants; | ||
import com.salessparrow.api.lib.httpLib.HttpClient; | ||
import com.salessparrow.api.lib.salesforce.dto.CompositeRequestDto; | ||
import com.salessparrow.api.lib.salesforce.helper.MakeCompositeRequest; | ||
|
||
/** | ||
* DeleteAccountSalesforceNote is a class for the DeleteAccountNote service for the Salesforce CRM. | ||
**/ | ||
@Component | ||
public class DeleteSalesforceAccountNote implements DeleteAccountNoteInterface { | ||
private Logger logger = org.slf4j.LoggerFactory.getLogger(DeleteSalesforceAccountNote.class); | ||
|
||
@Autowired | ||
private SalesforceConstants salesforceConstants; | ||
|
||
@Autowired | ||
private MakeCompositeRequest makeCompositeRequest; | ||
|
||
/** | ||
* Deletes a note from salesforce | ||
* | ||
* @param user | ||
* @param noteId | ||
* | ||
* @return void | ||
**/ | ||
public void deleteAccountNote(User user, String noteId) { | ||
logger.info("Delete Salesforce Account Note called"); | ||
|
||
String salesforceUserId = user.getExternalUserId(); | ||
|
||
String url = salesforceConstants.salesforceDeleteNoteUrl(noteId); | ||
|
||
CompositeRequestDto compositeReq = new CompositeRequestDto("DELETE", url, "DeleteNote"); | ||
|
||
List<CompositeRequestDto> compositeRequests = new ArrayList<CompositeRequestDto>(); | ||
compositeRequests.add(compositeReq); | ||
|
||
HttpClient.HttpResponse response = makeCompositeRequest.makePostRequest(compositeRequests, salesforceUserId); | ||
|
||
parseResponse(response.getResponseBody()); | ||
} | ||
|
||
/** | ||
* Parse Response | ||
* | ||
* @param responseBody | ||
* | ||
* @return void | ||
**/ | ||
public void parseResponse(String responseBody) { | ||
|
||
Util util = new Util(); | ||
JsonNode rootNode = util.getJsonNode(responseBody); | ||
|
||
JsonNode deleteNoteCompositeResponse = rootNode.get("compositeResponse").get(0); | ||
Integer deleteNoteStatusCode = deleteNoteCompositeResponse.get("httpStatusCode").asInt(); | ||
|
||
if (deleteNoteStatusCode != 200 && deleteNoteStatusCode != 201 && deleteNoteStatusCode != 204) { | ||
String errorBody = deleteNoteCompositeResponse.get("body").asText(); | ||
|
||
throw new CustomException( | ||
new ErrorObject( | ||
"l_ca_dan_dasn_pr_1", | ||
"internal_server_error", | ||
errorBody)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.