Skip to content

Commit 7d35652

Browse files
committed
room_exception의 update 부분도 마찬가지로 범위 검색 으로 변경
1 parent 1753dcf commit 7d35652

2 files changed

Lines changed: 33 additions & 18 deletions

File tree

grpc_service/service/room_exception_service.rb

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
# =========================================

proto_export/studyroom/room_exception/room_exception.proto

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ syntax = "proto3";
22

33
package bannote.studyroomservice.roomexception.v1;
44

5+
import "google/protobuf/empty.proto";
56
import "google/protobuf/timestamp.proto";
67

78
message RoomException {
@@ -27,14 +28,20 @@ message GetRoomExceptionsResponse {
2728
}
2829

2930
message RoomExceptionUpdateItem {
30-
int64 id = 1;
31-
string holiday_date = 2;
32-
string reason = 3;
33-
string opening_time = 4;
34-
string closing_time = 5;
31+
string holiday_date = 1;
32+
string reason = 2;
33+
string opening_time = 3;
34+
string closing_time = 4;
3535
}
3636

3737
message UpdateRoomExceptionsRequest {
3838
int64 room_id = 1;
39-
repeated RoomExceptionUpdateItem exceptions = 2;
39+
string from_date = 2;
40+
string to_date = 3;
41+
repeated RoomExceptionUpdateItem exceptions = 4;
42+
}
43+
44+
message UpdateRoomExceptionsResponse {
45+
string from_date = 1;
46+
string to_date = 2;
4047
}

0 commit comments

Comments
 (0)