Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRIB-105: Create endpoint for removing connection #146

Merged
merged 10 commits into from
Jan 19, 2024

Conversation

maryamkhan14
Copy link
Contributor

This PR addresses TRIB-105 and creates a DELETE endpoint for removing a connection. The following changes are made:

  • Add repository method for deleting connection from connections table in DB
  • Create ConnectionRemovalRequestDTO containing the user IDs of the connected users
  • Create relevant service method, controller endpoint, endpoint Swagger annotation
  • Write relevant unit tests

Copy link

codecov bot commented Jan 3, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (bd14a74) 75.50% compared to head (c6aed44) 75.72%.

Files Patch % Lines
...ato/tribeapp/controllers/ConnectAPIController.java 87.50% 2 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #146      +/-   ##
=============================================
+ Coverage      75.50%   75.72%   +0.21%     
- Complexity       627      632       +5     
=============================================
  Files             92       93       +1     
  Lines           1915     1924       +9     
  Branches         267      266       -1     
=============================================
+ Hits            1446     1457      +11     
+ Misses           426      425       -1     
+ Partials          43       42       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
@Connect
@PostMapping
public boolean connect(@RequestBody @Valid ConnectRequest connectRequest) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets return a ResponseEntity here as well, rather than just boolean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a different endpoint, but I'd be glad to refactor this in another issue! The endpoint in this PR is the one with the @DeleteMapping - this line seems to have changed due to reformatting.

@@ -102,7 +99,7 @@ public void connect(ConnectIncomingMessageDTO incoming) {

public ConnectOutgoingMessageDTO handleConnectionIntent(String connectionIntent, Long requestingUserId, Long toBeConnectedWithUserId) {
if (connectionIntent == "") {
List<Long> recipients = new ArrayList<>(Arrays.asList(toBeConnectedWithUserId));
List<Long> recipients = new ArrayList<>(Collections.singletonList(toBeConnectedWithUserId));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason you used Collections.singletonList rather than Array.asList?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was experimenting with the Collections.singletonList method and accidentally modified it here. I'll undo this change.

@@ -128,4 +125,16 @@ public ConnectOutgoingMessageDTO handleConnectionIntent(String connectionIntent,
}
return null;
}

public boolean removeConnection(ConnectionRemovalRequest connectionRemovalRequest) {
if (Objects.equals(connectionRemovalRequest.requestingUserId, connectionRemovalRequest.connectedWithUserId)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Object.equals() necessary here? Would == work as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the ConnectionRemovalRequest DTO uses the Long wrapper type for the user IDs, they're technically different objects, so I don't think == would work. But if I use the "long" primitive type, then == should also work fine. (Other DTO objects also use Long wrapper types though, so for consistency, using the wrapper type may be better.)

@haxwell haxwell merged commit b98d7e5 into savvato-software:develop Jan 19, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants