Skip to content

Commit

Permalink
[add] selected_team
Browse files Browse the repository at this point in the history
  • Loading branch information
Hwang-Jaeryeong committed Jan 20, 2024
1 parent c51a22d commit bf309ff
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 4 deletions.
Binary file modified accounts/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file modified accounts/__pycache__/views.cpython-311.pyc
Binary file not shown.
18 changes: 18 additions & 0 deletions accounts/migrations/0002_customuser_selected_team.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.16 on 2024-01-20 08:26

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='customuser',
name='selected_team',
field=models.IntegerField(blank=True, null=True),
),
]
Binary file not shown.
2 changes: 1 addition & 1 deletion accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
class CustomUser(AbstractUser):
phone_number = models.CharField(max_length=15, unique=True)
nickname = models.CharField(max_length=255, blank=True)

selected_team = models.IntegerField(null=True, blank=True)
3 changes: 2 additions & 1 deletion accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
def register_user(request):
data = request.data
serializer = CustomUserSerializer(data=data)
selected_team = request.data.get('selected_team')
if serializer.is_valid():
serializer.save()
serializer.save(selected_team=selected_team)
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

Expand Down
Binary file modified info/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified info/__pycache__/views.cpython-311.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion info/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.urls import path
from .views import get_fixtures, get_predictions, GetLineupPredictions,GetFixtureEvents, GetStandings
from .views import get_fixtures, get_predictions, GetLineupPredictions,GetFixtureEvents, GetStandings, get_top_scorers

urlpatterns = [
path('get_fixtures/', get_fixtures, name='get_fixtures'),
path('get_predictions/<int:fixture_id>/', get_predictions, name='get_predictions'),
path('get_lineup_predictions/<int:fixture_id>/', GetLineupPredictions.as_view(), name='get_lineup_predictions'),
path('get_events/<int:fixture_id>/', GetFixtureEvents.as_view(), name='get_fixture_events'),
path('get_standings/', GetStandings.as_view(), name='get_standings'),
path('get_top_scorers/', get_top_scorers, name='get_top_scorers'),
]
34 changes: 33 additions & 1 deletion info/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,36 @@ def get(self, request):
data = response.json()
return JsonResponse(data)
except Exception as e:
return JsonResponse({'error': str(e)})
return JsonResponse({'error': str(e)})

def get_top_scorers(request):
api_url = 'https://api-football-v1.p.rapidapi.com/v3/players/topscorers'
headers = {
'X-RapidAPI-Key': '24d52a531dmsh693cfe90d613d38p1a8e61jsn6a752b08adf5',
'X-RapidAPI-Host': 'api-football-v1.p.rapidapi.com'
}
params = {
'league': '39',
'season': request.GET.get('season', '2023'),
}

try:
response = requests.get(api_url, headers=headers, params=params)
response.raise_for_status() # 에러가 발생하면 예외를 일으킵니다.
data = response.json()

# 여기에서 API 응답을 가공하고 필요한 데이터를 추출합니다.
top_scorers = data.get('response', [])

# 예시: 간단하게 상위 5명의 득점자 이름과 골 수를 가져오는 코드
top_scorers_info = [{'name': player['player']['name'], 'goals': player['statistics'][0]['goals']} for player in top_scorers[:5]]

return JsonResponse({'top_scorers': top_scorers_info})
except requests.exceptions.HTTPError as errh:
return JsonResponse({'error': f'HTTP Error: {errh}'}, status=500)
except requests.exceptions.ConnectionError as errc:
return JsonResponse({'error': f'Error Connecting: {errc}'}, status=500)
except requests.exceptions.Timeout as errt:
return JsonResponse({'error': f'Timeout Error: {errt}'}, status=500)
except requests.exceptions.RequestException as err:
return JsonResponse({'error': f'Error: {err}'}, status=500)
Binary file modified madcamp_week4_BE/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file modified madcamp_week4_BE/__pycache__/urls.cpython-311.pyc
Binary file not shown.

0 comments on commit bf309ff

Please sign in to comment.