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,19 +1,21 @@
package com.nowait.applicationuser.storepayment.controller;

import java.util.Optional;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.nowait.applicationuser.storepayment.dto.StorePaymentReadDto;
import com.nowait.applicationuser.storepayment.service.StorePaymentService;
import com.nowait.common.api.ApiUtils;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -30,12 +32,25 @@ public class StorePaymentController {
@Operation(summary = "주점 결제 정보 조회", description = "주점 ID로 주점 결제 정보를 조회합니다.")
@ApiResponse(responseCode = "200", description = "주점 결제 정보 조회 성공")
public ResponseEntity<?> getStorePaymentByStoreId(@PathVariable Long storeId) {
return ResponseEntity
.status(HttpStatus.OK)
.body(
ApiUtils.success(
storePaymentService.getStorePaymentByStoreId(storeId)
)
);
Optional<StorePaymentReadDto> response = storePaymentService.getStorePaymentByStoreId(storeId);

if (response.isPresent()) {
return ResponseEntity
.status(HttpStatus.OK)
.body(
ApiUtils.success(
response
)
);
} else {
return ResponseEntity
.status(HttpStatus.NO_CONTENT)
.body(
ApiUtils.success(
response
)
);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.nowait.applicationuser.storepayment.service;

import java.util.Optional;

import com.nowait.applicationuser.storepayment.dto.StorePaymentReadDto;

public interface StorePaymentService {
StorePaymentReadDto getStorePaymentByStoreId(Long storeId);
Optional<StorePaymentReadDto> getStorePaymentByStoreId(Long storeId);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.nowait.applicationuser.storepayment.service;

import java.util.Optional;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.nowait.applicationuser.storepayment.dto.StorePaymentReadDto;
import com.nowait.domaincorerdb.store.exception.StoreNotFoundException;
import com.nowait.domaincorerdb.storepayment.entity.StorePayment;
import com.nowait.domaincorerdb.storepayment.exception.StorePaymentParamEmptyException;
import com.nowait.domaincorerdb.storepayment.repository.StorePaymentRepository;

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

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

StorePayment storePayment = storePaymentRepository.findByStoreId(storeId)
.orElseThrow(StoreNotFoundException::new);

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