-
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.
Browse files
Browse the repository at this point in the history
feat deal create
- Loading branch information
Showing
6 changed files
with
101 additions
and
0 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
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