Skip to content

Commit

Permalink
fix: Teacher 조회 시 Lesson이 없어도 조회 가능 (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ho-Tea authored Jan 23, 2025
1 parent e540ee3 commit d0232b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,9 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import be.dash.dashserver.core.domain.common.Genre;
import be.dash.dashserver.database.core.teacher.projection.TeacherLessonCount;

public interface LessonJpaEntityRepository extends JpaRepository<LessonJpaEntity, Long>, JpaSpecificationExecutor<LessonJpaEntity> {

@Query("select new be.dash.dashserver.database.core.teacher.projection.TeacherLessonCount(t.id, t.member.nickname, count(l)) " +
"from LessonJpaEntity l " +
"join l.teacher t " +
"where t.member.nickname like %:keyword% " +
"group by t.member.nickname " +
"order by count(l) desc")
List<TeacherLessonCount> findTeacherLessonCountsDesc(@Param("keyword") String keyword);

@Query("select l.genre " +
"from LessonJpaEntity l " +
"where l.teacher.id = :teacherId " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
package be.dash.dashserver.database.core.teacher;

import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import be.dash.dashserver.database.core.teacher.projection.TeacherLessonCount;

public interface TeacherJpaRepository extends JpaRepository<TeacherJpaEntity, Long> {
Optional<TeacherJpaEntity> findByMemberId(Long memberId);

@Query("select new be.dash.dashserver.database.core.teacher.projection.TeacherLessonCount(t.id, t.member.nickname, count(l)) " +
"from TeacherJpaEntity t " +
"left join LessonJpaEntity l on l.teacher.id = t.id " +
"where t.member.nickname like %:keyword% " +
"group by t.id, t.member.nickname " +
"order by count(l) desc")
List<TeacherLessonCount> findTeacherLessonCountsDesc(@Param("keyword") String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void save(Teacher teacher) {
@Override
public Teachers findTeachersSortByLessonCountsDesc(String keyword) {
List<Teacher> teachers = new ArrayList<>();
List<TeacherLessonCount> teacherLessonCounts = lessonJpaEntityRepository.findTeacherLessonCountsDesc(keyword);
List<TeacherLessonCount> teacherLessonCounts = teacherJpaRepository.findTeacherLessonCountsDesc(keyword);
teacherLessonCounts.forEach(teacherLessonCount -> {
List<String> teacherImages = teacherImageJpaRepository.findAllByTeacherId(teacherLessonCount.teacherId())
.stream().map(TeacherImageJpaEntity::getImageUrl).toList();
Expand Down

0 comments on commit d0232b4

Please sign in to comment.