package com.nurseryapi.service.lookup.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.nurseryapi.entity.lookup.MajorEntity;
import com.nurseryapi.exception.NoSuchElementFoundException;
import com.nurseryapi.repository.lookup.MajorRepository;
import com.nurseryapi.service.lookup.MajorService;

/**
 * 
 * @author Hamza Aljazara
 *
 */
@Service
public class MajorServiceImpl implements MajorService {

	@Autowired
	private MajorRepository MajorRepository;

	/*
	 * @see com.nurseryapi.service.lookup.MajorService#getMajor(long)
	 */
	@Override
	public MajorEntity getMajor(long majorId) {
		return MajorRepository.findById(majorId).orElseThrow(NoSuchElementFoundException::new);
	}

	/*
	 * @see
	 * com.nurseryapi.service.lookup.MajorService#getMajor(org.springframework.data.
	 * domain.Pageable)
	 */
	@Override
	public Page<MajorEntity> getMajor(Pageable pageable) {
		return MajorRepository.findAll(pageable);
	}
}
{'avg_line_length': 26.658536585365855, 'max_line_length': 89, 'alphanum_fraction': 0.7987191216834401, 'licenses': ['Apache-2.0'], 'repository_name': 'hamzajazara/nursery-api', 'path': 'src/main/java/com/nurseryapi/service/lookup/impl/MajorServiceImpl.java', 'size': 1093, 'lang': 'Java'}