-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Feature/#28 - 4.5 영수증 리뷰 등록하기 API 구현
- Loading branch information
1 parent
6ebd1bd
commit 785c325
Showing
9 changed files
with
150 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 22 additions & 1 deletion
23
...java/com/daon/onjung/onjung/application/controller/command/OnjungCommandV1Controller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,48 @@ | ||
package com.daon.onjung.onjung.application.controller.command; | ||
|
||
import com.daon.onjung.core.annotation.security.AccountID; | ||
import com.daon.onjung.core.dto.ResponseDto; | ||
import com.daon.onjung.onjung.application.dto.request.CreateReceiptRequestDto; | ||
import com.daon.onjung.onjung.application.dto.response.ReceiptOCRResponseDto; | ||
import com.daon.onjung.onjung.application.usecase.CreateReceiptUseCase; | ||
import com.daon.onjung.onjung.application.usecase.ReceiptOCRUseCase; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.util.UUID; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class OnjungCommandV1Controller { | ||
|
||
private final ReceiptOCRUseCase receiptOCRUseCase; | ||
private final CreateReceiptUseCase createReceiptUseCase; | ||
|
||
/** | ||
* 영수증 OCR 처리하기 | ||
* 4.4 가게 방문 인증용 영수증 OCR 조회하기 | ||
*/ | ||
@PostMapping(value = "/api/v1/receipts/ocr", consumes = "multipart/form-data") | ||
public ResponseDto<ReceiptOCRResponseDto> OCRReceipt( | ||
@RequestPart(value = "file") MultipartFile file | ||
) { | ||
return ResponseDto.ok(receiptOCRUseCase.execute(file)); | ||
} | ||
|
||
/** | ||
* 4.5 영수증 리뷰 등록하기 | ||
*/ | ||
@PostMapping("/api/v1/receipts") | ||
public ResponseDto<Void> reviewReceipt( | ||
@AccountID UUID accountId, | ||
@RequestBody @Valid CreateReceiptRequestDto requestDto | ||
) { | ||
createReceiptUseCase.execute(accountId, requestDto); | ||
return ResponseDto.created(null); | ||
} | ||
|
||
} |
Empty file.
18 changes: 18 additions & 0 deletions
18
src/main/java/com/daon/onjung/onjung/application/dto/request/CreateReceiptRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.daon.onjung.onjung.application.dto.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record CreateReceiptRequestDto( | ||
@JsonProperty("store_name") | ||
String storeName, | ||
|
||
@JsonProperty("store_address") | ||
String storeAddress, | ||
|
||
@JsonProperty("payment_date") | ||
String paymentDate, | ||
|
||
@JsonProperty("payment_amount") | ||
String paymentAmount | ||
) { | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/daon/onjung/onjung/application/service/CreateReceiptService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.daon.onjung.onjung.application.service; | ||
|
||
import com.daon.onjung.account.domain.Store; | ||
import com.daon.onjung.account.domain.User; | ||
import com.daon.onjung.account.repository.mysql.StoreRepository; | ||
import com.daon.onjung.account.repository.mysql.UserRepository; | ||
import com.daon.onjung.core.exception.error.ErrorCode; | ||
import com.daon.onjung.core.exception.type.CommonException; | ||
import com.daon.onjung.core.utility.DateTimeUtil; | ||
import com.daon.onjung.onjung.application.dto.request.CreateReceiptRequestDto; | ||
import com.daon.onjung.onjung.application.usecase.CreateReceiptUseCase; | ||
import com.daon.onjung.onjung.domain.Receipt; | ||
import com.daon.onjung.onjung.domain.service.ReceiptService; | ||
import com.daon.onjung.onjung.repository.mysql.ReceiptRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDate; | ||
import java.util.UUID; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CreateReceiptService implements CreateReceiptUseCase { | ||
|
||
private final UserRepository userRepository; | ||
private final StoreRepository storeRepository; | ||
private final ReceiptRepository receiptRepository; | ||
|
||
private final ReceiptService receiptService; | ||
|
||
@Override | ||
@Transactional | ||
public void execute(UUID accountId, CreateReceiptRequestDto requestDto) { | ||
|
||
// 유저 조회 | ||
User user = userRepository.findById(accountId) | ||
.orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_RESOURCE)); | ||
|
||
// 매장 조회 | ||
Store store = storeRepository.findByOcrStoreNameAndOcrStoreAddress(requestDto.storeName(), requestDto.storeAddress()) | ||
.orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_MATCHED_STORE)); | ||
|
||
// paymentDate 형변환 | ||
LocalDate paymentDate = DateTimeUtil.convertStringToLocalDate(requestDto.paymentDate()); | ||
|
||
// paymentAmount 쉼표 제거 및 형변환 | ||
Integer paymentAmount = Integer.parseInt(requestDto.paymentAmount().replaceAll(",", "")); | ||
|
||
// 영수증 생성 | ||
Receipt receipt = receiptRepository.save(receiptService.createReceipt( | ||
paymentDate, | ||
paymentAmount, | ||
user, | ||
store | ||
)); | ||
receiptRepository.save(receipt); | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/daon/onjung/onjung/application/usecase/CreateReceiptUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.daon.onjung.onjung.application.usecase; | ||
|
||
import com.daon.onjung.core.annotation.bean.UseCase; | ||
import com.daon.onjung.onjung.application.dto.request.CreateReceiptRequestDto; | ||
|
||
import java.util.UUID; | ||
|
||
@UseCase | ||
public interface CreateReceiptUseCase { | ||
void execute(UUID accountId, CreateReceiptRequestDto requestDto); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/daon/onjung/onjung/domain/service/ReceiptService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
package com.daon.onjung.onjung.domain.service; | ||
|
||
import com.daon.onjung.account.domain.Store; | ||
import com.daon.onjung.account.domain.User; | ||
import com.daon.onjung.onjung.domain.Receipt; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Service | ||
public class ReceiptService { | ||
|
||
public Receipt createReceipt( | ||
LocalDate paymentDate, | ||
Integer paymentAmount, | ||
User user, | ||
Store store | ||
) { | ||
return Receipt.builder() | ||
.paymentAmount(paymentAmount) | ||
.paymentDate(paymentDate) | ||
.user(user) | ||
.store(store) | ||
.build(); | ||
} | ||
} |