Update new API..
This commit is contained in:
75
rog/views.py
75
rog/views.py
@ -120,15 +120,23 @@ def update_entry_status(request, entry_id):
|
||||
if entry.owner != request.user and not entry.team.members.filter(user=request.user).exists():
|
||||
return Response({"error": "You don't have permission to update this entry"}, status=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
hasParticipated = request.data.get('hasParticipated')
|
||||
hasGoaled = request.data.get('hasGoaled')
|
||||
# フィールド名の両方のパターンを受け入れる
|
||||
hasParticipated = request.data.get('hasParticipated') or request.data.get('has_participated')
|
||||
hasGoaled = request.data.get('hasGoaled') or request.data.get('has_goaled')
|
||||
|
||||
if hasParticipated is not None:
|
||||
entry.hasParticipated = hasParticipated
|
||||
if hasGoaled is not None:
|
||||
entry.hasGoaled = hasGoaled
|
||||
|
||||
entry.save()
|
||||
# update()を使用してバリデーションをスキップ
|
||||
Entry.objects.filter(id=entry_id).update(
|
||||
hasParticipated=entry.hasParticipated,
|
||||
hasGoaled=entry.hasGoaled
|
||||
)
|
||||
|
||||
# 更新後のオブジェクトを再取得
|
||||
entry.refresh_from_db()
|
||||
serializer = EntrySerializer(entry)
|
||||
return Response(serializer.data)
|
||||
|
||||
@ -4085,3 +4093,64 @@ def location_checkin_test(request):
|
||||
"""ロケーションチェックインのテストページ"""
|
||||
from django.shortcuts import render
|
||||
return render(request, 'location_checkin_test.html')
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
def current_entry_info(request):
|
||||
"""
|
||||
ユーザーの最新エントリー情報取得API
|
||||
|
||||
GET /api/user/current-entry-info/
|
||||
"""
|
||||
user = request.user
|
||||
|
||||
# ユーザーの最新エントリーを取得(IDの降順でソート)
|
||||
latest_entry = Entry.objects.filter(
|
||||
team__owner=user
|
||||
).select_related('team', 'event', 'category', 'team__category').order_by('-id').first()
|
||||
|
||||
if not latest_entry:
|
||||
return Response({
|
||||
'error': 'No active entry found for user',
|
||||
'detail': 'User has no current entries'
|
||||
}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
# ユーザーの全エントリー数を取得
|
||||
entries_count = Entry.objects.filter(team__owner=user).count()
|
||||
|
||||
# レスポンスデータを構築
|
||||
response_data = {
|
||||
'user': {
|
||||
'id': user.id,
|
||||
'email': user.email,
|
||||
'firstname': user.firstname,
|
||||
'lastname': user.lastname,
|
||||
'is_staff': user.is_staff,
|
||||
'event_code': latest_entry.event.event_name # 最新エントリーのイベント名
|
||||
},
|
||||
'current_entry': {
|
||||
'id': latest_entry.id,
|
||||
'team': {
|
||||
'id': latest_entry.team.id,
|
||||
'team_name': latest_entry.team.team_name,
|
||||
'category': {
|
||||
'id': latest_entry.category.id,
|
||||
'category_name': latest_entry.category.category_name
|
||||
}
|
||||
},
|
||||
'event': {
|
||||
'id': latest_entry.event.id,
|
||||
'event_name': latest_entry.event.event_name,
|
||||
'start_datetime': latest_entry.event.start_datetime,
|
||||
'end_datetime': latest_entry.event.end_datetime
|
||||
},
|
||||
'date': latest_entry.date.strftime('%Y-%m-%d') if latest_entry.date else None,
|
||||
'has_participated': latest_entry.hasParticipated,
|
||||
'has_goaled': latest_entry.hasGoaled
|
||||
},
|
||||
'entries_count': entries_count,
|
||||
'latest_entry_date': latest_entry.date # created_atがないのでdateフィールドを使用
|
||||
}
|
||||
|
||||
return Response(response_data)
|
||||
|
||||
Reference in New Issue
Block a user