// Path: src/main/java/com/sivalabs/jblogger/entities/Tag.java
// @Entity
// @Table(name = "TAGS")
// @Data
// public class Tag implements Serializable, Comparable<Tag>
// {
// 	private static final long serialVersionUID = 1L;
// 
// 	@Id
// 	@SequenceGenerator(name="tag_id_generator", sequenceName="tag_id_seq", initialValue = 100, allocationSize=1)
// 	@GeneratedValue(generator = "tag_id_generator")
// 	private Long id;
// 
// 	@Column(name = "label", unique=true, nullable = false, length = 150)
// 	private String label;
// 	
// 	@JsonIgnore
// 	@ManyToMany(mappedBy="tags")
// 	private List<Post> posts;
// 
// 	@Override
// 	public int compareTo(Tag other)
// 	{
// 		return this.label.compareToIgnoreCase(other.label);
// 	}
// 
// }
// 
// Path: src/main/java/com/sivalabs/jblogger/exceptions/JBloggerException.java
// public class JBloggerException extends RuntimeException
// {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	public JBloggerException()
// 	{
// 	}
// 
// 	public JBloggerException(String message)
// 	{
// 		super(message);
// 	}
// 
// 	public JBloggerException(Throwable cause)
// 	{
// 		super(cause);
// 	}
// 
// 	public JBloggerException(String message, Throwable cause)
// 	{
// 		super(message, cause);
// 	}
// 
// }
// 
// Path: src/main/java/com/sivalabs/jblogger/repositories/TagRepository.java
// @Repository
// public interface TagRepository extends JpaRepository<Tag, Long>
// {
// 
// 	List<Tag> findByLabelLike(String query);
// 
// 	Optional<Tag> findByLabel(String trim);
// 	
// 	@Query("SELECT t.id, t.label, COUNT(post_id) as count FROM Tag t JOIN t.posts p GROUP BY t.id")
// 	List<Object[]> getTagsWithCount();
// 
// }


import com.sivalabs.jblogger.entities.Tag;
import com.sivalabs.jblogger.exceptions.JBloggerException;
import com.sivalabs.jblogger.repositories.TagRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
package com.sivalabs.jblogger.services;



@Service
@Transactional
public class TagService
{
	private TagRepository tagRepository;

	@Autowired
	public TagService(TagRepository tagRepository) {
		this.tagRepository = tagRepository;
	}

	public List<Tag> search(String query){
// Path: src/main/java/com/sivalabs/jblogger/entities/Tag.java
// @Entity
// @Table(name = "TAGS")
// @Data
// public class Tag implements Serializable, Comparable<Tag>
// {
// 	private static final long serialVersionUID = 1L;
// 
// 	@Id
// 	@SequenceGenerator(name="tag_id_generator", sequenceName="tag_id_seq", initialValue = 100, allocationSize=1)
// 	@GeneratedValue(generator = "tag_id_generator")
// 	private Long id;
// 
// 	@Column(name = "label", unique=true, nullable = false, length = 150)
// 	private String label;
// 	
// 	@JsonIgnore
// 	@ManyToMany(mappedBy="tags")
// 	private List<Post> posts;
// 
// 	@Override
// 	public int compareTo(Tag other)
// 	{
// 		return this.label.compareToIgnoreCase(other.label);
// 	}
// 
// }
// 
// Path: src/main/java/com/sivalabs/jblogger/exceptions/JBloggerException.java
// public class JBloggerException extends RuntimeException
// {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	public JBloggerException()
// 	{
// 	}
// 
// 	public JBloggerException(String message)
// 	{
// 		super(message);
// 	}
// 
// 	public JBloggerException(Throwable cause)
// 	{
// 		super(cause);
// 	}
// 
// 	public JBloggerException(String message, Throwable cause)
// 	{
// 		super(message, cause);
// 	}
// 
// }
// 
// Path: src/main/java/com/sivalabs/jblogger/repositories/TagRepository.java
// @Repository
// public interface TagRepository extends JpaRepository<Tag, Long>
// {
// 
// 	List<Tag> findByLabelLike(String query);
// 
// 	Optional<Tag> findByLabel(String trim);
// 	
// 	@Query("SELECT t.id, t.label, COUNT(post_id) as count FROM Tag t JOIN t.posts p GROUP BY t.id")
// 	List<Object[]> getTagsWithCount();
// 
// }


// Path: src/main/java/com/sivalabs/jblogger/services/TagService.java
import com.sivalabs.jblogger.entities.Tag;
import com.sivalabs.jblogger.exceptions.JBloggerException;
import com.sivalabs.jblogger.repositories.TagRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;

package com.sivalabs.jblogger.services;



@Service
@Transactional
public class TagService
{
	private TagRepository tagRepository;

	@Autowired
	public TagService(TagRepository tagRepository) {
		this.tagRepository = tagRepository;
	}

	public List<Tag> search(String query){
		return tagRepository.findByLabelLike(query+"%");