Skip to content

Commit

Permalink
�Refactor #41: 브랜치 합병 충돌 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
Juhyeok0202 committed Jul 29, 2023
2 parents 8d8a44b + 134f145 commit 0065c62
Show file tree
Hide file tree
Showing 29 changed files with 345 additions and 156 deletions.
Binary file modified .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.umc.DongnaeFriend.domain.account.book.dto.AccountBookDto;
import com.umc.DongnaeFriend.domain.account.book.service.AccountBookService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -16,28 +17,33 @@ public class AccountBookController {
private final AccountBookService accountBookService;

@GetMapping("/budget")
public AccountBookDto.BudgetResponse getBudget(@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "month", required = false) Integer month){
return accountBookService.getBudget(year, month);
public ResponseEntity<AccountBookDto.BudgetResponse> getBudget(@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "month", required = false) Integer month){
return ResponseEntity.status(HttpStatus.OK).body(accountBookService.getBudget(year, month));
}

@PostMapping("/budget")
public void createBudget(@RequestParam(value = "year", required = false) Integer year,
public ResponseEntity<?> createBudget(@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "month", required = false) Integer month,
@RequestParam(value = "amount", required = false) Long budget){
accountBookService.createBudget(year, month, budget);

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

@GetMapping("/category")
public List<AccountBookDto.AccountBookCategoryResponse> getTransactionAll(@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "month", required = false) Integer month){
return null;
@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){
accountBookService.updateBudget(year, month, budget);

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

@GetMapping("/all")
public AccountBookDto.AccountBookResponse getAccountBook(@RequestParam(value = "year", required = false) Integer year,
public ResponseEntity<AccountBookDto.AccountBookResponse> getAccountBook(@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "month", required = false) Integer month){

return accountBookService.getAccountBookResponse(year, month);
return ResponseEntity.status(HttpStatus.OK).body(accountBookService.getAccountBookResponse(year, month));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.umc.DongnaeFriend.domain.account.book.dto.MemoDto;
import com.umc.DongnaeFriend.domain.account.book.service.MemoService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -18,26 +20,32 @@ public class MemoController {
* 유저 권한 확인 필요
*/
@GetMapping
public MemoDto.MemoListResponse getMemoList(@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "month", required = false) Integer month){
return memoService.getMemoList(year, month);
public ResponseEntity<MemoDto.MemoListResponse> getMemoList(@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "month", required = false) Integer month){
return ResponseEntity.status(HttpStatus.OK).body(memoService.getMemoList(year, month));
}

@PostMapping
public void createMemo(@RequestParam(value = "year", required = false) Integer year,
public ResponseEntity<?> createMemo(@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "month", required = false) Integer month,
@RequestBody MemoDto.MemoRequest requestDto){
memoService.createMemo(requestDto, year,month);

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

@PutMapping
public void updateMemo(@RequestParam(value = "id", required = false) Long id,
public ResponseEntity<?> updateMemo(@RequestParam(value = "id", required = false) Long id,
@RequestBody MemoDto.MemoRequest requestDto){
memoService.updateMemo(requestDto, id);

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

@DeleteMapping
public void deleteMemo(@RequestParam(value = "id", required = false) Long id){
public ResponseEntity<?> deleteMemo(@RequestParam(value = "id", required = false) Long id){
memoService.deleteMemo(id);

return new ResponseEntity<>(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.umc.DongnaeFriend.domain.account.book.service.TransactionService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.transaction.Transactional;
Expand All @@ -17,25 +19,30 @@ public class TransactionController {
private final TransactionService transactionService;

@PostMapping
public void createTransaction(@RequestBody TransactionDto.TransactionRequest request){
public ResponseEntity<?> createTransaction(@RequestBody TransactionDto.TransactionRequest request){
transactionService.createTransaction(request);

return new ResponseEntity<>(HttpStatus.OK);

}

@GetMapping
public TransactionDto.TransactionListResponse getTransaction(@RequestParam(value = "year", required = false) Integer year,
public ResponseEntity<TransactionDto.TransactionListResponse> getTransaction(@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "month", required = false) Integer month,
@RequestParam(value = "day", required = false) Integer day, Pageable pageable){
return transactionService.getTransactions(year, month, day, pageable);
return ResponseEntity.status(HttpStatus.OK).body(transactionService.getTransactions(year, month, day, pageable));
}

@PutMapping
public void updateTransaction(@RequestBody TransactionDto.TransactionRequest requestDto,
public ResponseEntity<?> updateTransaction(@RequestBody TransactionDto.TransactionRequest requestDto,
@RequestParam(value = "id", required = false) Long id){
transactionService.updateTransaction(requestDto, id);
return new ResponseEntity<>(HttpStatus.OK);
}

@DeleteMapping
public void deleteTransaction(@RequestParam(value = "id", required = false) Long id){
public ResponseEntity<?> deleteTransaction(@RequestParam(value = "id", required = false) Long id){
transactionService.deleteTransaction(id);
return new ResponseEntity<>(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,4 @@ public static TransactionListResponse of(List<Transaction> transactionList){
return new TransactionListResponse(transactionResponses);
}
}


@Getter
@NoArgsConstructor
public static class TransactionByCategory{
private TransactionCategory transactionCategory;
private Long price;
private Long expenditure;
private Long income;
private Long budget;

public TransactionByCategory(TransactionCategory transactionCategory, Long price, Long expenditure, Long income, Long budget) {
this.transactionCategory = transactionCategory;
this.price = price;
this.expenditure = expenditure;
this.income = income;
this.budget = budget;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ public class AccountBook extends BaseTimeEntity {

@Column(nullable = false)
private Integer month;

public void updateBudget(Long budget){
this.budget = budget;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.umc.DongnaeFriend.domain.account.book.dto.Expense;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public class AccountBookService {
// 가계부 예산 설정 (한달)
@Transactional
public void createBudget(Integer year, Integer month, Long budget){
this.accountBookRepository.findByYearAndMonth(year, month)
.ifPresent(ab->{throw new IllegalStateException("이미 예산이 설정되어있습니다.");
});
accountBookRepository.save(AccountBookDto.BudgetRequest.toEntity(year, month, budget));
}

Expand All @@ -35,6 +32,12 @@ public AccountBookDto.BudgetResponse getBudget(Integer year, Integer month){
return AccountBookDto.BudgetResponse.of(accountBook.getId(),accountBook.getBudget());
}

// 가계부 예산 설정 수정
public void updateBudget(Integer year, Integer month, Long budget){
AccountBook accountBook = accountBookRepository.findByYearAndMonth(year, month).orElseThrow();
accountBook.updateBudget(budget);
}


// 가계부 조회 -> 이번달 남은 예산 & 지출, 저축(수입), 카테고리별 지출
public AccountBookDto.AccountBookResponse getAccountBookResponse(Integer year, Integer month) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
@RequiredArgsConstructor
public class TransactionService {

/**
* 월별 가계부 지출 및 수입 업데이트 시 지출(예산) 총액이 0보다 작아지면 예외 발생하게 만들기
* 유저 권한 확인 필요
*/

private final TransactionRepository transactionRepository;
private final AccountBookRepository accountBookRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.umc.DongnaeFriend.domain.account.sharing.dto;

import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingBoard;
import com.umc.DongnaeFriend.domain.dongnae.entity.Dongnae;
import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeBoard;
import com.umc.DongnaeFriend.domain.type.DongnaeBoardCategory;
import com.umc.DongnaeFriend.domain.type.SharingCategory;
import com.umc.DongnaeFriend.domain.user.entity.User;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.lang.Nullable;

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

public class SharingDto {
Expand All @@ -20,12 +19,17 @@ public class SharingDto {
@AllArgsConstructor
@NoArgsConstructor
public static class Request {

@NotNull(message = "카테고리는 필수입니다.")
private int category;

@NotNull(message = "제목은 필수입니다.")
private String title;

@NotNull(message = "내용은 필수입니다.")
private String content;


private List<String> images;

public SharingBoard toEntity(User user) {
Expand Down Expand Up @@ -82,6 +86,21 @@ public static class ListResponse {

}


/**
* 프로필 조회 시 필요한 정보
*/
@Getter @Builder
@AllArgsConstructor
@NoArgsConstructor
public static class AccountBookProfileListResponse {
private Long boardId;
private int category;
private String title;
private String imageUrl;
//private String town;
private String createdAt;
private int commentCount;
private int likeCount;
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.umc.DongnaeFriend.domain.account.sharing.repository;

import com.umc.DongnaeFriend.domain.account.sharing.dto.SharingDto;
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingBoard;
import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeBoard;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand Down Expand Up @@ -36,9 +34,10 @@ public interface SharingBoardRepository extends JpaRepository<SharingBoard,Long>
"LEFT JOIN sharing_sympathy ON sharing_board.sharing_board_id = sharing_sympathy.sharing_board_id\n" +
"WHERE (sharing_board.title LIKE %:keyword% OR sharing_board.content LIKE %:keyword%)\n" +
"AND sharing_board.category = :category GROUP BY sharing_board.sharing_board_id ", nativeQuery = true)
List<SharingBoard> findByKeywordOrderByLikes(@Param("keyword") String keyword, @Param("category") String category, Pageable pageable);

List<SharingBoard> findByKeyword(@Param("keyword") String keyword, @Param("category") String category, Pageable pageable);

List<SharingBoard> findAllByUserId(Long userId, Pageable pageable);
int countAllByUserId(Long userId);


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SharingCommentRepository extends JpaRepository<SharingComment, Long> {

public int countAllBySharingBoardId(Long sharing_board_id);
int countAllByUserId(Long userId);

@Query(value = "select c from SharingComment c join fetch c.sharingBoard sb " +
"where c.user.id = :userId order by c.createdAt desc")
List<SharingComment> getCommentByUserIdAndBoard(@Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.umc.DongnaeFriend.domain.account.sharing.repository;

import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingSympathy;
import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeSympathy;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface SharingSympathyRepository extends JpaRepository<SharingSympathy, Long> {

int countAllBySharingBoardId(Long sharing_board_id);

int countAllByUserId(Long userId);
List<SharingSympathy> findByUser_Id(long user_id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ public class AccountBookSharingServiceImpl implements AccountBookSharingService
@Override
public List<SharingDto.ListResponse> searchByKeyword(String keyword, int category, Pageable pageable) {
//TODO : 전체 카테고리 처리
List<SharingBoard> sharingBoards = sharingBoardRepository.findByKeywordOrderByLikes(keyword, SharingCategory.valueOf(category).name(), pageable);
List<SharingBoard> sharingBoards = sharingBoardRepository.findByKeyword(keyword, SharingCategory.valueOf(category).name(), pageable);
if (sharingBoards.isEmpty()) {
throw new CustomException(ErrorCode.NO_CONTENT_FOUND);
}
log.info("board found" + sharingBoards.get(0).getId());
return getListResponses(sharingBoards);
}

Expand Down Expand Up @@ -118,7 +117,7 @@ public SharingDto.Response getBoard(long board_id) {
@Override
public void updateBoard(long board_id, SharingDto.Request req) {
SharingBoard board = sharingBoardRepository.findById(board_id).orElseThrow(
() -> new CustomException(ErrorCode.INVALID_VALUE));
() -> new CustomException(ErrorCode.NO_CONTENT_FOUND));

board.updateBoard(req);
sharingBoardRepository.save(board);
Expand All @@ -132,6 +131,15 @@ public void updateBoard(long board_id, SharingDto.Request req) {
*/
@Override
public void deleteBoard(long board_id) {
Optional<SharingBoard> sharingBoard = sharingBoardRepository.findById(board_id);
if (sharingBoard.isEmpty()) {
throw new CustomException(ErrorCode.NO_CONTENT_FOUND);
}

if (!Objects.equals(sharingBoard.get().getUser().getId(), user.getId())) {
throw new CustomException(ErrorCode.INVALID_AUTH_TOKEN);
}

sharingBoardRepository.deleteById(board_id);
}

Expand Down
Loading

0 comments on commit 0065c62

Please sign in to comment.