Files
smartproc-be/src/main/java/com/iconplus/smartproc/service/jenispengadaan/DeleteJenisPengadaanService.java
2023-05-25 10:41:15 +07:00

40 lines
1.6 KiB
Java

package com.iconplus.smartproc.service.jenispengadaan;
import com.iconplus.smartproc.exception.BusinessException;
import com.iconplus.smartproc.helper.model.EmptyResponse;
import com.iconplus.smartproc.helper.service.BaseService;
import com.iconplus.smartproc.model.entity.JenisPengadaan;
import com.iconplus.smartproc.model.request.JenisPengadaanRequest;
import com.iconplus.smartproc.repository.JenisPengadaanRepository;
import com.iconplus.smartproc.util.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class DeleteJenisPengadaanService implements BaseService<JenisPengadaanRequest, EmptyResponse> {
private JenisPengadaanRepository jenisPengadaanRepository;
public DeleteJenisPengadaanService(JenisPengadaanRepository jenisPengadaanRepository) {
this.jenisPengadaanRepository = jenisPengadaanRepository;
}
@Override
public EmptyResponse execute(JenisPengadaanRequest input) {
var jenisPengadaan = jenisPengadaanRepository.findByIdAndDeletedFalse(input.getId())
.orElseThrow(() -> new BusinessException(HttpStatus.CONFLICT,
Constants.ERR_CODE_10001,
Constants.ERR_TTL_10001,
String.format(Constants.ERR_MSG_10001, input.getId())));
jenisPengadaan.setIsDelete(true);
jenisPengadaanRepository.save(jenisPengadaan);
log.info("success delete jenis pengadaan id {}", jenisPengadaan.getIsDelete());
return new EmptyResponse();
}
}