Skip to content

Commit 06e47ed

Browse files
authored
Merge pull request #181 from SMU-SATTO/feature/#180
feat: 친구와 시간표 비교 기능 추가
2 parents b696d7e + 5d06c19 commit 06e47ed

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

src/main/java/com/example/satto/domain/timeTable/controller/TimeTableController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public BaseResponse<List<TimeTableResponseDTO.timeTableListDTO>> getOtherTimeTa
6464
return BaseResponse.onSuccess(timeTableService.getOtherTimeTableList(studentId, users));
6565
}
6666

67+
@PostMapping("/compare")
68+
public BaseResponse<List<List<String>>> compareTimeTable(@RequestBody CompareTimeTableRequestDTO compare){
69+
return BaseResponse.onSuccess(timeTableService.compareTimeTable(compare));
70+
}
71+
6772
@PatchMapping("/{timeTableId}")
6873
public BaseResponse<String> updateTimeTable(@PathVariable(name = "timeTableId") Long timeTableId,@RequestBody UpdateTimeTableLectRequestDTO updateDTO){
6974
timeTableLectureService.deleteAll(timeTableId);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.example.satto.domain.timeTable.dto;
2+
3+
import java.util.List;
4+
5+
public record CompareTimeTableRequestDTO(
6+
List<String> studentIds
7+
) {
8+
}

src/main/java/com/example/satto/domain/timeTable/repository/TimeTableRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ public interface TimeTableRepository extends JpaRepository<TimeTable, Long> {
2626
TimeTable findLatestRepresentedTimeTableByUserId(@Param("userId") Long userId);
2727

2828
void deleteAllByUsers(Users users);
29+
30+
@Query("SELECT t.timetableId FROM TimeTable t WHERE t.users.studentId = :studentId AND t.isRepresented = true ORDER BY t.createdAt DESC")
31+
Long findLatestRepresentedTimeTableIdByUserId(@Param("studentId") String studentId);
2932
}

src/main/java/com/example/satto/domain/timeTable/service/TimeTableService.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,17 +381,32 @@ public List<TimeTableResponseDTO.timeTableListDTO> getOtherTimeTableList(String
381381
Users target = usersRepository.findByStudentId(studentId).orElseThrow();
382382
List<TimeTable> timeTables = new ArrayList<>();
383383

384-
//1차 배포시 공개, 비공개 사용자 구분x
385-
// if(!target.isPublic()){
386-
// if(!followRepository.existsByFollowerIdStudentIdAndFollowingIdStudentId(users.getStudentId(), studentId)){
387-
// throw new IllegalStateException("볼 수 있는 시간표가 존재하지 않습니다.");
388-
// }
389-
// }
384+
385+
if(!target.isPublic()){
386+
if(!followRepository.existsByFollowerIdStudentIdAndFollowingIdStudentId(users.getStudentId(), studentId)){
387+
throw new IllegalStateException("볼 수 있는 시간표가 존재하지 않습니다.");
388+
}
389+
}
390390
timeTables = timeTableRepository.findTimeTableByStudentId(studentId);
391391

392392
return TimeTableResponseDTO.timeTableListDTO.fromList(timeTables);
393393
}
394394

395+
public List<List<String>> compareTimeTable(CompareTimeTableRequestDTO compare){
396+
397+
List<Long> timeTableIds = new ArrayList<>();
398+
List<String> result = new ArrayList<>();
399+
List<List<String>> codeSectionLists = new ArrayList<>();
400+
for( String studentId : compare.studentIds()){
401+
timeTableIds.add(timeTableRepository.findLatestRepresentedTimeTableIdByUserId(studentId));
402+
}
403+
for( Long tinmeTableId : timeTableIds) {
404+
result = timeTableLectureRepository.findTimeTableLecturesCodeSectionByTimeTableId(tinmeTableId);
405+
codeSectionLists.add(result);
406+
}
407+
408+
return codeSectionLists;
409+
}
395410
public void updateTimeTableIsPublic(Long timeTableId, UpdateTimeTableRequestDTO isPublic){
396411

397412
TimeTable timeTable = timeTableRepository.findById(timeTableId).orElseThrow();

src/main/java/com/example/satto/domain/timeTableLecture/repository/TimeTableLectureRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ TimeTableLecture findTimeTableLectureByTimeTableIdAndCodeSection(@Param("timeTab
2323
@Query("select l from TimeTableLecture l where l.timeTable.timetableId = :timeTableId")
2424
List<TimeTableLecture> findTimeTableLecturesByTimeTableId(@Param("timeTableId")Long timeTableId);
2525

26+
@Query("select l.currentLecture.codeSection from TimeTableLecture l where l.timeTable.timetableId = :timeTableId")
27+
List<String> findTimeTableLecturesCodeSectionByTimeTableId(@Param("timeTableId")Long timeTableId);
28+
2629
@Transactional
2730
@Modifying
2831
@Query("delete from TimeTableLecture l where l.timeTable.timetableId = :timeTableId")

0 commit comments

Comments
 (0)