Skip to content

Commit

Permalink
fix : 카카오 로그인 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunWoo9930 committed Nov 20, 2024
1 parent 4740c90 commit 37e2846
Show file tree
Hide file tree
Showing 19 changed files with 357 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
Expand All @@ -16,9 +17,9 @@
import com.jangburich.domain.menu.domain.MenuGetResponseDTO;
import com.jangburich.domain.menu.domain.MenuUpdateRequestDTO;
import com.jangburich.domain.menu.domain.service.MenuService;
import com.jangburich.global.GetAuthorization;
import com.jangburich.global.payload.Message;
import com.jangburich.global.payload.ResponseCustom;
import com.jangburich.utils.parser.AuthenticationParser;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
Expand All @@ -33,31 +34,31 @@ public class MenuController {

@PostMapping("/register")
public ResponseCustom<Message> registerMenu(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader,
Authentication authentication,
@RequestBody MenuCreateRequestDTO menuCreateRequestDTO) {
menuService.registerMenu(GetAuthorization.getUserId(authorizationHeader), menuCreateRequestDTO);
menuService.registerMenu(AuthenticationParser.parseUserId(authentication), menuCreateRequestDTO);
return ResponseCustom.OK(Message.builder().message("success").build());
}

@PatchMapping("/update/{id}")
public ResponseCustom<Message> updateMenu(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader, @PathVariable Long id,
Authentication authentication, @PathVariable Long id,
@RequestBody MenuUpdateRequestDTO menuUpdateRequestDTO) {
menuService.updateMenu(GetAuthorization.getUserId(authorizationHeader), id, menuUpdateRequestDTO);
menuService.updateMenu(AuthenticationParser.parseUserId(authentication), id, menuUpdateRequestDTO);
return ResponseCustom.OK(Message.builder().message("success").build());
}

@DeleteMapping("/{id}")
public ResponseCustom<Message> deleteMenu(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader, @PathVariable Long id) {
menuService.deleteMenu(GetAuthorization.getUserId(authorizationHeader), id);
Authentication authentication, @PathVariable Long id) {
menuService.deleteMenu(AuthenticationParser.parseUserId(authentication), id);
return ResponseCustom.OK(Message.builder().message("success").build());
}

@GetMapping("")
public ResponseCustom<List<MenuGetResponseDTO>> getMenu(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader) {
List<MenuGetResponseDTO> menu = menuService.getMenu(GetAuthorization.getUserId(authorizationHeader));
Authentication authentication) {
List<MenuGetResponseDTO> menu = menuService.getMenu(AuthenticationParser.parseUserId(authentication));
return ResponseCustom.OK(menu);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
import com.jangburich.domain.order.dto.request.OrderRequest;
import com.jangburich.domain.order.dto.response.CartResponse;
import com.jangburich.domain.order.dto.response.GetCartItemsResponse;
import com.jangburich.domain.point.domain.repository.PointTransaction;
import com.jangburich.domain.store.domain.Store;
import com.jangburich.domain.store.domain.repository.StoreRepository;
import com.jangburich.domain.store.domain.repository.StoreTeamRepository;
import com.jangburich.domain.team.domain.Team;
import com.jangburich.domain.team.domain.repository.TeamRepository;
import com.jangburich.domain.user.domain.User;
import com.jangburich.domain.user.domain.repository.UserRepository;
import com.jangburich.domain.user.repository.UserRepository;
import com.jangburich.global.payload.Message;
import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.jangburich.domain.owner.domain.controller;

import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.jangburich.domain.oauth.domain.CustomOAuthUser;
import com.jangburich.domain.owner.domain.OwnerCreateReqDTO;
import com.jangburich.domain.owner.domain.OwnerGetResDTO;
import com.jangburich.domain.owner.domain.service.OwnerService;
import com.jangburich.global.GetAuthorization;
import com.jangburich.global.payload.Message;
import com.jangburich.global.payload.ResponseCustom;
import com.jangburich.utils.parser.AuthenticationParser;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -29,9 +28,9 @@ public class OwnerController {
@Operation(summary = "사장님 정보 등록", description = "사장님 상세 정보를 등록합니다.")
@PostMapping("/register")
public ResponseCustom<Message> registerOwner(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader,
Authentication authentication,
OwnerCreateReqDTO ownerCreateReqDTO) {
ownerService.registerOwner(GetAuthorization.getUserId(authorizationHeader), ownerCreateReqDTO);
ownerService.registerOwner(AuthenticationParser.parseUserId(authentication), ownerCreateReqDTO);
return ResponseCustom.OK(Message.builder()
.message("success")
.build());
Expand All @@ -40,7 +39,7 @@ public ResponseCustom<Message> registerOwner(
@Operation(summary = "사장님 정보 조회", description = "사장님 정보를 조회합니다.")
@GetMapping("")
public ResponseCustom<OwnerGetResDTO> getOwnerInfo(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader) {
return ResponseCustom.OK(ownerService.getOwnerInfo(GetAuthorization.getUserId(authorizationHeader)));
Authentication authentication) {
return ResponseCustom.OK(ownerService.getOwnerInfo(AuthenticationParser.parseUserId(authentication)));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jangburich.domain.payment.presentation;

import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -14,8 +14,8 @@
import com.jangburich.domain.payment.dto.response.ReadyResponse;
import com.jangburich.domain.payment.exception.PaymentCancellationException;
import com.jangburich.domain.payment.exception.PaymentFailedException;
import com.jangburich.global.GetAuthorization;
import com.jangburich.global.payload.ResponseCustom;
import com.jangburich.utils.parser.AuthenticationParser;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -32,10 +32,10 @@ public class PaymentController {
@Operation(summary = "결제 준비", description = "카카오페이 등 결제 수단을 준비한다.")
@PostMapping("/ready")
public ResponseCustom<ReadyResponse> payReady(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader,
Authentication authentication,
@RequestBody PayRequest payRequest) {
return ResponseCustom.OK(
paymentProcessingService.processPayment(GetAuthorization.getUserId(authorizationHeader), payRequest));
paymentProcessingService.processPayment(AuthenticationParser.parseUserId(authentication), payRequest));
}

@Operation(summary = "결제 성공", description = "결제 성공")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PatchMapping;
Expand All @@ -24,9 +25,9 @@
import com.jangburich.domain.store.domain.dto.response.PaymentGroupDetailResponse;
import com.jangburich.domain.store.domain.dto.response.SearchStoresResponse;
import com.jangburich.domain.store.domain.service.StoreService;
import com.jangburich.global.GetAuthorization;
import com.jangburich.global.payload.Message;
import com.jangburich.global.payload.ResponseCustom;
import com.jangburich.utils.parser.AuthenticationParser;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -64,62 +65,62 @@ public ResponseCustom<Page<SearchStoresResponse>> searchStores(
@Operation(summary = "가게 등록", description = "신규 파트너 가게를 등록합니다.")
@PostMapping("/create")
public ResponseCustom<Message> createStore(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader,
Authentication authentication,
@RequestBody StoreCreateRequestDTO storeCreateRequestDTO) {
storeService.createStore(GetAuthorization.getUserId(authorizationHeader), storeCreateRequestDTO);
storeService.createStore(AuthenticationParser.parseUserId(authentication), storeCreateRequestDTO);
return ResponseCustom.OK(Message.builder().message("success").build());
}

@Operation(summary = "가게 추가정보 저장", description = "예약 가능 여부, 최소 선결제 금액, 선결제 사용 기간을 저장합니다.")
@PostMapping("/create/additionalInfo")
public ResponseCustom<Message> createAdditionalInfo(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader,
Authentication authentication,
@RequestBody StoreAdditionalInfoCreateRequestDTO storeAdditionalInfoCreateRequestDTO) {
storeService.createAdditionalInfo(GetAuthorization.getUserId(authorizationHeader),
storeService.createAdditionalInfo(AuthenticationParser.parseUserId(authentication),
storeAdditionalInfoCreateRequestDTO);
return ResponseCustom.OK(Message.builder().message("success").build());
}

@Operation(summary = "가게 정보 수정", description = "가게 정보를 수정합니다.")
@PatchMapping("/update")
public ResponseCustom<Message> updateStore(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader,
Authentication authentication,
@RequestBody StoreUpdateRequestDTO storeUpdateRequestDTO) {
storeService.updateStore(GetAuthorization.getUserId(authorizationHeader), storeUpdateRequestDTO);
storeService.updateStore(AuthenticationParser.parseUserId(authentication), storeUpdateRequestDTO);
return ResponseCustom.OK(Message.builder().message("success").build());
}

@Operation(summary = "가게 정보 조회", description = "가게 상세 정보를 조회합니다.")
@GetMapping("")
public ResponseCustom<StoreGetResponseDTO> getStoreInfo(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader) {
return ResponseCustom.OK(storeService.getStoreInfo(GetAuthorization.getUserId(authorizationHeader)));
Authentication authentication) {
return ResponseCustom.OK(storeService.getStoreInfo(AuthenticationParser.parseUserId(authentication)));
}

@Operation(summary = "결제 그룹 조회", description = "장부 결제 그룹을 조회합니다.")
@GetMapping("/payment_group")
public ResponseCustom<Page<StoreTeamResponseDTO>> getPaymentGroup(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader,
Authentication authentication,
Pageable pageable) {
return ResponseCustom.OK(
storeService.getPaymentGroup(GetAuthorization.getUserId(authorizationHeader), pageable));
storeService.getPaymentGroup(AuthenticationParser.parseUserId(authentication), pageable));
}

@Operation(summary = "결제 그룹 상세 조회", description = "장부 결제 그룹을 상세 조회합니다.")
@GetMapping("/payment_group/{teamId}")
public ResponseCustom<PaymentGroupDetailResponse> getPaymentGroupDetail(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader, @PathVariable Long teamId,
Authentication authentication, @PathVariable Long teamId,
Pageable pageable) {
return ResponseCustom.OK(
storeService.getPaymentGroupDetail(GetAuthorization.getUserId(authorizationHeader), teamId, pageable));
storeService.getPaymentGroupDetail(AuthenticationParser.parseUserId(authentication), teamId, pageable));
}

@Operation(summary = "결제 내역 조회", description = "가게에서 일어난 결제 내역을 조회합니다.")
@GetMapping("/payment_history")
public ResponseCustom<?> getPaymentHistory(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader,
Authentication authentication,
Pageable pageable) {
return ResponseCustom.OK(
storeService.getPaymentHistory(GetAuthorization.getUserId(authorizationHeader), pageable));
storeService.getPaymentHistory(AuthenticationParser.parseUserId(authentication), pageable));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.jangburich.domain.team.domain.repository.TeamRepository;
import com.jangburich.domain.user.domain.User;
import com.jangburich.domain.user.repository.UserRepository;
import com.jangburich.global.GetAuthorization;
import com.jangburich.global.error.DefaultNullPointerException;
import com.jangburich.global.payload.ErrorCode;

Expand Down Expand Up @@ -173,15 +172,15 @@ public Page<StoreTeamResponseDTO> getPaymentGroup(String userId, Pageable pageab

public Page<SearchStoresResponse> searchByCategory(final String authentication, final Integer searchRadius,
final Category category, final StoreSearchCondition storeSearchCondition, final Pageable pageable) {
User user = userRepository.findByProviderId(GetAuthorization.getUserId(authentication))
User user = userRepository.findByProviderId(authentication)
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION));
return storeRepository.findStoresByCategory(user.getUserId(), searchRadius, category, storeSearchCondition,
pageable);
}

public Page<SearchStoresResponse> searchStores(final String authentication, final String keyword,
final StoreSearchConditionWithType storeSearchConditionWithType, final Pageable pageable) {
User user = userRepository.findByProviderId(GetAuthorization.getUserId(authentication))
User user = userRepository.findByProviderId(authentication)
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION));
return storeRepository.findStores(user.getUserId(), keyword, storeSearchConditionWithType, pageable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.jangburich.domain.team.dto.request.RegisterTeamRequest;
import com.jangburich.domain.user.domain.User;
import com.jangburich.domain.user.repository.UserRepository;
import com.jangburich.global.GetAuthorization;
import com.jangburich.global.payload.Message;

import lombok.RequiredArgsConstructor;
Expand All @@ -30,8 +29,7 @@ public class TeamService {

@Transactional
public Message registerTeam(String userId, RegisterTeamRequest registerTeamRequest) {

User user = userRepository.findByProviderId(GetAuthorization.getUserId(userId))
User user = userRepository.findByProviderId(userId)
.orElseThrow(() -> new NullPointerException());

Team team = Team.builder()
Expand All @@ -57,7 +55,7 @@ public Message registerTeam(String userId, RegisterTeamRequest registerTeamReque

@Transactional
public Message joinTeam(String userId, String joinCode) {
User user = userRepository.findByProviderId(GetAuthorization.getUserId(userId))
User user = userRepository.findByProviderId(userId)
.orElseThrow(() -> new NullPointerException());

Team team = teamRepository.findBySecretCode(joinCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -29,19 +28,19 @@ public class TeamController {
@Operation(summary = "팀 생성", description = "팀을 생성한다. 팀 리더는 생성자")
@PostMapping
public ResponseCustom<Message> registerTeam(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader,
Authentication authentication,
@RequestBody RegisterTeamRequest registerTeamRequest
) {
return ResponseCustom.OK(
teamService.registerTeam(authorizationHeader, registerTeamRequest));
teamService.registerTeam(AuthenticationParser.parseUserId(authentication), registerTeamRequest));
}

@Operation(summary = "팀 가입", description = "비밀 코드를 입력하여, 팀에 가입한다.")
@PostMapping("/join/{joinCode}")
public ResponseCustom<Message> joinTeam(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader,
Authentication authentication,
@PathVariable("joinCode") String joinCode
) {
return ResponseCustom.OK(teamService.joinTeam(authorizationHeader, joinCode));
return ResponseCustom.OK(teamService.joinTeam(AuthenticationParser.parseUserId(authentication), joinCode));
}
}
Loading

0 comments on commit 37e2846

Please sign in to comment.