Update new API..

This commit is contained in:
2025-09-02 20:06:58 +09:00
parent 0acaa6ea1f
commit a8dc2ba3b1
6 changed files with 500 additions and 15 deletions

View File

@ -1,7 +1,7 @@
from sys import prefix
from rest_framework import urlpatterns
from rest_framework.routers import DefaultRouter
from .views import CategoryByNameView, LocationViewSet, Location_lineViewSet, Location_polygonViewSet, Jpn_Main_PerfViewSet, LocationsInPerf, ExtentForSubPerf, SubPerfInMainPerf, ExtentForMainPerf, LocationsInSubPerf, CatView, RegistrationAPI, LoginAPI, UserAPI, UserActionViewset, UserMakeActionViewset, UserDestinations, UpdateOrder, LocationInBound, DeleteDestination, CustomAreaLocations, GetAllGifuAreas, CustomAreaNames, userDetials, UserTracksViewSet, CatByCity, ChangePasswordView, GoalImageViewSet, CheckinImageViewSet, ExtentForLocations, DeleteAccount, PrivacyView, RegistrationView, TeamViewSet,MemberViewSet,EntryViewSet,RegisterView, VerifyEmailView, NewEventListView,NewEvent2ListView,NewCategoryListView,CategoryListView, MemberUserDetailView, TeamMembersWithUserView,MemberAddView,UserActivationView,RegistrationView,TempUserRegistrationView,ResendInvitationEmailView,update_user_info,update_user_detail,ActivateMemberView, ActivateNewMemberView, PasswordResetRequestView, PasswordResetConfirmView, NewCategoryViewSet,LocationInBound2,UserLastGoalTimeView,TeamEntriesView,update_entry_status,get_events,get_zekken_numbers,get_team_info,get_checkins,update_checkins,export_excel,debug_urls,get_ranking, all_ranking_top3
from .views import CategoryByNameView, LocationViewSet, Location_lineViewSet, Location_polygonViewSet, Jpn_Main_PerfViewSet, LocationsInPerf, ExtentForSubPerf, SubPerfInMainPerf, ExtentForMainPerf, LocationsInSubPerf, CatView, RegistrationAPI, LoginAPI, UserAPI, UserActionViewset, UserMakeActionViewset, UserDestinations, UpdateOrder, LocationInBound, DeleteDestination, CustomAreaLocations, GetAllGifuAreas, CustomAreaNames, userDetials, UserTracksViewSet, CatByCity, ChangePasswordView, GoalImageViewSet, CheckinImageViewSet, ExtentForLocations, DeleteAccount, PrivacyView, RegistrationView, TeamViewSet,MemberViewSet,EntryViewSet,RegisterView, VerifyEmailView, NewEventListView,NewEvent2ListView,NewCategoryListView,CategoryListView, MemberUserDetailView, TeamMembersWithUserView,MemberAddView,UserActivationView,RegistrationView,TempUserRegistrationView,ResendInvitationEmailView,update_user_info,update_user_detail,ActivateMemberView, ActivateNewMemberView, PasswordResetRequestView, PasswordResetConfirmView, NewCategoryViewSet,LocationInBound2,UserLastGoalTimeView,TeamEntriesView,update_entry_status,get_events,get_zekken_numbers,get_team_info,get_checkins,update_checkins,export_excel,debug_urls,get_ranking, all_ranking_top3, current_entry_info
from .views_apis.api_auth import check_event_code
from .views_apis.api_teams import register_team,update_team_name,team_class_changer,team_register,zekken_max_num,zekken_double_check,get_team_list,get_zekken_list
@ -140,6 +140,7 @@ urlpatterns += [
#path('admin/', admin.site.urls),
path('entries/<int:entry_id>/update-status/', update_entry_status, name='update-entry-status'),
path('user/current-entry-info/', views.current_entry_info, name='current-entry-info'),
# for Supervisor Web app

View File

@ -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)