-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
27 changed files
with
1,037 additions
and
67 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
190 changes: 190 additions & 0 deletions
190
src/main/java/com/example/traveler/controller/AccountBookController.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,190 @@ | ||
package com.example.traveler.controller; | ||
|
||
|
||
import com.example.traveler.config.BaseException; | ||
import com.example.traveler.config.BaseResponse; | ||
import com.example.traveler.model.dto.*; | ||
import com.example.traveler.model.entity.Travel; | ||
import com.example.traveler.service.AccountBookService; | ||
import com.example.traveler.service.TransactionService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
|
||
import static com.example.traveler.config.BaseResponseStatus.DELETE_ACCOUNTBOOK_FAIL; | ||
import static com.example.traveler.config.BaseResponseStatus.DELETE_TRANSACTION_FAIL; | ||
|
||
|
||
|
||
|
||
@RestController | ||
@RequestMapping("/accountbook") | ||
public class AccountBookController { | ||
private final AccountBookService accountBookService; | ||
private final TransactionService transactionService; | ||
|
||
|
||
@Autowired | ||
public AccountBookController(AccountBookService accountBookService, TransactionService transactionService) { | ||
this.accountBookService = accountBookService; | ||
this.transactionService = transactionService; | ||
} | ||
|
||
|
||
@GetMapping("/travel/{tId}") | ||
public List<AccountBookResponse> getAllAccountBookByTravel(@PathVariable Travel tId) throws BaseException { | ||
return accountBookService.getAllAccountBookByTravel(tId); | ||
} | ||
|
||
|
||
// AccountBook | ||
|
||
// 새로운 가계부 정보 저장 | ||
@PostMapping("/{tId}") | ||
public BaseResponse<AccountBookResponse> saveAccountBook( | ||
@RequestHeader("Authorization") String accessToken, | ||
@PathVariable Travel tId, | ||
@RequestParam double totalBudget, | ||
@RequestParam double foodExpense, | ||
@RequestParam double transportationExpense, | ||
@RequestParam double sightseeingExpense, | ||
@RequestParam double shoppingExpense, | ||
@RequestParam double otherExpense) { | ||
try { | ||
AccountBookResponse accountBookResponse = accountBookService.saveAccountBook( | ||
accessToken, tId, totalBudget, foodExpense, transportationExpense, | ||
sightseeingExpense, shoppingExpense, otherExpense); | ||
return new BaseResponse<>(accountBookResponse); | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
|
||
// 특정 가계부 정보 조회 | ||
@GetMapping("/{accountId}") | ||
public BaseResponse<AccountBookResponse> getAccountBook(@PathVariable("accountId") int accountId) { | ||
try { | ||
AccountBookResponse accountBookResponse = accountBookService.getAccountBook(accountId); | ||
return new BaseResponse<>(accountBookResponse); | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
|
||
// 가계부 수정 | ||
@PatchMapping("/{accountId}") | ||
public BaseResponse<AccountBookResponse> patchAccountBook(@RequestHeader("Authorization") String accessToken, @PathVariable("accountId") Long accountId, @RequestBody AccountBookRequest accountBookRequest) { | ||
try { | ||
AccountBookResponse accountBookResponse = accountBookService.patchAccountBook(accessToken, accountId, accountBookRequest.getAccountName()); | ||
return new BaseResponse<>(accountBookResponse); | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
|
||
// 가계부 삭제 | ||
@DeleteMapping("/{accountId}") | ||
public BaseResponse<String> deleteAccountBook( | ||
@RequestHeader("Authorization") String accessToken, @PathVariable("accountId") Long accountId) { | ||
try { | ||
int result = accountBookService.deleteAccountBook(accessToken, accountId); | ||
if (result != 1) { | ||
throw new BaseException(DELETE_ACCOUNTBOOK_FAIL); | ||
} else { | ||
return new BaseResponse<>("가계부 삭제에 성공했습니다."); | ||
} | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
|
||
|
||
// Transaction(내역) 관련 기능 | ||
@PostMapping("/{accountId}/transaction") | ||
public BaseResponse<TransactionResponse> saveTransaction(@RequestHeader("Authorization") String accessToken, @PathVariable("accountId") int accountId, @RequestBody TransactionRequest transactionRequest) { | ||
try { | ||
TransactionResponse transactionResponse = transactionService.saveTransaction(accessToken, accountId, transactionRequest); | ||
return new BaseResponse<>(transactionResponse); | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
|
||
|
||
@GetMapping("/transactions/accountbook/{accountId}") | ||
public BaseResponse<List<TransactionResponse>> getAllTransactionByAccountBook(@PathVariable("accountId") int accountId) { | ||
try { | ||
List<TransactionResponse> transactionResponseList = transactionService.getAllTransactionByAccountBook(accountId); | ||
return new BaseResponse<>(transactionResponseList); | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
|
||
|
||
@GetMapping("/transactions/{transactionId}") | ||
public BaseResponse<TransactionResponse> getTransaction(@PathVariable("transactionId") int transactionId) { | ||
try { | ||
TransactionResponse transactionResponse = transactionService.getTransaction(transactionId); | ||
return new BaseResponse<>(transactionResponse); | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
@PatchMapping("/transactions/{transactionId}") | ||
public BaseResponse<TransactionResponse> patchTransaction(@RequestHeader("Authorization") String accessToken, @PathVariable("transactionId") int transactionId, @RequestBody TransactionRequest transactionRequest) { | ||
try { | ||
TransactionResponse transactionResponse = transactionService.patchTransaction(accessToken, transactionId, transactionRequest); | ||
return new BaseResponse<>(transactionResponse); | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
|
||
|
||
@DeleteMapping("/transactions/{transactionId}/{num}") | ||
public BaseResponse<String> deleteTransaction(@RequestHeader("Authorization") String accessToken, @PathVariable("transactionId") int transactionId, @PathVariable("num") int num) { | ||
try { | ||
int result = transactionService.deleteTransaction(accessToken, transactionId, num); | ||
if (result != 1) { | ||
throw new BaseException(DELETE_TRANSACTION_FAIL); | ||
} else { | ||
return new BaseResponse<>("내역 삭제에 성공했습니다."); | ||
} | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
|
||
|
||
// DateEntity(날짜) 관련 기능 | ||
@GetMapping("/{accountId}/dates") | ||
public BaseResponse<List<Date>> getDatesForAccountBook(@PathVariable("accountId") Long accountId) { | ||
try { | ||
List<Date> dates = accountBookService.getDatesForAccountBook(accountId); | ||
return new BaseResponse<>(dates); | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
|
||
// 가계부 요약 관련 기능 | ||
@GetMapping("/{accountId}/summary") | ||
public BaseResponse<SummaryResponse> getAccountBookSummary(@PathVariable("accountId") Long accountId) { | ||
try { | ||
SummaryResponse summaryResponse = accountBookService.getAccountBookSummary(accountId); | ||
return new BaseResponse<>(summaryResponse); | ||
} catch (BaseException exception) { | ||
return new BaseResponse<>(exception.getStatus()); | ||
} | ||
} | ||
|
||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/example/traveler/model/dto/AccountBookRequest.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,26 @@ | ||
package com.example.traveler.model.dto; | ||
|
||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
public class AccountBookRequest { | ||
private String accountName; | ||
private Long accountId; | ||
private Long tId; // 여행 ID | ||
private double budget; | ||
private List<TransactionRequest> transactions; | ||
|
||
public AccountBookRequest(String accountName) { | ||
this.accountName = accountName; | ||
} | ||
|
||
public String getAccountName() { | ||
return accountName; | ||
} | ||
|
||
public void setAccountName(String accountName) { | ||
this.accountName = accountName; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/example/traveler/model/dto/AccountBookResponse.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,30 @@ | ||
package com.example.traveler.model.dto; | ||
|
||
import com.example.traveler.model.entity.AccountBook; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
public class AccountBookResponse { | ||
private String accountName; | ||
private Long accountId; | ||
private Long tId; // 여행 I | ||
private double budget; | ||
private List<TransactionResponse> transactions; | ||
|
||
public AccountBookResponse() { | ||
this.accountName = getAccountName(); | ||
this.accountId = getAccountId(); | ||
this.tId = getTId(); | ||
this.budget = getBudget(); | ||
} | ||
|
||
public AccountBookResponse(String accountName, Long accountId) { | ||
} | ||
|
||
public AccountBookResponse(AccountBook accountBook, AccountBook accountBook1) { | ||
} | ||
} |
Oops, something went wrong.