package com.its.op.service.database; import com.its.op.model.dto.NodeDto; import com.its.op.model.entity.Node; import com.its.op.repository.NodeRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; import java.util.Optional; @Slf4j @RequiredArgsConstructor @Service public class TbNodeService { private final NodeRepository repo; public List findAll() { try { return this.repo.findAll(); } catch (Exception e) { log.error("{}.findAll: Exception: {}", getClass().getSimpleName(), e.getMessage()); } return new ArrayList(); } public Node findById(Long id) { try { Optional data = this.repo.findById(id); if (data.isPresent()) { return data.get(); } } catch (Exception e) { log.error("{}.findById: Object: {}, Exception: {}", getClass().getSimpleName(), id, e.getMessage()); } return null; } // 노드명 변경 public Node updateNameById(Long id, NodeDto.NameUpdateReq req) { try { Optional data = this.repo.findById(id); if (data.isPresent()) { Node node = data.get(); node.updateName(req); this.repo.save(node); return node; } } catch (Exception e) { log.error("{}.updateNameById: Object: {}, Exception: {}", getClass().getSimpleName(), req, e.getMessage()); } return null; } }