-
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.
- Loading branch information
1 parent
c7030ef
commit 3f755c4
Showing
6 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/main/java/com/eum/bank/common/dto/request/DealRequestDTO.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,22 @@ | ||
package com.eum.bank.common.dto.request; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
public class DealRequestDTO { | ||
@Builder | ||
@Getter | ||
public static class Create{ | ||
//송금자 계좌번호 | ||
private String accountNumber; | ||
// 비밀번호 | ||
private String password; | ||
// 예치금 ( 지급해야 하는 금액 ) | ||
private Long deposit; | ||
// 최대 인원수 | ||
private Long maxPeople; | ||
// 글 id | ||
private Long postId; | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/eum/bank/common/dto/response/DealResponseDTO.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,15 @@ | ||
package com.eum.bank.common.dto.response; | ||
|
||
import jakarta.validation.GroupSequence; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
public class DealResponseDTO { | ||
|
||
@Getter | ||
@Builder | ||
public static class Create { | ||
// 거래 id | ||
private Long id; | ||
} | ||
} |
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,48 @@ | ||
package com.eum.bank.controller; | ||
|
||
import com.eum.bank.common.APIResponse; | ||
import com.eum.bank.common.dto.request.DealRequestDTO; | ||
import com.eum.bank.common.dto.response.DealResponseDTO; | ||
import com.eum.bank.domain.account.entity.Account; | ||
import com.eum.bank.service.AccountService; | ||
import com.eum.bank.service.DealService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/deal") | ||
@RequiredArgsConstructor | ||
public class DealController { | ||
private final DealService dealService; | ||
private final AccountService accountService; | ||
|
||
@PostMapping("/create") | ||
public ResponseEntity<?> create(@RequestBody DealRequestDTO.Create create) { | ||
|
||
String accountNumber = create.getAccountNumber(); | ||
String password = create.getPassword(); | ||
Long deposit = create.getDeposit(); | ||
Long maxPeople = create.getMaxPeople(); | ||
Long postId = create.getPostId(); | ||
|
||
APIResponse<?> apiResponse = accountService.getAccount(accountNumber, password); | ||
|
||
Account account = accountService.getAccount(accountNumber); | ||
|
||
if (apiResponse.getStatus() == 200){ | ||
// 계좌가 존재하고 비밀번호가 일치하는 경우 | ||
// 거래 생성 | ||
dealService.createDeal(account, deposit, maxPeople, postId); | ||
} else if (apiResponse.getStatus() == 400){ | ||
// 계좌가 존재하지 않는 경우 | ||
return ResponseEntity.badRequest().body(apiResponse); | ||
} else if (apiResponse.getStatus() == 401){ | ||
// 비밀번호가 일치하지 않는 경우 | ||
return ResponseEntity.status(401).body(apiResponse); | ||
} | ||
|
||
APIResponse<DealResponseDTO.Create> response = new APIResponse<>(); | ||
return ResponseEntity.ok(response); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.eum.bank.service; | ||
|
||
import com.eum.bank.common.APIResponse; | ||
import com.eum.bank.domain.account.entity.Account; | ||
import com.eum.bank.domain.deal.entity.Deal; | ||
import com.eum.bank.repository.DealRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class DealService { | ||
|
||
private final DealRepository dealRepository; | ||
|
||
// 거래 생성 | ||
public void createDeal(Account accountNumber, Long deposit, Long maxPeople, Long postId){ | ||
// 거래 생성 | ||
// 거래상태 a -> WAITING | ||
Deal deal = Deal.builder() | ||
.senderAccount(accountNumber) | ||
.status("WAITING") | ||
.deposit(deposit) | ||
.numberOfPeople(maxPeople) | ||
.postId(postId) | ||
.build(); | ||
|
||
dealRepository.save(deal); | ||
} | ||
} |