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
70 changes: 69 additions & 1 deletion eunbi/room-measure/backend-cloud/src/database/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,52 @@ def save_room_layout(self, layout_data: dict):
except Exception as e:
logger.error(f"MongoDB 저장 오류: {e}")
return False, None

def delete_room_layout(self, layout_id: str, user_id: int):
"""로그인 사용자의 방 레이아웃 삭제"""
if not self.is_connected():
return False

try:
from bson import ObjectId
result = self.room_layouts_collection.delete_one({
"_id": ObjectId(layout_id),
"user_id": user_id
})

if result.deleted_count > 0:
logger.info(f"MongoDB에서 삭제 완료: 레이아웃 ID {layout_id}, 사용자 {user_id}")
return True
else:
logger.warning(f"MongoDB에서 삭제할 레이아웃을 찾을 수 없음: ID {layout_id}, 사용자 {user_id}")
return False

except Exception as e:
logger.error(f"MongoDB 삭제 오류: {e}")
return False

def delete_room_layout_guest(self, layout_id: str):
"""게스트 사용자의 방 레이아웃 삭제"""
if not self.is_connected():
return False

try:
from bson import ObjectId
result = self.room_layouts_collection.delete_one({
"_id": ObjectId(layout_id),
"user_id": None
})

if result.deleted_count > 0:
logger.info(f"MongoDB에서 삭제 완료 (게스트): 레이아웃 ID {layout_id}")
return True
else:
logger.warning(f"MongoDB에서 삭제할 게스트 레이아웃을 찾을 수 없음: ID {layout_id}")
return False

except Exception as e:
logger.error(f"MongoDB 삭제 오류 (게스트): {e}")
return False


class SimpleStorageService:
Expand Down Expand Up @@ -123,4 +169,26 @@ def get_layout_by_id(self, layout_id: str):
for layout in self.data:
if layout.get('scene', {}).get('room', {}).get('id') == layout_id:
return layout
return None
return None

def delete_room_layout(self, layout_id: str):
"""JSON 파일에서 방 레이아웃 삭제"""
try:
original_count = len(self.data)
self.data = [
layout for layout in self.data
if layout.get('scene', {}).get('room', {}).get('id') != layout_id
]

if len(self.data) < original_count:
success = self.save_data()
if success:
logger.info(f"JSON 파일에서 삭제 완료: 레이아웃 ID {layout_id}")
return success
else:
logger.warning(f"JSON 파일에서 삭제할 레이아웃을 찾을 수 없음: ID {layout_id}")
return False

except Exception as e:
logger.error(f"JSON 파일 삭제 오류: {e}")
return False
66 changes: 66 additions & 0 deletions eunbi/room-measure/backend-cloud/src/routes/layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,70 @@ async def get_room_layout(layout_id: str):
return JSONResponse(
status_code=500,
content={"success": False, "error": "레이아웃 조회 중 오류가 발생했습니다"}
)


@router.delete("/{layout_id}")
async def delete_room_layout(layout_id: str, current_user_id: int = Depends(verify_token)):
"""방 레이아웃 삭제 (로그인 사용자)"""
try:
# MongoDB에서 삭제 시도
mongodb_success = mongodb_service.delete_room_layout(layout_id, current_user_id)

# MySQL에서도 삭제 시도 (있다면)
mysql_success = False
conn = db_service.get_connection()
if conn:
with conn.cursor() as cursor:
cursor.execute(
"DELETE FROM room_layouts WHERE id = %s AND user_id = %s",
(layout_id, current_user_id)
)
mysql_success = cursor.rowcount > 0
conn.commit()

# JSON 파일에서도 삭제 (백업)
json_success = storage_service.delete_room_layout(layout_id)

if mongodb_success or mysql_success or json_success:
logger.info(f"방 레이아웃 삭제 완료: 레이아웃 ID {layout_id}, 사용자 {current_user_id}")
return {"success": True, "message": "방 레이아웃이 삭제되었습니다"}
else:
return JSONResponse(
status_code=404,
content={"success": False, "error": "삭제할 레이아웃을 찾을 수 없습니다"}
)

except Exception as e:
logger.error(f"레이아웃 삭제 오류: {e}")
return JSONResponse(
status_code=500,
content={"success": False, "error": "레이아웃 삭제 중 오류가 발생했습니다"}
)


@router.delete("/guest/{layout_id}")
async def delete_room_layout_guest(layout_id: str):
"""방 레이아웃 삭제 (게스트 사용자)"""
try:
# MongoDB에서 삭제 시도 (게스트)
mongodb_success = mongodb_service.delete_room_layout_guest(layout_id)

# JSON 파일에서도 삭제
json_success = storage_service.delete_room_layout(layout_id)

if mongodb_success or json_success:
logger.info(f"방 레이아웃 삭제 완료 (게스트): 레이아웃 ID {layout_id}")
return {"success": True, "message": "방 레이아웃이 삭제되었습니다"}
else:
return JSONResponse(
status_code=404,
content={"success": False, "error": "삭제할 레이아웃을 찾을 수 없습니다"}
)

except Exception as e:
logger.error(f"레이아웃 삭제 오류 (게스트): {e}")
return JSONResponse(
status_code=500,
content={"success": False, "error": "레이아웃 삭제 중 오류가 발생했습니다"}
)
Binary file modified eunbi/room-measure/backend-local/outputs/undistorted_image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading