package com.dbnt.faisp.main.hashTag.service;

import com.dbnt.faisp.main.hashTag.model.HashTag;
import com.dbnt.faisp.main.hashTag.repository.HashTagRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class HashTagService {
  private final HashTagRepository hashTagRepository;

  @Transactional
  public Integer selectTagKey(String tagNm){
    HashTag savedTag = hashTagRepository.findByTagNm(tagNm).orElse(null);
    if(savedTag==null){
      HashTag tag = new HashTag();
      tag.setTagNm(tagNm);
      return hashTagRepository.save(tag).getTagKey();
    }else{
      return savedTag.getTagKey();
    }
  }
}
