#31 loan: delete application

This commit is contained in:
haerong22
2023-01-17 03:06:06 +09:00
parent acb28890ca
commit ad7dcf7b4e
4 changed files with 36 additions and 0 deletions

View File

@@ -34,4 +34,12 @@ public class ApplicationController extends AbstractController {
) {
return ok(applicationService.update(applicationId, request));
}
@DeleteMapping("/{applicationId}")
public ResponseDto<Void> delete(
@PathVariable Long applicationId
) {
applicationService.delete(applicationId);
return ok();
}
}

View File

@@ -9,4 +9,6 @@ public interface ApplicationService {
ApplicationDto.Response get(Long applicationId);
ApplicationDto.Response update(Long applicationId, ApplicationDto.Request request);
void delete(Long applicationId);
}

View File

@@ -50,4 +50,14 @@ public class ApplicationServiceImpl implements ApplicationService {
return modelMapper.map(application, ApplicationDto.Response.class);
}
@Override
public void delete(Long applicationId) {
Application application = applicationRepository.findById(applicationId)
.orElseThrow(() -> new BaseException(ResultType.SYSTEM_ERROR));
application.setIsDeleted(true);
applicationRepository.save(application);
}
}

View File

@@ -93,4 +93,20 @@ class ApplicationServiceTest {
assertThat(actual.getApplicationId()).isSameAs(findId);
assertThat(actual.getHopeAmount()).isSameAs(request.getHopeAmount());
}
@Test
void Should_DeletedApplicationEntity_When_RequestDeleteExistApplicationInfo() {
Long targetId = 1L;
Application entity = Application.builder()
.applicationId(1L)
.build();
when(applicationRepository.save(ArgumentMatchers.any(Application.class))).thenReturn(entity);
when(applicationRepository.findById(targetId)).thenReturn(Optional.ofNullable(entity));
applicationService.delete(targetId);
assertThat(entity.getIsDeleted()).isTrue();
}
}