Skip to content

Commit 98d3307

Browse files
committed
refactor(storePayment): 결제 데이터 없는 경우 204 반환하도록 변경
1 parent 510efb5 commit 98d3307

3 files changed

Lines changed: 31 additions & 16 deletions

File tree

nowait-app-user-api/src/main/java/com/nowait/applicationuser/storepayment/controller/StorePaymentController.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package com.nowait.applicationuser.storepayment.controller;
22

3+
import java.util.Optional;
4+
35
import org.springframework.http.HttpStatus;
46
import org.springframework.http.ResponseEntity;
57
import org.springframework.web.bind.annotation.GetMapping;
68
import org.springframework.web.bind.annotation.PathVariable;
79
import org.springframework.web.bind.annotation.RequestMapping;
810
import org.springframework.web.bind.annotation.RestController;
911

12+
import com.nowait.applicationuser.storepayment.dto.StorePaymentReadDto;
1013
import com.nowait.applicationuser.storepayment.service.StorePaymentService;
1114
import com.nowait.common.api.ApiUtils;
1215

1316
import io.swagger.v3.oas.annotations.Operation;
1417
import io.swagger.v3.oas.annotations.responses.ApiResponse;
1518
import io.swagger.v3.oas.annotations.tags.Tag;
16-
import jakarta.validation.Valid;
1719
import lombok.RequiredArgsConstructor;
1820
import lombok.extern.slf4j.Slf4j;
1921

@@ -30,12 +32,25 @@ public class StorePaymentController {
3032
@Operation(summary = "주점 결제 정보 조회", description = "주점 ID로 주점 결제 정보를 조회합니다.")
3133
@ApiResponse(responseCode = "200", description = "주점 결제 정보 조회 성공")
3234
public ResponseEntity<?> getStorePaymentByStoreId(@PathVariable Long storeId) {
33-
return ResponseEntity
34-
.status(HttpStatus.OK)
35-
.body(
36-
ApiUtils.success(
37-
storePaymentService.getStorePaymentByStoreId(storeId)
38-
)
39-
);
35+
Optional<StorePaymentReadDto> response = storePaymentService.getStorePaymentByStoreId(storeId);
36+
37+
if (response.isPresent()) {
38+
return ResponseEntity
39+
.status(HttpStatus.OK)
40+
.body(
41+
ApiUtils.success(
42+
response
43+
)
44+
);
45+
} else {
46+
return ResponseEntity
47+
.status(HttpStatus.NO_CONTENT)
48+
.body(
49+
ApiUtils.success(
50+
response
51+
)
52+
);
53+
}
54+
4055
}
4156
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.nowait.applicationuser.storepayment.service;
22

3+
import java.util.Optional;
4+
35
import com.nowait.applicationuser.storepayment.dto.StorePaymentReadDto;
46

57
public interface StorePaymentService {
6-
StorePaymentReadDto getStorePaymentByStoreId(Long storeId);
8+
Optional<StorePaymentReadDto> getStorePaymentByStoreId(Long storeId);
79
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.nowait.applicationuser.storepayment.service;
22

3+
import java.util.Optional;
4+
35
import org.springframework.stereotype.Service;
46
import org.springframework.transaction.annotation.Transactional;
57
import com.nowait.applicationuser.storepayment.dto.StorePaymentReadDto;
6-
import com.nowait.domaincorerdb.store.exception.StoreNotFoundException;
7-
import com.nowait.domaincorerdb.storepayment.entity.StorePayment;
88
import com.nowait.domaincorerdb.storepayment.exception.StorePaymentParamEmptyException;
99
import com.nowait.domaincorerdb.storepayment.repository.StorePaymentRepository;
1010

@@ -18,12 +18,10 @@ public class StorePaymentServiceImpl implements StorePaymentService {
1818

1919
@Override
2020
@Transactional(readOnly = true)
21-
public StorePaymentReadDto getStorePaymentByStoreId(Long storeId) {
21+
public Optional<StorePaymentReadDto> getStorePaymentByStoreId(Long storeId) {
2222
if (storeId == null) throw new StorePaymentParamEmptyException();
2323

24-
StorePayment storePayment = storePaymentRepository.findByStoreId(storeId)
25-
.orElseThrow(StoreNotFoundException::new);
26-
27-
return StorePaymentReadDto.fromEntity(storePayment);
24+
return storePaymentRepository.findByStoreId(storeId)
25+
.map(StorePaymentReadDto::fromEntity);
2826
}
2927
}

0 commit comments

Comments
 (0)