Skip to content

Commit 316cad7

Browse files
committed
Merge branch 'devdev' into feature/golony/payment
2 parents b7ba20d + 1f52783 commit 316cad7

File tree

6 files changed

+61
-12
lines changed

6 files changed

+61
-12
lines changed

account/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
2222
path("api/logout/", logout_api, name="logout-api"),
2323
# path("api/logout/", )
2424

25+
path("api/mypage/", MyPage.as_view(), name="mypage-api"),
2526
]

account/view_models.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from dataclasses import dataclass, asdict
2+
3+
from ticket.models import Ticket
4+
5+
6+
@dataclass(init=False)
7+
class UserTicketInfo:
8+
ticket_type_name: str
9+
date: str
10+
price: int
11+
payment_key: str
12+
13+
def __init__(self, ticket: Ticket):
14+
self.ticket_type_name = ticket.ticket_type.name
15+
self.date = ticket.ticket_type.day
16+
self.price = ticket.payment.money
17+
self.payment_key = ticket.payment.payment_key
18+
19+
def to_dict(self):
20+
return asdict(self)

account/views.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,27 @@
77
from django.contrib.auth.decorators import login_required
88
from django.shortcuts import render
99
from django.contrib.auth import login, logout, authenticate
10+
from functional import seq
1011

1112
from rest_framework.response import Response
1213
from rest_framework.views import APIView
1314
from rest_framework.decorators import api_view
1415

16+
from account.view_models import UserTicketInfo
1517
from ticket.models import Ticket
1618

1719
from allauth.account.views import LoginView, LogoutView
1820

21+
1922
class IdLogin(LoginView):
2023
template_name = "account/login.html"
2124
success_url = "/"
2225

26+
2327
class Logout(LogoutView):
2428
template_name = "account/logout.html"
2529

30+
2631
class GitHubLogin(SocialLoginView):
2732
adapter_class = GitHubOAuth2Adapter
2833
callback_url = settings.OAUTH_GITHUB_CALLBACK_URL
@@ -34,8 +39,27 @@ class GoogleLogin(SocialLoginView):
3439
callback_url = settings.OAUTH_GOOGLE_CALLBACK_URL
3540
client_class = OAuth2Client
3641

42+
3743
class MyPage(APIView):
38-
pass
44+
def get(self, request):
45+
dto = {
46+
"ticket": self.get_ticket_info(request)
47+
}
48+
49+
return Response(dto)
50+
51+
def get_ticket_info(self, request) -> list:
52+
all_tickets = Ticket.objects.filter(
53+
user=request.user,
54+
is_refunded=False
55+
)
56+
57+
return list(
58+
seq(all_tickets)
59+
.map(UserTicketInfo)
60+
.map(lambda info: info.to_dict())
61+
)
62+
3963

4064
@login_required
4165
def mypage_payments(request):
@@ -46,7 +70,6 @@ def mypage_payments(request):
4670

4771
@api_view(["POST"])
4872
def login_api(request):
49-
5073
if request.user.is_authenticated:
5174
return Response({"msg": "already logged in"})
5275

@@ -66,7 +89,6 @@ def login_api(request):
6689

6790
@api_view(["POST"])
6891
def logout_api(request):
69-
7092
if not request.user.is_authenticated:
7193
return Response({"msg": "not logged in"})
7294

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ drf-spectacular==0.25.1
2222
shortuuid==1.0.11
2323
jsons==1.6.3
2424
django-cors-headers==3.14.0
25-
requests==2.28.2
25+
requests==2.28.2
26+
PyFunctional==1.4.3

ticket/urls.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
from . import views
44

55
urlpatterns = [
6-
path("conference-ticket-types", views.get__get_ticket_types),
6+
path("ticket-types", views.get__get_ticket_types),
77
re_path(
8-
r"^conference-ticket-types/(?P<ticket_type_id>\w+)/check",
8+
r"^ticket-types/(?P<ticket_type_id>\w+)/check",
99
views.get__check_ticket_type_buyable,
1010
),
11-
path("conference-tickets", views.post__add_ticket),
12-
path("list", views.get__ticket_list, name="ticket-list"),
13-
path("<int:item_id>", views.TicketDetailView.as_view(), name="ticket-detail"),
14-
path("success", views.ticket_success, name="page-ticket-success"),
15-
path("failed", views.ticket_failed, name="page-ticket-failed"),
11+
# path("conference-tickets", views.post__add_ticket), # 티켓 생성은 payment에서
12+
####################################################################################
13+
# 템플릿 기반 API 비활성화
14+
####################################################################################
15+
# path("list", views.get__ticket_type_list, name="ticket-list"),
16+
# path("<int:item_id>", views.TicketDetailView.as_view(), name="ticket-detail"),
17+
# path("success", views.ticket_success, name="page-ticket-success"),
18+
# path("failed", views.ticket_failed, name="page-ticket-failed"),
19+
####################################################################################
1620
path("<int:ticket_id>/refund", views.ticket_refund, name="page-ticket-refund-success"),
1721
]

ticket/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def post__add_ticket(request: HttpRequest, **kwargs) -> HttpResponse:
168168
return HttpResponse(ticket.id)
169169

170170

171-
def get__ticket_list(request):
171+
def get__ticket_type_list(request):
172172
all_types = TicketType.objects.all()
173173

174174
dto = {
@@ -178,6 +178,7 @@ def get__ticket_list(request):
178178
return render(request, "ticket-list.html", dto)
179179

180180

181+
# Django Template 기반 코드
181182
class TicketDetailView(View):
182183
def get(self, request, item_id: int):
183184
ticket_type = TicketType.objects.get(id=item_id)

0 commit comments

Comments
 (0)