Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

[Refactor/Fix] Wish 엔드포인트 조정 및 부분 오류 수정 #176

Merged
merged 5 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ public class WishController {
private final WishService wishService;

@PostMapping
public ApiResponse<WishAddResponse> addWish(@Valid @RequestBody WishAddRequest wishAddRequest) {
public ApiResponse<WishAddResponse> addWish(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@Valid @RequestBody WishAddRequest wishAddRequest
) {
return ApiResponse.ok(
wishService.addWish(wishAddRequest)
wishService.addWish(userPrincipal.id(), wishAddRequest)
);
}

Expand All @@ -29,17 +32,18 @@ public ApiResponse<Boolean> isWished(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@PathVariable Integer placeId
) {
Long memberId = userPrincipal.id();
return ApiResponse.ok(
wishService.isWished(memberId, placeId)
wishService.isWished(userPrincipal.id(), placeId)
);
}

@DeleteMapping("{placeId}")
public ApiResponse<Boolean> deleteWish(@PathVariable Integer placeId) {
Long memberId = 1L;
public ApiResponse<Boolean> deleteWish(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@PathVariable Integer placeId
) {
return ApiResponse.ok(
wishService.deleteWish(memberId, placeId)
wishService.deleteWish(userPrincipal.id(), placeId)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import jakarta.validation.constraints.Positive;

public record WishAddRequest(
@Positive Long memberId,
@Positive Integer placeId,
@Positive Integer contentTypeId
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public class WishService {
private final PlaceService placeService;

@Transactional
public WishAddResponse addWish(WishAddRequest wishAddRequest) {
public WishAddResponse addWish(Long memberId, WishAddRequest wishAddRequest) {
int placeId = wishAddRequest.placeId();
int contentTypeId = wishAddRequest.contentTypeId();

Place place = placeService.saveOrUpdatePlace(placeId, contentTypeId);

Wish wish = Wish.builder()
.memberId(wishAddRequest.memberId())
.memberId(memberId)
.place(place)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
.successHandlerLogin(loginAuthenticationSuccessHandler)
.failureHandlerLogin(new LoginAuthenticationFailureHandler(handlerExceptionResolver)))
.anonymous(anonymous -> anonymous
.principal(new UserPrincipal(null, "anonymous", AuthProvider.NONE)));
.principal(new UserPrincipal(0L, "anonymous", AuthProvider.NONE)));

// 세션 유지 필터
httpSecurity
Expand Down
1 change: 0 additions & 1 deletion app/src/test/http/wish.http
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ POST http://localhost:8080/wishes
Content-Type: application/json

{
"memberId": {{memberId}},
"placeId": {{accommodationId}},
"contentTypeId": {{accommodationTypeId}}
}
Expand Down