Skip to content

Commit

Permalink
Merge pull request #51 from 9oormthon-univ/fix/login
Browse files Browse the repository at this point in the history
Fix/login
  • Loading branch information
HyunWoo9930 authored Nov 20, 2024
2 parents 0cf2f14 + 37e2846 commit b161c8e
Show file tree
Hide file tree
Showing 18 changed files with 356 additions and 169 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
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.jangburich.domain.user.domain.KakaoApiResponseDTO;
import com.jangburich.domain.user.domain.TokenResponseDTO;
import com.jangburich.domain.user.service.UserService;
import com.jangburich.global.payload.Message;
import com.jangburich.global.payload.ResponseCustom;
import com.jangburich.utils.parser.AuthenticationParser;

import lombok.RequiredArgsConstructor;

Expand All @@ -32,32 +33,36 @@ public class UserController {
private final UserService userService;

@PostMapping("/login")
public ResponseCustom<Map<String, Object>> login(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader) {

return ResponseCustom.OK(null);
public ResponseCustom<TokenResponseDTO> login(
@RequestParam String authorizationHeader) {
TokenResponseDTO login = userService.login(authorizationHeader);
return ResponseCustom.OK(login);
}

@GetMapping("/user-info")
public ResponseEntity<KakaoApiResponseDTO> getUserInfo(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader) {
KakaoApiResponseDTO userInfo = userService.getUserInfo(authorizationHeader);
Authentication authentication) {
KakaoApiResponseDTO userInfo = userService.getUserInfo(AuthenticationParser.parseUserId(authentication));

return ResponseEntity.ok(userInfo);
}

@PostMapping("/join/user")
public ResponseCustom<Message> joinUser(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader) {
userService.joinUser(authorizationHeader);
return ResponseCustom.OK(Message.builder().message("success").build());
public ResponseCustom<TokenResponseDTO> joinUser(
@RequestParam String authorizationHeader) {
return ResponseCustom.OK(userService.joinUser(authorizationHeader));
}

@PostMapping("/join/owner")
public ResponseCustom<Message> joinOwner(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader) {
userService.joinOwner(authorizationHeader);
return ResponseCustom.OK(Message.builder().message("success").build());
public ResponseCustom<TokenResponseDTO> joinOwner(
@RequestParam String authorizationHeader) {
return ResponseCustom.OK(userService.joinOwner(authorizationHeader));
}

@PostMapping("/token/reissue")
public ResponseEntity<String> reissueAccessToken(@RequestParam String refreshToken) {
String newAccessToken = userService.reissueAccessToken(refreshToken);
return ResponseEntity.ok(newAccessToken);
}

@PostMapping("/token")
Expand Down
Loading

0 comments on commit b161c8e

Please sign in to comment.