#31 loan: approve judgement

This commit is contained in:
haerong22
2023-03-28 00:53:43 +09:00
parent f063e89ea2
commit 83af0c334a
6 changed files with 72 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
package com.example.loan.controller;
import com.example.loan.dto.ApplicationDto;
import com.example.loan.dto.JudgementDto;
import com.example.loan.dto.ResponseDto;
import com.example.loan.service.JudgementService;
@@ -47,4 +48,11 @@ public class JudgementController extends AbstractController {
judgementService.delete(judgementId);
return ok();
}
@PatchMapping("/{judgementId}/grants")
public ResponseDto<ApplicationDto.GrantAmount> grant(
@PathVariable Long judgementId
) {
return ok(judgementService.grant(judgementId));
}
}

View File

@@ -47,4 +47,7 @@ public class Application extends BaseEntity {
@Column(columnDefinition = "datetime DEFAULT NULL COMMENT '신청일자'")
private LocalDateTime appliedAt;
@Column(columnDefinition = "decimal(15,2) DEFAULT NULL COMMENT '승인 금액'")
private BigDecimal approvalAmount;
}

View File

@@ -48,4 +48,16 @@ public class ApplicationDto implements Serializable {
List<Long> acceptTermsIds;
}
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Builder
public static class GrantAmount {
private Long applicationId;
private BigDecimal approvalAmount;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
}
}

View File

@@ -1,5 +1,6 @@
package com.example.loan.service;
import com.example.loan.dto.ApplicationDto;
import com.example.loan.dto.JudgementDto;
public interface JudgementService {
@@ -13,4 +14,6 @@ public interface JudgementService {
JudgementDto.Response update(Long judgementId, JudgementDto.Request request);
void delete(Long judgementId);
ApplicationDto.GrantAmount grant(Long judgementId);
}

View File

@@ -1,6 +1,8 @@
package com.example.loan.service;
import com.example.loan.domain.Application;
import com.example.loan.domain.Judgement;
import com.example.loan.dto.ApplicationDto;
import com.example.loan.dto.JudgementDto;
import com.example.loan.exception.BaseException;
import com.example.loan.exception.ResultType;
@@ -10,6 +12,8 @@ import lombok.RequiredArgsConstructor;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
@Service
@RequiredArgsConstructor
public class JudgementServiceImpl implements JudgementService {
@@ -78,6 +82,22 @@ public class JudgementServiceImpl implements JudgementService {
judgementRepository.save(judgement);
}
@Override
public ApplicationDto.GrantAmount grant(Long judgementId) {
Judgement judgement = judgementRepository.findById(judgementId)
.orElseThrow(() -> new BaseException(ResultType.SYSTEM_ERROR));
Long applicationId = judgement.getApplicationId();
Application application = applicationRepository.findById(applicationId)
.orElseThrow(() -> new BaseException(ResultType.SYSTEM_ERROR));
BigDecimal approvalAmount = judgement.getApprovalAmount();
application.setApprovalAmount(approvalAmount);
applicationRepository.save(application);
return modelMapper.map(application, ApplicationDto.GrantAmount.class);
}
private boolean isPresentApplication(Long applicationId) {
return applicationRepository.findById(applicationId).isPresent();
}

View File

@@ -2,6 +2,7 @@ package com.example.loan.service;
import com.example.loan.domain.Application;
import com.example.loan.domain.Judgement;
import com.example.loan.dto.ApplicationDto;
import com.example.loan.dto.JudgementDto;
import com.example.loan.repository.ApplicationRepository;
import com.example.loan.repository.JudgementRepository;
@@ -130,4 +131,29 @@ class JudgementServiceImplTest {
assertThat(entity.getIsDeleted()).isTrue();
}
@Test
void Should_ReturnUpdateResponseOfExistApplicationEntity_When_RequestGrantApprovalAmountOfJudgementInfo() {
Judgement judgementEntity = Judgement.builder()
.name("kim")
.applicationId(1L)
.approvalAmount(BigDecimal.valueOf(5000000))
.build();
Application applicationEntity = Application.builder()
.applicationId(1L)
.approvalAmount(BigDecimal.valueOf(5000000))
.build();
when(judgementRepository.findById(1L)).thenReturn(Optional.ofNullable(judgementEntity));
when(applicationRepository.findById(1L)).thenReturn(Optional.ofNullable(applicationEntity));
when(applicationRepository.save(ArgumentMatchers.any(Application.class))).thenReturn(applicationEntity);
ApplicationDto.GrantAmount actual = judgementService.grant(1L);
assertThat(actual.getApplicationId()).isSameAs(1L);
assertThat(actual.getApprovalAmount()).isSameAs(judgementEntity.getApprovalAmount());
}
}