@@ -25,18 +25,27 @@ class RoomExceptionServiceHandler < RoomExceptionService::Service
2525 def get_room_exceptions ( request , _call )
2626 authorize! ( "student" )
2727
28- # 기준 날짜 파싱
29- from_date =
30- if request . from_date . present?
31- Date . parse ( request . from_date )
32- else
33- Date . today # 기본 검색 기준은 현 시점으로
34- end
28+ scope = RoomException . where ( room_id : request . room_id , deleted_at : nil )
29+
30+ # from_date, to_date 둘 다 있을 경우
31+ if request . from_date . present? && request . to_date . present?
32+ start_date = Date . parse ( request . from_date )
33+ end_date = Date . parse ( request . to_date )
34+ scope = scope . where ( holiday_date : start_date ..end_date )
35+
36+ # from_date 만 있는 경우
37+ elsif request . from_date . present?
38+ start_date = Date . parse ( request . from_date )
39+ scope = scope . where ( "holiday_date >= ?" , start_date )
40+
41+ # to_date 만 있는 경우
42+ elsif request . to_date . present?
43+ end_date = Date . parse ( request . to_date )
44+ scope = scope . where ( "holiday_date <= ?" , end_date )
45+ end
3546
36- exceptions = ::RoomException
37- . where ( room_id : request . room_id , deleted_at : nil )
38- . where ( "holiday_date >= ?" , from_date )
39- . order ( :holiday_date )
47+
48+ exceptions = scope . order ( :holiday_date )
4049
4150 response_items = exceptions . map { |ex | room_exception_to_proto ( ex ) }
4251
@@ -45,7 +54,6 @@ def get_room_exceptions(request, _call)
4554 )
4655 end
4756
48-
4957 # =========================================
5058 # 2) 리스트 기반 업데이트
5159 # =========================================
0 commit comments