update APIs

This commit is contained in:
2025-09-04 19:25:14 +09:00
parent 32f860af41
commit e0543e2b4e
8 changed files with 759 additions and 64 deletions

View File

@ -361,19 +361,27 @@ def start_from_rogapp(request):
with transaction.atomic():
# スタート情報をGpsLogとして登録
logger.info(f"[START_API] Creating start record - ID: {request_id}")
start_time = timezone.now()
start_info = GpsLog.objects.create(
zekken_number=entry.zekken_number,
event_code=event.event_name,
cp_number="START",
serial_number=0,
checkin_time=timezone.now(),
create_at=timezone.now(),
update_at=timezone.now(),
checkin_time=start_time,
create_at=start_time,
update_at=start_time,
buy_flag=False,
colabo_company_memo=""
)
# 競技状態を更新
entry.is_in_rog = True
entry.start_time = start_time
entry.last_checkin_time = start_time
entry.save()
logger.info(f"[START_API] ✅ Start record created - ID: {request_id}, GpsLog ID: {start_info.id}")
logger.info(f"[START_API] ✅ Competition status updated - is_in_rog: True")
# 統計情報取得
try:
@ -387,9 +395,20 @@ def start_from_rogapp(request):
response_data = {
"status": "OK",
"message": "スタート処理が完了しました",
"competition_status": {
"is_in_rog": entry.is_in_rog,
"rogaining_counted": entry.rogaining_counted,
"ready_for_goal": entry.ready_for_goal,
"is_at_goal": entry.is_at_goal,
"start_time": start_info.checkin_time.strftime("%Y-%m-%dT%H:%M:%S%z")
},
"checkin_record": {
"id": start_info.id,
"cp_number": "START",
"checkin_time": start_info.checkin_time.strftime("%Y-%m-%dT%H:%M:%S%z")
},
"team_name": team_name,
"event_code": event_code,
"start_time": start_info.checkin_time.strftime("%Y-%m-%d %H:%M:%S"),
"zekken_number": entry.zekken_number,
"entry_id": entry.id
}
@ -659,6 +678,13 @@ def checkin_from_rogapp(request):
logger.info(f"[CHECKIN] ✅ SUCCESS - Team: {team_name}, Zekken: {entry.zekken_number}, CP: {cp_number}, Points: {point_value}, Bonus: {bonus_points}, Time: {checkpoint.checkin_time}, Has Image: {bool(image_url)}, Buy Flag: {buy_flag}, Client IP: {client_ip}, User: {user_info}")
# 競技状態を更新(スタート・ゴール以外のチェックイン時)
if cp_number not in ["START", "GOAL", -2, -1]:
entry.rogaining_counted = True
entry.last_checkin_time = checkpoint.checkin_time
entry.save()
logger.info(f"[CHECKIN] ✅ Competition status updated - rogaining_counted: True")
# 拡張情報があれば保存
if gps_coordinates or camera_metadata:
try:
@ -689,7 +715,13 @@ def checkin_from_rogapp(request):
"scoring_breakdown": scoring_breakdown,
"validation_status": "pending",
"requires_manual_review": bool(gps_coordinates.get('accuracy', 0) > 10), # 10m以上は要審査
"image_url": s3_image_url # S3画像URLを返す
"image_url": s3_image_url, # S3画像URLを返す
"competition_status": {
"is_in_rog": entry.is_in_rog,
"rogaining_counted": entry.rogaining_counted,
"ready_for_goal": entry.ready_for_goal,
"is_at_goal": entry.is_at_goal
}
})
except Exception as e:
@ -880,11 +912,25 @@ def goal_from_rogapp(request):
colabo_company_memo=""
)
# 競技状態を更新
entry.is_at_goal = True
entry.goal_time = goal_time
entry.last_checkin_time = goal_time
entry.save()
logger.info(f"[GOAL] ✅ SUCCESS - Team: {team_name}, Zekken: {entry.zekken_number}, Event: {event_code}, Goal Time: {goal_time}, Score: {score}, Has Image: {bool(image_url)}, Client IP: {client_ip}, User: {user_info}")
logger.info(f"[GOAL] ✅ Competition status updated - is_at_goal: True")
return Response({
"status": "OK",
"message": "ゴール処理が正常に完了しました",
"competition_status": {
"is_in_rog": entry.is_in_rog,
"rogaining_counted": entry.rogaining_counted,
"ready_for_goal": entry.ready_for_goal,
"is_at_goal": entry.is_at_goal,
"goal_time": goal_time.strftime("%Y-%m-%dT%H:%M:%S%z")
},
"team_name": team_name,
"goal_time": goal_info.checkin_time.strftime("%Y-%m-%d %H:%M:%S"),
"score": score,