Skip to content

Commit

Permalink
Merge branch 'be/dev/feat-sns-login#1726-refactorAuth' of github.com:…
Browse files Browse the repository at this point in the history
…innovationacademy-kr/Cabi into be/dev/feat-sns-login#1726-refactorAuth
  • Loading branch information
lamodadite committed Feb 18, 2025
2 parents 2ec04ee + 5d2e76c commit feefa92
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.ftclub.cabinet.auth.domain.AuthGuard;
import org.ftclub.cabinet.auth.domain.AuthLevel;
import org.ftclub.cabinet.config.security.UserInfoDto;
import org.ftclub.cabinet.dto.CoinCollectionRewardResponseDto;
import org.ftclub.cabinet.dto.CoinHistoryPaginationDto;
import org.ftclub.cabinet.dto.CoinMonthlyCollectionDto;
Expand All @@ -18,6 +17,7 @@
import org.ftclub.cabinet.log.Logging;
import org.ftclub.cabinet.user.domain.UserSession;
import org.springframework.data.domain.Pageable;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -40,7 +40,6 @@ public class ItemController {
* @return
*/
@GetMapping("")
@AuthGuard(level = AuthLevel.USER_OR_ADMIN)
public ItemStoreResponseDto getAllItems() {
return itemFacadeService.getAllItems();
}
Expand All @@ -52,8 +51,7 @@ public ItemStoreResponseDto getAllItems() {
* @param sku
*/
@PostMapping("/{sku}/purchase")
@AuthGuard(level = AuthLevel.USER_ONLY)
public void purchaseItem(@UserSession UserSessionDto user,
public void purchaseItem(@AuthenticationPrincipal UserInfoDto user,
@PathVariable Sku sku) {
itemFacadeService.purchaseItem(user.getUserId(), sku);
}
Expand All @@ -66,20 +64,19 @@ public void purchaseItem(@UserSession UserSessionDto user,
* @return
*/
@GetMapping("/history")
@AuthGuard(level = AuthLevel.USER_ONLY)
public ItemHistoryPaginationDto getItemHistory(@UserSession UserSessionDto user,
public ItemHistoryPaginationDto getItemHistory(@AuthenticationPrincipal UserInfoDto user,
Pageable pageable) {
return itemFacadeService.getItemHistory(user.getUserId(), pageable);
}

// TODO: UserSession을 AuthenticationPrincipal로 변경
/**
* 유저가 보유하고 있는 아이템 목록 조회
*
* @param user
* @return
*/
@GetMapping("/me")
@AuthGuard(level = AuthLevel.USER_ONLY)
public MyItemResponseDto getMyItems(@UserSession UserSessionDto user) {
return itemFacadeService.getMyItems(user);
}
Expand All @@ -93,8 +90,7 @@ public MyItemResponseDto getMyItems(@UserSession UserSessionDto user) {
* @return
*/
@GetMapping("/coin/history")
@AuthGuard(level = AuthLevel.USER_ONLY)
public CoinHistoryPaginationDto getCoinHistory(@UserSession UserSessionDto user,
public CoinHistoryPaginationDto getCoinHistory(@AuthenticationPrincipal UserInfoDto user,
@RequestParam CoinHistoryType type, Pageable pageable) {
return itemFacadeService.getCoinHistory(user.getUserId(), type, pageable);
}
Expand All @@ -106,9 +102,8 @@ public CoinHistoryPaginationDto getCoinHistory(@UserSession UserSessionDto user,
* @return
*/
@GetMapping("/coin")
@AuthGuard(level = AuthLevel.USER_ONLY)
public CoinMonthlyCollectionDto getCoinMonthlyCollectionCount(
@UserSession UserSessionDto user) {
@AuthenticationPrincipal UserInfoDto user) {
return itemFacadeService.getCoinCollectionCountInMonth(user.getUserId());
}

Expand All @@ -118,8 +113,7 @@ public CoinMonthlyCollectionDto getCoinMonthlyCollectionCount(
* @param user 유저 세션
*/
@PostMapping("/coin")
@AuthGuard(level = AuthLevel.USER_ONLY)
public CoinCollectionRewardResponseDto collectCoin(@UserSession UserSessionDto user) {
public CoinCollectionRewardResponseDto collectCoin(@AuthenticationPrincipal UserInfoDto user) {
return itemFacadeService.collectCoinAndIssueReward(user.getUserId());
}

Expand All @@ -131,8 +125,7 @@ public CoinCollectionRewardResponseDto collectCoin(@UserSession UserSessionDto u
* @param data sku 에 따라 다르게 필요한 정보
*/
@PostMapping("{sku}/use")
@AuthGuard(level = AuthLevel.USER_ONLY)
public void useItem(@UserSession UserSessionDto user,
public void useItem(@AuthenticationPrincipal UserInfoDto user,
@PathVariable("sku") Sku sku,
@Valid @RequestBody ItemUseRequestDto data) {
itemFacadeService.useItem(user.getUserId(), sku, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.ftclub.cabinet.auth.domain.AuthGuard;
import org.ftclub.cabinet.auth.domain.AuthLevel;
import org.ftclub.cabinet.config.security.UserInfoDto;
import org.ftclub.cabinet.dto.CabinetInfoRequestDto;
import org.ftclub.cabinet.dto.LentEndMemoDto;
import org.ftclub.cabinet.dto.LentHistoryPaginationDto;
Expand All @@ -16,6 +15,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -39,9 +39,8 @@ public class LentController {
* @param cabinetId 대여할 사물함 ID
*/
@PostMapping("/cabinets/{cabinetId}")
@AuthGuard(level = AuthLevel.USER_ONLY)
public void startLentCabinet(
@UserSession UserSessionDto user,
@AuthenticationPrincipal UserInfoDto user,
@PathVariable Long cabinetId) {
lentFacadeService.startLentCabinet(user.getUserId(), cabinetId);
}
Expand All @@ -54,9 +53,8 @@ public void startLentCabinet(
* @param shareCodeDto 공유 사물함 초대 코드
*/
@PostMapping("/cabinets/share/{cabinetId}")
@AuthGuard(level = AuthLevel.USER_ONLY)
public void startLentShareCabinet(
@UserSession UserSessionDto user,
@AuthenticationPrincipal UserInfoDto user,
@PathVariable Long cabinetId,
@Valid @RequestBody ShareCodeDto shareCodeDto) {
lentFacadeService.startLentShareCabinet(user.getUserId(), cabinetId,
Expand All @@ -70,9 +68,8 @@ public void startLentShareCabinet(
* @param cabinetId 대여 취소할 사물함 ID
*/
@PatchMapping("/cabinets/share/cancel/{cabinetId}")
@AuthGuard(level = AuthLevel.USER_OR_ADMIN)
public void cancelLentShareCabinet(
@UserSession UserSessionDto user,
@AuthenticationPrincipal UserInfoDto user,
@PathVariable Long cabinetId) {
lentFacadeService.cancelShareCabinetLent(user.getUserId(), cabinetId);
}
Expand All @@ -83,9 +80,8 @@ public void cancelLentShareCabinet(
* @param userSessionDto 사용자 세션
*/
@PatchMapping("/return")
@AuthGuard(level = AuthLevel.USER_ONLY)
public void endLent(
@UserSession UserSessionDto userSessionDto) {
@AuthenticationPrincipal UserInfoDto userSessionDto) {
lentFacadeService.endUserLent(userSessionDto.getUserId(), null);
}

Expand All @@ -98,9 +94,8 @@ public void endLent(
* @param lentEndMemoDto 반납 메모
*/
@PatchMapping("/return-memo")
@AuthGuard(level = AuthLevel.USER_ONLY)
public void endLentWithMemo(
@UserSession UserSessionDto userSessionDto,
@AuthenticationPrincipal UserInfoDto userSessionDto,
@Valid @RequestBody LentEndMemoDto lentEndMemoDto) {
lentFacadeService.endUserLent(userSessionDto.getUserId(), lentEndMemoDto.getCabinetMemo());
}
Expand All @@ -114,22 +109,21 @@ public void endLentWithMemo(
* @param cabinetInfoRequestDto 수정할 사물함 정보
*/
@PatchMapping("/me/cabinet")
@AuthGuard(level = AuthLevel.USER_ONLY)
public void updateCabinetInfo(
@UserSession UserSessionDto user,
@AuthenticationPrincipal UserInfoDto user,
@Valid @RequestBody CabinetInfoRequestDto cabinetInfoRequestDto) {
lentFacadeService.updateLentCabinetInfo(user.getUserId(),
cabinetInfoRequestDto.getTitle(), cabinetInfoRequestDto.getMemo());
}

// TODO: UserSession을 AuthenticationPrincipal로 변경
/**
* 내 사물함 대여 정보 조회
*
* @param user 사용자 세션
* @return 내 사물함 대여 정보 HTTP 응답
*/
@GetMapping("/me")
@AuthGuard(level = AuthLevel.USER_ONLY)
public ResponseEntity<MyCabinetResponseDto> getMyLentInfo(
@UserSession UserSessionDto user) {
MyCabinetResponseDto myCabinetResponseDto = lentFacadeService.getMyLentInfo(user);
Expand All @@ -139,6 +133,7 @@ public ResponseEntity<MyCabinetResponseDto> getMyLentInfo(
return ResponseEntity.status(HttpStatus.OK).body(myCabinetResponseDto);
}

// TODO: UserSession을 AuthenticationPrincipal로 변경
/**
* 내 대여 이력 조회
*
Expand All @@ -147,7 +142,6 @@ public ResponseEntity<MyCabinetResponseDto> getMyLentInfo(
* @return 내 대여 이력
*/
@GetMapping("/me/histories")
@AuthGuard(level = AuthLevel.USER_ONLY)
public LentHistoryPaginationDto getMyLentLog(
@UserSession UserSessionDto user,
@Valid Pageable pageable) {
Expand All @@ -161,9 +155,8 @@ public LentHistoryPaginationDto getMyLentLog(
* @param cabinetId 이동할 사물함의 ID
*/
@PostMapping("/swap/{cabinetId}")
@AuthGuard(level = AuthLevel.USER_ONLY)
public void swap(
@UserSession UserSessionDto user,
@AuthenticationPrincipal UserInfoDto user,
@PathVariable Long cabinetId) {
lentFacadeService.swapPrivateCabinet(user.getUserId(), cabinetId);
}
Expand Down

0 comments on commit feefa92

Please sign in to comment.