package com.eshore.gringotts.web.domain.base.service;

import cn.hutool.core.util.ObjectUtil;
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList;

/**
 * @author lanyuanxiaoyao
 * @date 2024-11-21
 */
public abstract class SimpleService<E, ID> {
    protected abstract SimpleRepository<E, ID> repository();

    public ImmutableList<E> list() {
        return Lists.immutable.ofAll(repository().findAll());
    }

    public E detail(ID id) {
        if (ObjectUtil.isNull(id)) {
            return null;
        }
        return repository().findById(id).orElse(null);
    }
}
