Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#42
Browse files Browse the repository at this point in the history
  • Loading branch information
Juhyeok0202 authored Jul 30, 2023
2 parents 23162e3 + 06006d2 commit 35c85ec
Show file tree
Hide file tree
Showing 39 changed files with 736 additions and 149 deletions.
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ dependencies {

//thymeleaf
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'


}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

@RestController
@RequiredArgsConstructor
Expand All @@ -17,32 +18,38 @@ public class AccountBookController {
private final AccountBookService accountBookService;

@GetMapping("/budget")
public ResponseEntity<AccountBookDto.BudgetResponse> getBudget(@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "month", required = false) Integer month){
public ResponseEntity<AccountBookDto.BudgetResponse> getBudget(@RequestParam(value = "year") Integer year,
@RequestParam(value = "month")
@Max(value = 12, message = "12월까지만 입력해주세요") Integer month){
return ResponseEntity.status(HttpStatus.OK).body(accountBookService.getBudget(year, month));
}

@PostMapping("/budget")
public ResponseEntity<?> createBudget(@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "month", required = false) Integer month,
@RequestParam(value = "amount", required = false) Long budget){
public ResponseEntity<?> createBudget(@RequestParam(value = "year") Integer year,
@RequestParam(value = "month")
@Max(value = 12, message = "12월까지만 입력해주세요") Integer month,
@RequestParam(value = "amount")
@Min(value =0, message = "예산은 0원 이상이어야 합니다") Long budget){
accountBookService.createBudget(year, month, budget);

return new ResponseEntity<>(HttpStatus.OK);
}

@PutMapping("/budget")
public ResponseEntity<?> updateBudget(@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "month", required = false) Integer month,
@RequestParam(value = "amount", required = false) Long budget){
public ResponseEntity<?> updateBudget(@RequestParam(value = "year") Integer year,
@RequestParam(value = "month")
@Max(value = 12, message = "12월까지만 입력해주세요") Integer month,
@RequestParam(value = "amount")
@Min(value =0, message = "예산은 0원 이상이어야 합니다") Long budget){
accountBookService.updateBudget(year, month, budget);

return new ResponseEntity<>(HttpStatus.OK);
}

@GetMapping("/all")
public ResponseEntity<AccountBookDto.AccountBookResponse> getAccountBook(@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "month", required = false) Integer month){
public ResponseEntity<AccountBookDto.AccountBookResponse> getAccountBook(@RequestParam(value = "year") Integer year,
@RequestParam(value = "month")
@Max(value = 12, message = "12월까지만 입력해주세요") Integer month){

return ResponseEntity.status(HttpStatus.OK).body(accountBookService.getAccountBookResponse(year, month));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class AccountBookDto {
@NoArgsConstructor
@AllArgsConstructor
public static class AccountBookCategoryResponse{

private TransactionCategory transactionCategory;
private Long price;
}


@Getter
@NoArgsConstructor
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -17,13 +18,27 @@ public class TransactionDto {
@AllArgsConstructor
@NoArgsConstructor
public static class TransactionRequest{

@NotNull(message = "년도는 필수입니다")
private Integer year;

@NotNull(message = "월은 필수입니다")
private Integer month;

@NotNull(message = "일은 필수입니다")
private Integer day;

@NotNull(message = "지출 또는 수입을 선택해주세요")
private Integer type;

@NotNull(message = "금액은 필수입니다")
private Long price;

@NotNull(message = "카테고리는 필수입니다")
private TransactionCategory transactionCategory;

private PayCategory payCategory;

private String categoryMemo;

public Transaction toEntity(AccountBook accountBook){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Transaction extends BaseTimeEntity {
private PayCategory payCategory; //현금, 체크카드 등

@Enumerated(value = STRING)
//@Column(nullable = false)
@Column(nullable = false)
private TransactionCategory transactionCategory; //식비, 교육 등

@Column(columnDefinition = "MEDIUMTEXT")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package com.umc.DongnaeFriend.domain.account.book.repository.accountBook;

import com.umc.DongnaeFriend.domain.account.book.dto.AccountBookDto;
import com.umc.DongnaeFriend.domain.account.book.entity.AccountBook;
import com.umc.DongnaeFriend.domain.account.book.service.AccountBookService;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;

public interface AccountBookRepository extends JpaRepository<AccountBook, Long>, AccountBookRepositoryCustom {

//Optional<AccountBook> findByIdAndYearAndMonth(Long accountBookId, Integer year, Integer month);
Optional<AccountBook> findByYearAndMonth(Integer year, Integer month);
@Modifying
@Query(value = "update AccountBook ab "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.umc.DongnaeFriend.domain.account.book.dto.AccountBookDto;
import com.umc.DongnaeFriend.domain.account.book.entity.AccountBook;
import com.umc.DongnaeFriend.domain.account.book.repository.accountBook.AccountBookRepository;
import com.umc.DongnaeFriend.global.exception.CustomException;
import com.umc.DongnaeFriend.global.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
Expand All @@ -15,8 +17,6 @@
@RequiredArgsConstructor
public class AccountBookService {

// User 권한 확인 필요 //

private final AccountBookRepository accountBookRepository;


Expand All @@ -28,20 +28,24 @@ public void createBudget(Integer year, Integer month, Long budget){

// 가계부 예산 설정 조회
public AccountBookDto.BudgetResponse getBudget(Integer year, Integer month){
AccountBook accountBook = accountBookRepository.findByYearAndMonth(year, month).orElseThrow();
AccountBook accountBook = accountBookRepository.findByYearAndMonth(year, month)
.orElseThrow(() -> new CustomException(ErrorCode.NO_CONTENT_FOUND));
return AccountBookDto.BudgetResponse.of(accountBook.getId(),accountBook.getBudget());
}

// 가계부 예산 설정 수정
@Transactional
public void updateBudget(Integer year, Integer month, Long budget){
AccountBook accountBook = accountBookRepository.findByYearAndMonth(year, month).orElseThrow();
AccountBook accountBook = accountBookRepository.findByYearAndMonth(year, month)
.orElseThrow(() -> new CustomException(ErrorCode.NO_CONTENT_FOUND));
accountBook.updateBudget(budget);
}


// 가계부 조회 -> 이번달 남은 예산 & 지출, 저축(수입), 카테고리별 지출
public AccountBookDto.AccountBookResponse getAccountBookResponse(Integer year, Integer month) {
AccountBook accountBook = accountBookRepository.findByYearAndMonth(year, month).orElseThrow();
AccountBook accountBook = accountBookRepository.findByYearAndMonth(year, month)
.orElseThrow(() -> new CustomException(ErrorCode.NO_CONTENT_FOUND));
return AccountBookDto.AccountBookResponse.builder()
.income(accountBook.getIncome())
.expenditure(accountBook.getExpenditure())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.umc.DongnaeFriend.domain.account.book.entity.Memo;
import com.umc.DongnaeFriend.domain.account.book.repository.accountBook.AccountBookRepository;
import com.umc.DongnaeFriend.domain.account.book.repository.memo.MemoRepository;
import com.umc.DongnaeFriend.global.exception.CustomException;
import com.umc.DongnaeFriend.global.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -23,8 +25,9 @@ public class MemoService {
// 메모 전체 조회 -> 리스트
public MemoDto.MemoListResponse getMemoList(Integer year, Integer month){

// User 권한 확인
AccountBook accountBook = accountBookRepository.findByYearAndMonth(year, month).orElseThrow();
AccountBook accountBook = accountBookRepository.findByYearAndMonth(year, month)
.orElseThrow(() -> new CustomException(ErrorCode.NO_CONTENT_FOUND));

List<Memo> memoList = memoRepository.findMemoListByAccountBookId(accountBook.getId());
return MemoDto.MemoListResponse.of(memoList);
}
Expand All @@ -34,32 +37,33 @@ public MemoDto.MemoListResponse getMemoList(Integer year, Integer month){
public void createMemo(MemoDto.MemoRequest memoRequest, Integer year, Integer month){

// User 권한 확인
AccountBook accountBook = accountBookRepository.findByYearAndMonth(year, month).orElseThrow();
AccountBook accountBook = accountBookRepository.findByYearAndMonth(year, month)
.orElseThrow(() -> new CustomException(ErrorCode.NO_CONTENT_FOUND));
Integer memoCnt = memoRepository.getMemoCnt(year, month);

if(memoCnt<8){
memoRepository.save(memoRequest.toEntity(accountBook));
}else{
// 개수 초과 예외처리
log.info("메모 개수 초과 발생 !");
throw new CustomException(ErrorCode.MEMO_LIMIT);
}
}

// 메모 수정
@Transactional
public void updateMemo(MemoDto.MemoRequest memoRequest, Long memoId){

// User 권한 확인
Memo memo = memoRepository.findById(memoId).orElseThrow();
Memo memo = memoRepository.findById(memoId)
.orElseThrow(() -> new CustomException(ErrorCode.NO_CONTENT_FOUND));
memo.updateMemo(memoRequest);
}

// 메모 삭제
@Transactional
public void deleteMemo(Long memoId){

// User 권한 확인
Memo memo = memoRepository.findById(memoId).orElseThrow();
Memo memo = memoRepository.findById(memoId)
.orElseThrow(() -> new CustomException(ErrorCode.NO_CONTENT_FOUND));
memoRepository.deleteById(memo.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.umc.DongnaeFriend.domain.account.book.entity.Transaction;
import com.umc.DongnaeFriend.domain.account.book.repository.accountBook.AccountBookRepository;
import com.umc.DongnaeFriend.domain.account.book.repository.transaction.TransactionRepository;
import com.umc.DongnaeFriend.global.exception.CustomException;
import com.umc.DongnaeFriend.global.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
Expand All @@ -25,20 +27,14 @@ public class TransactionService {
@Transactional
public void createTransaction(TransactionDto.TransactionRequest request){

log.info("Year : " + request.getYear() + " Month : " + request.getMonth());
AccountBook accountBook = findTarget(request.getYear(), request.getMonth());

transactionRepository.save(request.toEntity(accountBook));

// AccountBook income, expenditure 값 변경

// Type=1이면 수입, 0이면 지출
if(request.getType()==1){
log.info("Price 추가 : " + request.getPrice());

accountBookRepository.updateAccountBookIncome(accountBook.getId(), request.getPrice());
}else{
log.info("Price 추가 : " + request.getPrice());

accountBookRepository.updateAccountBookExpenditure(accountBook.getId(), request.getPrice());
}
}
Expand All @@ -54,16 +50,14 @@ public TransactionDto.TransactionListResponse getTransactions(Integer year, Inte
@Transactional
public void deleteTransaction(Long transactionId){

Transaction transaction = transactionRepository.findById(transactionId).orElseThrow();
Transaction transaction = transactionRepository.findById(transactionId)
.orElseThrow(() -> new CustomException(ErrorCode.NO_CONTENT_FOUND));
AccountBook accountBook = findTarget(transaction.getYear(), transaction.getMonth());

// AccountBook income, expenditure 값이 변경되어야 함.

if(transaction.getType()==1){
log.info("Price 삭제: " + transaction.getPrice());
accountBookRepository.updateAccountBookIncomeDelete(accountBook.getId(), transaction.getPrice());
}else{
log.info("Price 삭제 : " + transaction.getPrice());

accountBookRepository.updateAccountBookExpenditureDelete(accountBook.getId(), transaction.getPrice());
}
transactionRepository.deleteById(transaction.getId());
Expand All @@ -72,12 +66,12 @@ public void deleteTransaction(Long transactionId){
// 지출 또는 수입 내역 수정
@Transactional
public void updateTransaction(TransactionDto.TransactionRequest request, Long transactionId){
Transaction transaction = transactionRepository.findById(transactionId).orElseThrow();
Transaction transaction = transactionRepository.findById(transactionId)
.orElseThrow(() -> new CustomException(ErrorCode.NO_CONTENT_FOUND));
AccountBook accountBook = findTarget(transaction.getYear(), transaction.getMonth());

Transaction updateTrans = request.toEntity(accountBook);
Long priceGap = updateTrans.getPrice()-transaction.getPrice();
log.info("priceGap : " + priceGap);

if(transaction.getType()==1){
accountBookRepository.updateAccountBookIncomeEdit(accountBook.getId(), priceGap);
Expand All @@ -89,6 +83,7 @@ public void updateTransaction(TransactionDto.TransactionRequest request, Long tr
}

private AccountBook findTarget(Integer year, Integer month){
return accountBookRepository.findByYearAndMonth(year, month).orElseThrow();
return accountBookRepository.findByYearAndMonth(year, month)
.orElseThrow(() -> new CustomException(ErrorCode.NO_CONTENT_FOUND));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.umc.DongnaeFriend.domain.account.sharing.controller;

import com.umc.DongnaeFriend.domain.account.sharing.dto.ReqSharingCommentDto;
import com.umc.DongnaeFriend.domain.account.sharing.dto.ResSharingCommentList;
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment;
import com.umc.DongnaeFriend.domain.account.sharing.service.SharingCommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/account-books/sharing/comments")
public class SharingCommentController {
private final SharingCommentService sharingCommentService;

// [가계부 공유] 댓글 등록
@PostMapping("/{accountBookId}")
public String postComment(@PathVariable("accountBookId") Long accountBookId, @RequestBody ReqSharingCommentDto reqSharingCommentDto) {
sharingCommentService.newComment(accountBookId, reqSharingCommentDto);
return "";
}

// [가계부 공유] 댓글 수정
@PutMapping("/{commentId}")
public String putComment(@PathVariable("commentId") Long commentId, @RequestBody ReqSharingCommentDto reqSharingCommentDto) {
sharingCommentService.modifyComment(commentId, reqSharingCommentDto);
return "";
}

// [가계부 공유] 댓글 삭제
@DeleteMapping("/{commentId}")
public String deleteComment(@PathVariable("commentId") Long commentId) {
sharingCommentService.deleteComment(commentId);
return "";
}

// [가계부 공유] 댓글 목록 조회
@GetMapping("")
public ResSharingCommentList getList(@RequestParam Long accountBookId) {
ResSharingCommentList resSharingCommentList = sharingCommentService.getCommentList(accountBookId);
return resSharingCommentList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.umc.DongnaeFriend.domain.account.sharing.controller;

import com.umc.DongnaeFriend.domain.account.sharing.dto.ReqSharingCommentDto;
import com.umc.DongnaeFriend.domain.account.sharing.service.SharingCommentLikeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@RestController
@RequestMapping("/account-books/sharing/likes")
public class SharingCommentLikeController {
private final SharingCommentLikeService sharingCommentLikeService;

// [가계부 공유] 댓글 좋아요
@PostMapping("/{commentId}")
public String postCommentLike(@PathVariable("commentId") Long commentId) {
sharingCommentLikeService.newLike(commentId);
return "";
}
}
Loading

0 comments on commit 35c85ec

Please sign in to comment.