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

Add QuestionRepository and QuestionRepositoryImpl

parent 873e371e
No related branches found
No related tags found
3 merge requests!31M2,!28M2 user,!27Draft: M2 user
package org.fuseri.moduleexercise.question;
import org.fuseri.moduleexercise.common.DomainRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
/**
* A repository interface for managing Question entities
*/
public interface QuestionRepository extends DomainRepository<Question, String> {
/**
* Find a page of questions associated with the exercise with the specified ID
*
* @param exerciseId the ID of the exercise to find questions for
* @param pageRequest the page request specifying the page number and page size
* @return a page of questions associated with the specified exercise
*/
Page<Question> findByExerciseId(String exerciseId, PageRequest pageRequest);
}
\ No newline at end of file
package org.fuseri.moduleexercise.question;
import org.fuseri.moduleexercise.common.DomainRepositoryImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* An implementation of the QuestionRepository interface
* Provides access to Question entities stored in a data source
*/
@Repository
public class QuestionRepositoryImpl extends DomainRepositoryImpl<Question, String> implements QuestionRepository {
/**
* Find a page of questions associated with the exercise with the specified ID
*
* @param exerciseId the ID of the exercise to find questions for
* @param pageRequest the page request specifying the page number and page size
* @return a page of questions associated with the specified exercise
*/
@Override
public Page<Question> findByExerciseId(String exerciseId, PageRequest pageRequest) {
List<Question> filteredQuestions = getItems()
.stream()
.filter(e -> e.getExerciseId().equals(exerciseId))
.skip(pageRequest.getOffset())
.limit(pageRequest.getPageSize())
.toList();
return new PageImpl<>(filteredQuestions, pageRequest, filteredQuestions.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