Skip to content
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
@@ -1,5 +1,7 @@
package com.nowait.applicationadmin.storepayment.controller;

import java.util.Optional;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand All @@ -12,6 +14,7 @@

import com.nowait.applicationadmin.storepayment.dto.StorePaymentCreateRequest;
import com.nowait.applicationadmin.storepayment.dto.StorePaymentCreateResponse;
import com.nowait.applicationadmin.storepayment.dto.StorePaymentReadDto;
import com.nowait.applicationadmin.storepayment.dto.StorePaymentUpdateRequest;
import com.nowait.applicationadmin.storepayment.service.StorePaymentService;
import com.nowait.common.api.ApiUtils;
Expand Down Expand Up @@ -52,13 +55,25 @@ public ResponseEntity<?> createStorePayment(@Valid @RequestBody StorePaymentCrea
@Operation(summary = "주점 결제 정보 조회", description = "인증된 사용자의 주점 결제 정보를 조회합니다.")
@ApiResponse(responseCode = "200", description = "주점 결제 정보 조회 성공")
public ResponseEntity<?> getStorePaymentByStoreId(@AuthenticationPrincipal MemberDetails memberDetails) {
return ResponseEntity
.status(HttpStatus.OK)
.body(
ApiUtils.success(
storePaymentService.getStorePaymentByStoreId(memberDetails)
)
);
Optional<StorePaymentReadDto> response = storePaymentService.getStorePaymentByStoreId(memberDetails);

if (response.isPresent()) {
return ResponseEntity
.status(HttpStatus.OK)
.body(
ApiUtils.success(
response
)
);
} else {
return ResponseEntity
.status(HttpStatus.OK)
.body(
ApiUtils.success(
"해당 주점의 등록된 결제 정보가 존재하지 않습니다."
)
);
}
}

@PatchMapping("/update")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nowait.applicationadmin.storepayment.service;

import java.util.Optional;

import com.nowait.applicationadmin.storepayment.dto.StorePaymentCreateRequest;
import com.nowait.applicationadmin.storepayment.dto.StorePaymentCreateResponse;
import com.nowait.applicationadmin.storepayment.dto.StorePaymentReadDto;
Expand All @@ -9,6 +11,6 @@
public interface StorePaymentService {

StorePaymentCreateResponse createStorePayment(StorePaymentCreateRequest request, MemberDetails memberDetails);
StorePaymentReadDto getStorePaymentByStoreId(MemberDetails memberDetails);
Optional<StorePaymentReadDto> getStorePaymentByStoreId(MemberDetails memberDetails);
StorePaymentReadDto updateStorePayment(StorePaymentUpdateRequest request, MemberDetails memberDetails);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nowait.applicationadmin.storepayment.service;

import java.util.Optional;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -51,18 +53,17 @@ public StorePaymentCreateResponse createStorePayment(StorePaymentCreateRequest r

@Override
@Transactional(readOnly = true)
public StorePaymentReadDto getStorePaymentByStoreId(MemberDetails memberDetails) {
public Optional<StorePaymentReadDto> getStorePaymentByStoreId(MemberDetails memberDetails) {
if (memberDetails == null) throw new StorePaymentParamEmptyException();

User user = userRepository.findById(memberDetails.getId()).orElseThrow(UserNotFoundException::new);
Long storeId = user.getStoreId();
if (!Role.SUPER_ADMIN.equals(user.getRole()) && !user.getStoreId().equals(storeId)) {
throw new StorePaymentViewUnauthorizedException();
}
StorePayment storePayment = storePaymentRepository.findByStoreId(storeId)
.orElseThrow(StorePaymentNotFoundException::new);

return StorePaymentReadDto.fromEntity(storePayment);
return storePaymentRepository.findByStoreId(storeId)
.map(StorePaymentReadDto::fromEntity);
}

@Override
Expand Down