-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 배달팟 삭제 API 구현 #92
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
Open
daekyochung
wants to merge
1
commit into
develop
Choose a base branch
from
feature/party-delete-api
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| 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; | ||
|
|
@@ -84,4 +85,21 @@ public ResponseEntity<Void> updateDeliveryParty( | |
|
|
||
| return ResponseEntity.ok().build(); | ||
| } | ||
|
|
||
|
|
||
| // 배달팟 삭제(취소) API | ||
| @DeleteMapping("/{partyId}") | ||
| public ResponseEntity<Long> deleteDeliveryParty( | ||
| @PathVariable Long partyId, | ||
| @AuthenticationPrincipal Long currentUserId | ||
| ) { | ||
|
|
||
| Long deletedPartyId = | ||
| deliveryPartyService.deleteDeliveryParty( | ||
| partyId, | ||
| currentUserId | ||
| ); | ||
|
|
||
| return ResponseEntity.ok(deletedPartyId); | ||
| } | ||
|
Comment on lines
+90
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Complete the Swagger contract for this endpoint. The PR explicitly leaves Swagger unfinished, so consumers will not see the owner-only cancellation behavior, 🤖 Prompt for AI Agents |
||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: Leets-Official/TDD-BE
Length of output: 50377
🏁 Script executed:
Repository: Leets-Official/TDD-BE
Length of output: 35002
🌐 Web query:
Spring Security@AuthenticationPrincipalLong principal needs SecurityContext AuthenticationPrincipalArgumentResolver converter Long💡 Result:
In Spring Security, the
@AuthenticationPrincipalannotation relies on the AuthenticationPrincipalArgumentResolver to resolve the principal from the SecurityContext to a method argument [1][2]. When attempting to use@AuthenticationPrincipaldirectly with a Long or primitive long, you may encounter issues because the resolver checks if the principal is assignable to the requested parameter type [3][4]. Important technical constraints: 1. Primitive Types Not Supported: You cannot use primitive types (e.g., long) as arguments for@AuthenticationPrincipal, as these are not considered assignable from the object stored in the SecurityContext, which is typically a wrapper type or custom object [3][4]. Even if the underlying principal is a Long, using a primitive long parameter often causes errors or results in a null value [4]. 2. Type Mismatch: If the principal stored in the SecurityContext is not directly assignable to the type requested in your controller (e.g., you are trying to inject a Long but the principal is a custom UserDetails object), the resolver will return null by default [1][5]. If you set errorOnInvalidType = true in the annotation, it will throw a ClassCastException [1][6]. Recommended Approaches: If your principal object is a custom user class and you simply need to extract a Long ID: 1. Use a SpEL Expression: You can use the expression attribute of@AuthenticationPrincipalto navigate to the desired field [6][2]. If your principal has a getId method, you can use:@AuthenticationPrincipal(expression = "id") Long userId 2. Use a Custom Meta-Annotation or Argument Resolver: If you need more complex conversion logic that SpEL cannot handle, you should create a custom argument resolver. You can implement the HandlerMethodArgumentResolver interface to inspect the security context and perform manual conversion of the principal to your desired Long type. 3. Controller Logic: Alternatively, inject the full principal object (e.g.,@AuthenticationPrincipalCustomUser user) and retrieve the ID inside your method body using user.getId. This is often the cleanest and most readable approach [2]. If you are encountering specific errors with Long conversion, ensure that the object stored in your Authentication principal is indeed the type you expect (e.g., verify that principal is not a UserDetails wrapper when you are expecting a raw Long) [1][7].Citations:
Require authentication and accept the configured principal type.
/api/v1/delivery-parties/**is permitted to all requests inSecurityConfig, so this delete endpoint and the matching update endpoint bypass the JWT checker. If a token is present,JwtAuthenticationFilterstores aUserPrincipal, not aLong, so@AuthenticationPrincipal Longwill not resolve under the current config. Remove this fromPUBLIC_ENDPOINTSunless these methods are genuinely public, and/or change these parameters to@AuthenticationPrincipal UserPrincipal. Add a failing@WebMvcTestfor the unauthenticated endpoint.🤖 Prompt for AI Agents