Skip to content

Commit

Permalink
Merge pull request #101 from yejineeeeee/feat/#86
Browse files Browse the repository at this point in the history
Feat/#86
  • Loading branch information
ozll-zinni authored Aug 19, 2023
2 parents 27e8189 + eb3bad9 commit fcf26bc
Show file tree
Hide file tree
Showing 27 changed files with 1,037 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,29 @@ public enum BaseResponseStatus {
SAVE_ITEM_FAIL(false, 6011, "준비물 생성에 실패했습니다."),
UPDATE_ITEM_FAIL(false, 6012, "준비물 수정에 실패했습니다."),
DELETE_ITEM_FAIL(false, 6013, "준비물 삭제에 실패했습니다."),
ITEM_NOT_FOUND(false,6014, "준비물 조회 실패했습니다.");
ITEM_NOT_FOUND(false,6014, "준비물 조회 실패했습니다."),


/**
* 7000 : 가계부 오류
*/
REQUEST_IS_EMPTY(false, 7001, "요청을 찾을 수 없습니다."),
REQUEST_IS_INVALID(false, 7002, "요청을 찾을 수 없습니다."),
SAVE_DATE_FAIL(false, 7003, "날짜 생성 실패했습니다."),
DATE_NOT_FOUND(false, 7004, "날짜를 찾을 수 없습니다."),
UPDATE_DATE_FAIL(false, 7005, "날자 수정 실패했습니다."),
DELETE_DATE_FAIL(false, 7006, "널짜 삭제 실패했습니다."),
SAVE_ACCOUNTBOOK_FAIL(false, 7011, "가계부 생성 실패했습니다."),
ACCOUNTBOOK_NOT_FOUND(false, 7012, "가계부를 찾을 수 없습니다."),
ACCOUNTBOOK_USER_NOT_MATCH(false, 7013,"가계부 사용자가 맞지 않습니다."),
UPDATE_ACCOUNTBOOK_FAIL(false, 7014, "가계부 수정에 실패했습니다."),
DELETE_ACCOUNTBOOK_FAIL(false, 7015, "가계부 삭제에 실패했습니다."),
ACCOUNTBOOK_IS_EMPTY(false, 7016, "가계부가 존재하지 않습니다."),
SAVE_TRANSACTION_FAIL(false, 7021, "내역 생성에 실패했습니다."),
TRANSACTION_NOT_FOUND(false, 7022, "내역을 찾을 수 없습니다."),
UPDATE_TRANSACTION_FAIL(false, 7023, "내역 수정에 실패했습니다."),
DELETE_TRANSACTION_FAIL(false, 7025, "내역 삭제에 실패했습니다.");



private final boolean isSuccess;
Expand Down
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());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.traveler.config.BaseResponse;
import com.example.traveler.model.dto.ChecklistRequest;
import com.example.traveler.model.dto.ChecklistResponse;
import com.example.traveler.model.dto.TitleChangeRequest;
import com.example.traveler.service.ChecklistService;
import org.springframework.beans.factory.annotation.Autowired;

Expand All @@ -29,18 +30,18 @@ public List<ChecklistResponse> getAllChecklistsByTravel(@PathVariable Integer tI
return checklistService.getAllChecklistsByTravel(tId);
}
// 새로운 체크리스트 정보 저장
@PostMapping("/checklist")
public BaseResponse<ChecklistResponse> saveChecklist(@RequestBody Integer checklistRequest) {
@PostMapping("/{tId}")
public BaseResponse<ChecklistResponse> saveChecklist(@RequestHeader("Authorization") String accessToken, @PathVariable Integer tId, @RequestBody ChecklistRequest checklistRequest) {
try {
ChecklistResponse checklistResponse = checklistService.saveChecklist(checklistRequest);
ChecklistResponse checklistResponse = checklistService.saveChecklist(accessToken, tId, checklistRequest);
return new BaseResponse<>(checklistResponse);
} catch (BaseException exception) {
return new BaseResponse<>(exception.getStatus());
}
}

// 특정 카테고리 정보 조회
@GetMapping("/checklist/{cId}")
@GetMapping("/{cId}")
public BaseResponse<ChecklistResponse> getChecklist(@PathVariable("cId") int cId) {
try {
ChecklistResponse checklistResponse = checklistService.getChecklist(cId);
Expand All @@ -51,12 +52,13 @@ public BaseResponse<ChecklistResponse> getChecklist(@PathVariable("cId") int cId
}

// 카테고리명 수정 API
@PatchMapping("/{cId}")
@PatchMapping("/{cId}/title") // 기존의 {cId}에 "/title"을 추가하여 제목 변경 API로 구성
public BaseResponse<ChecklistResponse> patchChecklist(
@RequestHeader("Authorization") String accessToken,
@PathVariable("cId") int cId,
@RequestBody ChecklistRequest request) {
@RequestBody TitleChangeRequest request) {
try {
ChecklistResponse checklistResponse = checklistService.patchChecklist(cId, request.getTitle());
ChecklistResponse checklistResponse = checklistService.patchChecklist(accessToken, cId, request.getNewTitle());
return new BaseResponse<>(checklistResponse);
} catch (BaseException exception) {
return new BaseResponse<>(exception.getStatus());
Expand All @@ -65,10 +67,9 @@ public BaseResponse<ChecklistResponse> patchChecklist(

// 카테고리 삭제 API
@DeleteMapping("/{cId}")
public BaseResponse<String> deleteChecklist(
@PathVariable("cId") int cId) {
public BaseResponse<String> deleteChecklist(@RequestHeader("Authorization") String accessToken, @PathVariable("cId") int cId) {
try {
int result = checklistService.deleteChecklist(cId);
int result = checklistService.deleteChecklist(accessToken, cId);
if (result != 1) {
throw new BaseException(DELETE_CATEGORY_FAIL);
} else {
Expand All @@ -79,11 +80,4 @@ public BaseResponse<String> deleteChecklist(
}
}

// // 모든 카테고리 조회 API
// @GetMapping("/checklist")
// public BaseResponse<List<ChecklistResponse>> getAllChecklist() {
// List<ChecklistResponse> checklistResponses = checklistService.getAllChecklist();
// return new BaseResponse<>(checklistResponses);
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.example.traveler.config.BaseException;
import com.example.traveler.config.BaseResponse;
import com.example.traveler.model.dto.*;
import com.example.traveler.service.ChecklistService;
import com.example.traveler.service.DayCourseService;
import com.example.traveler.service.SpotService;
import com.example.traveler.service.TravelService;
Expand All @@ -25,6 +26,9 @@ public class TravelController {
private DayCourseService dayCourseService;
@Autowired
private SpotService spotService;
@Autowired
private ChecklistService checklistService;

@PostMapping("")
public BaseResponse<TravelResponse> saveTravel(@RequestHeader("Authorization") String accessToken, @RequestBody TravelRequest travelRequest) {
try {
Expand All @@ -34,6 +38,7 @@ public BaseResponse<TravelResponse> saveTravel(@RequestHeader("Authorization") S
System.out.println(travelRequest.getEnd_date());
System.out.println(travelRequest.getWriteStatus());
TravelResponse travelResponse = travelService.saveTravel(accessToken, travelRequest);

return new BaseResponse<>(travelResponse);
} catch (BaseException exception) {
return new BaseResponse<>(exception.getStatus());
Expand Down
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;
}
}
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) {
}
}
Loading

0 comments on commit fcf26bc

Please sign in to comment.