#31 loan: delete counsel

This commit is contained in:
haerong22
2023-01-16 02:35:21 +09:00
parent b87d68fd7e
commit af8b0ed0e9
4 changed files with 34 additions and 0 deletions

View File

@@ -28,4 +28,10 @@ public class CounselController extends AbstractController {
return ok(counselService.update(counselId, request));
}
@DeleteMapping("/{counselId}")
public ResponseDto<CounselDto.Response> delete(@PathVariable Long counselId) {
counselService.delete(counselId);
return ok();
}
}

View File

@@ -9,4 +9,6 @@ public interface CounselService {
CounselDto.Response get(Long counselId);
CounselDto.Response update(Long counselId, CounselDto.Request request);
void delete(Long counselId);
}

View File

@@ -52,4 +52,14 @@ public class CounselServiceImpl implements CounselService {
counselRepository.save(counsel);
return modelMapper.map(counsel, CounselDto.Response.class);
}
@Override
public void delete(Long counselId) {
Counsel counsel = counselRepository.findById(counselId)
.orElseThrow(() -> new BaseException(ResultType.SYSTEM_ERROR));
counsel.setIsDeleted(true);
counselRepository.save(counsel);
}
}

View File

@@ -108,4 +108,20 @@ class CounselServiceTest {
assertThat(actual.getCounselId()).isSameAs(findId);
assertThat(actual.getName()).isSameAs("jung");
}
@Test
void Should_DeletedCounselEntity_When_RequestDeleteExistCounselInfo() {
Long targetId = 1L;
Counsel entity = Counsel.builder()
.counselId(1L)
.build();
when(counselRepository.save(ArgumentMatchers.any(Counsel.class))).thenReturn(entity);
when(counselRepository.findById(targetId)).thenReturn(Optional.ofNullable(entity));
counselService.delete(targetId);
assertThat(entity.getIsDeleted()).isSameAs(true);
}
}