Skip to content

Commit

Permalink
feat:청구 결과 리스트,멤버별 청구 확인 저장기능
Browse files Browse the repository at this point in the history
  • Loading branch information
dPwls0125 committed Sep 25, 2023
1 parent a5596d3 commit 2d85dfe
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ public ResponseEntity<?> claimList() throws Exception {
summary = "청구 관련 지불한 멤버 check",
description = "클럽에 소속된 모든 user에게 청구 신청"
)
public ResponseEntity<?> claimMemberIsPaid(@PathVariable(name ="memberId") Long memberId,@PathVariable(name="claimId") Long claimId) throws Exception{
public ResponseEntity<?> claimMemberIsPaid(@PathVariable Long claimResultId ) throws Exception{
log.info("정산 청구 api 호출");
log.info(memberId.toString());
return accountService.checkMemberPaid(memberId,claimId);
return accountService.checkMemberPaid(claimResultId);
};

@Override
public ResponseEntity<?> claimResultList(@PathVariable Long claimId) throws Exception {
return accountService.getMemberPaidList(claimId);
}
@Override
@Operation(
summary = "입출금 내역 입력 api",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public interface AccountingController {
@GetMapping("/claim/list")
ResponseEntity<?> claimList() throws Exception;

@PostMapping("/claim/{memberId}/{claimId}")
ResponseEntity<?> claimMemberIsPaid(@PathVariable Long memberId, @PathVariable Long claimId) throws Exception;

@PostMapping("/claim/{claimResultId}")
ResponseEntity<?> claimMemberIsPaid(@PathVariable Long claimResultId) throws Exception;

@GetMapping("/claim/result/list/{claimId}")
ResponseEntity<?> claimResultList(@PathVariable Long claimId) throws Exception;
//입출금 내역 입력
@PostMapping("/book/create")
ResponseEntity createBook(@RequestBody AccountBookCreateDto accountBookCreateDto) throws Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ClaimResultRepository extends JpaRepository<ClaimResult, Long> {
Optional<ClaimResult> findByMember_memberId(Long memberId);
Optional<ClaimResult> findByMemberAndClaim(Member member, Claim claim);
List<ClaimResult> findAllByClaim(Claim claim);
}
27 changes: 19 additions & 8 deletions src/main/java/gdg/whatssue/service/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import gdg.whatssue.service.dto.AccountBookCreateDto;
import gdg.whatssue.service.dto.AccountBookListDto;
import gdg.whatssue.service.dto.AccountClaimDto;
import gdg.whatssue.service.dto.AccountClaimResDto;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -45,6 +46,7 @@ public ResponseEntity<?> createClaim(AccountClaimDto dto) throws Exception {
.claimName(dto.getClaimName())
.build();
claimRepository.save(claim);

List<Member> members = memberRepository.findAllByClub(club);
for(Member member : members){
ClaimResult claimResult = ClaimResult.builder()
Expand All @@ -58,6 +60,7 @@ public ResponseEntity<?> createClaim(AccountClaimDto dto) throws Exception {
.member(null)
.claim(claim)
.build();

return ResponseEntity.ok("정산 청구 완료");
}

Expand All @@ -76,21 +79,29 @@ public ResponseEntity<?> getClaimList(Long ClubId) {
return ResponseEntity.ok(accountClaimDtoList);
}else return ResponseEntity.status(HttpStatus.NOT_FOUND).body("클럽을 찾을 수 없습니다.");
}
public ResponseEntity<?> checkMemberPaid(Long memberId, Long claimId){
Member member = memberRepository.findById(memberId).orElseThrow(() -> (
new ResponseStatusException(HttpStatus.NOT_FOUND, "멤버를 찾을 수 없습니다.")
));
Claim claim = claimRepository.findById(claimId).orElseThrow(() -> (
new ResponseStatusException(HttpStatus.NOT_FOUND, "정산 청구를 찾을 수 없습니다.")
));
ClaimResult claimResult = claimResultRepository.findByMemberAndClaim(member,claim).orElseThrow(() -> (

public ResponseEntity<?> checkMemberPaid(Long claimResultId){
ClaimResult claimResult = claimResultRepository.findById(claimResultId).orElseThrow(() -> (
new ResponseStatusException(HttpStatus.NOT_FOUND, "일치하는 유저의 청구 결과표가 없습니다.")
));
claimResult.setIsPaid(true);
claimResultRepository.save(claimResult);
return ResponseEntity.ok("정산 청구 결과 저장 완료");
}

public ResponseEntity<?> getMemberPaidList(Long claimId){
Claim claim = claimRepository.findById(claimId).orElseThrow(() -> (
new ResponseStatusException(HttpStatus.NOT_FOUND, "정산 청구를 찾을 수 없습니다.")
));
List<ClaimResult> claimResultList = claimResultRepository.findAllByClaim(claim);
List<AccountClaimResDto> accountClaimResDtosList = claimResultList.stream().map(claimResult -> AccountClaimResDto.builder()
.memberName(claimResult.getMember().getMemberName())
.claimResultId(claimResult.getClaimResultId())
.claimAmount(claimResult.getClaim().getClaimAmount().toString())
.isPaid(claimResult.getIsPaid())
.build()).toList();
return ResponseEntity.ok(accountClaimResDtosList);
}
@Transactional
//변경 (삭제, 입력) 이 일어날때마다 clubId에 해당하는 모든 TotalPaidAmount 가 같은 값을 가져야하는데 그게 안됨 (어려움)
public ResponseEntity createBook(AccountBookCreateDto accountBookCreateDto) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/gdg/whatssue/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ResponseEntity createClub(ClubDetailDto clubDetailDto) {
return ResponseEntity.badRequest().body("이미 클럽이 존재합니다.");
}
//존재하지 않는 경우
else{
else {
Club newclub = Club.builder()
.clubName(clubDetailDto.getClubName())
.clubInfo(clubDetailDto.getClubInfo())
Expand All @@ -60,7 +60,6 @@ public ResponseEntity createClub(ClubDetailDto clubDetailDto) {
return ResponseEntity.ok().build();
}


}

public ResponseEntity updateClub(ClubDetailDto clubDetailDto) {
Expand All @@ -78,7 +77,6 @@ public ResponseEntity updateClub(ClubDetailDto clubDetailDto) {

@Transactional
public ResponseEntity createInviteLink(Long userId, LinkInfoDto linkInfoDto){

Club club = memberRepository.findById(userId).get().getClub();
//클럽이 존재하지 않는경우 예외처리
if (club == null) {
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/gdg/whatssue/service/dto/AccountClaimResDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package gdg.whatssue.service.dto;


import gdg.whatssue.entity.Member;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@Schema(description = "정산 청구 결과 멤버별 확인 DTO")
public class AccountClaimResDto {
private Long claimResultId;
private String memberName ;
private String claimAmount;
private boolean isPaid;

@Builder
public AccountClaimResDto(String memberName, String claimAmount, boolean isPaid, Long claimResultId){
this.claimResultId = claimResultId;
this.memberName = memberName;
this.claimAmount = claimAmount;
this.isPaid = isPaid;
}
}
7 changes: 7 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ spring:

# profiles:
# include: mysql
jpa:
hibernate:
ddl-auto: update

generate-ddl: true
defer-datasource-initialization: true


mvc:
pathmatch:
Expand Down

0 comments on commit 2d85dfe

Please sign in to comment.