From 906c3a9d9bd0c569d0db638856ad97d5ebd2bc3f Mon Sep 17 00:00:00 2001 From: Jeongjin Lee Date: Tue, 21 Nov 2023 00:10:53 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=EA=B3=BC=EB=A6=BF=201.1.7=20(#339)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: Homework 정보 반환 시, 클래스 색상 사용자 지정 색으로 반환되도록 수정 (#336) * Fix: 학생 초대 시, FCM 토큰 없이도 초대되도록 수정 (#337) --- .../repository/HomeworkRepositoryCustom.java | 2 +- .../repository/HomeworkRepositoryImpl.java | 49 +++++++++++++------ .../homework/service/HomeworkService.java | 2 +- .../lecture/service/LectureService.java | 2 +- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/selfrunner/gwalit/domain/homework/repository/HomeworkRepositoryCustom.java b/src/main/java/com/selfrunner/gwalit/domain/homework/repository/HomeworkRepositoryCustom.java index 18cc5096..5cccfe2d 100644 --- a/src/main/java/com/selfrunner/gwalit/domain/homework/repository/HomeworkRepositoryCustom.java +++ b/src/main/java/com/selfrunner/gwalit/domain/homework/repository/HomeworkRepositoryCustom.java @@ -25,7 +25,7 @@ public interface HomeworkRepositoryCustom { Optional> findAllHomeworkByMemberAndType(Member member, Boolean type); - HomeworkMainRes findHomeworkByHomeworkId(Long homeworkId); + HomeworkMainRes findHomeworkByHomeworkId(Member member, Long homeworkId); Optional> findAllHomeworkByMemberAndLectureId(Member member, Long lectureId); diff --git a/src/main/java/com/selfrunner/gwalit/domain/homework/repository/HomeworkRepositoryImpl.java b/src/main/java/com/selfrunner/gwalit/domain/homework/repository/HomeworkRepositoryImpl.java index 2943c110..cf6da62a 100644 --- a/src/main/java/com/selfrunner/gwalit/domain/homework/repository/HomeworkRepositoryImpl.java +++ b/src/main/java/com/selfrunner/gwalit/domain/homework/repository/HomeworkRepositoryImpl.java @@ -1,6 +1,7 @@ package com.selfrunner.gwalit.domain.homework.repository; import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.CaseBuilder; import com.querydsl.jpa.impl.JPAQueryFactory; import com.selfrunner.gwalit.domain.homework.dto.response.HomeworkMainRes; import com.selfrunner.gwalit.domain.homework.dto.response.HomeworkRes; @@ -56,9 +57,12 @@ public Optional> findRecentHomeworkByMemberAndLessonIdList return Optional.ofNullable( queryFactory.selectFrom(homework) .leftJoin(lesson).on(lesson.lessonId.eq(homework.lessonId)) - .leftJoin(lecture).on(lecture.lectureId.eq(lesson.lecture.lectureId)) + .leftJoin(memberAndLecture).on(memberAndLecture.lecture.lectureId.eq(lesson.lecture.lectureId)) .where(homework.lessonId.in(lessonIdList), homework.memberId.eq(member.getMemberId()), homework.deletedAt.isNull()) - .transform(groupBy(homework.homeworkId).list(Projections.constructor(HomeworkMainRes.class, homework.homeworkId, lecture.lectureId, lecture.color, lesson.lessonId, homework.memberId, homework.body, homework.deadline, homework.isFinish))) + .orderBy(homework.homeworkId.asc(), new CaseBuilder() + .when(memberAndLecture.member.memberId.eq(member.getMemberId())).then(0) + .otherwise(1).asc()) + .transform(groupBy(homework.homeworkId).list(Projections.constructor(HomeworkMainRes.class, homework.homeworkId, memberAndLecture.lecture.lectureId, memberAndLecture.color, lesson.lessonId, homework.memberId, homework.body, homework.deadline, homework.isFinish))) ); } @@ -67,9 +71,12 @@ public Optional> findAllHomeworkByMember(Member member) { return Optional.ofNullable( queryFactory.selectFrom(homework) .leftJoin(lesson).on(lesson.lessonId.eq(homework.lessonId)) - .leftJoin(lecture).on(lecture.lectureId.eq(lesson.lecture.lectureId)) + .leftJoin(memberAndLecture).on(memberAndLecture.lecture.lectureId.eq(lesson.lecture.lectureId)) .where(homework.memberId.eq(member.getMemberId()), homework.deletedAt.isNull()) - .transform(groupBy(homework.homeworkId).list(Projections.constructor(HomeworkMainRes.class, homework.homeworkId, lecture.lectureId, lecture.color, lesson.lessonId, homework.memberId, homework.body, homework.deadline, homework.isFinish))) + .orderBy(homework.homeworkId.asc(), new CaseBuilder() + .when(memberAndLecture.member.memberId.eq(member.getMemberId())).then(0) + .otherwise(1).asc()) + .transform(groupBy(homework.homeworkId).list(Projections.constructor(HomeworkMainRes.class, homework.homeworkId, memberAndLecture.lecture.lectureId, memberAndLecture.color, lesson.lessonId, homework.memberId, homework.body, homework.deadline, homework.isFinish))) ); } @@ -78,19 +85,25 @@ public Optional> findAllHomeworkByMemberAndType(Member mem return Optional.ofNullable( queryFactory.selectFrom(homework) .leftJoin(lesson).on(lesson.lessonId.eq(homework.lessonId)) - .leftJoin(lecture).on(lecture.lectureId.eq(lesson.lecture.lectureId)) + .leftJoin(memberAndLecture).on(memberAndLecture.lecture.lectureId.eq(lesson.lecture.lectureId)) .where(homework.memberId.eq(member.getMemberId()), homework.isFinish.eq(type), homework.deletedAt.isNull()) - .transform(groupBy(homework.homeworkId).list(Projections.constructor(HomeworkMainRes.class, homework.homeworkId, lecture.lectureId, lecture.color, lesson.lessonId, homework.memberId, homework.body, homework.deadline, homework.isFinish))) + .orderBy(homework.homeworkId.asc(), new CaseBuilder() + .when(memberAndLecture.member.memberId.eq(member.getMemberId())).then(0) + .otherwise(1).asc()) + .transform(groupBy(homework.homeworkId).list(Projections.constructor(HomeworkMainRes.class, homework.homeworkId, memberAndLecture.lecture.lectureId, memberAndLecture.color, lesson.lessonId, homework.memberId, homework.body, homework.deadline, homework.isFinish))) ); } @Override - public HomeworkMainRes findHomeworkByHomeworkId(Long homeworkId) { - return queryFactory.select(Projections.constructor(HomeworkMainRes.class, homework.homeworkId, lecture.lectureId, lecture.color, lesson.lessonId, homework.memberId, homework.body, homework.deadline, homework.isFinish)) + public HomeworkMainRes findHomeworkByHomeworkId(Member member, Long homeworkId) { + return queryFactory.select(Projections.constructor(HomeworkMainRes.class, homework.homeworkId, memberAndLecture.lecture.lectureId, memberAndLecture.color, lesson.lessonId, homework.memberId, homework.body, homework.deadline, homework.isFinish)) .from(homework) .leftJoin(lesson).on(lesson.lessonId.eq(homework.lessonId)) - .leftJoin(lecture).on(lecture.lectureId.eq(lesson.lecture.lectureId)) + .leftJoin(memberAndLecture).on(memberAndLecture.lecture.lectureId.eq(lesson.lecture.lectureId)) .where(homework.homeworkId.eq(homeworkId), homework.deletedAt.isNull()) + .orderBy(homework.homeworkId.asc(), new CaseBuilder() + .when(memberAndLecture.member.memberId.eq(member.getMemberId())).then(0) + .otherwise(1).asc()) .fetchOne(); } @@ -100,9 +113,12 @@ public Optional> findAllHomeworkByMemberAndLectureId(Membe return Optional.ofNullable( queryFactory.selectFrom(homework) .leftJoin(lesson).on(lesson.lessonId.eq(homework.lessonId)) - .leftJoin(lecture).on(lecture.lectureId.eq(lesson.lecture.lectureId)) - .where(homework.memberId.eq(member.getMemberId()), homework.deletedAt.isNull(), lecture.lectureId.eq(lectureId)) - .transform(groupBy(homework.homeworkId).list(Projections.constructor(HomeworkMainRes.class, homework.homeworkId, lecture.lectureId, lecture.color, lesson.lessonId, homework.memberId, homework.body, homework.deadline, homework.isFinish))) + .leftJoin(memberAndLecture).on(memberAndLecture.lecture.lectureId.eq(lesson.lecture.lectureId)) + .where(homework.memberId.eq(member.getMemberId()), homework.deletedAt.isNull(), memberAndLecture.lecture.lectureId.eq(lectureId)) + .orderBy(homework.homeworkId.asc(), new CaseBuilder() + .when(memberAndLecture.member.memberId.eq(member.getMemberId())).then(0) + .otherwise(1).asc()) + .transform(groupBy(homework.homeworkId).list(Projections.constructor(HomeworkMainRes.class, homework.homeworkId, memberAndLecture.lecture.lectureId, memberAndLecture.color, lesson.lessonId, homework.memberId, homework.body, homework.deadline, homework.isFinish))) ); } @@ -111,9 +127,12 @@ public Optional> findAllHomeworkByMemberAndLectureIdAndTyp return Optional.ofNullable( queryFactory.selectFrom(homework) .leftJoin(lesson).on(lesson.lessonId.eq(homework.lessonId)) - .leftJoin(lecture).on(lecture.lectureId.eq(lesson.lecture.lectureId)) - .where(homework.memberId.eq(member.getMemberId()), homework.isFinish.eq(type), homework.deletedAt.isNull(), lecture.lectureId.eq(lectureId)) - .transform(groupBy(homework.homeworkId).list(Projections.constructor(HomeworkMainRes.class, homework.homeworkId, lecture.lectureId, lecture.color, lesson.lessonId, homework.memberId, homework.body, homework.deadline, homework.isFinish))) + .leftJoin(memberAndLecture).on(memberAndLecture.lecture.lectureId.eq(lesson.lecture.lectureId)) + .where(homework.memberId.eq(member.getMemberId()), homework.isFinish.eq(type), homework.deletedAt.isNull(), memberAndLecture.lecture.lectureId.eq(lectureId)) + .orderBy(homework.homeworkId.asc(), new CaseBuilder() + .when(memberAndLecture.member.memberId.eq(member.getMemberId())).then(0) + .otherwise(1).asc()) + .transform(groupBy(homework.homeworkId).list(Projections.constructor(HomeworkMainRes.class, homework.homeworkId, memberAndLecture.lecture.lectureId, memberAndLecture.color, lesson.lessonId, homework.memberId, homework.body, homework.deadline, homework.isFinish))) ); } diff --git a/src/main/java/com/selfrunner/gwalit/domain/homework/service/HomeworkService.java b/src/main/java/com/selfrunner/gwalit/domain/homework/service/HomeworkService.java index 83dc784b..61910a31 100644 --- a/src/main/java/com/selfrunner/gwalit/domain/homework/service/HomeworkService.java +++ b/src/main/java/com/selfrunner/gwalit/domain/homework/service/HomeworkService.java @@ -71,7 +71,7 @@ public HomeworkMainRes update(Member member, Long homeworkId, HomeworkReq homewo // Business Logic homework.update(homeworkReq); - HomeworkMainRes homeworkMainRes = homeworkRepository.findHomeworkByHomeworkId(homeworkId); + HomeworkMainRes homeworkMainRes = homeworkRepository.findHomeworkByHomeworkId(member, homeworkId); // Response return homeworkMainRes; diff --git a/src/main/java/com/selfrunner/gwalit/domain/lecture/service/LectureService.java b/src/main/java/com/selfrunner/gwalit/domain/lecture/service/LectureService.java index 74fe4479..98db835c 100644 --- a/src/main/java/com/selfrunner/gwalit/domain/lecture/service/LectureService.java +++ b/src/main/java/com/selfrunner/gwalit/domain/lecture/service/LectureService.java @@ -287,7 +287,7 @@ public void inviteStudent(Member member, Long lectureId, PostInviteReq postInvit if(check.getState().equals(MemberState.INVITE)) { smsClient.sendInvitation(member.getName(), lectureName, postInviteReq, Boolean.TRUE); } - if(check.getState().equals(MemberState.ACTIVE)) { + if(check.getState().equals(MemberState.ACTIVE) && check.getToken() != null) { // smsClient.sendInvitation(member.getName(), lectureName,postInviteReq, Boolean.FALSE); String title = lectureName + "클래스 초대"; String body = "[과릿] " + member.getName() + " 선생님으로부터 " + lectureName + " 클래스 초대가 도착했습니다." + "\n" + "접속하여 초대된 클래스를 확인해보세요!";