Skip to content
Snippets Groups Projects
Commit 5affdde6 authored by Dominika Zemanovičová's avatar Dominika Zemanovičová Committed by Martin Gargalovič
Browse files

Add QuestionService

parent a07699b2
No related branches found
No related tags found
3 merge requests!31M2,!28M2 user,!27Draft: M2 user
package org.fuseri.moduleexercise.question;
import jakarta.persistence.EntityNotFoundException;
import lombok.Getter;
import org.fuseri.moduleexercise.common.DomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* Represent a service for managing Question entities
*/
@Service
public class QuestionService extends DomainService<Question> {
/**
* The repository instance used by this service
*/
@Getter
private final QuestionRepository repository;
/**
* Construct a new instance of QuestionService with the specified repository
*
* @param repository the repository instance to be used by this service
*/
@Autowired
public QuestionService(QuestionRepository repository) {
this.repository = repository;
}
/**
* Retrieve the Question entity with the specified ID
*
* @param id the ID of the Question entity to retrieve
* @return the Question entity with the specified ID
* @throws EntityNotFoundException if no Question entity exists with the specified ID
*/
@Transactional(readOnly = true)
public Question find(String id) {
return repository.findById(id)
.orElseThrow(() -> new EntityNotFoundException("Question '" + id + "' not found."));
}
/**
* Retrieve a page of Question entities associated with the specified exercise ID
*
* @param exerciseId the ID of the exercise to retrieve questions for
* @param page the page number to retrieve (0-indexed)
* @return a page of Question entities associated with the specified exercise ID
*/
@Transactional(readOnly = true)
public Page<Question> findByExerciseId(String exerciseId, int page) {
return repository.findByExerciseId(
exerciseId,
PageRequest.of(page, DomainService.DEFAULT_PAGE_SIZE));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment