package com.interplug.qcast.biz.canvasStatus; import com.interplug.qcast.biz.canvasStatus.dto.CanvasStatus; import com.interplug.qcast.biz.canvasStatus.dto.CanvasStatusResponse; import com.interplug.qcast.config.Exception.ErrorCode; import com.interplug.qcast.config.Exception.QcastException; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor public class CanvasStatusService { private final CanvasStatusMapper canvasStatusMapper; // 사용자(userId)에 해당하는 전체 캔버스 조회 public List selectAllCanvasStatus(String userId) throws QcastException { List result = null; if (userId != null && !userId.trim().isEmpty()) { result = canvasStatusMapper.selectAllCanvasStatus(userId); } else { throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, "올바르지 않은 입력값입니다."); } return result; } // 사용자(userId)와 물건번호(objectNo)에 해당하는 캔버스 조회 public List selectObjectNoCanvasStatus(String objectNo, String userId) throws QcastException { List result = null; if (objectNo != null && !objectNo.trim().isEmpty() && userId != null && !userId.trim().isEmpty()) { result = canvasStatusMapper.selectObjectNoCanvasStatus(objectNo, userId); } else { throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, "올바르지 않은 입력값입니다."); } return result; } // 캔버스 등록 public Integer insertCanvasStatus(CanvasStatus cs) throws QcastException { Integer id = 0; // 데이터가 없으면 저장 try { canvasStatusMapper.insertCanvasStatus(cs); // 데이터 저장 후 Max id 확인 List maxId = canvasStatusMapper.getMaxIdCanvasStatus(cs.getObjectNo(), cs.getUserId()); id = maxId.get(0).getId(); } catch (Exception e) { throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, "캔버스 등록 중 오류 발생"); } // 생성된 id 반환 return id; } // 캔버스 수정 public void updateCanvasStatus(CanvasStatus cs) throws QcastException { if (cs.getId() == null) { throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, "올바르지 않은 입력값입니다."); } // 먼저 데이터가 존재하는지 확인 List existingStatus = canvasStatusMapper.getIdCanvasStatus(cs.getId()); // 데이터가 존재하지 않으면 수정하지 않고 예외를 던짐 if (existingStatus.size() > 0) { canvasStatusMapper.updateCanvasStatus(cs); } else { throw new QcastException(ErrorCode.NOT_FOUND, "수정할 캔버스가 존재하지 않습니다."); } } // 물건번호(objectNo)에 해당하는 캔버스 삭제 public void deleteObjectNoCanvasStatus(String objectNo) throws QcastException { if (objectNo == null || objectNo.trim().isEmpty()) { throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, "올바르지 않은 입력값입니다."); } // 먼저 데이터가 존재하는지 확인 List existingStatus = canvasStatusMapper.getObjectNoCanvasStatus(objectNo); // 데이터가 존재하지 않으면 수정하지 않고 예외를 던짐 if (existingStatus.size() > 0) { canvasStatusMapper.deleteObjectNoCanvasStatus(objectNo); } else { throw new QcastException(ErrorCode.NOT_FOUND, "삭제할 캔버스가 존재하지 않습니다."); } } // id에 해당하는 캔버스 삭제 public void deleteIdCanvasStatus(Integer id) throws QcastException { if (id == null) { throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, "올바르지 않은 입력값입니다."); } // 먼저 데이터가 존재하는지 확인 List existingStatus = canvasStatusMapper.getIdCanvasStatus(id); // 데이터가 존재하지 않으면 수정하지 않고 예외를 던짐 if (existingStatus.size() > 0) { canvasStatusMapper.deleteIdCanvasStatus(id); } else { throw new QcastException(ErrorCode.NOT_FOUND, "삭제할 캔버스가 존재하지 않습니다."); } } }