| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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<Node> findAll() {
- try {
- return this.repo.findAll();
- }
- catch (Exception e) {
- log.error("{}.findAll: Exception: {}", getClass().getSimpleName(), e.getMessage());
- }
- return new ArrayList<Node>();
- }
- public Node findById(Long id) {
- try {
- Optional<Node> 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<Node> 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;
- }
- }
|