Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,11 @@ public ApiResponse<TimeTableResponseDTO.MyTimeTableDTO> dailyTimeTable(
timeTableService.getSubjectsByDay(userDetails, dayOfWeek);
return ApiResponse.onSuccess(result);
}

@Override
public ApiResponse<TimeTableResponseDTO.TimeTableListDTO> searchTimeTable(
UserDetails userDetails, String name) {
TimeTableResponseDTO.TimeTableListDTO result = timeTableService.searchSubjects(name);
return ApiResponse.onSuccess(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,11 @@ ApiResponse<TimeTableResponseDTO.MyTimeTableDTO> dailyTimeTable(
@AuthenticationPrincipal
UserDetails userDetails,
@Parameter(description = "조회할 요일", example = "MONDAY") @PathVariable String dayOfWeek);

@GetMapping("/search/name")
@Operation(summary = "과목명으로 과목 검색하기", description = "과목 검색하기 api")
@ApiErrorCodeExample(TimeTableErrorStatus.class)
ApiResponse<TimeTableResponseDTO.TimeTableListDTO> searchTimeTable(
@Parameter(hidden = true) @AuthenticationPrincipal UserDetails userDetails,
@Parameter(description = "검색할 과목명", example = "알고리즘") @RequestParam String name);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package org.example.skuhomepage.domain.timetable.repository;

import org.example.skuhomepage.domain.timetable.entity.Subject;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface SubjectRepository extends JpaRepository<Subject, Long> {}
public interface SubjectRepository extends JpaRepository<Subject, Long> {
@Query("select s from Subject s where s.subject like %:name%")
Page<Subject> findBySubjectName(String name, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.example.skuhomepage.domain.timetable.repository.TimeTableRepository;
import org.example.skuhomepage.domain.timetable.repository.TimeTableSubjectRepository;
import org.example.skuhomepage.global.exception.GeneralException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.security.core.userdetails.UserDetails;
Expand Down Expand Up @@ -210,6 +212,19 @@ public TimeTableResponseDTO.MyTimeTableDTO getSubjectsByDay(
return new TimeTableResponseDTO.MyTimeTableDTO(subjects);
}

public TimeTableResponseDTO.TimeTableListDTO searchSubjects(String name) {
Pageable pageable = PageRequest.of(0, 10);
Page<Subject> subjectPage = subjectRepository.findBySubjectName(name, pageable);
List<TimeTableResponseDTO.TimeTableDTO> subjects =
subjectPage.getContent().stream()
.map(TimeTableResponseDTO.TimeTableDTO::new)
.collect(Collectors.toList());

boolean hasNext = subjectPage.hasNext();
int nextPage = hasNext ? subjectPage.getNumber() + 1 : subjectPage.getNumber();
return new TimeTableResponseDTO.TimeTableListDTO(subjects, hasNext, nextPage);
}

private boolean isSubjectOnToday(Subject subject, DayOfWeek today) {
String time = subject.getTime();

Expand Down
Loading