#31 loan: approve judgement
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.example.loan.controller;
|
package com.example.loan.controller;
|
||||||
|
|
||||||
|
import com.example.loan.dto.ApplicationDto;
|
||||||
import com.example.loan.dto.JudgementDto;
|
import com.example.loan.dto.JudgementDto;
|
||||||
import com.example.loan.dto.ResponseDto;
|
import com.example.loan.dto.ResponseDto;
|
||||||
import com.example.loan.service.JudgementService;
|
import com.example.loan.service.JudgementService;
|
||||||
@@ -47,4 +48,11 @@ public class JudgementController extends AbstractController {
|
|||||||
judgementService.delete(judgementId);
|
judgementService.delete(judgementId);
|
||||||
return ok();
|
return ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PatchMapping("/{judgementId}/grants")
|
||||||
|
public ResponseDto<ApplicationDto.GrantAmount> grant(
|
||||||
|
@PathVariable Long judgementId
|
||||||
|
) {
|
||||||
|
return ok(judgementService.grant(judgementId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,4 +47,7 @@ public class Application extends BaseEntity {
|
|||||||
|
|
||||||
@Column(columnDefinition = "datetime DEFAULT NULL COMMENT '신청일자'")
|
@Column(columnDefinition = "datetime DEFAULT NULL COMMENT '신청일자'")
|
||||||
private LocalDateTime appliedAt;
|
private LocalDateTime appliedAt;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "decimal(15,2) DEFAULT NULL COMMENT '승인 금액'")
|
||||||
|
private BigDecimal approvalAmount;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,4 +48,16 @@ public class ApplicationDto implements Serializable {
|
|||||||
List<Long> acceptTermsIds;
|
List<Long> acceptTermsIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public static class GrantAmount {
|
||||||
|
|
||||||
|
private Long applicationId;
|
||||||
|
private BigDecimal approvalAmount;
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.example.loan.service;
|
package com.example.loan.service;
|
||||||
|
|
||||||
|
import com.example.loan.dto.ApplicationDto;
|
||||||
import com.example.loan.dto.JudgementDto;
|
import com.example.loan.dto.JudgementDto;
|
||||||
|
|
||||||
public interface JudgementService {
|
public interface JudgementService {
|
||||||
@@ -13,4 +14,6 @@ public interface JudgementService {
|
|||||||
JudgementDto.Response update(Long judgementId, JudgementDto.Request request);
|
JudgementDto.Response update(Long judgementId, JudgementDto.Request request);
|
||||||
|
|
||||||
void delete(Long judgementId);
|
void delete(Long judgementId);
|
||||||
|
|
||||||
|
ApplicationDto.GrantAmount grant(Long judgementId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.example.loan.service;
|
package com.example.loan.service;
|
||||||
|
|
||||||
|
import com.example.loan.domain.Application;
|
||||||
import com.example.loan.domain.Judgement;
|
import com.example.loan.domain.Judgement;
|
||||||
|
import com.example.loan.dto.ApplicationDto;
|
||||||
import com.example.loan.dto.JudgementDto;
|
import com.example.loan.dto.JudgementDto;
|
||||||
import com.example.loan.exception.BaseException;
|
import com.example.loan.exception.BaseException;
|
||||||
import com.example.loan.exception.ResultType;
|
import com.example.loan.exception.ResultType;
|
||||||
@@ -10,6 +12,8 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.modelmapper.ModelMapper;
|
import org.modelmapper.ModelMapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class JudgementServiceImpl implements JudgementService {
|
public class JudgementServiceImpl implements JudgementService {
|
||||||
@@ -78,6 +82,22 @@ public class JudgementServiceImpl implements JudgementService {
|
|||||||
judgementRepository.save(judgement);
|
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) {
|
private boolean isPresentApplication(Long applicationId) {
|
||||||
return applicationRepository.findById(applicationId).isPresent();
|
return applicationRepository.findById(applicationId).isPresent();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.example.loan.service;
|
|||||||
|
|
||||||
import com.example.loan.domain.Application;
|
import com.example.loan.domain.Application;
|
||||||
import com.example.loan.domain.Judgement;
|
import com.example.loan.domain.Judgement;
|
||||||
|
import com.example.loan.dto.ApplicationDto;
|
||||||
import com.example.loan.dto.JudgementDto;
|
import com.example.loan.dto.JudgementDto;
|
||||||
import com.example.loan.repository.ApplicationRepository;
|
import com.example.loan.repository.ApplicationRepository;
|
||||||
import com.example.loan.repository.JudgementRepository;
|
import com.example.loan.repository.JudgementRepository;
|
||||||
@@ -130,4 +131,29 @@ class JudgementServiceImplTest {
|
|||||||
|
|
||||||
assertThat(entity.getIsDeleted()).isTrue();
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user