package com.crunii.micro.domain.repo.main;

import com.crunii.micro.domain.common.BaseRepo;
import com.crunii.micro.domain.entity.main.TsmPost;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TsmPostRepo extends BaseRepo<TsmPost, Long> {

    @Query(value = "select * from tsm_post where code=:code and del_flag='0'",nativeQuery = true)
    List<TsmPost> findByCode(@Param("code") String code);

    @Query(value = "select * from tsm_post where name=:name and del_flag='0'",nativeQuery = true)
    List<TsmPost> findByName(@Param("name") String name);

    @Query(value = "select * from tsm_post where id=:id and del_flag='0'",nativeQuery = true)
    TsmPost getOnePost(@Param("id") Long id);

    @Query(value = "update tsm_post set del_flag='1' where id =:id", nativeQuery = true)
    void deletePost(@Param("id") Long id);

    @Query(value = "select * from tsm_post where state=1 and del_flag='0'",nativeQuery = true)
    List<TsmPost> findAllPost();
}
