package se.kits.gakusei.content.repository;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import se.kits.gakusei.content.model.Lesson;
import se.kits.gakusei.content.model.Nugget;

import java.util.List;

public interface LessonRepository extends CrudRepository<Lesson, Long> {

    Lesson findByName(String name);

    List<Nugget> findNuggetsByTwoFactTypes(
            @Param("lessonName") String lessonName,
            @Param("factType1") String questionType,
            @Param("factType2") String answerType);

    List<Nugget> findNuggetsBySuccessrate(
            @Param("username") String username,
            @Param("lessonName") String lessonName,
            @Param("factType1") String questionType,
            @Param("factType2") String answerType);


    List<Nugget> findUnansweredNuggets(
            @Param("username") String username,
            @Param("lessonName") String lessonName,
            @Param("factType1") String questionType,
            @Param("factType2") String answerType);

    @Query("select l from Lesson l where not l.description = 'quiz'")
    List<Lesson> findVocabularyLessons();

    @Query("select l from Lesson l where l.description = 'quiz'")
    List<Lesson> findQuizLessons();
}

package se.kits.gakusei.content.repository;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import se.kits.gakusei.content.model.Lesson;
import se.kits.gakusei.content.model.Nugget;

import java.util.List;

public interface LessonRepository extends CrudRepository<Lesson, Long> {

    Lesson findByName(String name);

    List<Nugget> findNuggetsByTwoFactTypes(
            @Param("lessonName") String lessonName,
            @Param("factType1") String questionType,
            @Param("factType2") String answerType);

    List<Nugget> findNuggetsBySuccessrate(
            @Param("username") String username,
            @Param("lessonName") String lessonName,
            @Param("factType1") String questionType,
            @Param("factType2") String answerType);


    List<Nugget> findUnansweredNuggets(
            @Param("username") String username,
            @Param("lessonName") String lessonName,
            @Param("factType1") String questionType,
            @Param("factType2") String answerType);

    @Query("select l from Lesson l where not l.description = 'quiz' order by l.name")
    List<Lesson> findVocabularyLessons();

    @Query("select l from Lesson l where l.description = 'quiz' order by l.name")
    List<Lesson> findQuizLessons();
}

Sort lessons by name when retrieving from db
Sort lessons by name when retrieving from db
