#31 loan: get application

This commit is contained in:
haerong22
2023-01-17 02:50:52 +09:00
parent 668b078042
commit f969a5e6fa
4 changed files with 36 additions and 4 deletions

View File

@@ -4,10 +4,7 @@ import com.example.loan.dto.ApplicationDto;
import com.example.loan.dto.ResponseDto;
import com.example.loan.service.ApplicationService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
@RestController
@RequiredArgsConstructor
@@ -22,4 +19,11 @@ public class ApplicationController extends AbstractController {
) {
return ok(applicationService.create(request));
}
@GetMapping("/{applicationId}")
public ResponseDto<ApplicationDto.Response> get(
@PathVariable Long applicationId
) {
return ok(applicationService.get(applicationId));
}
}

View File

@@ -5,4 +5,6 @@ import com.example.loan.dto.ApplicationDto;
public interface ApplicationService {
ApplicationDto.Response create(ApplicationDto.Request request);
ApplicationDto.Response get(Long applicationId);
}

View File

@@ -2,6 +2,8 @@ package com.example.loan.service;
import com.example.loan.domain.Application;
import com.example.loan.dto.ApplicationDto;
import com.example.loan.exception.BaseException;
import com.example.loan.exception.ResultType;
import com.example.loan.repository.ApplicationRepository;
import lombok.RequiredArgsConstructor;
import org.modelmapper.ModelMapper;
@@ -25,4 +27,12 @@ public class ApplicationServiceImpl implements ApplicationService {
return modelMapper.map(applied, ApplicationDto.Response.class);
}
@Override
public ApplicationDto.Response get(Long applicationId) {
Application application = applicationRepository.findById(applicationId)
.orElseThrow(() -> new BaseException(ResultType.SYSTEM_ERROR));
return modelMapper.map(application, ApplicationDto.Response.class);
}
}

View File

@@ -13,6 +13,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.modelmapper.ModelMapper;
import java.math.BigDecimal;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -55,4 +56,19 @@ class ApplicationServiceTest {
assertThat(actual.getCellPhone()).isSameAs(entity.getCellPhone());
assertThat(actual.getEmail()).isSameAs(entity.getEmail());
}
@Test
void Should_ReturnResponseOfExistApplicationEntity_When_RequestExistApplicationId() {
Long findId = 1L;
Application entity = Application.builder()
.applicationId(1L)
.build();
when(applicationRepository.findById(findId)).thenReturn(Optional.ofNullable(entity));
ApplicationDto.Response actual = applicationService.get(findId);
assertThat(actual.getApplicationId()).isSameAs(findId);
}
}