51 lines
1.5 KiB
Java
51 lines
1.5 KiB
Java
package de.ph87.homeautomation.property;
|
|
|
|
import de.ph87.homeautomation.RepositorySearchHelper;
|
|
import de.ph87.homeautomation.web.NotFoundException;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.util.List;
|
|
|
|
@Slf4j
|
|
@Service
|
|
@Transactional
|
|
@RequiredArgsConstructor
|
|
public class PropertyReader {
|
|
|
|
private final PropertyRepository propertyRepository;
|
|
|
|
private final PropertyMapper propertyMapper;
|
|
|
|
public List<Property> findAllByReadChannel_Id(final long readChannelId) {
|
|
return propertyRepository.findAllByReadChannel_Id(readChannelId);
|
|
}
|
|
|
|
public List<PropertyDto> search(final String term) {
|
|
return RepositorySearchHelper.search(term, propertyRepository, "title", propertyMapper::toDto);
|
|
}
|
|
|
|
public PropertyDto getDtoById(final long id) {
|
|
return propertyMapper.toDto(getById(id));
|
|
}
|
|
|
|
public Property getById(final long id) {
|
|
return propertyRepository.findById(id).orElseThrow(() -> new NotFoundException("Property.id=%d", id));
|
|
}
|
|
|
|
public Property getBySlug(final String slug) {
|
|
return propertyRepository.findBySlug(slug).orElseThrow(() -> new NotFoundException("Property.slug=%s", slug));
|
|
}
|
|
|
|
public List<PropertyDto> findAllDto() {
|
|
return propertyRepository.findAll().stream().map(propertyMapper::toDto).toList();
|
|
}
|
|
|
|
public List<Property> findAllByReadChannelNotNull() {
|
|
return propertyRepository.findAllByReadChannelNotNull();
|
|
}
|
|
|
|
}
|