From 8d95599751fe3824a45b2db917736471cce54c58 Mon Sep 17 00:00:00 2001 From: Hayeon101 Date: Wed, 12 Nov 2025 13:08:46 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=EC=99=B8=EB=B0=95=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=20=EB=B0=8F=20=EA=B5=AC=EB=8F=85=20=EC=B2=98=EB=A6=AC?= =?UTF-8?q?=EC=97=90=EC=84=9C=20Cognito=20username=EC=9D=84=20=EB=8C=80?= =?UTF-8?q?=EB=AC=B8=EC=9E=90=EB=A1=9C=20=EB=B3=80=ED=99=98=ED=95=98?= =?UTF-8?q?=EC=97=AC=20=EC=9D=BC=EA=B4=80=EC=84=B1=20=EC=9C=A0=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handlers/overnight_stays_handler.py | 14 ++++++++++---- src/handlers/subscriptions_handler.py | 20 +++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/handlers/overnight_stays_handler.py b/src/handlers/overnight_stays_handler.py index 8b2f5e2..83b50b5 100644 --- a/src/handlers/overnight_stays_handler.py +++ b/src/handlers/overnight_stays_handler.py @@ -47,11 +47,14 @@ def create(event, context): return responses.create_error_response(validation_error, 400) user_info = event.get("user_info", {}) - student_no = user_info.get("username") - if not student_no: + username = user_info.get("username") + if not username: logger.error("❌ Unauthorized request: student number missing in session") return responses.create_error_response("Unauthorized", 401) + # Cognito username을 대문자로 변환 (DB의 studentNo와 일치시키기 위해) + student_no = username.upper() + result, error = overnight_stays_service.create_overnight_stay( student_no=student_no, start_date=request_dto.startDate, @@ -80,12 +83,15 @@ def get_student_requests(event, context): logger.info("✅ Processing get student overnight stays request") user_info = event.get("user_info", {}) - student_no = user_info.get("username") + username = user_info.get("username") - if not student_no: + if not username: logger.error("❌ Unauthorized request: student number missing in session") return responses.create_error_response("Unauthorized", 401) + # Cognito username을 대문자로 변환 (DB의 studentNo와 일치시키기 위해) + student_no = username.upper() + try: data, summary, error = overnight_stays_service.get_student_overnight_stays( student_no diff --git a/src/handlers/subscriptions_handler.py b/src/handlers/subscriptions_handler.py index 4cd2b20..4e69ffe 100644 --- a/src/handlers/subscriptions_handler.py +++ b/src/handlers/subscriptions_handler.py @@ -44,7 +44,10 @@ def create_subscription_handler(event, context): "Unauthorized: user information not found", 401 ) - logger.info(f"📱 사용자 {username}의 FCM 구독 생성 요청") + # Cognito username을 대문자로 변환 (DB의 studentNo와 일치시키기 위해) + student_no = username.upper() + + logger.info(f"📱 사용자 {student_no}의 FCM 구독 생성 요청") # 2. JSON 파싱 try: @@ -70,14 +73,14 @@ def create_subscription_handler(event, context): return create_error_response(error_msg, 400) # 5. 서비스 호출 (student_no를 별도로 전달) - subscription_dto, error = create_subscription(request_dto, username) + subscription_dto, error = create_subscription(request_dto, student_no) if error: logger.error(f"❌ 구독 생성 실패: {error}") return create_error_response(error, 500) # 6. 성공 응답 logger.info( - f"✅ FCM 구독 생성 완료: id={subscription_dto.id}, student_no={username}" + f"✅ FCM 구독 생성 완료: id={subscription_dto.id}, student_no={student_no}" ) return create_success_response(subscription_dto.to_dict()) @@ -145,6 +148,9 @@ def patch_subscription_handler(event, context): "Unauthorized: user information not found", 401 ) + # Cognito username을 대문자로 변환 (DB의 studentNo와 일치시키기 위해) + student_no = username.upper() + # 2. JSON 파싱 try: body = json.loads(event.get("body", "{}")) @@ -173,11 +179,11 @@ def patch_subscription_handler(event, context): return create_error_response(error_msg, 400) action = "활성화" if request_dto.active else "비활성화" - logger.info(f"📱 사용자 {username}의 모든 FCM 구독 {action} 요청") + logger.info(f"📱 사용자 {student_no}의 모든 FCM 구독 {action} 요청") # 6. 서비스 호출 updated_count, error = update_all_subscriptions_active_by_student_no( - username, request_dto.active + student_no, request_dto.active ) if error: @@ -188,13 +194,13 @@ def patch_subscription_handler(event, context): response_dto = SubscriptionUpdateResponseDTO( message=f"Subscription(s) {'activated' if request_dto.active else 'deactivated'} successfully", updated_count=updated_count, - student_no=username, + student_no=student_no, active=request_dto.active, ) # 8. 성공 응답 logger.info( - f"✅ FCM 구독 상태 변경 완료: student_no={username}, updated_count={updated_count}, active={request_dto.active}" + f"✅ FCM 구독 상태 변경 완료: student_no={student_no}, updated_count={updated_count}, active={request_dto.active}" ) return create_success_response(response_dto.to_dict()) From 4c9b0e889098f038d489a1aabe2f9c7d54b71451 Mon Sep 17 00:00:00 2001 From: Hayeon101 Date: Wed, 12 Nov 2025 13:09:20 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20serverless.yml=20=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=EA=B4=80=EB=A6=AC=EB=B9=84=20=EB=B2=84=EC=BC=93=20=EC=A0=91?= =?UTF-8?q?=EA=B7=BC=EC=9D=84=20=EC=9C=84=ED=95=9C=20S3=20=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- serverless.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/serverless.yml b/serverless.yml index 432ed7f..94015e7 100644 --- a/serverless.yml +++ b/serverless.yml @@ -46,6 +46,14 @@ provider: Resource: - arn:aws:dynamodb:${self:provider.region}:${aws:accountId}:table/${self:provider.environment.SESSION_TABLE} - arn:aws:dynamodb:${self:provider.region}:${aws:accountId}:table/${self:provider.environment.SESSION_TABLE}/index/* + - Effect: Allow + Action: + - s3:ListBucket + - s3:GetObject + - s3:PutObject + Resource: + - arn:aws:s3:::${file(envs/config.${self:provider.stage}.json):BILL_BUCKET_NAME} + - arn:aws:s3:::${file(envs/config.${self:provider.stage}.json):BILL_BUCKET_NAME}/* httpApi: cors: allowedOrigins: ${file(envs/config.${self:provider.stage}.json):CORS_ORIGINS} From 9778ce08581619afe0785c3a42b8170e0ee87277 Mon Sep 17 00:00:00 2001 From: Hayeon101 Date: Wed, 12 Nov 2025 13:22:39 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20S3=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=EC=9D=B4=20=EB=B0=B0=ED=8F=AC=20=EC=8B=9C?= =?UTF-8?q?=EB=A7=88=EB=8B=A4=20=EC=B6=A9=EB=8F=8C=EC=9D=84=20=EC=9D=BC?= =?UTF-8?q?=EC=9C=BC=ED=82=A4=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- serverless.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serverless.yml b/serverless.yml index 94015e7..c033107 100644 --- a/serverless.yml +++ b/serverless.yml @@ -181,6 +181,6 @@ functions: bucket: ${file(envs/config.${self:provider.stage}.json):BILL_BUCKET_NAME} event: s3:ObjectCreated:Put rules: - - prefix: "bills/*" + - prefix: "bills/" existing: true forceDeploy: true